mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 14:44:31 +00:00
Optimistic response for languagePost
This commit is contained in:
parent
6b8a637d3c
commit
63d729e546
@ -98,11 +98,15 @@ export function languagesFetchSucceeded(appLanguages, listLanguages) {
|
||||
});
|
||||
});
|
||||
|
||||
// Init the react-select
|
||||
const selectedLanguage = { 'language.defaultLocale': selectOptionsObject.items[0].value };
|
||||
|
||||
return {
|
||||
type: LANGUAGES_FETCH_SUCCEEDED,
|
||||
configs,
|
||||
listLanguages,
|
||||
selectOptions,
|
||||
selectedLanguage,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import { fromJS, Map, OrderedMap } from 'immutable';
|
||||
import { remove } from 'lodash';
|
||||
import { remove, sortBy } from 'lodash';
|
||||
import {
|
||||
CONFIG_FETCH_SUCCEEDED,
|
||||
CHANGE_DEFAULT_LANGUAGE,
|
||||
@ -21,6 +21,7 @@ import {
|
||||
LANGUAGE_ACTION_ERROR,
|
||||
DATABASE_DELETE,
|
||||
DATABASE_ACTION_ERROR,
|
||||
NEW_LANGUAGE_POST,
|
||||
} from './constants';
|
||||
|
||||
/* eslint-disable new-cap */
|
||||
@ -75,7 +76,7 @@ function homeReducer(state = initialState, action) {
|
||||
.set('didCreatedNewLanguage', false)
|
||||
.set('configsDisplay', OrderedMap(action.configs))
|
||||
.set('initialData', Map())
|
||||
.set('modifiedData', Map())
|
||||
.set('modifiedData', Map(action.selectedLanguage))
|
||||
.set('selectOptions', Map(action.selectOptions))
|
||||
.set('listLanguages', Map(action.listLanguages));
|
||||
case EDIT_SETTINGS_SUCCEEDED:
|
||||
@ -99,6 +100,11 @@ function homeReducer(state = initialState, action) {
|
||||
.set('dbNameTarget', action.dbNameTarget)
|
||||
.set('initialData', Map(action.data))
|
||||
.set('modifiedData', Map(action.data));
|
||||
case NEW_LANGUAGE_POST: // eslint-disable-line no-case-declarations
|
||||
const sections = state.getIn(['configsDisplay', 'sections']);
|
||||
sections.push({ active: false, name: state.getIn(['modifiedData', 'language.defaultLocale']) });
|
||||
const newSections = sortBy(sections, (o) => o.name);
|
||||
return state.setIn(['configsDisplay', 'sections'], newSections);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
@ -25,7 +25,6 @@ import {
|
||||
configFetchSucceded,
|
||||
databasesFetchSucceeded,
|
||||
languagesFetchSucceeded,
|
||||
languageActionSucceded,
|
||||
languageActionError,
|
||||
databaseActionSucceeded,
|
||||
specificDatabaseFetchSucceeded,
|
||||
@ -189,17 +188,9 @@ export function* postLanguage() {
|
||||
yield call(request, requestUrl, opts);
|
||||
|
||||
window.Strapi.notification.success('Adding a new language...');
|
||||
// TODO remove counter
|
||||
yield new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 4000);
|
||||
});
|
||||
|
||||
yield put(languageActionSucceded());
|
||||
|
||||
} catch(error) {
|
||||
// TODO handle error i18n
|
||||
yield put(languageActionError());
|
||||
window.Strapi.notification.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user