import { useState, ReactElement } from "react"; import { observer } from "mobx-react-lite"; import { useRouter } from "next/router"; import useSWR from "swr"; // components import { PageHead } from "@/components/core"; import { ProjectSettingHeader } from "@/components/headers"; import { ArchiveRestoreProjectModal, ArchiveProjectSelection, DeleteProjectModal, DeleteProjectSection, ProjectDetailsForm, ProjectDetailsFormLoader, } from "@/components/project"; // hooks import { useProject } from "@/hooks/store"; // layouts import { AppLayout } from "@/layouts/app-layout"; import { ProjectSettingLayout } from "@/layouts/settings-layout"; // types import { NextPageWithLayout } from "@/lib/types"; const GeneralSettingsPage: NextPageWithLayout = observer(() => { // states const [selectProject, setSelectedProject] = useState(null); const [archiveProject, setArchiveProject] = useState(false); // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // store hooks const { currentProjectDetails, fetchProjectDetails } = useProject(); // api call to fetch project details // TODO: removed this API if not necessary const { isLoading } = useSWR( workspaceSlug && projectId ? `PROJECT_DETAILS_${projectId}` : null, workspaceSlug && projectId ? () => fetchProjectDetails(workspaceSlug.toString(), projectId.toString()) : null ); // derived values const isAdmin = currentProjectDetails?.member_role === 20; const pageTitle = currentProjectDetails?.name ? `${currentProjectDetails?.name} - General Settings` : undefined; // const currentNetwork = NETWORK_CHOICES.find((n) => n.key === projectDetails?.network); // const selectedNetwork = NETWORK_CHOICES.find((n) => n.key === watch("network")); return ( <> {currentProjectDetails && workspaceSlug && projectId && ( <> setArchiveProject(false)} archive /> setSelectedProject(null)} /> )}
{currentProjectDetails && workspaceSlug && projectId && !isLoading ? ( ) : ( )} {isAdmin && ( <> setArchiveProject(true)} /> setSelectedProject(currentProjectDetails.id ?? null)} /> )}
); }); GeneralSettingsPage.getLayout = function getLayout(page: ReactElement) { return ( } withProjectWrapper> {page} ); }; export default GeneralSettingsPage;