Skip to content

Commit 364fc66

Browse files
committed
Merge branch 'develop' into feature-fe-#374
2 parents 6d19598 + 231a0f7 commit 364fc66

File tree

4 files changed

+51
-50
lines changed

4 files changed

+51
-50
lines changed

apps/frontend/src/app/routes/join/index.tsx

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { useEffect } from "react";
2-
import { createFileRoute, useNavigate } from "@tanstack/react-router";
1+
import { useEffect, useState } from "react";
2+
import { createFileRoute } from "@tanstack/react-router";
33
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
44

55
import { useValidateWorkspaceInviteLink } from "@/features/workspace";
@@ -16,53 +16,58 @@ function JoinWrapper() {
1616

1717
export const Route = createFileRoute("/join/")({
1818
validateSearch: (search: Record<string, unknown>) => {
19-
const workspaceId = search.workspaceId as string;
20-
const token = search.token as string;
21-
22-
if (!workspaceId || !token) {
19+
if (!search.workspaceId || !search.token) {
20+
window.location.href = "/";
2321
throw new Error("유효한 링크가 아닙니다.");
2422
}
2523

26-
return { workspaceId, token };
24+
return {
25+
workspaceId: search.workspaceId as string,
26+
token: search.token as string,
27+
};
2728
},
2829
component: JoinWrapper,
2930
});
3031

3132
function JoinComponent() {
32-
const { workspaceId, token } = Route.useSearch();
33-
const navigate = useNavigate();
33+
const rawWorkspaceId = new URLSearchParams(window.location.search).get(
34+
"workspaceId",
35+
);
36+
const { token } = Route.useSearch();
3437
const { mutate: validateInvite, isPending } =
3538
useValidateWorkspaceInviteLink();
39+
const [validated, setValidated] = useState(false);
3640

3741
useEffect(() => {
38-
if (!token || !workspaceId) {
39-
navigate({ to: "/" });
42+
if (!token || !rawWorkspaceId) {
43+
window.location.href = "/";
4044
return;
4145
}
4246

43-
validateInvite(token, {
47+
validateInvite(String(token), {
4448
onSuccess: () => {
45-
navigate({
46-
to: "/workspace/$workspaceId",
47-
params: { workspaceId },
48-
replace: true,
49-
});
49+
setValidated(true);
5050
},
5151
onError: () => {
52-
navigate({ to: "/" });
52+
window.location.href = "/";
5353
},
5454
});
55-
}, [token, workspaceId, validateInvite, navigate]);
55+
}, [token, rawWorkspaceId, validateInvite]);
56+
57+
if (validated && rawWorkspaceId) {
58+
window.location.href = `/workspace/${rawWorkspaceId}`;
59+
return null;
60+
}
5661

5762
return (
5863
<div className="flex h-screen items-center justify-center">
5964
<div className="text-center">
6065
<div className="mb-2 text-lg font-medium">
6166
워크스페이스 초대 확인 중
6267
</div>
63-
{isPending && (
68+
{isPending && rawWorkspaceId && (
6469
<div className="text-sm text-gray-500">
65-
워크스페이스 {workspaceId} 입장 중...
70+
워크스페이스 {rawWorkspaceId} 입장 중...
6671
</div>
6772
)}
6873
</div>
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
import { useEffect } from "react";
22
import { useNavigate } from "@tanstack/react-router";
33
import { useCurrentWorkspace } from "@/features/workspace/model/workspaceQuries";
4+
import { useGetUser } from "@/features/auth";
45

56
export const useProtectedWorkspace = () => {
67
const navigate = useNavigate();
7-
const { data: workspaceData, isLoading, error } = useCurrentWorkspace();
8+
const { isLoading: isUserLoading } = useGetUser();
9+
const {
10+
data: workspaceData,
11+
isLoading: isWorkspaceLoading,
12+
error,
13+
} = useCurrentWorkspace();
814

915
useEffect(() => {
10-
if (!isLoading && (error || !workspaceData)) {
16+
if (!isUserLoading && !isWorkspaceLoading && (error || !workspaceData)) {
1117
navigate({ to: "/" });
1218
}
13-
}, [isLoading, workspaceData, error, navigate]);
19+
}, [isUserLoading, isWorkspaceLoading, workspaceData, error, navigate]);
1420

1521
return {
16-
isLoading,
22+
isLoading: isUserLoading || isWorkspaceLoading,
1723
workspaceData,
1824
};
1925
};

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
1-
// TODO: admin이 아니라면 tooltip 추가 "권한이 없습니다."
2-
3-
import { useWorkspace } from "@/shared/lib";
4-
import { useUserWorkspace } from "../../model/workspaceQuries";
5-
61
export function Sharebutton() {
7-
const currentWorkspaceId = useWorkspace();
8-
const { data } = useUserWorkspace();
9-
const workspaces = data?.workspaces;
10-
const workspace = workspaces?.find(
11-
(workspace) => workspace.workspaceId === currentWorkspaceId,
12-
);
13-
const isGuest = workspace?.role === "guest";
14-
152
return (
163
<div className="flex h-9 items-center justify-center">
174
<button
18-
disabled={isGuest}
19-
className="rounded-md bg-blue-400 px-2 py-1 text-sm text-white hover:bg-blue-500"
5+
type="button"
6+
className="rounded-md bg-blue-400 px-2 py-1 text-sm text-white hover:bg-blue-500 disabled:cursor-not-allowed disabled:opacity-50"
207
>
218
공유
229
</button>

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useState } from "react";
22
import { Globe2, Lock, Copy, CheckCheck } from "lucide-react";
3-
43
import { useCreateWorkspaceInviteLink } from "../../model/workspaceMutations";
54
import { useCurrentWorkspace } from "../../model/workspaceQuries";
65
import { useToggleWorkspaceStatus } from "../../model/workspaceMutations";
@@ -36,7 +35,6 @@ export function SharePanel() {
3635

3736
const isPublic =
3837
workspaceId === "main" ? true : workspaceVisibility === "public";
39-
4038
const isGuest =
4139
workspaceId === "main" || currentWorkspace?.workspace?.role === "guest";
4240

@@ -49,21 +47,26 @@ export function SharePanel() {
4947
}
5048
};
5149

52-
const getCurrentUrl = () => {
50+
const getDisplayUrl = () => {
5351
if (isUserLoading || isWorkspaceLoading)
5452
return "워크스페이스를 불러오는 중...";
5553
if (isPending) return "처리 중...";
54+
if (isGuest) return "권한이 없습니다";
5655
if (isPublic) return PUBLIC_URL;
57-
if (createInviteLinkMutation.data) {
58-
return createFrontendUrl(createInviteLinkMutation.data, workspaceId);
59-
}
60-
return "권한이 없습니다";
56+
return `${window.location.origin}/join/***********`;
6157
};
6258

6359
const handleCopy = async () => {
64-
const urlToCopy = getCurrentUrl();
6560
if (!isPending && !isWorkspaceLoading) {
66-
await navigator.clipboard.writeText(urlToCopy);
61+
const urlToCopy = isPublic
62+
? PUBLIC_URL
63+
: createInviteLinkMutation.data
64+
? createFrontendUrl(createInviteLinkMutation.data, workspaceId)
65+
: await createInviteLinkMutation.mutateAsync(workspaceId);
66+
67+
await navigator.clipboard.writeText(
68+
isPublic ? urlToCopy : createFrontendUrl(urlToCopy, workspaceId),
69+
);
6770
setCopied(true);
6871
setTimeout(() => setCopied(false), 2000);
6972
}
@@ -96,7 +99,7 @@ export function SharePanel() {
9699
}`}
97100
>
98101
<div className="w-48 flex-1 truncate rounded-md bg-gray-100 px-3 py-2 text-sm text-gray-600">
99-
{getCurrentUrl()}
102+
{getDisplayUrl()}
100103
</div>
101104
<button
102105
onClick={handleCopy}

0 commit comments

Comments
 (0)