11import { Switch } from "@/shared/ui/Switch" ;
22import { Globe2 , Lock , Copy , CheckCheck } from "lucide-react" ;
3- import { useState , useEffect } from "react" ;
4- import {
5- useWorkspaceStatus ,
6- useToggleWorkspaceStatus ,
7- } from "@/features/workspace/model/useWorkspaceStatus" ;
8- import { useCreateWorkspaceInviteLink } from "@/features/workspace/model/useWorkspaceInvite" ;
9- import { useWorkspace } from "@/shared/lib/useWorkspace" ;
10- import { useInviteLinkStore } from "@/features/workspace/model/useInviteLinkStore" ;
11-
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- } ;
3+ import { useState } from "react" ;
194
205export function SharePanel ( ) {
216 const [ copied , setCopied ] = useState ( false ) ;
22- const currentWorkspaceId = useWorkspace ( ) ;
23- const workspaceStatus = useWorkspaceStatus ( ) ;
24-
25- const { inviteLink, setInviteLink } = useInviteLinkStore ( ) ;
26-
27- const { mutate : toggleStatus , isPending : isTogglingStatus } =
28- useToggleWorkspaceStatus ( workspaceStatus ) ;
29- const { mutate : createLink , isPending : isCreatingLink } =
30- useCreateWorkspaceInviteLink ( ) ;
31-
32- const isPublic = workspaceStatus === "public" ;
33- const isLoading = isTogglingStatus || isCreatingLink ;
7+ const [ isPublic , setIsPublic ] = useState ( false ) ;
348
35- useEffect ( ( ) => {
36- if ( isPublic ) {
37- setInviteLink ( window . location . href ) ;
38- } else if ( ! inviteLink && currentWorkspaceId ) {
39- createLink ( currentWorkspaceId , {
40- onSuccess : ( inviteUrl ) => {
41- const frontendUrl = createFrontendUrl ( inviteUrl , currentWorkspaceId ) ;
42- setInviteLink ( frontendUrl ) ;
43- } ,
44- } ) ;
45- }
46- } , [ isPublic , currentWorkspaceId ] ) ;
9+ const url = "https://octodocs.com" ;
4710
4811 const handleCopy = async ( ) => {
49- const linkToCopy = isPublic ? window . location . href : inviteLink ;
50- if ( ! linkToCopy ) return ;
51-
52- await navigator . clipboard . writeText ( linkToCopy ) ;
12+ await navigator . clipboard . writeText ( url ) ;
5313 setCopied ( true ) ;
5414 setTimeout ( ( ) => setCopied ( false ) , 2000 ) ;
5515 } ;
5616
57- const handleSwitchChange = ( ) => {
58- toggleStatus ( ) ;
59- } ;
60-
61- const displayedLink = isPublic ? window . location . href : inviteLink ;
62-
6317 return (
6418 < div className = "w-full" >
6519 < div className = "flex w-full items-center gap-2 p-1" >
6620 < div className = "flex-row text-sm text-slate-400" > 공개 범위</ div >
6721 < div className = "flex items-center space-x-2" >
6822 < Switch
6923 checked = { isPublic }
70- onChange = { handleSwitchChange }
24+ onChange = { setIsPublic }
7125 CheckedIcon = { Globe2 }
7226 UncheckedIcon = { Lock }
7327 />
@@ -79,13 +33,13 @@ export function SharePanel() {
7933 } `}
8034 >
8135 < div className = "w-48 flex-1 truncate rounded-md bg-gray-100 px-3 py-2 text-sm text-gray-600" >
82- { isLoading ? "링크 생성 중..." : displayedLink }
36+ { isPublic ? url : "비공개 모드입니다." }
8337 </ div >
8438 < button
8539 onClick = { handleCopy }
8640 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"
8741 aria-label = "Copy URL"
88- disabled = { isLoading || ! displayedLink }
42+ disabled = { ! isPublic }
8943 >
9044 { copied ? (
9145 < CheckCheck className = "h-4 w-4 text-green-500" />
0 commit comments