import React from "react"; // next import type { NextPage } from "next"; import Link from "next/link"; import { useRouter } from "next/router"; // swr import useSWR from "swr"; // services import workspaceService from "lib/services/workspace.service"; // constants import { WORKSPACE_INVITATION } from "constants/fetch-keys"; // hooks import useUser from "lib/hooks/useUser"; // layouts import DefaultLayout from "layouts/DefaultLayout"; // ui import { Button, Spinner } from "ui"; // icons import { ChartBarIcon, CheckIcon, ChevronRightIcon, CubeIcon, ShareIcon, StarIcon, UserIcon, XMarkIcon, } from "@heroicons/react/24/outline"; import { EmptySpace, EmptySpaceItem } from "ui/empty-space"; 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((res) => { 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;