@@ -3,8 +3,12 @@ import { Switch } from "@/shared/ui/Switch";
33import { Globe2 , Lock , Copy , CheckCheck } from "lucide-react" ;
44import { useCreateWorkspaceInviteLink } from "../../model/useWorkspaceInvite" ;
55import { useCurrentWorkspace } from "../../model/useWorkspace" ;
6- import { useToggleWorkspaceStatus } from "../../model/useWorkspaceStatus" ;
6+ import {
7+ useToggleWorkspaceStatus ,
8+ useWorkspaceStatus ,
9+ } from "../../model/useWorkspaceStatus" ;
710import { useWorkspace } from "@/shared/lib/useWorkspace" ;
11+ import { useGetUser } from "@/features/auth" ;
812
913const createFrontendUrl = ( apiUrl : string , currentWorkspaceId : string ) => {
1014 const searchParams = new URLSearchParams ( ) ;
@@ -15,22 +19,27 @@ const createFrontendUrl = (apiUrl: string, currentWorkspaceId: string) => {
1519
1620export function SharePanel ( ) {
1721 const workspaceId = useWorkspace ( ) ;
18- const { data : currentWorkspace , isPending : isWorkspaceLoading } =
22+ const { isLoading : isUserLoading } = useGetUser ( ) ;
23+ const { data : currentWorkspace , isLoading : isWorkspaceLoading } =
1924 useCurrentWorkspace ( ) ;
25+ const workspaceVisibility = useWorkspaceStatus ( ) ;
2026 const [ copied , setCopied ] = useState ( false ) ;
27+
2128 const createInviteLinkMutation = useCreateWorkspaceInviteLink ( ) ;
22- const toggleStatusMutation = useToggleWorkspaceStatus (
23- currentWorkspace ?. workspace ?. visibility ,
24- ) ;
29+ const toggleStatusMutation = useToggleWorkspaceStatus ( workspaceVisibility ) ;
2530
2631 const PUBLIC_URL = window . location . href ;
2732
2833 const isPending =
29- isWorkspaceLoading ||
34+ isUserLoading ||
3035 createInviteLinkMutation . isPending ||
3136 toggleStatusMutation . isPending ;
32- const isPublic = currentWorkspace ?. workspace ?. visibility === "public" ;
33- const isGuest = currentWorkspace ?. workspace ?. role === "guest" ;
37+
38+ const isPublic =
39+ workspaceId === "main" ? true : workspaceVisibility === "public" ;
40+
41+ const isGuest =
42+ workspaceId === "main" || currentWorkspace ?. workspace ?. role === "guest" ;
3443
3544 const handlePublicToggle = async ( ) => {
3645 if ( isGuest ) return ;
@@ -42,25 +51,26 @@ export function SharePanel() {
4251 } ;
4352
4453 const getCurrentUrl = ( ) => {
45- if ( isWorkspaceLoading ) return "워크스페이스를 불러오는 중..." ;
54+ if ( isUserLoading || isWorkspaceLoading )
55+ return "워크스페이스를 불러오는 중..." ;
4656 if ( isPending ) return "처리 중..." ;
4757 if ( isPublic ) return PUBLIC_URL ;
4858 if ( createInviteLinkMutation . data ) {
4959 return createFrontendUrl ( createInviteLinkMutation . data , workspaceId ) ;
5060 }
51- return "링크 생성 중... " ;
61+ return "권한이 없습니다 " ;
5262 } ;
5363
5464 const handleCopy = async ( ) => {
5565 const urlToCopy = getCurrentUrl ( ) ;
56- if ( ! isPending ) {
66+ if ( ! isPending && ! isWorkspaceLoading ) {
5767 await navigator . clipboard . writeText ( urlToCopy ) ;
5868 setCopied ( true ) ;
5969 setTimeout ( ( ) => setCopied ( false ) , 2000 ) ;
6070 }
6171 } ;
6272
63- const isDisabled = ! currentWorkspace ?. workspace || isGuest || isPending ;
73+ const isDisabled = isGuest || isPending ;
6474
6575 return (
6676 < div className = "w-full" >
@@ -73,7 +83,7 @@ export function SharePanel() {
7383 onChange = { handlePublicToggle }
7484 CheckedIcon = { Globe2 }
7585 UncheckedIcon = { Lock }
76- disabled = { ! currentWorkspace ?. workspace || isPending || isGuest }
86+ disabled = { isDisabled || isUserLoading }
7787 />
7888 </ div >
7989 </ div >
@@ -93,7 +103,7 @@ export function SharePanel() {
93103 onClick = { handleCopy }
94104 className = "inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-gray-100 disabled:cursor-not-allowed disabled:hover:bg-transparent"
95105 aria-label = "Copy URL"
96- disabled = { isDisabled }
106+ disabled = { isDisabled || isUserLoading || isWorkspaceLoading }
97107 >
98108 { copied ? (
99109 < CheckCheck className = "h-4 w-4 text-green-500" />
0 commit comments