From 6650f1b5c0aaf6c83b29cff894ff998e374cd27d Mon Sep 17 00:00:00 2001 From: Soumen Date: Mon, 9 Sep 2024 13:11:56 +0200 Subject: [PATCH] Editing the terms shouldn't throw alerts. (#1701) --- .../Terms/TermSearch/TermForm/TermsForm.tsx | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/odd-platform-ui/src/components/Terms/TermSearch/TermForm/TermsForm.tsx b/odd-platform-ui/src/components/Terms/TermSearch/TermForm/TermsForm.tsx index 7404ed249..c8ed77662 100644 --- a/odd-platform-ui/src/components/Terms/TermSearch/TermForm/TermsForm.tsx +++ b/odd-platform-ui/src/components/Terms/TermSearch/TermForm/TermsForm.tsx @@ -80,18 +80,23 @@ const TermsForm: FC = ({ btnCreateEl }) => { }; const onSubmit = (data: TermFormData) => { - const duplicateTerm = existingTerms.find( - (existingTerm: TermDetails) => - existingTerm.name === data.name && - existingTerm.namespace.name === data.namespaceName - ); - - if (duplicateTerm) { - setError('A term with the same name already exists in this namespace.'); - return; + // Check if we're in create mode (no term.id present) + if (!term?.id) { + const duplicateTerm = existingTerms.find( + (existingTerm: TermDetails) => + existingTerm.name === data.name && + existingTerm.namespace.name === data.namespaceName + ); + + if (duplicateTerm) { + setError('A term with the same name already exists in this namespace.'); + return; + } } const parsedData = { ...data }; + + // Determine whether to create or update the term (term && term.id ? dispatch(updateTerm({ termId: term.id, termFormData: parsedData })) : dispatch(createTerm({ termFormData: parsedData })) @@ -210,4 +215,4 @@ const TermsForm: FC = ({ btnCreateEl }) => { ); }; -export default TermsForm; +export default TermsForm; \ No newline at end of file