import React from "react"; // next import { useRouter } from "next/router"; import useSWR from "swr"; import { CheckIcon, CubeIcon, ShareIcon, StarIcon, UserIcon, XMarkIcon, } from "@heroicons/react/24/outline"; // swr // 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 "components/ui"; // icons import { EmptySpace, EmptySpaceItem } from "components/ui/empty-space"; // types import type { NextPage } from "next"; // constants import { WORKSPACE_INVITATION } from "constants/fetch-keys"; const WorkspaceInvitation: NextPage = () => { const router = useRouter(); const { invitationId, email } = router.query; const { user } = useUser(); const { data: invitationDetail, error } = useSWR(invitationId && WORKSPACE_INVITATION, () => invitationId ? workspaceService.getWorkspaceInvitation(invitationId 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("/signin"); } }) .catch((err) => console.error(err)); }; return (
{invitationDetail ? ( <> {error ? (

INVITATION NOT FOUND

) : ( <> {invitationDetail.accepted ? ( <> router.push("/")} /> ) : ( { router.push("/"); }} /> )} )} ) : error ? ( {!user ? ( { router.push("/signin"); }} /> ) : ( { router.push("/"); }} /> )} { router.push("https://github.com/makeplane"); }} /> { router.push("https://discord.com/invite/8SR2N9PAcJ"); }} /> ) : (
)}
); }; export default WorkspaceInvitation;