From 9d891ecce153e5ffebdfc0c82984661abc2cc6fb Mon Sep 17 00:00:00 2001 From: Dakshesh Jain <65905942+dakshesh14@users.noreply.github.com> Date: Tue, 18 Jul 2023 12:08:09 +0530 Subject: [PATCH] fix: selecting label once create using modal (#1537) --- apps/app/components/issues/form.tsx | 4 ++++ apps/app/components/labels/create-label-modal.tsx | 10 +++++++++- .../projects/[projectId]/pages/[pageId].tsx | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/apps/app/components/issues/form.tsx b/apps/app/components/issues/form.tsx index 5faa4073b..872d6def2 100644 --- a/apps/app/components/issues/form.tsx +++ b/apps/app/components/issues/form.tsx @@ -254,6 +254,10 @@ export const IssueForm: FC = ({ handleClose={() => setLabelModal(false)} projectId={projectId} user={user} + onSuccess={(response) => { + setValue("labels", [...watch("labels"), response.id]); + setValue("labels_list", [...watch("labels_list"), response.id]); + }} /> )} diff --git a/apps/app/components/labels/create-label-modal.tsx b/apps/app/components/labels/create-label-modal.tsx index c420e45b4..7af86888d 100644 --- a/apps/app/components/labels/create-label-modal.tsx +++ b/apps/app/components/labels/create-label-modal.tsx @@ -26,6 +26,7 @@ type Props = { isOpen: boolean; projectId: string; handleClose: () => void; + onSuccess?: (response: IIssueLabels) => void; user: ICurrentUserResponse | undefined; }; @@ -34,7 +35,13 @@ const defaultValues: Partial = { color: "rgb(var(--color-text-200))", }; -export const CreateLabelModal: React.FC = ({ isOpen, projectId, handleClose, user }) => { +export const CreateLabelModal: React.FC = ({ + isOpen, + projectId, + handleClose, + user, + onSuccess, +}) => { const router = useRouter(); const { workspaceSlug } = router.query; @@ -66,6 +73,7 @@ export const CreateLabelModal: React.FC = ({ isOpen, projectId, handleClo false ); onClose(); + if (onSuccess) onSuccess(res); }) .catch((error) => { console.log(error); diff --git a/apps/app/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx b/apps/app/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx index 659437ce3..334799663 100644 --- a/apps/app/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx +++ b/apps/app/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx @@ -553,6 +553,11 @@ const SinglePage: NextPage = () => { handleClose={() => setLabelModal(false)} projectId={projectId} user={user} + onSuccess={(response) => { + partialUpdatePage({ + labels_list: [...(pageDetails.labels ?? []), response.id], + }); + }} /> )}