LP-5677: fixed the possibility of creating an achievement with a duplicate name in one type
This commit is contained in:
parent
d06422a711
commit
eabb1603bd
@ -77,6 +77,7 @@
|
||||
"badges.modal.error_generic": "An error occurred",
|
||||
"badges.modal.error_type_name_required": "Enter type name",
|
||||
"badges.modal.error_type_required": "Select achievement type",
|
||||
"badges.modal.error_duplicate_name": "An achievement with this name already exists in this type",
|
||||
"badges.modal.create_type_title": "Create Type",
|
||||
"badges.modal.edit_type_title": "Edit Type",
|
||||
"badges.modal.btn_delete_type": "Delete type",
|
||||
|
||||
@ -77,6 +77,7 @@
|
||||
"badges.modal.error_generic": "Произошла ошибка",
|
||||
"badges.modal.error_type_name_required": "Введите название типа",
|
||||
"badges.modal.error_type_required": "Выберите тип достижения",
|
||||
"badges.modal.error_duplicate_name": "Достижение с таким названием уже существует в данном типе",
|
||||
"badges.modal.create_type_title": "Создать тип",
|
||||
"badges.modal.edit_type_title": "Редактировать тип",
|
||||
"badges.modal.btn_delete_type": "Удалить тип",
|
||||
|
||||
@ -200,6 +200,18 @@ const BadgeModal: React.FC = () => {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
const allBadges = await client.getAllBadges();
|
||||
const trimmedName = form.name.trim().toLowerCase();
|
||||
const duplicate = allBadges.find(
|
||||
(b) => b.name.toLowerCase() === trimmedName &&
|
||||
String(b.type) === typeID &&
|
||||
(!isEditMode || !editData || b.id !== editData.id),
|
||||
);
|
||||
if (duplicate) {
|
||||
setError(intl.formatMessage({id: 'badges.modal.error_duplicate_name', defaultMessage: 'Достижение с таким названием уже существует в данном типе'}));
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
if (isEditMode && editData) {
|
||||
await client.updateBadge({
|
||||
id: String(editData.id),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user