import React, { useState } from "react"; import type { NextPage } from "next"; import { useRouter } from "next/router"; import useSWR, { mutate } from "swr"; // services import projectService from "lib/services/project.service"; import workspaceService from "lib/services/workspace.service"; // constants import { WORKSPACE_DETAILS, PROJECTS_LIST, PROJECT_MEMBERS } from "constants/fetch-keys"; // layouts import AppLayout from "layouts/app-layout"; // components import { JoinProjectModal } from "components/project/join-project-modal"; import ProjectMemberInvitations from "components/project/member-invitations"; import ConfirmProjectDeletion from "components/project/confirm-project-deletion"; // ui import { HeaderButton, Breadcrumbs, BreadcrumbItem, EmptySpace, EmptySpaceItem, Loader } from "ui"; // icons import { ClipboardDocumentListIcon, PlusIcon } from "@heroicons/react/24/outline"; const Projects: NextPage = () => { const [deleteProject, setDeleteProject] = useState(null); const [selectedProjectToJoin, setSelectedProjectToJoin] = useState(null); const { query: { workspaceSlug }, } = useRouter(); const { data: activeWorkspace } = useSWR( workspaceSlug ? WORKSPACE_DETAILS(workspaceSlug as string) : null, () => (workspaceSlug ? workspaceService.getWorkspace(workspaceSlug as string) : null) ); const { data: projects } = useSWR( workspaceSlug ? PROJECTS_LIST(workspaceSlug as string) : null, () => (workspaceSlug ? projectService.getProjects(workspaceSlug as string) : null) ); return ( } right={ { const e = new KeyboardEvent("keydown", { key: "p", ctrlKey: true }); document.dispatchEvent(e); }} /> } > item.id === selectedProjectToJoin)} onClose={() => setSelectedProjectToJoin(null)} onJoin={async () => { const project = projects?.find((item) => item.id === selectedProjectToJoin); if (!project) return; await projectService .joinProject(workspaceSlug as string, { project_ids: [project.id], }) .then(async () => { mutate(PROJECT_MEMBERS(project.id)); setSelectedProjectToJoin(null); }) .catch(() => { setSelectedProjectToJoin(null); }); }} /> 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.map((item) => ( ))}
)} ) : ( )}
); }; export default Projects;