Repository navigation
[Feature/#368] 워크스페이스 초대 수락 페이지 연동 #376
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
523c8af
feat: 조직 초대 수락 API 응답 타입 정리
jjjsun 64351f2
feat: 조직 초대 수락 API 훅 추가
jjjsun b8fc910
feat: 조직 초대 수락페이지 라우트 추가
jjjsun a8c2124
feat: 워크스페이스 초대 수락 페이지 연동
jjjsun cf063c4
fix: 미로그인상태로 초대URL접근시 로그인 페이지로 3.5초후 자동으로 이동하도록 UX개선
jjjsun f515899
fix: 미로그인상태로 초대 URL 접근시 로그인페이지로 이동시 로딩 스패너와 초수 Countdown으로 변경하여 UX개선
jjjsun e331da3
fix: processed boolean대신 토큰값 저장 후 비교로 변경
jjjsun 8902ff8
fix: 초대수락요청 useCoreMutation으로 수정
jjjsun 9f52a1f
fix: 초대를 확인하는 중 무한 대기 버그 수정 (error 나타내는 화면 나오도록 수정)
jjjsun 673d163
fix: 무한로딩상태문제 해결
jjjsun c7a55e0
fix: 새 워크스페이스 저장 전에 saved() 무효화 제거하여 목록만 갱신(예전 org로 갈수있는 상황 방지)
jjjsun 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 hidden or 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 hidden or 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 hidden or 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,220 @@ | ||
| import { useEffect, useRef, useState } from "react"; | ||
| import { useNavigate, useParams } from "react-router-dom"; | ||
| import { toast } from "sonner"; | ||
|
|
||
| import type { IApiErrorResponse } from "@/types/common/common"; | ||
| import type { TAcceptInvitationResponse } from "@/types/workspace/workspace"; | ||
|
|
||
| import { buildPathWithReturnUrl } from "@/utils/auth/returnUrl"; | ||
|
|
||
| import { useCoreMutation } from "@/hooks/customQuery"; | ||
|
|
||
| import Button from "@/components/common/button/Button"; | ||
| import ErrorLayout from "@/components/common/error/ErrorLayout"; | ||
|
|
||
| import { acceptInvitaton, saveSelectedWorkspace } from "@/api/workspace/org"; | ||
| import { QUERY_KEYS } from "@/lib/queryKeys"; | ||
| import useAuthStore from "@/store/useAuthStore"; | ||
| import useWorkspaceStore from "@/store/useWorkspaceStore"; | ||
|
|
||
| type TInviteUiStatus = | ||
| | "loading" | ||
| | "needLogin" | ||
| | "invalidToken" | ||
| | "error" | ||
| | "success"; | ||
|
|
||
| const LOGIN_REDIRECT_SECONDS = 3; | ||
|
|
||
| function getInviteErrorCopy(error: IApiErrorResponse | null): { | ||
| title: string; | ||
| description: string; | ||
| } { | ||
| const message = error?.message ?? ""; | ||
| const code = error?.code ?? ""; | ||
|
|
||
| if ( | ||
| code.includes("EXPIRED") || | ||
| code.includes("ORG_INVITATION_400") || | ||
| message.includes("만료") || | ||
| message.includes("유효하지 않") || | ||
| message.toLowerCase().includes("expired") || | ||
| message.toLowerCase().includes("invalid") | ||
| ) { | ||
| return { | ||
| title: "초대 링크가 만료되었거나\n유효하지 않습니다", | ||
| description: | ||
| "초대 링크가 만료되었거나 더 이상 사용할 수 없습니다.\n워크스페이스 관리자에게 다시 초대를 요청해 주세요", | ||
| }; | ||
| } | ||
| if ( | ||
| code.includes("ALREADY") || | ||
| message.includes("이미") || | ||
| message.toLowerCase().includes("already") | ||
| ) { | ||
| return { | ||
| title: "이미 완료된 초대입니다", | ||
| description: "이미 이 워크스페이스에 참여중이거나 초대 완료한 상태입니다", | ||
| }; | ||
| } | ||
| if ( | ||
| code.includes("EMAIL") || | ||
| message.includes("이메일") || | ||
| message.toLowerCase().includes("email") | ||
| ) { | ||
| return { | ||
| title: "초대 이메일이\n일치하지 않습니다", | ||
| description: | ||
| "초대받은 이메일 계정으로 로그인한 뒤\n다시 링크를 열어주세요", | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| title: "초대를 수락할 수 없습니다", | ||
| description: | ||
| message || | ||
| "초대 처리 중 오류가 발생했습니다.\n잠시 후 다시 시도해 주세요", | ||
| }; | ||
| } | ||
|
|
||
| export default function InviteAcceptPage() { | ||
| const { token } = useParams<{ token: string }>(); | ||
| const nav = useNavigate(); | ||
|
|
||
| const isLoggedIn = useAuthStore((s) => s.isLoggedIn); | ||
| const isTokenInitialized = useAuthStore((s) => s.isTokenInitialized); | ||
| const setSelectedOrgId = useWorkspaceStore((s) => s.setSelectedOrgId); | ||
|
|
||
| const [uiStatus, setUiStatus] = useState<TInviteUiStatus>("loading"); | ||
| const [acceptError, setAcceptError] = useState<IApiErrorResponse | null>( | ||
| null, | ||
| ); | ||
| const [countdown, setCountdown] = useState(LOGIN_REDIRECT_SECONDS); | ||
| const processedRef = useRef<string | null>(null); | ||
|
|
||
| const { mutate: acceptInvite } = useCoreMutation(acceptInvitaton, { | ||
| invalidateKeys: [QUERY_KEYS.workspace.list(), QUERY_KEYS.workspace.saved()], | ||
| userOnSuccess: async (data: TAcceptInvitationResponse) => { | ||
| await saveSelectedWorkspace(data.orgId); | ||
|
jjjsun marked this conversation as resolved.
Resolved
|
||
| setSelectedOrgId(data.orgId); | ||
| toast.success(data.message || "초대를 수락했습니다"); | ||
| setUiStatus("success"); | ||
| nav("/dashboard", { replace: true }); | ||
| }, | ||
| userOnError: (err) => { | ||
| setAcceptError(err); | ||
| setUiStatus("error"); | ||
| }, | ||
| }); | ||
|
jjjsun marked this conversation as resolved.
Resolved
|
||
|
|
||
| const acceptInviteRef = useRef(acceptInvite); | ||
| acceptInviteRef.current = acceptInvite; | ||
|
|
||
| useEffect(() => { | ||
| if (!isTokenInitialized) return; | ||
|
|
||
| if (!token) { | ||
| setUiStatus("invalidToken"); | ||
| return; | ||
| } | ||
|
|
||
| if (!isLoggedIn) { | ||
| setUiStatus("needLogin"); | ||
| return; | ||
| } | ||
|
|
||
| if (processedRef.current === token) return; | ||
| processedRef.current = token; | ||
| setAcceptError(null); | ||
| setUiStatus("loading"); | ||
| acceptInviteRef.current(token); | ||
| }, [isTokenInitialized, isLoggedIn, token]); | ||
|
|
||
| useEffect(() => { | ||
| if (uiStatus !== "needLogin" || !token) return; | ||
|
|
||
| setCountdown(LOGIN_REDIRECT_SECONDS); | ||
|
|
||
| const interval = window.setInterval(() => { | ||
| setCountdown((prev) => Math.max(prev - 1, 0)); | ||
| }, 1000); | ||
|
|
||
| const timer = window.setTimeout(() => { | ||
| nav(buildPathWithReturnUrl("/login", `/invite/${token}`), { | ||
| replace: true, | ||
| }); | ||
| }, LOGIN_REDIRECT_SECONDS * 1000); | ||
|
|
||
| return () => { | ||
| window.clearInterval(interval); | ||
| window.clearTimeout(timer); | ||
| }; | ||
| }, [uiStatus, token, nav]); | ||
|
|
||
| const invalidTokenError: IApiErrorResponse = { | ||
| status: "error", | ||
| code: "INVALID_TOKEN", | ||
| message: "유효하지 않은 초대 링크입니다", | ||
| method: "POST", | ||
| requestURI: "/api/org/invitations", | ||
| }; | ||
|
|
||
| if (uiStatus === "invalidToken" || uiStatus === "error") { | ||
| const copy = getInviteErrorCopy( | ||
| uiStatus === "invalidToken" ? invalidTokenError : acceptError, | ||
| ); | ||
| return ( | ||
| <ErrorLayout | ||
| title={copy.title} | ||
| description={copy.description} | ||
| actions={ | ||
| <> | ||
| <Button | ||
| size="big" | ||
| variant="primary" | ||
| fullWidth | ||
| onClick={() => nav("/login", { replace: true })} | ||
| > | ||
| 로그인으로 이동 | ||
| </Button> | ||
| <Button | ||
| size="big" | ||
| variant="secondary" | ||
| fullWidth | ||
| onClick={() => nav("/", { replace: true })} | ||
| > | ||
| 홈으로 이동 | ||
| </Button> | ||
| </> | ||
| } | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| if (uiStatus === "needLogin") { | ||
| return ( | ||
| <div className="relative flex h-screen w-full flex-col items-center justify-center gap-5 bg-surface-100"> | ||
| <span | ||
| className="h-12 w-12 animate-spin rounded-full border-4 border-primary-400 border-t-transparent" | ||
| aria-hidden | ||
| /> | ||
| <p className="text-center font-heading3 text-text-title"> | ||
| 로그인이 필요합니다 | ||
| </p> | ||
| <p className="text-center font-body1 text-text-muted"> | ||
| {countdown}초 후 로그인 페이지로 이동합니다 | ||
| </p> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="relative flex h-screen w-full items-center justify-center bg-surface-100"> | ||
| <p className="animate-pulse font-body1 text-text-muted"> | ||
| {uiStatus === "success" | ||
| ? "워크스페이스로 이동 중..." | ||
| : "초대를 확인하는 중..."} | ||
| </p> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.