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"; type Props = { setStep: React.Dispatch>; setWorkspace: React.Dispatch>; }; const Workspace: React.FC = ({ setStep, setWorkspace }) => { const [isJoiningWorkspaces, setIsJoiningWorkspaces] = useState(false); const [invitationsRespond, setInvitationsRespond] = useState([]); 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-lg px-6 py-2 ${selected ? "bg-gray-300" : "hover:bg-gray-200"}` } > New workspace `rounded-lg px-6 py-2 ${selected ? "bg-gray-300" : "hover:bg-gray-200"}` } > Invited workspaces { setWorkspace(res); setStep(3); }} />
{invitations && invitations.length > 0 ? ( invitations.map((invitation) => (
)) ) : (

You have no invitations

)}
); }; export default Workspace;