LP-5674: fixed a bug with creating an achievement with a non-existent emoji
This commit is contained in:
parent
eabb1603bd
commit
47fbaef659
@ -78,6 +78,7 @@
|
|||||||
"badges.modal.error_type_name_required": "Enter type name",
|
"badges.modal.error_type_name_required": "Enter type name",
|
||||||
"badges.modal.error_type_required": "Select achievement type",
|
"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.error_duplicate_name": "An achievement with this name already exists in this type",
|
||||||
|
"badges.modal.error_not_found_emoji": "This emoji was not found",
|
||||||
"badges.modal.create_type_title": "Create Type",
|
"badges.modal.create_type_title": "Create Type",
|
||||||
"badges.modal.edit_type_title": "Edit Type",
|
"badges.modal.edit_type_title": "Edit Type",
|
||||||
"badges.modal.btn_delete_type": "Delete type",
|
"badges.modal.btn_delete_type": "Delete type",
|
||||||
|
|||||||
@ -78,6 +78,7 @@
|
|||||||
"badges.modal.error_type_name_required": "Введите название типа",
|
"badges.modal.error_type_name_required": "Введите название типа",
|
||||||
"badges.modal.error_type_required": "Выберите тип достижения",
|
"badges.modal.error_type_required": "Выберите тип достижения",
|
||||||
"badges.modal.error_duplicate_name": "Достижение с таким названием уже существует в данном типе",
|
"badges.modal.error_duplicate_name": "Достижение с таким названием уже существует в данном типе",
|
||||||
|
"badges.modal.error_not_found_emoji": "Этот эмодзи не найден",
|
||||||
"badges.modal.create_type_title": "Создать тип",
|
"badges.modal.create_type_title": "Создать тип",
|
||||||
"badges.modal.edit_type_title": "Редактировать тип",
|
"badges.modal.edit_type_title": "Редактировать тип",
|
||||||
"badges.modal.btn_delete_type": "Удалить тип",
|
"badges.modal.btn_delete_type": "Удалить тип",
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import {GlobalState} from 'mattermost-redux/types/store';
|
|||||||
|
|
||||||
import RenderEmoji from 'components/emoji/emoji';
|
import RenderEmoji from 'components/emoji/emoji';
|
||||||
|
|
||||||
import {isCreateBadgeModalVisible, getEditBadgeModalData} from 'selectors';
|
import {isCreateBadgeModalVisible, getEditBadgeModalData, getEmojiMap} from 'selectors';
|
||||||
import {closeCreateBadgeModal, closeEditBadgeModal, setRHSView} from 'actions/actions';
|
import {closeCreateBadgeModal, closeEditBadgeModal, setRHSView} from 'actions/actions';
|
||||||
import {RHS_STATE_ALL} from '../../constants';
|
import {RHS_STATE_ALL} from '../../constants';
|
||||||
import {BadgeFormData, BadgeTypeDefinition, TypeFormData} from 'types/badges';
|
import {BadgeFormData, BadgeTypeDefinition, TypeFormData} from 'types/badges';
|
||||||
@ -49,6 +49,7 @@ const BadgeModal: React.FC = () => {
|
|||||||
const createVisible = useSelector(isCreateBadgeModalVisible);
|
const createVisible = useSelector(isCreateBadgeModalVisible);
|
||||||
const editData = useSelector(getEditBadgeModalData);
|
const editData = useSelector(getEditBadgeModalData);
|
||||||
const channelId = useSelector((state: GlobalState) => getCurrentChannelId(state));
|
const channelId = useSelector((state: GlobalState) => getCurrentChannelId(state));
|
||||||
|
const emojiMap = useSelector((state: GlobalState) => getEmojiMap(state));
|
||||||
const isOpen = createVisible || editData !== null;
|
const isOpen = createVisible || editData !== null;
|
||||||
const isEditMode = editData !== null;
|
const isEditMode = editData !== null;
|
||||||
|
|
||||||
@ -207,6 +208,11 @@ const BadgeModal: React.FC = () => {
|
|||||||
String(b.type) === typeID &&
|
String(b.type) === typeID &&
|
||||||
(!isEditMode || !editData || b.id !== editData.id),
|
(!isEditMode || !editData || b.id !== editData.id),
|
||||||
);
|
);
|
||||||
|
if (!emojiMap.has(form.image)) {
|
||||||
|
setError(intl.formatMessage({id: 'badges.modal.error_not_found_emoji', defaultMessage: 'Этот эмодзи не найден'}));
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (duplicate) {
|
if (duplicate) {
|
||||||
setError(intl.formatMessage({id: 'badges.modal.error_duplicate_name', defaultMessage: 'Достижение с таким названием уже существует в данном типе'}));
|
setError(intl.formatMessage({id: 'badges.modal.error_duplicate_name', defaultMessage: 'Достижение с таким названием уже существует в данном типе'}));
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@ -238,7 +244,7 @@ const BadgeModal: React.FC = () => {
|
|||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, [form, showCreateType, newTypeForm, isEditMode, editData, handleClose, intl, channelId, dispatch]);
|
}, [form, showCreateType, newTypeForm, isEditMode, editData, handleClose, intl, channelId, dispatch, emojiMap]);
|
||||||
|
|
||||||
const handleDelete = useCallback(async () => {
|
const handleDelete = useCallback(async () => {
|
||||||
if (!editData) {
|
if (!editData) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user