Skip to content

Commit

Permalink
Editing the terms shouldn't throw alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
mavenzer committed Sep 1, 2024
1 parent d2172b4 commit 585007f
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,23 @@ const TermsForm: FC<TermsFormDialogProps> = ({ 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 }))
Expand Down Expand Up @@ -210,4 +215,4 @@ const TermsForm: FC<TermsFormDialogProps> = ({ btnCreateEl }) => {
);
};

export default TermsForm;
export default TermsForm;

0 comments on commit 585007f

Please sign in to comment.