Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:DeveloperRyou/eollugage-fe into …
Browse files Browse the repository at this point in the history
…develop
  • Loading branch information
DeveloperRyou committed Jun 13, 2024
2 parents 45d9347 + d73ffc6 commit 805a64f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 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
5 changes: 5 additions & 0 deletions 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 Down

0 comments on commit 805a64f

Please sign in to comment.