Skip to content

Commit

Permalink
Merge pull request #93 from iOdiO89/develop
Browse files Browse the repository at this point in the history
FIX: 직원초대정보 dynamoDB post&get 오류 수정
  • Loading branch information
DeveloperRyou authored Jun 13, 2024
2 parents 615fee0 + 0ebc95c commit d73ffc6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
21 changes: 10 additions & 11 deletions src/pages/oauth/redirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -15,37 +15,36 @@ export default function Redirect() {
const { mutate: postPlanListMutate } = usePostPlanList();

async function getInviteData(inviteDataId: string) {
const response = await axios.get<InviteDataType>(
`/api/dynamoDB/?=${inviteDataId}`,
const response = await axios.get<InviteResponse>(
`/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,
};
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");
})
Expand Down
7 changes: 6 additions & 1 deletion src/screen/manage/ShareLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
() => {
Expand Down

0 comments on commit d73ffc6

Please sign in to comment.