import { useState } from "react"; import Image from "next/image"; import useSWR from "swr"; // headless ui import { Tab } from "@headlessui/react"; // services import workspaceService from "services/workspace.service"; // types import { IWorkspaceMemberInvitation } from "types"; // fetch-keys import { USER_WORKSPACE_INVITATIONS } from "constants/fetch-keys"; // constants import { CreateWorkspaceForm } from "components/workspace"; // ui import { PrimaryButton } from "components/ui"; type Props = { setStep: React.Dispatch>; setWorkspace: React.Dispatch>; }; export const Workspace: React.FC = ({ setStep, setWorkspace }) => { const [isJoiningWorkspaces, setIsJoiningWorkspaces] = useState(false); const [invitationsRespond, setInvitationsRespond] = useState([]); const [defaultValues, setDefaultValues] = useState({ name: "", slug: "", company_size: null, }); const { data: invitations, mutate } = useSWR(USER_WORKSPACE_INVITATIONS, () => workspaceService.userWorkspaceInvitations() ); const handleInvitation = ( workspace_invitation: IWorkspaceMemberInvitation, action: "accepted" | "withdraw" ) => { if (action === "accepted") { setInvitationsRespond((prevData) => [...prevData, workspace_invitation.id]); } else if (action === "withdraw") { setInvitationsRespond((prevData) => prevData.filter((item: string) => item !== workspace_invitation.id) ); } }; const submitInvitations = async () => { if (invitationsRespond.length <= 0) return; setIsJoiningWorkspaces(true); await workspaceService .joinWorkspaces({ invitations: invitationsRespond }) .then(async () => { await mutate(); setStep(4); setIsJoiningWorkspaces(false); }) .catch((err) => { console.error(err); setIsJoiningWorkspaces(false); }); }; return (
`rounded-3xl border px-4 py-2 outline-none ${ selected ? "border-brand-accent bg-brand-accent text-white" : "border-brand-base bg-brand-surface-2 hover:bg-brand-surface-1" }` } > New Workspace `rounded-3xl border px-5 py-2 outline-none ${ selected ? "border-brand-accent bg-brand-accent text-white" : "border-brand-base bg-brand-surface-2 hover:bg-brand-surface-1" }` } > Invited Workspace { setWorkspace(res); setStep(3); }} defaultValues={defaultValues} setDefaultValues={setDefaultValues} />
{invitations && invitations.length > 0 ? ( invitations.map((invitation) => (
)) ) : (

You have no invitations

)}
Join Workspace
); };