[i18n] don't add locale in settings when it already exists (#9776)

This commit is contained in:
Marvin Frachet 2021-03-19 09:46:03 +01:00 committed by GitHub
parent 92c98cdc2a
commit 7d46206d9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View File

@ -1,6 +1,7 @@
import { useState } from 'react';
import { request } from 'strapi-helper-plugin';
import { useDispatch } from 'react-redux';
import get from 'lodash/get';
import { getTrad } from '../../utils';
import { ADD_LOCALE } from '../constants';
@ -22,12 +23,21 @@ const addLocale = async ({ code, name, isDefault }) => {
return data;
} catch (e) {
strapi.notification.toggle({
type: 'warning',
message: { id: 'notification.error' },
});
const message = get(e, 'response.payload.message', null);
return e;
if (message && message.includes('already exists')) {
strapi.notification.toggle({
type: 'warning',
message: { id: getTrad('Settings.locales.modal.create.alreadyExist') },
});
} else {
strapi.notification.toggle({
type: 'warning',
message: { id: 'notification.error' },
});
}
throw e;
}
};

View File

@ -39,6 +39,7 @@
"Settings.locales.modal.create.defaultLocales.loading": "Loading the available locales...",
"Settings.locales.modal.create.confirmation": "Add locale",
"Settings.locales.modal.create.success": "Locale successfully added",
"Settings.locales.modal.create.alreadyExist": "This locale already exists",
"Settings.locales.modal.locales.label": "Locales",
"Settings.locales.modal.edit.locales.label": "Locales",
"Settings.locales.modal.locales.displayName": "Locale display name",