import React, { useState } from "react"; import { observer } from "mobx-react-lite"; import { useRouter } from "next/router"; import useSWR from "swr"; // hooks import { Plus } from "lucide-react"; import { Loader } from "@plane/ui"; import { CreateUpdateStateInline, DeleteStateModal, StateGroup, StatesListItem } from "components/states"; import { STATES_LIST } from "constants/fetch-keys"; import { sortByField } from "helpers/array.helper"; import { orderStateGroups } from "helpers/state.helper"; import { useEventTracker, useProjectState } from "hooks/store"; // components // ui // icons // helpers // fetch-keys export const ProjectSettingStateList: React.FC = observer(() => { // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // store const { setTrackElement } = useEventTracker(); const { groupedProjectStates, projectStates, fetchProjectStates } = useProjectState(); // state const [activeGroup, setActiveGroup] = useState(null); const [selectedState, setSelectedState] = useState(null); const [selectDeleteState, setSelectDeleteState] = useState(null); useSWR( workspaceSlug && projectId ? STATES_LIST(projectId.toString()) : null, workspaceSlug && projectId ? () => fetchProjectStates(workspaceSlug.toString(), projectId.toString()) : null ); // derived values const orderedStateGroups = orderStateGroups(groupedProjectStates!); return ( <> setSelectDeleteState(null)} data={projectStates?.find((s) => s.id === selectDeleteState) ?? null} />
{orderedStateGroups ? ( <> {Object.keys(orderedStateGroups).map((group) => (

{group}

{group === activeGroup && ( { setActiveGroup(null); setSelectedState(null); }} selectedGroup={group as keyof StateGroup} /> )} {sortByField(orderedStateGroups[group], "sequence").map((state, index) => state.id !== selectedState ? ( setSelectedState(state.id)} handleDeleteState={() => setSelectDeleteState(state.id)} /> ) : (
{ setActiveGroup(null); setSelectedState(null); }} groupLength={orderedStateGroups[group].length} data={projectStates?.find((state) => state.id === selectedState) ?? null} selectedGroup={group as keyof StateGroup} />
) )}
))} ) : ( )}
{/*
{states && currentProjectDetails && orderedStateGroups ? ( Object.keys(orderedStateGroups || {}).map((key) => { if (orderedStateGroups[key].length !== 0) return (

{key}

{key === activeGroup && ( { setActiveGroup(null); setSelectedState(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); }} groupLength={orderedStateGroups[key].length} data={statesList?.find((state) => state.id === selectedState) ?? null} selectedGroup={key as keyof StateGroup} />
) )}
); }) ) : ( )}
*/} ); });