Create a delete custom field component
[MAILPOET-2463]
This commit is contained in:
committed by
Rostislav Wolný
parent
5adda60fbf
commit
3b21e21fba
50
assets/js/src/form_editor/blocks/custom_field_delete.jsx
Normal file
50
assets/js/src/form_editor/blocks/custom_field_delete.jsx
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import React, { useLayoutEffect } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
} from '@wordpress/components';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import MailPoet from 'mailpoet';
|
||||||
|
|
||||||
|
const CustomFieldDelete = ({
|
||||||
|
isBusy,
|
||||||
|
displayConfirm,
|
||||||
|
onDeleteClick,
|
||||||
|
onDeleteConfirm,
|
||||||
|
}) => {
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
if (displayConfirm) {
|
||||||
|
const result = window.confirm(MailPoet.I18n.t('customFieldDeleteConfirm'));// eslint-disable-line no-alert
|
||||||
|
if (result) {
|
||||||
|
onDeleteConfirm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
isDestructive
|
||||||
|
isLink
|
||||||
|
isBusy={isBusy}
|
||||||
|
onClick={onDeleteClick}
|
||||||
|
className="button-on-top"
|
||||||
|
>
|
||||||
|
{MailPoet.I18n.t('customFieldDeleteCTA')}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
CustomFieldDelete.propTypes = {
|
||||||
|
isBusy: PropTypes.bool,
|
||||||
|
displayConfirm: PropTypes.bool,
|
||||||
|
onDeleteClick: PropTypes.func,
|
||||||
|
onDeleteConfirm: PropTypes.func,
|
||||||
|
};
|
||||||
|
|
||||||
|
CustomFieldDelete.defaultProps = {
|
||||||
|
isBusy: false,
|
||||||
|
displayConfirm: false,
|
||||||
|
onDeleteClick: () => {},
|
||||||
|
onDeleteConfirm: () => {},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CustomFieldDelete;
|
@@ -7,11 +7,16 @@ import {
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
|
|
||||||
|
import CustomFieldDelete from '../custom_field_delete.jsx';
|
||||||
|
|
||||||
const CustomFieldSettings = ({
|
const CustomFieldSettings = ({
|
||||||
mandatory,
|
mandatory,
|
||||||
validate,
|
validate,
|
||||||
isSaving,
|
isSaving,
|
||||||
onSave,
|
onSave,
|
||||||
|
displayCustomFieldDeleteConfirm,
|
||||||
|
onCustomFieldDeleteClick,
|
||||||
|
onCustomFieldDeleteConfirm,
|
||||||
}) => {
|
}) => {
|
||||||
const [localMandatory, setLocalMandatory] = useState(mandatory);
|
const [localMandatory, setLocalMandatory] = useState(mandatory);
|
||||||
const [localValidate, setLocalValidate] = useState(validate);
|
const [localValidate, setLocalValidate] = useState(validate);
|
||||||
@@ -31,6 +36,12 @@ const CustomFieldSettings = ({
|
|||||||
>
|
>
|
||||||
{MailPoet.I18n.t('customFieldSaveCTA')}
|
{MailPoet.I18n.t('customFieldSaveCTA')}
|
||||||
</Button>
|
</Button>
|
||||||
|
<CustomFieldDelete
|
||||||
|
isBusy={isSaving}
|
||||||
|
displayConfirm={displayCustomFieldDeleteConfirm}
|
||||||
|
onDeleteClick={onCustomFieldDeleteClick}
|
||||||
|
onDeleteConfirm={onCustomFieldDeleteConfirm}
|
||||||
|
/>
|
||||||
<ToggleControl
|
<ToggleControl
|
||||||
label={MailPoet.I18n.t('blockMandatory')}
|
label={MailPoet.I18n.t('blockMandatory')}
|
||||||
checked={localMandatory}
|
checked={localMandatory}
|
||||||
@@ -68,12 +79,18 @@ CustomFieldSettings.propTypes = {
|
|||||||
validate: PropTypes.string,
|
validate: PropTypes.string,
|
||||||
onSave: PropTypes.func.isRequired,
|
onSave: PropTypes.func.isRequired,
|
||||||
isSaving: PropTypes.bool,
|
isSaving: PropTypes.bool,
|
||||||
|
displayCustomFieldDeleteConfirm: PropTypes.bool,
|
||||||
|
onCustomFieldDeleteClick: PropTypes.func,
|
||||||
|
onCustomFieldDeleteConfirm: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
CustomFieldSettings.defaultProps = {
|
CustomFieldSettings.defaultProps = {
|
||||||
mandatory: false,
|
mandatory: false,
|
||||||
isSaving: false,
|
isSaving: false,
|
||||||
validate: '',
|
validate: '',
|
||||||
|
displayCustomFieldDeleteConfirm: false,
|
||||||
|
onCustomFieldDeleteClick: () => {},
|
||||||
|
onCustomFieldDeleteConfirm: () => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default CustomFieldSettings;
|
export default CustomFieldSettings;
|
||||||
|
@@ -18,7 +18,11 @@ const CustomTextEdit = ({ attributes, setAttributes, clientId }) => {
|
|||||||
(sel) => sel('mailpoet-form-editor').getIsCustomFieldSaving(),
|
(sel) => sel('mailpoet-form-editor').getIsCustomFieldSaving(),
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
const { saveCustomField } = useDispatch('mailpoet-form-editor');
|
const displayCustomFieldDeleteConfirm = useSelect(
|
||||||
|
(sel) => sel('mailpoet-form-editor').getDisplayCustomFieldDeleteConfirm(),
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
const { saveCustomField, onCustomFieldDeleteClick, onCustomFieldDeleteConfirm } = useDispatch('mailpoet-form-editor');
|
||||||
|
|
||||||
const inspectorControls = (
|
const inspectorControls = (
|
||||||
<InspectorControls>
|
<InspectorControls>
|
||||||
@@ -45,6 +49,9 @@ const CustomTextEdit = ({ attributes, setAttributes, clientId }) => {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
displayCustomFieldDeleteConfirm={displayCustomFieldDeleteConfirm}
|
||||||
|
onCustomFieldDeleteClick={onCustomFieldDeleteClick}
|
||||||
|
onCustomFieldDeleteConfirm={onCustomFieldDeleteConfirm}
|
||||||
/>
|
/>
|
||||||
</PanelBody>
|
</PanelBody>
|
||||||
</Panel>
|
</Panel>
|
||||||
|
@@ -20,6 +20,12 @@ export function changeFormName(name) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function onCustomFieldDeleteClick() {
|
||||||
|
return {
|
||||||
|
type: 'CUSTOM_FIELD_DELETE_CLICK',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function changeFormStyles(styles) {
|
export function changeFormStyles(styles) {
|
||||||
return {
|
return {
|
||||||
type: 'CHANGE_FORM_STYLES',
|
type: 'CHANGE_FORM_STYLES',
|
||||||
|
@@ -13,6 +13,7 @@ import changeFormBlocks from './reducers/change_form_blocks.jsx';
|
|||||||
import saveCustomFieldDone from './reducers/save_custom_field_done.jsx';
|
import saveCustomFieldDone from './reducers/save_custom_field_done.jsx';
|
||||||
import saveCustomFieldFailed from './reducers/save_custom_field_failed.jsx';
|
import saveCustomFieldFailed from './reducers/save_custom_field_failed.jsx';
|
||||||
import saveCustomFieldStarted from './reducers/save_custom_field_started.jsx';
|
import saveCustomFieldStarted from './reducers/save_custom_field_started.jsx';
|
||||||
|
import customFieldDeleteClick from './reducers/custom_field_delete_click.jsx';
|
||||||
|
|
||||||
const saveFormStarted = saveFormStartedFactory(MailPoet);
|
const saveFormStarted = saveFormStartedFactory(MailPoet);
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ export default (defaultState) => (state = defaultState, action) => {
|
|||||||
case 'SWITCH_SIDEBAR_TAB': return switchSidebarTab(state, action);
|
case 'SWITCH_SIDEBAR_TAB': return switchSidebarTab(state, action);
|
||||||
case 'TOGGLE_SIDEBAR': return toggleSidebar(state, action);
|
case 'TOGGLE_SIDEBAR': return toggleSidebar(state, action);
|
||||||
case 'TOGGLE_SIDEBAR_PANEL': return toggleSidebarPanel(state, action);
|
case 'TOGGLE_SIDEBAR_PANEL': return toggleSidebarPanel(state, action);
|
||||||
|
case 'CUSTOM_FIELD_DELETE_CLICK': return customFieldDeleteClick(state, action);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
export default (state) => ({
|
||||||
|
...state,
|
||||||
|
displayCustomFieldDeleteConfirm: true,
|
||||||
|
});
|
@@ -32,6 +32,9 @@ export default {
|
|||||||
getIsCustomFieldSaving(state) {
|
getIsCustomFieldSaving(state) {
|
||||||
return state.isCustomFieldSaving;
|
return state.isCustomFieldSaving;
|
||||||
},
|
},
|
||||||
|
getDisplayCustomFieldDeleteConfirm(state) {
|
||||||
|
return state.displayCustomFieldDeleteConfirm;
|
||||||
|
},
|
||||||
getDismissibleNotices(state) {
|
getDismissibleNotices(state) {
|
||||||
return state.notices.filter((notice) => notice.isDismissible === true);
|
return state.notices.filter((notice) => notice.isDismissible === true);
|
||||||
},
|
},
|
||||||
|
@@ -51,6 +51,8 @@
|
|||||||
'customFieldsBlocksCategory': __('Custom Fields'),
|
'customFieldsBlocksCategory': __('Custom Fields'),
|
||||||
'customFieldNumberOfLines': __('Number of lines'),
|
'customFieldNumberOfLines': __('Number of lines'),
|
||||||
'customFieldSaveCTA': _x('Update custom field', 'Text on the save button'),
|
'customFieldSaveCTA': _x('Update custom field', 'Text on the save button'),
|
||||||
|
'customFieldDeleteCTA': _x('Delete this custom field', 'Text on the delete button'),
|
||||||
|
'customFieldDeleteConfirm': __('This field will be deleted for all your subscribers. Are you sure?'),
|
||||||
'customFieldDateType': __('Type of date'),
|
'customFieldDateType': __('Type of date'),
|
||||||
'customFieldDateFormat': __('Order'),
|
'customFieldDateFormat': __('Order'),
|
||||||
'customFieldDefaultToday': __('Preselect today’s date'),
|
'customFieldDefaultToday': __('Preselect today’s date'),
|
||||||
|
Reference in New Issue
Block a user