From c9b1a2590a0c487703264a4ddffd7ad65db06e37 Mon Sep 17 00:00:00 2001 From: Dakshesh Jain Date: Tue, 13 Dec 2022 18:45:23 +0530 Subject: [PATCH] feat: create/update state according to group from project settings pages refractor: followed naming convension and made components easy to use --- ...eDeletion.tsx => confirm-state-delete.tsx} | 12 +- ...odal.tsx => create-update-state-modal.tsx} | 21 +- .../issues/CreateUpdateIssueModal/index.tsx | 2 +- .../project/settings/StatesSettings.tsx | 315 +++++++++++++++--- apps/app/constants/index.ts | 8 + 5 files changed, 296 insertions(+), 62 deletions(-) rename apps/app/components/project/issues/BoardView/state/{ConfirmStateDeletion.tsx => confirm-state-delete.tsx} (95%) rename apps/app/components/project/issues/BoardView/state/{CreateUpdateStateModal.tsx => create-update-state-modal.tsx} (91%) diff --git a/apps/app/components/project/issues/BoardView/state/ConfirmStateDeletion.tsx b/apps/app/components/project/issues/BoardView/state/confirm-state-delete.tsx similarity index 95% rename from apps/app/components/project/issues/BoardView/state/ConfirmStateDeletion.tsx rename to apps/app/components/project/issues/BoardView/state/confirm-state-delete.tsx index 448c50acc..d39962ca1 100644 --- a/apps/app/components/project/issues/BoardView/state/ConfirmStateDeletion.tsx +++ b/apps/app/components/project/issues/BoardView/state/confirm-state-delete.tsx @@ -18,11 +18,11 @@ import { Button } from "ui"; import type { IState } from "types"; type Props = { isOpen: boolean; - setIsOpen: React.Dispatch>; - data?: IState; + onClose: () => void; + data: IState | null; }; -const ConfirmStateDeletion: React.FC = ({ isOpen, setIsOpen, data }) => { +const ConfirmStateDeletion: React.FC = ({ isOpen, onClose, data }) => { const [isDeleteLoading, setIsDeleteLoading] = useState(false); const { activeWorkspace } = useUser(); @@ -30,7 +30,7 @@ const ConfirmStateDeletion: React.FC = ({ isOpen, setIsOpen, data }) => { const cancelButtonRef = useRef(null); const handleClose = () => { - setIsOpen(false); + onClose(); setIsDeleteLoading(false); }; @@ -53,10 +53,6 @@ const ConfirmStateDeletion: React.FC = ({ isOpen, setIsOpen, data }) => { }); }; - useEffect(() => { - data && setIsOpen(true); - }, [data, setIsOpen]); - return ( = { name: "", description: "", color: "#000000", + group: "backlog", }; const CreateUpdateStateModal: React.FC = ({ isOpen, data, projectId, handleClose }) => { @@ -161,6 +164,22 @@ const CreateUpdateStateModal: React.FC = ({ isOpen, data, projectId, hand }} /> +
+ + + + +
+ ); +}; + +const StatesSettings: React.FC = ({ projectId }) => { + const [activeGroup, setActiveGroup] = useState(null); + const [selectedState, setSelectedState] = useState(null); + const [selectDeleteState, setSelectDeleteState] = useState(null); + + const { states, activeWorkspace } = useUser(); + + const groupedStates: { + [key: string]: Array; + } = groupBy(states ?? [], "group"); return ( <> - { - setSelectedState(undefined); - setIsCreateStateModal(false); - }} - projectId={projectId as string} - data={selectedState ? states?.find((state) => state.id === selectedState) : undefined} + state.id === selectDeleteState) ?? null} + onClose={() => setSelectDeleteState(null)} /> +

State

Manage the state of this project.

-
-
- {states?.map((state) => ( -
-
-
-

{addSpaceIfCamelCase(state.name)}

-
-
- -
+
+ {Object.keys(groupedStates).map((key) => ( +
+
+

{key} states

+
- ))} - -
+ {groupedStates[key]?.map((state) => + state.id !== selectedState ? ( +
+
+
+

{addSpaceIfCamelCase(state.name)}

+
+
+ + +
+
+ ) : ( + { + setActiveGroup(null); + setSelectedState(null); + }} + workspaceSlug={activeWorkspace?.slug} + data={states?.find((state) => state.id === selectedState) ?? null} + selectedGroup={key as keyof StateGroup} + /> + ) + )} + {key === activeGroup && ( + { + setActiveGroup(null); + setSelectedState(null); + }} + workspaceSlug={activeWorkspace?.slug} + data={null} + selectedGroup={key as keyof StateGroup} + /> + )} +
+ ))}
diff --git a/apps/app/constants/index.ts b/apps/app/constants/index.ts index 603652e9f..0e9a67788 100644 --- a/apps/app/constants/index.ts +++ b/apps/app/constants/index.ts @@ -8,3 +8,11 @@ export const ROLE = { }; export const NETWORK_CHOICES = { "0": "Secret", "2": "Public" }; + +export const GROUP_CHOICES = { + backlog: "Backlog", + unstarted: "Unstarted", + started: "Started", + completed: "Completed", + cancelled: "Cancelled", +};