-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature-fe-#374
- Loading branch information
Showing
14 changed files
with
310 additions
and
67 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { useEffect } from "react"; | ||
import { createFileRoute, useNavigate } from "@tanstack/react-router"; | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
|
||
import { useValidateWorkspaceInviteLink } from "@/features/workspace"; | ||
|
||
const joinQueryClient = new QueryClient(); | ||
|
||
function JoinWrapper() { | ||
return ( | ||
<QueryClientProvider client={joinQueryClient}> | ||
<JoinComponent /> | ||
</QueryClientProvider> | ||
); | ||
} | ||
|
||
export const Route = createFileRoute("/join/")({ | ||
validateSearch: (search: Record<string, unknown>) => { | ||
const workspaceId = search.workspaceId as string; | ||
const token = search.token as string; | ||
|
||
if (!workspaceId || !token) { | ||
throw new Error("유효한 링크가 아닙니다."); | ||
} | ||
|
||
return { workspaceId, token }; | ||
}, | ||
component: JoinWrapper, | ||
}); | ||
|
||
function JoinComponent() { | ||
const { workspaceId, token } = Route.useSearch(); | ||
const navigate = useNavigate(); | ||
const { mutate: validateInvite, isPending } = | ||
useValidateWorkspaceInviteLink(); | ||
|
||
useEffect(() => { | ||
if (!token || !workspaceId) { | ||
navigate({ to: "/" }); | ||
return; | ||
} | ||
|
||
validateInvite(token, { | ||
onSuccess: () => { | ||
navigate({ | ||
to: "/workspace/$workspaceId", | ||
params: { workspaceId }, | ||
replace: true, | ||
}); | ||
}, | ||
onError: () => { | ||
navigate({ to: "/" }); | ||
}, | ||
}); | ||
}, [token, workspaceId, validateInvite, navigate]); | ||
|
||
return ( | ||
<div className="flex h-screen items-center justify-center"> | ||
<div className="text-center"> | ||
<div className="mb-2 text-lg font-medium"> | ||
워크스페이스 초대 확인 중 | ||
</div> | ||
{isPending && ( | ||
<div className="text-sm text-gray-500"> | ||
워크스페이스 {workspaceId} 입장 중... | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} |
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,26 @@ | ||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; | ||
|
||
import { getUser, logout } from "../api/authApi"; | ||
|
||
export const useGetUser = () => { | ||
return useQuery({ | ||
queryKey: ["user"], | ||
queryFn: getUser, | ||
retry: false, | ||
refetchOnWindowFocus: false, | ||
}); | ||
}; | ||
|
||
export const useLogout = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
const logoutMutation = useMutation({ | ||
mutationFn: logout, | ||
onSuccess: async () => { | ||
queryClient.setQueryData(["user"], null); | ||
await queryClient.invalidateQueries({ queryKey: ["user"] }); | ||
}, | ||
}); | ||
|
||
return logoutMutation; | ||
}; |
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
8 changes: 3 additions & 5 deletions
8
apps/frontend/src/features/workspace/api/workspaceStatusApi.ts
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,14 +1,12 @@ | ||
import { SetWorkspaceStatusResponse } from "../model/workspaceInviteTypes"; | ||
import { Post } from "@/shared/api"; | ||
import { Patch } from "@/shared/api"; | ||
|
||
export const setWorkspaceStatusToPrivate = async (id: string) => { | ||
// TODO: URL 맞게 고치기. | ||
const url = `/api/workspace/${id}/private`; | ||
await Post<SetWorkspaceStatusResponse, null>(url); | ||
await Patch<SetWorkspaceStatusResponse, null>(url); | ||
}; | ||
|
||
export const setWorkspaceStatusToPublic = async (id: string) => { | ||
// TODO: URL 맞게 고치기. | ||
const url = `/api/workspace/${id}/public`; | ||
await Post<SetWorkspaceStatusResponse, null>(url); | ||
await Patch<SetWorkspaceStatusResponse, null>(url); | ||
}; |
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
19 changes: 19 additions & 0 deletions
19
apps/frontend/src/features/workspace/model/useProtectedWorkspace.ts
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,19 @@ | ||
import { useEffect } from "react"; | ||
import { useNavigate } from "@tanstack/react-router"; | ||
import { useCurrentWorkspace } from "@/features/workspace/model/workspaceQuries"; | ||
|
||
export const useProtectedWorkspace = () => { | ||
const navigate = useNavigate(); | ||
const { data: workspaceData, isLoading, error } = useCurrentWorkspace(); | ||
|
||
useEffect(() => { | ||
if (!isLoading && (error || !workspaceData)) { | ||
navigate({ to: "/" }); | ||
} | ||
}, [isLoading, workspaceData, error, navigate]); | ||
|
||
return { | ||
isLoading, | ||
workspaceData, | ||
}; | ||
}; |
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.