mirror of
https://github.com/strapi/strapi.git
synced 2025-07-24 09:25:25 +00:00
Move timer in request file for settings-manager plugin
This commit is contained in:
parent
76290f2034
commit
3ee78ceeea
@ -51,7 +51,7 @@ function formatQueryParams(params) {
|
||||
*
|
||||
* @return {object} The response data
|
||||
*/
|
||||
export default function request(url, options = {}) {
|
||||
export default function request(url, options = {}, shouldWatchServerRestart = false) {
|
||||
// Set headers
|
||||
options.headers = {
|
||||
'Content-Type': 'application/json',
|
||||
@ -72,5 +72,14 @@ function formatQueryParams(params) {
|
||||
options.body = JSON.stringify(options.body);
|
||||
}
|
||||
|
||||
return fetch(url, options).then(checkStatus).then(parseJSON);
|
||||
return fetch(url, options)
|
||||
.then(checkStatus)
|
||||
.then(parseJSON)
|
||||
.then((response) => {
|
||||
if (shouldWatchServerRestart) {
|
||||
return serverRestartWatcher(response);
|
||||
}
|
||||
|
||||
return response;
|
||||
});
|
||||
}
|
||||
|
@ -49,17 +49,12 @@ export function* editDatabase(action) {
|
||||
|
||||
const requestUrl = `/settings-manager/configurations/databases/${action.apiUrl}`;
|
||||
|
||||
yield call(request, requestUrl, opts);
|
||||
const resp = yield call(request, requestUrl, opts, true);
|
||||
|
||||
// TODO remove counter
|
||||
yield new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
window.Strapi.notification.success('settings-manager.strapi.notification.success.databaseEdit');
|
||||
yield put(databaseActionSucceeded());
|
||||
if (resp.ok) {
|
||||
window.Strapi.notification.success('settings-manager.strapi.notification.success.databaseEdit');
|
||||
yield put(databaseActionSucceeded());
|
||||
}
|
||||
|
||||
} catch(error) {
|
||||
const formErrors = map(error.response.payload.message, err => ({ target: err.target, errors: map(err.messages, mess => ({ id: `settings-manager.${mess.id}`})) }));
|
||||
@ -76,14 +71,11 @@ export function* deleteDatabase(action) {
|
||||
|
||||
const requestUrl = `settings-manager/configurations/databases/${action.databaseToDelete}/${action.endPoint}`;
|
||||
|
||||
yield call(request, requestUrl, opts);
|
||||
const resp = yield call(request, requestUrl, opts, true);
|
||||
|
||||
// TODO remove counter
|
||||
yield new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 4000);
|
||||
});
|
||||
if (resp.ok) {
|
||||
window.Strapi.notification.success('settings-manager.strapi.notification.success.databaseDeleted');
|
||||
}
|
||||
|
||||
|
||||
} catch(error) {
|
||||
@ -100,9 +92,11 @@ export function* deleteLanguage(action) {
|
||||
|
||||
const requestUrl = `/settings-manager/configurations/languages/${action.languageToDelete}`;
|
||||
|
||||
yield call(request, requestUrl, opts);
|
||||
const resp = yield call(request, requestUrl, opts, true);
|
||||
|
||||
window.Strapi.notification.success('settings-manager.strapi.notification.success.languageDelete');
|
||||
if (resp.ok) {
|
||||
window.Strapi.notification.success('settings-manager.strapi.notification.success.languageDelete');
|
||||
}
|
||||
|
||||
} catch(error) {
|
||||
|
||||
@ -193,11 +187,13 @@ export function* postLanguage() {
|
||||
|
||||
const requestUrl = '/settings-manager/configurations/languages';
|
||||
|
||||
yield call(request, requestUrl, opts);
|
||||
const resp = yield call(request, requestUrl, opts, true);
|
||||
|
||||
window.Strapi.notification.success('settings-manager.strapi.notification.success.languageAdd');
|
||||
if (resp.ok) {
|
||||
window.Strapi.notification.success('settings-manager.strapi.notification.success.languageAdd');
|
||||
|
||||
yield put(languageActionSucceeded());
|
||||
yield put(languageActionSucceeded());
|
||||
}
|
||||
|
||||
} catch(error) {
|
||||
yield put(languageActionError());
|
||||
@ -220,18 +216,13 @@ export function* postDatabase(action) {
|
||||
};
|
||||
|
||||
const requestUrl = `/settings-manager/configurations/databases/${action.endPoint}`;
|
||||
const shouldWatchServerRestart = true;
|
||||
const resp = yield call(request, requestUrl, opts, shouldWatchServerRestart);
|
||||
|
||||
yield call(request, requestUrl, opts);
|
||||
|
||||
// TODO remove counter
|
||||
yield new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 3000);
|
||||
});
|
||||
|
||||
yield put(databaseActionSucceeded());
|
||||
window.Strapi.notification.success('settings-manager.strapi.notification.success.databaseAdd');
|
||||
if (resp.ok) {
|
||||
yield put(databaseActionSucceeded());
|
||||
window.Strapi.notification.success('settings-manager.strapi.notification.success.databaseAdd');
|
||||
}
|
||||
|
||||
} catch(error) {
|
||||
const formErrors = map(error.response.payload.message, (err) => {
|
||||
@ -255,12 +246,14 @@ export function* settingsEdit(action) {
|
||||
};
|
||||
|
||||
const requestUrl = `/settings-manager/configurations/${action.endPoint}`;
|
||||
const shouldWatchServerRestart = true;
|
||||
const resp = yield call(request, requestUrl, opts, shouldWatchServerRestart);
|
||||
|
||||
yield call(request, requestUrl, opts);
|
||||
if (resp.ok) {
|
||||
window.Strapi.notification.success('settings-manager.strapi.notification.success.settingsEdit');
|
||||
yield put(editSettingsSucceeded());
|
||||
}
|
||||
|
||||
// TODO handle server reload to get response
|
||||
window.Strapi.notification.success('settings-manager.strapi.notification.success.settingsEdit');
|
||||
yield put(editSettingsSucceeded());
|
||||
|
||||
} catch(error) {
|
||||
window.Strapi.notification.error('settings-manager.strapi.notification.error');
|
||||
|
@ -146,6 +146,7 @@
|
||||
"strapi.notification.success.languageAdd": "The language has been successfully added.",
|
||||
"strapi.notification.success.databaseAdd": "The database has been successfully added.",
|
||||
"strapi.notification.success.databaseEdit": "The database settings have been successfully updated.",
|
||||
"strapi.notification.success.databaseDeleted": "The database has been deleted.",
|
||||
"strapi.notification.success.settingsEdit": "The settings have been successfully updated.",
|
||||
"strapi.notification.error": "An error occurred",
|
||||
|
||||
|
@ -147,6 +147,7 @@
|
||||
"strapi.notification.success.languageAdd": "Le nouveau langage a été ajouté",
|
||||
"strapi.notification.success.databaseAdd": "La nouvelle base de données a été ajoutée",
|
||||
"strapi.notification.success.databaseEdit": "La base de données a bien été éditée",
|
||||
"strapi.notification.success.databaseDeleted": "La base de données a bien été supprimée",
|
||||
"strapi.notification.success.settingsEdit": "Les modifications ont été effectuées",
|
||||
"strapi.notification.error": "Une erreur est apparue",
|
||||
|
||||
|
@ -45,6 +45,14 @@ function formatQueryParams(params) {
|
||||
.join('&');
|
||||
}
|
||||
|
||||
function serverRestartWatcher(response) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve(response);
|
||||
}, 5000);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests a URL, returning a promise
|
||||
*
|
||||
@ -53,7 +61,7 @@ function formatQueryParams(params) {
|
||||
*
|
||||
* @return {object} The response data
|
||||
*/
|
||||
export default function request(url, options) {
|
||||
export default function request(url, options, shouldWatchServerRestart = false) {
|
||||
const optionsObj = options || {};
|
||||
|
||||
// Set headers
|
||||
@ -76,5 +84,14 @@ export default function request(url, options) {
|
||||
optionsObj.body = JSON.stringify(optionsObj.body);
|
||||
}
|
||||
|
||||
return fetch(urlFormatted, optionsObj).then(checkStatus).then(parseJSON);
|
||||
return fetch(urlFormatted, optionsObj)
|
||||
.then(checkStatus)
|
||||
.then(parseJSON)
|
||||
.then((response) => {
|
||||
if (shouldWatchServerRestart) {
|
||||
return serverRestartWatcher(response);
|
||||
}
|
||||
|
||||
return response;
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user