import React, { useState } from "react"; import { useRouter } from "next/router"; import Link from "next/link"; import useSWR from "swr"; // services import { ProjectStateService } from "services/project"; // hooks import useProjectDetails from "hooks/use-project-details"; import useUserAuth from "hooks/use-user-auth"; // layouts import { ProjectAuthorizationWrapper } from "layouts/auth-layout-legacy"; // components import { CreateUpdateStateInline, DeleteStateModal, SingleState, StateGroup } from "components/states"; import { SettingsSidebar } from "components/project"; // ui import { BreadcrumbItem, Breadcrumbs, Loader } from "@plane/ui"; // icons import { Plus } from "lucide-react"; // helpers import { getStatesList, orderStateGroups } from "helpers/state.helper"; import { truncateText } from "helpers/string.helper"; // types import type { NextPage } from "next"; // fetch-keys import { STATES_LIST } from "constants/fetch-keys"; // services const projectStateService = new ProjectStateService(); 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 { user } = useUserAuth(); const { projectDetails } = useProjectDetails(); const { data: states } = useSWR( workspaceSlug && projectId ? STATES_LIST(projectId as string) : null, workspaceSlug && projectId ? () => projectStateService.getStates(workspaceSlug as string, projectId as string) : null ); const orderedStateGroups = orderStateGroups(states); const statesList = getStatesList(orderedStateGroups); return ( <> s.id === selectDeleteState) ?? null} onClose={() => setSelectDeleteState(null)} user={user} /> router.back()}>

{`${truncateText(projectDetails?.name ?? "Project", 32)}`}

} /> } >

States

{states && projectDetails && orderedStateGroups ? ( 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} user={user} /> )} {orderedStateGroups[key].map((state, index) => state.id !== selectedState ? ( setSelectedState(state.id)} handleDeleteState={() => setSelectDeleteState(state.id)} user={user} /> ) : (
{ setActiveGroup(null); setSelectedState(null); }} groupLength={orderedStateGroups[key].length} data={statesList?.find((state) => state.id === selectedState) ?? null} selectedGroup={key as keyof StateGroup} user={user} />
) )}
); }) ) : ( )}
); }; export default StatesSettings;