Skip to content

Commit 2238b4b

Browse files
committed
feat: 워크스페이스 초대 수락 라우팅 구현
1 parent 1446281 commit 2238b4b

File tree

3 files changed

+91
-6
lines changed

3 files changed

+91
-6
lines changed

apps/frontend/src/features/workspace/ui/ShareTool/SharePanel.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ import { useCreateWorkspaceInviteLink } from "@/features/workspace/model/useWork
99
import { useWorkspace } from "@/shared/lib/useWorkspace";
1010
import { useInviteLinkStore } from "@/features/workspace/model/useInviteLinkStore";
1111

12+
const createFrontendUrl = (apiUrl: string, currentWorkspaceId: string) => {
13+
const searchParams = new URLSearchParams();
14+
15+
searchParams.set("workspaceId", currentWorkspaceId);
16+
searchParams.set("token", new URL(apiUrl).searchParams.get("token") || "");
17+
return `${window.location.origin}/join?${searchParams.toString()}`;
18+
};
19+
1220
export function SharePanel() {
1321
const [copied, setCopied] = useState(false);
1422
const currentWorkspaceId = useWorkspace();
@@ -30,7 +38,8 @@ export function SharePanel() {
3038
} else if (!inviteLink && currentWorkspaceId) {
3139
createLink(currentWorkspaceId, {
3240
onSuccess: (inviteUrl) => {
33-
setInviteLink(inviteUrl);
41+
const frontendUrl = createFrontendUrl(inviteUrl, currentWorkspaceId);
42+
setInviteLink(frontendUrl);
3443
},
3544
});
3645
}

apps/frontend/src/routeTree.gen.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
import { Route as rootRoute } from './routes/__root'
1414
import { Route as IndexImport } from './routes/index'
15-
import { Route as WorkspaceWorkspaceIdImport } from './routes/workspace/$workspaceId'
15+
import { Route as JoinIndexImport } from './routes/join/index'
16+
import { Route as WorkspaceWorkspaceIdImpo./routes/joinworkspace/$workspaceId'
1617

1718
// Create/Update Routes
1819

@@ -22,6 +23,12 @@ const IndexRoute = IndexImport.update({
2223
getParentRoute: () => rootRoute,
2324
} as any)
2425

26+
const JoinIndexRoute = JoinIndexImport.update({
27+
id: '/join/',
28+
path: '/join/',
29+
getParentRoute: () => rootRoute,
30+
} as any)
31+
2532
const WorkspaceWorkspaceIdRoute = WorkspaceWorkspaceIdImport.update({
2633
id: '/workspace/$workspaceId',
2734
path: '/workspace/$workspaceId',
@@ -46,6 +53,13 @@ declare module '@tanstack/react-router' {
4653
preLoaderRoute: typeof WorkspaceWorkspaceIdImport
4754
parentRoute: typeof rootRoute
4855
}
56+
'/join/': {
57+
id: '/join/'
58+
path: '/join'
59+
fullPath: '/join'
60+
preLoaderRoute: typeof JoinIndexImport
61+
parentRoute: typeof rootRoute
62+
}
4963
}
5064
}
5165

@@ -54,36 +68,41 @@ declare module '@tanstack/react-router' {
5468
export interface FileRoutesByFullPath {
5569
'/': typeof IndexRoute
5670
'/workspace/$workspaceId': typeof WorkspaceWorkspaceIdRoute
71+
'/join': typeof JoinIndexRoute
5772
}
5873

5974
export interface FileRoutesByTo {
6075
'/': typeof IndexRoute
6176
'/workspace/$workspaceId': typeof WorkspaceWorkspaceIdRoute
77+
'/join': typeof JoinIndexRoute
6278
}
6379

6480
export interface FileRoutesById {
6581
__root__: typeof rootRoute
6682
'/': typeof IndexRoute
6783
'/workspace/$workspaceId': typeof WorkspaceWorkspaceIdRoute
84+
'/join/': typeof JoinIndexRoute
6885
}
6986

7087
export interface FileRouteTypes {
7188
fileRoutesByFullPath: FileRoutesByFullPath
72-
fullPaths: '/' | '/workspace/$workspaceId'
89+
fullPaths: '/' | '/workspace/$workspaceId' | '/join'
7390
fileRoutesByTo: FileRoutesByTo
74-
to: '/' | '/workspace/$workspaceId'
75-
id: '__root__' | '/' | '/workspace/$workspaceId'
91+
to: '/' | '/workspace/$workspaceId' | '/join'
92+
id: '__root__' | '/' | '/workspace/$workspaceId' | '/join/'
7693
fileRoutesById: FileRoutesById
7794
}
7895

7996
export interface RootRouteChildren {
8097
IndexRoute: typeof IndexRoute
8198
WorkspaceWorkspaceIdRoute: typeof WorkspaceWorkspaceIdRoute
99+
JoinIndexRoute: typeof JoinIndexRoute
82100
}
83101

84102
const rootRouteChildren: RootRouteChildren = {
85103
IndexRoute: IndexRoute,
86104
WorkspaceWorkspaceIdRoute: WorkspaceWorkspaceIdRoute,
105+
JoinIndexRoute: JoinIndexRoute,
87106
}
88107

89108
export const routeTree = rootRoute
@@ -97,14 +116,18 @@ export const routeTree = rootRoute
97116
"filePath": "__root.tsx",
98117
"children": [
99118
"/",
100-
"/workspace/$workspaceId"
119+
"/workspace/$workspaceId",
120+
"/join/"
101121
]
102122
},
103123
"/": {
104124
"filePath": "index.tsx"
105125
},
106126
"/workspace/$workspaceId": {
107127
"filePath": "workspace/$workspaceId.tsx"
128+
},
129+
"/join/": {
130+
"filePath": "join/index.tsx"
108131
}
109132
}
110133
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { useEffect } from "react";
2+
import { createFileRoute, useNavigate } from "@tanstack/react-router";
3+
import { useValidateWorkspaceInviteLink } from "@/features/workspace/model/useWorkspaceInvite";
4+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
5+
6+
const joinQueryClient = new QueryClient();
7+
8+
function JoinWrapper() {
9+
return (
10+
<QueryClientProvider client={joinQueryClient}>
11+
<JoinComponent />
12+
</QueryClientProvider>
13+
);
14+
}
15+
16+
export const Route = createFileRoute("/join/")({
17+
validateSearch: (search: Record<string, unknown>) => {
18+
return {
19+
workspaceId: search.workspaceId as string,
20+
token: search.token as string,
21+
};
22+
},
23+
component: JoinWrapper,
24+
});
25+
26+
function JoinComponent() {
27+
const { workspaceId, token } = Route.useSearch();
28+
const navigate = useNavigate();
29+
const { mutate: validateInvite, isPending } =
30+
useValidateWorkspaceInviteLink();
31+
32+
useEffect(() => {
33+
if (!token || !workspaceId) {
34+
navigate({ to: "/" });
35+
return;
36+
}
37+
38+
validateInvite(token, {
39+
onSuccess: () => {
40+
navigate({ to: "/workspace/$workspaceId", params: { workspaceId } });
41+
},
42+
onError: () => {
43+
navigate({ to: "/" });
44+
},
45+
});
46+
}, [token, workspaceId, validateInvite, navigate]);
47+
48+
if (isPending) {
49+
return <div>워크스페이스 {workspaceId} 입장 중 ...</div>;
50+
}
51+
52+
return null;
53+
}

0 commit comments

Comments
 (0)