Display notice on failure
[MAILPOET-2463]
This commit is contained in:
committed by
Rostislav Wolný
parent
2d98e26281
commit
95e5a8628d
@@ -46,6 +46,12 @@ export function deleteCustomFieldDone(customFieldId, clientId) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function deleteCustomFieldFailed(message = undefined) {
|
||||||
|
return {
|
||||||
|
type: 'DELETE_CUSTOM_FIELD_FAILED',
|
||||||
|
message,
|
||||||
|
};
|
||||||
|
}
|
||||||
export function changeFormStyles(styles) {
|
export function changeFormStyles(styles) {
|
||||||
return {
|
return {
|
||||||
type: 'CHANGE_FORM_STYLES',
|
type: 'CHANGE_FORM_STYLES',
|
||||||
|
@@ -64,22 +64,24 @@ export default {
|
|||||||
|
|
||||||
DELETE_CUSTOM_FIELD(actionData) {
|
DELETE_CUSTOM_FIELD(actionData) {
|
||||||
dispatch('mailpoet-form-editor').deleteCustomFieldStarted();
|
dispatch('mailpoet-form-editor').deleteCustomFieldStarted();
|
||||||
// MailPoet.Ajax.post({
|
MailPoet.Ajax.post({
|
||||||
// api_version: window.mailpoet_api_version,
|
api_version: window.mailpoet_api_version,
|
||||||
// endpoint: 'customFields',
|
endpoint: 'customFields',
|
||||||
// action: 'delete',
|
action: 'delete',
|
||||||
// data: {
|
data: {
|
||||||
// id: actionData.customFieldId
|
id: actionData.customFieldId,
|
||||||
// }
|
},
|
||||||
// })
|
})
|
||||||
setTimeout(() => {
|
.then(() => {
|
||||||
console.log('xxx', actionData);
|
dispatch('mailpoet-form-editor').deleteCustomFieldDone(actionData.customFieldId, actionData.clientId);
|
||||||
console.log('before', select('core/block-editor').getBlocks());
|
dispatch('core/block-editor').removeBlock(actionData.clientId);
|
||||||
dispatch('mailpoet-form-editor').deleteCustomFieldDone(actionData.customFieldId, actionData.clientId);
|
})
|
||||||
dispatch('core/block-editor').removeBlock(actionData.clientId);
|
.fail((response) => {
|
||||||
}, 1000);
|
let errorMessage = null;
|
||||||
setTimeout(() => {
|
if (response.errors.length > 0) {
|
||||||
console.log('after', select('core/block-editor').getBlocks());
|
errorMessage = response.errors.map((error) => (error.message));
|
||||||
}, 2000);
|
}
|
||||||
|
dispatch('mailpoet-form-editor').deleteCustomFieldFailed(errorMessage);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@@ -18,6 +18,7 @@ import {
|
|||||||
customFieldDeleteCancel,
|
customFieldDeleteCancel,
|
||||||
customFieldDeleteStart,
|
customFieldDeleteStart,
|
||||||
customFieldDeleteDone,
|
customFieldDeleteDone,
|
||||||
|
customFieldDeleteFailed,
|
||||||
} from './reducers/custom_field_delete.jsx';
|
} from './reducers/custom_field_delete.jsx';
|
||||||
|
|
||||||
const saveFormStarted = saveFormStartedFactory(MailPoet);
|
const saveFormStarted = saveFormStartedFactory(MailPoet);
|
||||||
@@ -42,6 +43,7 @@ export default (defaultState) => (state = defaultState, action) => {
|
|||||||
case 'CUSTOM_FIELD_DELETE_CANCEL': return customFieldDeleteCancel(state, action);
|
case 'CUSTOM_FIELD_DELETE_CANCEL': return customFieldDeleteCancel(state, action);
|
||||||
case 'DELETE_CUSTOM_FIELD_STARTED': return customFieldDeleteStart(state, action);
|
case 'DELETE_CUSTOM_FIELD_STARTED': return customFieldDeleteStart(state, action);
|
||||||
case 'DELETE_CUSTOM_FIELD_DONE': return customFieldDeleteDone(state, action);
|
case 'DELETE_CUSTOM_FIELD_DONE': return customFieldDeleteDone(state, action);
|
||||||
|
case 'DELETE_CUSTOM_FIELD_FAILED': return customFieldDeleteFailed(state, action);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@@ -8,12 +8,30 @@ export const customFieldDeleteClick = (state) => ({
|
|||||||
displayCustomFieldDeleteConfirm: true,
|
displayCustomFieldDeleteConfirm: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const customFieldDeleteStart = (state) => ({
|
export const customFieldDeleteStart = (state) => {
|
||||||
...state,
|
const notices = state.notices.filter((notice) => notice.id !== 'custom-field');
|
||||||
displayCustomFieldDeleteConfirm: false,
|
return ({
|
||||||
isCustomFieldDeleting: true,
|
...state,
|
||||||
});
|
...notices,
|
||||||
|
displayCustomFieldDeleteConfirm: false,
|
||||||
|
isCustomFieldDeleting: true,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const customFieldDeleteFailed = (state, action) => {
|
||||||
|
const notices = state.notices.filter((notice) => notice.id !== 'custom-field');
|
||||||
|
notices.push({
|
||||||
|
id: 'custom-field',
|
||||||
|
content: action.message,
|
||||||
|
isDismissible: true,
|
||||||
|
status: 'error',
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
isCustomFieldSaving: false,
|
||||||
|
notices,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export const customFieldDeleteDone = (state, action) => {
|
export const customFieldDeleteDone = (state, action) => {
|
||||||
const customFields = state
|
const customFields = state
|
||||||
@@ -23,7 +41,7 @@ export const customFieldDeleteDone = (state, action) => {
|
|||||||
const formBlocks = state
|
const formBlocks = state
|
||||||
.formBlocks
|
.formBlocks
|
||||||
.filter((block) => block.clientId !== action.clientId);
|
.filter((block) => block.clientId !== action.clientId);
|
||||||
console.log('blocks', formBlocks);
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
formBlocks,
|
formBlocks,
|
||||||
|
Reference in New Issue
Block a user