From b56d188a83777448f2f09f0e822b6d96136e97f9 Mon Sep 17 00:00:00 2001 From: rahulramesha <71900764+rahulramesha@users.noreply.github.com> Date: Tue, 7 Nov 2023 18:22:52 +0530 Subject: [PATCH] add errors for duplicate labels (#2706) Co-authored-by: rahulramesha --- .../issues/sidebar-select/label.tsx | 12 ++++++++ web/components/labels/create-label-modal.tsx | 10 ++++++- .../labels/create-update-label-inline.tsx | 29 ++++++++++++++++--- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/web/components/issues/sidebar-select/label.tsx b/web/components/issues/sidebar-select/label.tsx index 464554aec..e997b6f49 100644 --- a/web/components/issues/sidebar-select/label.tsx +++ b/web/components/issues/sidebar-select/label.tsx @@ -18,6 +18,7 @@ import { Plus, X } from "lucide-react"; import { IIssue, IIssueLabels } from "types"; // fetch-keys import { PROJECT_ISSUE_LABELS } from "constants/fetch-keys"; +import useToast from "hooks/use-toast"; type Props = { issueDetails: IIssue | undefined; @@ -44,6 +45,9 @@ export const SidebarLabelSelect: React.FC = ({ const [createLabelForm, setCreateLabelForm] = useState(false); const router = useRouter(); + + const { setToastAlert } = useToast(); + const { workspaceSlug, projectId } = router.query; const { @@ -79,6 +83,14 @@ export const SidebarLabelSelect: React.FC = ({ submitChanges({ labels: [...(issueDetails?.labels ?? []), res.id] }); setCreateLabelForm(false); + }) + .catch((error) => { + setToastAlert({ + title: "Oops!", + type: "error", + message: error?.error ?? "Error while adding the label", + }); + reset(formData); }); }; diff --git a/web/components/labels/create-label-modal.tsx b/web/components/labels/create-label-modal.tsx index 7f42f0095..6fe578459 100644 --- a/web/components/labels/create-label-modal.tsx +++ b/web/components/labels/create-label-modal.tsx @@ -15,6 +15,7 @@ import { ChevronDown } from "lucide-react"; import type { IIssueLabels, IState } from "types"; // constants import { LABEL_COLOR_OPTIONS, getRandomLabelColor } from "constants/label"; +import useToast from "hooks/use-toast"; // types type Props = { @@ -58,6 +59,8 @@ export const CreateLabelModal: React.FC = observer((props) => { reset(defaultValues); }; + const { setToastAlert } = useToast(); + const onSubmit = async (formData: IIssueLabels) => { if (!workspaceSlug) return; @@ -68,7 +71,12 @@ export const CreateLabelModal: React.FC = observer((props) => { if (onSuccess) onSuccess(res); }) .catch((error) => { - console.log(error); + setToastAlert({ + title: "Oops!", + type: "error", + message: error?.error ?? "Error while adding the label", + }); + reset(formData); }); }; diff --git a/web/components/labels/create-update-label-inline.tsx b/web/components/labels/create-update-label-inline.tsx index 16cab89ed..f27bd517e 100644 --- a/web/components/labels/create-update-label-inline.tsx +++ b/web/components/labels/create-update-label-inline.tsx @@ -14,6 +14,7 @@ import { Button, Input } from "@plane/ui"; import { IIssueLabels } from "types"; // fetch-keys import { getRandomLabelColor, LABEL_COLOR_OPTIONS } from "constants/label"; +import useToast from "hooks/use-toast"; type Props = { labelForm: boolean; @@ -39,6 +40,8 @@ export const CreateUpdateLabelInline = observer( // store const { projectLabel: projectLabelStore } = useMobxStore(); + const { setToastAlert } = useToast(); + const { handleSubmit, control, @@ -60,10 +63,20 @@ export const CreateUpdateLabelInline = observer( const handleLabelCreate: SubmitHandler = async (formData) => { if (!workspaceSlug || !projectId || isSubmitting) return; - await projectLabelStore.createLabel(workspaceSlug.toString(), projectId.toString(), formData).then(() => { - handleClose(); - reset(defaultValues); - }); + await projectLabelStore + .createLabel(workspaceSlug.toString(), projectId.toString(), formData) + .then(() => { + handleClose(); + reset(defaultValues); + }) + .catch((error) => { + setToastAlert({ + title: "Oops!", + type: "error", + message: error?.error ?? "Error while adding the label", + }); + reset(formData); + }); }; const handleLabelUpdate: SubmitHandler = async (formData) => { @@ -74,6 +87,14 @@ export const CreateUpdateLabelInline = observer( .then(() => { reset(defaultValues); handleClose(); + }) + .catch((error) => { + setToastAlert({ + title: "Oops!", + type: "error", + message: error?.error ?? "Error while updating the label", + }); + reset(formData); }); };