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EAAAA,IAKjBC,EAAgBC,CAAAA,EAAAA,EAAAA,WAAAA,EAAY,KAChCN,EACEhB,EAAWH,SAAS,CAACC,EAAE,CACvByB,EAAAA,EAAgBA,CAACC,GAAG,CACpBC,EAAAA,CAAUA,CAACC,OAAO,CAEtB,EAAG,CAAC1B,EAAWH,SAAS,CAACC,EAAE,CAAEkB,EAAc,QAmB3C,CAjBAJ,CAAAA,EAAAA,EAAAA,SAAAA,EAAU,KACY,oBAAhBF,GAAsCJ,GAExCQ,EACE,CAAC,WAAW,EAAEd,EAAWH,SAAS,CAACC,EAAE,CAAC,IAAI,CAAC,CAC3C2B,EAAAA,CAAUA,CAACC,OAAO,CAGxB,EAAG,CACD1B,EAAWH,SAAS,CAACC,EAAE,CACvBQ,EACAQ,EACAJ,EACAW,EACAJ,EACD,EAEGP,kBAAAA,GAEA,UAACiB,EAAAA,EAAgBA,CAAAA,CACf3B,WAAYA,EACZ4B,gBAAiBP,C,GAKhB,IACT,C","sources":["webpack://@affine/web/../core/src/pages/invite.tsx"],"sourcesContent":["import { AcceptInvitePage } from '@affine/component/member-components';\nimport { WorkspaceSubPath } from '@affine/core/shared';\nimport type { GetInviteInfoQuery } from '@affine/graphql';\nimport {\n acceptInviteByInviteIdMutation,\n fetcher,\n getInviteInfoQuery,\n} from '@affine/graphql';\nimport { useLiveData, useService } from '@toeverything/infra';\nimport { useSetAtom } from 'jotai';\nimport { useCallback, useEffect } from 'react';\nimport type { LoaderFunction } from 'react-router-dom';\nimport { redirect, useLoaderData } from 'react-router-dom';\n\nimport { authAtom } from '../atoms';\nimport { RouteLogic, useNavigateHelper } from '../hooks/use-navigate-helper';\nimport { AuthService } from '../modules/cloud';\n\nexport const loader: LoaderFunction = async args => {\n const inviteId = args.params.inviteId || '';\n const res = await fetcher({\n query: getInviteInfoQuery,\n variables: {\n inviteId,\n },\n }).catch(console.error);\n\n // If the inviteId is invalid, redirect to 404 page\n if (!res || !res?.getInviteInfo) {\n return redirect('/404');\n }\n\n // No mater sign in or not, we need to accept the invite\n await fetcher({\n query: acceptInviteByInviteIdMutation,\n variables: {\n workspaceId: res.getInviteInfo.workspace.id,\n inviteId,\n sendAcceptMail: true,\n },\n }).catch(console.error);\n\n return {\n inviteId,\n inviteInfo: res.getInviteInfo,\n };\n};\n\nexport const Component = () => {\n const authService = useService(AuthService);\n const isRevalidating = useLiveData(authService.session.isRevalidating$);\n const loginStatus = useLiveData(authService.session.status$);\n\n useEffect(() => {\n authService.session.revalidate();\n }, [authService]);\n\n const { jumpToSignIn } = useNavigateHelper();\n const { jumpToSubPath } = useNavigateHelper();\n\n const setAuthAtom = useSetAtom(authAtom);\n const { inviteInfo } = useLoaderData() as {\n inviteId: string;\n inviteInfo: GetInviteInfoQuery['getInviteInfo'];\n };\n\n const openWorkspace = useCallback(() => {\n jumpToSubPath(\n inviteInfo.workspace.id,\n WorkspaceSubPath.ALL,\n RouteLogic.REPLACE\n );\n }, [inviteInfo.workspace.id, jumpToSubPath]);\n\n useEffect(() => {\n if (loginStatus === 'unauthenticated' && !isRevalidating) {\n // We can not pass function to navigate state, so we need to save it in atom\n jumpToSignIn(\n `/workspace/${inviteInfo.workspace.id}/all`,\n RouteLogic.REPLACE\n );\n }\n }, [\n inviteInfo.workspace.id,\n isRevalidating,\n jumpToSignIn,\n loginStatus,\n openWorkspace,\n setAuthAtom,\n ]);\n\n if (loginStatus === 'authenticated') {\n return (\n \n );\n }\n\n return null;\n};\n"],"names":["loader","args","inviteId","params","res","fetcher","query","getInviteInfoQuery","variables","catch","console","error","getInviteInfo","acceptInviteByInviteIdMutation","workspaceId","workspace","id","sendAcceptMail","inviteInfo","redirect","Component","authService","useService","AuthService","isRevalidating","useLiveData","session","isRevalidating$","loginStatus","status$","useEffect","revalidate","jumpToSignIn","useNavigateHelper","jumpToSubPath","setAuthAtom","useSetAtom","authAtom","useLoaderData","openWorkspace","useCallback","WorkspaceSubPath","ALL","RouteLogic","REPLACE","AcceptInvitePage","onOpenWorkspace"],"sourceRoot":""}