import React, { useState } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // services import stateService from "services/state.service"; // hooks import useProjectDetails from "hooks/use-project-details"; // layouts import { ProjectAuthorizationWrapper } from "layouts/auth-layout"; // components import { CreateUpdateStateInline, DeleteStateModal, SingleState, StateGroup, } from "components/states"; import { SettingsHeader } from "components/project"; // ui import { Loader } from "components/ui"; import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs"; // icons import { PlusIcon } from "@heroicons/react/24/outline"; // helpers import { getStatesList, orderStateGroups } from "helpers/state.helper"; // types import type { NextPage } from "next"; // fetch-keys import { STATES_LIST } from "constants/fetch-keys"; const StatesSettings: NextPage = () => { const [activeGroup, setActiveGroup] = useState(null); const [selectedState, setSelectedState] = useState(null); const [selectDeleteState, setSelectDeleteState] = useState(null); const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { projectDetails } = useProjectDetails(); const { data: states } = useSWR( workspaceSlug && projectId ? STATES_LIST(projectId as string) : null, workspaceSlug && projectId ? () => stateService.getStates(workspaceSlug as string, projectId as string) : null ); const orderedStateGroups = orderStateGroups(states ?? {}); const statesList = getStatesList(orderedStateGroups ?? {}); return ( <> s.id === selectDeleteState) ?? null} onClose={() => setSelectDeleteState(null)} /> } >

States

Manage the states of this project.

{states && projectDetails ? ( Object.keys(orderedStateGroups).map((key) => { if (orderedStateGroups[key].length !== 0) return (

{key}

{key === activeGroup && ( { setActiveGroup(null); setSelectedState(null); }} data={null} selectedGroup={key as keyof StateGroup} /> )} {orderedStateGroups[key].map((state, index) => state.id !== selectedState ? ( setSelectedState(state.id)} handleDeleteState={() => setSelectDeleteState(state.id)} /> ) : (
{ setActiveGroup(null); setSelectedState(null); }} data={ statesList?.find((state) => state.id === selectedState) ?? null } selectedGroup={key as keyof StateGroup} />
) )}
); }) ) : ( )}
); }; export default StatesSettings;