diff --git a/src/pages/oauth/redirect.tsx b/src/pages/oauth/redirect.tsx index 6c1fd28..3694bf3 100644 --- a/src/pages/oauth/redirect.tsx +++ b/src/pages/oauth/redirect.tsx @@ -2,7 +2,7 @@ import { PostRelationBody } from "@/apis/relation"; import { myAtom } from "@/data/global"; import { usePostPlanList } from "@/hooks/query/plan"; import { usePostRelation } from "@/hooks/query/relation"; -import { InviteDataType } from "@/screen/manage/ShareLink"; +import { InviteResponse, InviteDataType } from "@/screen/manage/ShareLink"; import axios from "axios"; import { useAtom } from "jotai"; import { useRouter } from "next/router"; @@ -15,12 +15,12 @@ export default function Redirect() { const { mutate: postPlanListMutate } = usePostPlanList(); async function getInviteData(inviteDataId: string) { - const response = await axios.get( - `/api/dynamoDB/?=${inviteDataId}`, + const response = await axios.get( + `/api/dynamoDB?id=${inviteDataId}`, ); return response.data; } - function createNewEmployee(inviteData: InviteDataType, memberId: string) { + const createNewEmployee = (inviteData: InviteDataType, memberId: string) => { const body: PostRelationBody = { role: "STAFF", position: inviteData.position, @@ -28,24 +28,23 @@ export default function Redirect() { postRelationMutate( { storeId: inviteData.storeId, memberId: my?.id as string, body }, { - onSettled: () => + onSuccess: () => postPlanListMutate({ storeId: inviteData.storeId, memberId, inviteSchedule: inviteData.schedule, }), + onError: () => console.log("fail"), }, ); - } + }; useEffect(() => { if (my?.id === undefined || my?.id === null) return; if (localStorage.getItem("inviteDataId") !== null) { - const inviteDataId: string = JSON.parse( - localStorage.getItem("inviteDataId") as string, - ); + const inviteDataId = String(localStorage.getItem("inviteDataId")); getInviteData(inviteDataId) - .then(inviteData => { - createNewEmployee(inviteData, my?.id); + .then(data => { + createNewEmployee(data.inviteData, my?.id); localStorage.removeItem("inviteDataId"); push("/main"); }) diff --git a/src/screen/manage/ShareLink.tsx b/src/screen/manage/ShareLink.tsx index 8fb784f..7d5c8d3 100644 --- a/src/screen/manage/ShareLink.tsx +++ b/src/screen/manage/ShareLink.tsx @@ -13,6 +13,11 @@ import { useAtom } from "jotai"; import Image from "next/image"; import { useEffect, useState } from "react"; +export interface InviteResponse { + id: string; + inviteData: InviteDataType; +} + interface InviteDataType { storeId: string; position: string; @@ -28,7 +33,7 @@ function ShareLink() { const inviteId = createRandomString(8); const handleCopyLink = (id: string) => { - const link = `${window.location.origin}/id?=${id}`; + const link = `${window.location.origin}/?id=${id}`; copy( link, () => {