diff --git a/apps/app/components/states/create-update-state-inline.tsx b/apps/app/components/states/create-update-state-inline.tsx index ddeee199a44..46043b0cdda 100644 --- a/apps/app/components/states/create-update-state-inline.tsx +++ b/apps/app/components/states/create-update-state-inline.tsx @@ -15,7 +15,7 @@ import useToast from "hooks/use-toast"; // ui import { Button, CustomSelect, Input } from "components/ui"; // types -import type { IState } from "types"; +import type { IState, StateResponse } from "types"; // fetch-keys import { STATE_LIST } from "constants/fetch-keys"; // constants @@ -85,7 +85,7 @@ export const CreateUpdateStateInline: React.FC = ({ await stateService .createState(workspaceSlug, projectId, { ...payload }) .then((res) => { - mutate(STATE_LIST(projectId), (prevData) => [...(prevData ?? []), res]); + mutate(STATE_LIST(projectId)); handleClose(); setToastAlert({ diff --git a/apps/app/components/states/create-update-state-modal.tsx b/apps/app/components/states/create-update-state-modal.tsx index c757c501f44..806d05e7d4a 100644 --- a/apps/app/components/states/create-update-state-modal.tsx +++ b/apps/app/components/states/create-update-state-modal.tsx @@ -81,7 +81,7 @@ export const CreateUpdateStateModal: React.FC = ({ await stateService .createState(workspaceSlug as string, projectId, payload) .then((res) => { - mutate(STATE_LIST(projectId), (prevData) => [...(prevData ?? []), res], false); + mutate(STATE_LIST(projectId)); onClose(); }) .catch((err) => { @@ -95,19 +95,7 @@ export const CreateUpdateStateModal: React.FC = ({ await stateService .updateState(workspaceSlug as string, projectId, data.id, payload) .then((res) => { - mutate( - STATE_LIST(projectId), - (prevData) => { - const newData = prevData?.map((item) => { - if (item.id === res.id) { - return res; - } - return item; - }); - return newData; - }, - false - ); + mutate(STATE_LIST(projectId)); onClose(); }) .catch((err) => { diff --git a/apps/app/components/states/delete-state-modal.tsx b/apps/app/components/states/delete-state-modal.tsx index b517ddbf97f..cd5dab3be62 100644 --- a/apps/app/components/states/delete-state-modal.tsx +++ b/apps/app/components/states/delete-state-modal.tsx @@ -59,11 +59,7 @@ export const DeleteStateModal: React.FC = ({ isOpen, onClose, data }) => await stateServices .deleteState(workspaceSlug as string, data.project, data.id) .then(() => { - mutate( - STATE_LIST(data.project), - (prevData) => prevData?.filter((state) => state.id !== data?.id), - false - ); + mutate(STATE_LIST(data.project)); handleClose(); setToastAlert({ diff --git a/apps/app/helpers/state.helper.ts b/apps/app/helpers/state.helper.ts index a852157a94a..7229957d0f5 100644 --- a/apps/app/helpers/state.helper.ts +++ b/apps/app/helpers/state.helper.ts @@ -9,10 +9,7 @@ export const orderStateGroups = (unorderedStateGroups: StateResponse) => export const getStatesList = (stateGroups: any): IState[] => { // order the unordered state groups first - const orderedStateGroups = Object.assign( - { backlog: [], unstarted: [], started: [], completed: [], cancelled: [] }, - stateGroups - ); + const orderedStateGroups = orderStateGroups(stateGroups); // extract states from the groups and return them return Object.keys(orderedStateGroups) diff --git a/apps/app/pages/[workspaceSlug]/projects/[projectId]/settings/states.tsx b/apps/app/pages/[workspaceSlug]/projects/[projectId]/settings/states.tsx index 880e44967d7..267f812a356 100644 --- a/apps/app/pages/[workspaceSlug]/projects/[projectId]/settings/states.tsx +++ b/apps/app/pages/[workspaceSlug]/projects/[projectId]/settings/states.tsx @@ -52,14 +52,13 @@ const StatesSettings: NextPage = (props) => { : null ); const orderedStateGroups = orderStateGroups(states ?? {}); - - const statesList = getStatesList(orderStateGroups ?? {}); + const statesList = getStatesList(orderedStateGroups ?? {}); return ( <> state.id === selectDeleteState) ?? null} + data={statesList?.find((s) => s.id === selectDeleteState) ?? null} onClose={() => setSelectDeleteState(null)} /> = (props) => {