Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editing the terms shouldn't throw alerts. #1701

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Loading