import React, { ReactElement } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // swr import { Boxes, Check, Share2, Star, User2, X } from "lucide-react"; // services import { WorkspaceService } from "services/workspace.service"; // hooks import useUser from "hooks/use-user"; // layouts import DefaultLayout from "layouts/default-layout"; // ui import { Spinner } from "@plane/ui"; // icons import { EmptySpace, EmptySpaceItem } from "components/ui/empty-space"; // types import { NextPageWithLayout } from "types/app"; // constants import { WORKSPACE_INVITATION } from "constants/fetch-keys"; // services const workspaceService = new WorkspaceService(); const WorkspaceInvitationPage: NextPageWithLayout = () => { const router = useRouter(); const { invitation_id, email } = router.query; const { user } = useUser(); const { data: invitationDetail, error } = useSWR( invitation_id && WORKSPACE_INVITATION(invitation_id.toString()), () => (invitation_id ? workspaceService.getWorkspaceInvitation(invitation_id as string) : null) ); const handleAccept = () => { if (!invitationDetail) return; workspaceService .joinWorkspace(invitationDetail.workspace.slug, invitationDetail.id, { accepted: true, email: invitationDetail.email, }) .then(() => { if (email === user?.email) { router.push("/invitations"); } else { router.push("/"); } }) .catch((err) => console.error(err)); }; return (
{invitationDetail ? ( <> {error ? (

INVITATION NOT FOUND

) : ( <> {invitationDetail.accepted ? ( <> router.push("/")} /> ) : ( { router.push("/"); }} /> )} )} ) : error ? ( {!user ? ( { router.push("/"); }} /> ) : ( { router.push("/"); }} /> )} { router.push("https://github.com/makeplane"); }} /> { router.push("https://discord.com/invite/8SR2N9PAcJ"); }} /> ) : (
)}
); }; WorkspaceInvitationPage.getLayout = function getLayout(page: ReactElement) { return {page}; }; export default WorkspaceInvitationPage;