-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: 초대링크를 통한 가입시 storeId 받아올 수 있게 로직 변경 #98
Merged
DeveloperRyou
merged 7 commits into
the-kingdoms:develop
from
iOdiO89:97-직원초대링크-생성과-가입-플로우를-안정화한다
Jul 13, 2024
The head ref may contain hidden characters: "97-\uC9C1\uC6D0\uCD08\uB300\uB9C1\uD06C-\uC0DD\uC131\uACFC-\uAC00\uC785-\uD50C\uB85C\uC6B0\uB97C-\uC548\uC815\uD654\uD55C\uB2E4"
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
71e9648
#97 fix: 초대링크를 통한 가입시 storeId 받아올 수 있게 로직 변경
iOdiO89 e917a5b
#97 fix: esLint error
iOdiO89 a588b0a
#97 FIX: mutateAsync 활용
iOdiO89 8a6158c
REFACTOR: /redirect api들 한번씩만 호출되게 변경
iOdiO89 2e0a76f
FIX: 경우별 /redirect 분기
iOdiO89 b25be35
FIX: 토스트메시지 일시적으로 뜨게 수정
iOdiO89 f46ed42
REFACTOR: 직원초대정보 post 플로우 수정
iOdiO89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { InviteSchedule } from "@/data/inviteSchedule"; | ||
import axios from "axios"; | ||
|
||
export interface InviteResponse { | ||
id: string; | ||
inviteData: InviteDataType; | ||
} | ||
interface InviteDataType { | ||
storeId: string; | ||
position: string; | ||
schedule: InviteSchedule; | ||
createdAt: string; | ||
} | ||
|
||
async function getInviteData(inviteDataId: string) { | ||
const { data } = await axios.get<InviteResponse>( | ||
`/api/dynamoDB?id=${inviteDataId}`, | ||
); | ||
return data; | ||
} | ||
|
||
async function postInviteData(body: InviteResponse) { | ||
const { data } = await axios.post("/api/dynamoDB", body); | ||
return data; | ||
} | ||
|
||
export { getInviteData, postInviteData }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { InviteResponse, getInviteData, postInviteData } from "@/apis/dynamodb"; | ||
import { myAtom } from "@/data/global"; | ||
import { copyLink } from "@/libs/copy"; | ||
import { useMutation, useQuery } from "@tanstack/react-query"; | ||
import { useAtom } from "jotai"; | ||
|
||
function useGetInviteData() { | ||
const [my] = useAtom(myAtom); | ||
const inviteId = localStorage.getItem("inviteDataId"); | ||
const { data, isSuccess } = useQuery({ | ||
queryKey: ["getInviteData"], | ||
queryFn: () => getInviteData(inviteId as string), | ||
enabled: !(my?.id === undefined || my?.id === null || inviteId === null), | ||
}); | ||
|
||
return { data, isSuccess }; | ||
} | ||
|
||
function usePostInviteData(inviteId: string) { | ||
const { mutate, isSuccess } = useMutation({ | ||
mutationKey: ["getInviteData"], | ||
mutationFn: (body: InviteResponse) => postInviteData(body), | ||
onSuccess: () => copyLink(inviteId), | ||
}); | ||
|
||
return { mutate, isSuccess }; | ||
} | ||
|
||
export { useGetInviteData, usePostInviteData }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,42 @@ | ||
import { PostRelationBody } from "@/apis/relation"; | ||
import { myAtom } from "@/data/global"; | ||
import { usePostPlanList } from "@/hooks/query/plan"; | ||
import { usePostRelation } from "@/hooks/query/relation"; | ||
import { InviteResponse, InviteDataType } from "@/screen/manage/ShareLink"; | ||
import axios from "axios"; | ||
import { useGetInviteData } from "@/hooks/query/dynamodb"; | ||
import { useStaffJoin } from "@/hooks/query/relation"; | ||
import { useAtom } from "jotai"; | ||
import { useRouter } from "next/router"; | ||
import { useEffect } from "react"; | ||
|
||
export default function Redirect() { | ||
const { push } = useRouter(); | ||
const router = useRouter(); | ||
|
||
const [my] = useAtom(myAtom); | ||
const { mutate: postRelationMutate } = usePostRelation(); | ||
const { mutate: postPlanListMutate } = usePostPlanList(); | ||
|
||
async function getInviteData(inviteDataId: string) { | ||
const response = await axios.get<InviteResponse>( | ||
`/api/dynamoDB?id=${inviteDataId}`, | ||
); | ||
return response.data; | ||
} | ||
const createNewEmployee = (inviteData: InviteDataType, memberId: string) => { | ||
const body: PostRelationBody = { | ||
role: "STAFF", | ||
position: inviteData.position, | ||
}; | ||
postRelationMutate( | ||
{ storeId: inviteData.storeId, memberId: my?.id as string, body }, | ||
{ | ||
onSuccess: () => | ||
postPlanListMutate({ | ||
storeId: inviteData.storeId, | ||
memberId, | ||
inviteSchedule: inviteData.schedule, | ||
}), | ||
onError: () => console.log("fail"), | ||
}, | ||
); | ||
}; | ||
const { data: inviteResponse, isSuccess } = useGetInviteData(); | ||
const { mutate: staffJoinMutate } = useStaffJoin(); | ||
|
||
useEffect(() => { | ||
if (my?.id === undefined || my?.id === null) return; | ||
if (localStorage.getItem("inviteDataId") !== null) { | ||
const inviteDataId = String(localStorage.getItem("inviteDataId")); | ||
getInviteData(inviteDataId) | ||
.then(data => { | ||
createNewEmployee(data.inviteData, my?.id); | ||
localStorage.removeItem("inviteDataId"); | ||
push("/main"); | ||
}) | ||
.catch(() => { | ||
push("/main"); | ||
}); | ||
const inviteId = localStorage.getItem("inviteDataId"); | ||
if (inviteId !== null) { | ||
// 1. 직원초대링크를 통해 들어온 새 직원 | ||
if (isSuccess && inviteResponse) { | ||
const body: PostRelationBody = { | ||
role: "STAFF", | ||
position: inviteResponse.inviteData.position, | ||
}; | ||
const inviteRequestBody = { | ||
storeId: inviteResponse.inviteData.storeId, | ||
memberId: my?.id as string, | ||
body, | ||
inviteSchedule: inviteResponse.inviteData.schedule, | ||
}; | ||
staffJoinMutate(inviteRequestBody); | ||
} | ||
} else if (my?.relationList.length === 0) { | ||
push("/signup"); | ||
// 2. 회원가입 | ||
router.push("/signup"); | ||
} else { | ||
push("/main"); | ||
// 3. 기존회원 로그인 | ||
router.push("/main"); | ||
} | ||
}, [my]); | ||
}, [isSuccess]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mutateAsync라는게 있었네요.. 이걸 알았으면 더 빨리 되었을것 같습니다.
postPlanListMutate도 await 걸 수 있을거 같아요