import React, { useState } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; import { PencilSquareIcon, PlusIcon, TrashIcon } from "@heroicons/react/24/outline"; import { IState } from "types"; // services import stateService from "services/state.service"; import projectService from "services/project.service"; // lib import { requiredAdmin } from "lib/auth"; // layouts import SettingsLayout from "layouts/settings-layout"; // components import ConfirmStateDeletion from "components/project/issues/BoardView/state/confirm-state-delete"; import { CreateUpdateStateInline, StateGroup, } from "components/project/issues/BoardView/state/create-update-state-inline"; // ui import { Loader } from "components/ui"; import { BreadcrumbItem, Breadcrumbs } from "components/breadcrumbs"; // helpers import { addSpaceIfCamelCase } from "helpers/string.helper"; import { groupBy } from "helpers/array.helper"; // types import type { NextPage, NextPageContext } from "next"; // fetch-keys import { PROJECT_DETAILS, STATE_LIST } from "constants/fetch-keys"; type TStateSettingsProps = { isMember: boolean; isOwner: boolean; isViewer: boolean; isGuest: boolean; }; const StatesSettings: NextPage = (props) => { const { isMember, isOwner, isViewer, isGuest } = props; const [activeGroup, setActiveGroup] = useState(null); const [selectedState, setSelectedState] = useState(null); const [selectDeleteState, setSelectDeleteState] = useState(null); const { query: { workspaceSlug, projectId }, } = useRouter(); const { data: activeProject } = useSWR( workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null, workspaceSlug && projectId ? () => projectService.getProject(workspaceSlug as string, projectId as string) : null ); const { data: states } = useSWR( workspaceSlug && projectId ? STATE_LIST(projectId as string) : null, workspaceSlug && projectId ? () => stateService.getStates(workspaceSlug as string, projectId as string) : null ); const groupedStates: { [key: string]: IState[]; } = groupBy(states ?? [], "group"); return ( <> state.id === selectDeleteState) ?? null} onClose={() => setSelectDeleteState(null)} /> } >

States

Manage the state of this project.

{states && activeProject ? ( Object.keys(groupedStates).map((key) => (

{key} states

{key === activeGroup && ( { setActiveGroup(null); setSelectedState(null); }} workspaceSlug={workspaceSlug as string} data={null} selectedGroup={key as keyof StateGroup} /> )} {groupedStates[key]?.map((state) => state.id !== selectedState ? (
{addSpaceIfCamelCase(state.name)}
) : (
{ setActiveGroup(null); setSelectedState(null); }} workspaceSlug={workspaceSlug as string} data={states?.find((state) => state.id === selectedState) ?? null} selectedGroup={key as keyof StateGroup} />
) )}
)) ) : ( )}
); }; export const getServerSideProps = async (ctx: NextPageContext) => { const projectId = ctx.query.projectId as string; const workspaceSlug = ctx.query.workspaceSlug as string; const memberDetail = await requiredAdmin(workspaceSlug, projectId, ctx.req?.headers.cookie); return { props: { isOwner: memberDetail?.role === 20, isMember: memberDetail?.role === 15, isViewer: memberDetail?.role === 10, isGuest: memberDetail?.role === 5, }, }; }; export default StatesSettings;