Add revert template confirmation modal
[MAILPOET-6336]
This commit is contained in:
committed by
Rostislav Wolný
parent
fb74526d9d
commit
c7049468c2
@@ -4,10 +4,15 @@ import {
|
|||||||
PanelRow,
|
PanelRow,
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
|
Modal,
|
||||||
|
Button,
|
||||||
|
Flex,
|
||||||
|
FlexItem,
|
||||||
} from '@wordpress/components';
|
} from '@wordpress/components';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { useSelect } from '@wordpress/data';
|
import { useSelect, useDispatch } from '@wordpress/data';
|
||||||
import { Icon, layout, moreVertical } from '@wordpress/icons';
|
import { Icon, layout, moreVertical } from '@wordpress/icons';
|
||||||
|
import { useState } from '@wordpress/element';
|
||||||
import { storeName } from '../../store';
|
import { storeName } from '../../store';
|
||||||
|
|
||||||
export function TemplateInfo() {
|
export function TemplateInfo() {
|
||||||
@@ -15,10 +20,15 @@ export function TemplateInfo() {
|
|||||||
( select ) => select( storeName ).getCurrentTemplate(),
|
( select ) => select( storeName ).getCurrentTemplate(),
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
const [ isResetConfirmOpen, setResetConfirmOpen ] = useState( false );
|
||||||
|
const { revertAndSaveTemplate } = useDispatch( storeName );
|
||||||
|
|
||||||
// @ts-expect-error Todo template type is not defined
|
// @ts-expect-error Todo template type is not defined
|
||||||
const description = template?.description || '';
|
const description = template?.description || '';
|
||||||
|
const closeResetConfirm = () => setResetConfirmOpen( false );
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<Panel className="mailpoet-email-sidebar__email-type-info">
|
<Panel className="mailpoet-email-sidebar__email-type-info">
|
||||||
<PanelBody>
|
<PanelBody>
|
||||||
<PanelRow>
|
<PanelRow>
|
||||||
@@ -34,11 +44,15 @@ export function TemplateInfo() {
|
|||||||
</h2>
|
</h2>
|
||||||
<DropdownMenu
|
<DropdownMenu
|
||||||
icon={ moreVertical }
|
icon={ moreVertical }
|
||||||
label={ __( 'Template actions', 'mailpoet' ) }
|
label={ __(
|
||||||
|
'Template actions',
|
||||||
|
'mailpoet'
|
||||||
|
) }
|
||||||
>
|
>
|
||||||
{ ( { onClose } ) => (
|
{ ( { onClose } ) => (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
onClick={ () => {
|
onClick={ () => {
|
||||||
|
setResetConfirmOpen( true );
|
||||||
onClose();
|
onClose();
|
||||||
} }
|
} }
|
||||||
info={ __(
|
info={ __(
|
||||||
@@ -62,5 +76,42 @@ export function TemplateInfo() {
|
|||||||
</PanelRow>
|
</PanelRow>
|
||||||
</PanelBody>
|
</PanelBody>
|
||||||
</Panel>
|
</Panel>
|
||||||
|
{ isResetConfirmOpen && (
|
||||||
|
<Modal
|
||||||
|
title={ __( 'Reset template to default', 'mailpoet' ) }
|
||||||
|
size="medium"
|
||||||
|
onRequestClose={ closeResetConfirm }
|
||||||
|
__experimentalHideHeader
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
{ __(
|
||||||
|
'Reset to default and clear all customization?',
|
||||||
|
'mailpoet'
|
||||||
|
) }
|
||||||
|
</p>
|
||||||
|
<Flex justify={ 'end' }>
|
||||||
|
<FlexItem>
|
||||||
|
<Button
|
||||||
|
variant="tertiary"
|
||||||
|
onClick={ closeResetConfirm }
|
||||||
|
>
|
||||||
|
{ __( 'Cancel', 'mailpoet' ) }
|
||||||
|
</Button>
|
||||||
|
</FlexItem>
|
||||||
|
<FlexItem>
|
||||||
|
<Button
|
||||||
|
variant="primary"
|
||||||
|
onClick={ async () => {
|
||||||
|
await revertAndSaveTemplate( template );
|
||||||
|
closeResetConfirm();
|
||||||
|
} }
|
||||||
|
>
|
||||||
|
{ __( 'Reset', 'mailpoet' ) }
|
||||||
|
</Button>
|
||||||
|
</FlexItem>
|
||||||
|
</Flex>
|
||||||
|
</Modal>
|
||||||
|
) }
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user