From dd8c7a748703be481449bfe46ae09e6dcf14dba2 Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Wed, 22 Nov 2023 15:35:24 +0530 Subject: [PATCH] fix: cycle and module create/update modal fix (#2833) --- web/components/cycles/modal.tsx | 18 ++++++++++++------ web/components/modules/modal.tsx | 9 ++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/web/components/cycles/modal.tsx b/web/components/cycles/modal.tsx index d63201236..0db3a5ed1 100644 --- a/web/components/cycles/modal.tsx +++ b/web/components/cycles/modal.tsx @@ -30,9 +30,11 @@ export const CycleCreateUpdateModal: React.FC = (props) => { // toast const { setToastAlert } = useToast(); - const createCycle = async (payload: Partial) => - cycleStore - .createCycle(workspaceSlug, projectId, payload) + const createCycle = async (payload: Partial) => { + if (!workspaceSlug || !projectId) return; + const selectedProjectId = payload.project ?? projectId.toString(); + await cycleStore + .createCycle(workspaceSlug, selectedProjectId, payload) .then(() => { setToastAlert({ type: "success", @@ -47,10 +49,13 @@ export const CycleCreateUpdateModal: React.FC = (props) => { message: "Error in creating cycle. Please try again.", }); }); + }; - const updateCycle = async (cycleId: string, payload: Partial) => - cycleStore - .patchCycle(workspaceSlug, projectId, cycleId, payload) + const updateCycle = async (cycleId: string, payload: Partial) => { + if (!workspaceSlug || !projectId) return; + const selectedProjectId = payload.project ?? projectId.toString(); + await cycleStore + .patchCycle(workspaceSlug, selectedProjectId, cycleId, payload) .then(() => { setToastAlert({ type: "success", @@ -65,6 +70,7 @@ export const CycleCreateUpdateModal: React.FC = (props) => { message: "Error in updating cycle. Please try again.", }); }); + }; const dateChecker = async (payload: CycleDateCheckData) => { let status = false; diff --git a/web/components/modules/modal.tsx b/web/components/modules/modal.tsx index 297dba3bb..e1f92051f 100644 --- a/web/components/modules/modal.tsx +++ b/web/components/modules/modal.tsx @@ -49,9 +49,9 @@ export const CreateUpdateModuleModal: React.FC = observer((props) => { const createModule = async (payload: Partial) => { if (!workspaceSlug || !projectId) return; - + const selectedProjectId = payload.project ?? projectId.toString(); await moduleStore - .createModule(workspaceSlug.toString(), projectId.toString(), payload) + .createModule(workspaceSlug.toString(), selectedProjectId, payload) .then(() => { handleClose(); @@ -72,9 +72,9 @@ export const CreateUpdateModuleModal: React.FC = observer((props) => { const updateModule = async (payload: Partial) => { if (!workspaceSlug || !projectId || !data) return; - + const selectedProjectId = payload.project ?? projectId.toString(); await moduleStore - .updateModuleDetails(workspaceSlug.toString(), projectId.toString(), data.id, payload) + .updateModuleDetails(workspaceSlug.toString(), selectedProjectId, data.id, payload) .then(() => { handleClose(); @@ -99,7 +99,6 @@ export const CreateUpdateModuleModal: React.FC = observer((props) => { const payload: Partial = { ...formData, }; - if (!data) await createModule(payload); else await updateModule(payload); };