mirror of
https://github.com/strapi/strapi.git
synced 2025-11-08 22:32:02 +00:00
Fix loading information on error when adding a locale that already exists (#9875)
This commit is contained in:
parent
f3fe056367
commit
f30895b588
@ -6,7 +6,6 @@ import { getTrad } from '../../utils';
|
|||||||
import { ADD_LOCALE } from '../constants';
|
import { ADD_LOCALE } from '../constants';
|
||||||
|
|
||||||
const addLocale = async ({ code, name, isDefault }) => {
|
const addLocale = async ({ code, name, isDefault }) => {
|
||||||
try {
|
|
||||||
const data = await request(`/i18n/locales`, {
|
const data = await request(`/i18n/locales`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: {
|
body: {
|
||||||
@ -22,6 +21,18 @@ const addLocale = async ({ code, name, isDefault }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
const useAddLocale = () => {
|
||||||
|
const [isLoading, setLoading] = useState(false);
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
const persistLocale = async locale => {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const newLocale = await addLocale(locale);
|
||||||
|
dispatch({ type: ADD_LOCALE, newLocale });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const message = get(e, 'response.payload.message', null);
|
const message = get(e, 'response.payload.message', null);
|
||||||
|
|
||||||
@ -38,20 +49,9 @@ const addLocale = async ({ code, name, isDefault }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
} finally {
|
||||||
};
|
|
||||||
|
|
||||||
const useAddLocale = () => {
|
|
||||||
const [isLoading, setLoading] = useState(false);
|
|
||||||
const dispatch = useDispatch();
|
|
||||||
|
|
||||||
const persistLocale = async locale => {
|
|
||||||
setLoading(true);
|
|
||||||
|
|
||||||
const newLocale = await addLocale(locale);
|
|
||||||
|
|
||||||
dispatch({ type: ADD_LOCALE, newLocale });
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return { isAdding: isLoading, addLocale: persistLocale };
|
return { isAdding: isLoading, addLocale: persistLocale };
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user