import React, { useState } from "react"; // next import type { NextPage } from "next"; // hooks import useUser from "lib/hooks/useUser"; // hoc import withAuth from "lib/hoc/withAuthWrapper"; // layouts import AppLayout from "layouts/AppLayout"; // components import ProjectMemberInvitations from "components/project/memberInvitations"; import ConfirmProjectDeletion from "components/project/confirm-project-deletion"; // ui import { Button, Spinner, HeaderButton, Breadcrumbs, BreadcrumbItem, EmptySpace, EmptySpaceItem, } from "ui"; // services import projectService from "lib/services/project.service"; // icons import { ClipboardDocumentListIcon, PlusIcon } from "@heroicons/react/24/outline"; const Projects: NextPage = () => { const [deleteProject, setDeleteProject] = useState(null); const [invitationsRespond, setInvitationsRespond] = useState([]); const { projects, activeWorkspace, mutateProjects } = useUser(); const handleInvitation = (project_invitation: any, action: "accepted" | "withdraw") => { if (action === "accepted") { setInvitationsRespond((prevData) => { return [...prevData, project_invitation.id]; }); } else if (action === "withdraw") { setInvitationsRespond((prevData) => { return prevData.filter((item: string) => item !== project_invitation.id); }); } }; const submitInvitations = () => { projectService .joinProject((activeWorkspace as any)?.slug, { project_ids: invitationsRespond }) .then(async (res: any) => { console.log(res); setInvitationsRespond([]); await mutateProjects(); }) .catch((err: any) => { console.log(err); }); }; return ( setDeleteProject(null)} data={projects?.find((item) => item.id === deleteProject) ?? null} /> {projects ? ( <> {projects.length === 0 ? (
Use{" "}
Ctrl/Command + P
{" "} shortcut to create a new project } Icon={PlusIcon} action={() => { const e = new KeyboardEvent("keydown", { key: "p", ctrlKey: true }); document.dispatchEvent(e); }} />
) : (

Projects

{ const e = new KeyboardEvent("keydown", { key: "p", ctrlKey: true }); document.dispatchEvent(e); }} />
{projects.map((item) => ( ))}
{invitationsRespond.length > 0 && (
)}
)} ) : (
)}
); }; export default withAuth(Projects);