Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add confirmation step when deleting a Template #52236

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions packages/edit-site/src/components/template-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
*/
import { useDispatch, useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { useState } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
import {
DropdownMenu,
MenuGroup,
MenuItem,
__experimentalConfirmDialog as ConfirmDialog,
} from '@wordpress/components';
import { moreVertical } from '@wordpress/icons';
import { store as noticesStore } from '@wordpress/notices';

Expand Down Expand Up @@ -84,17 +90,14 @@ export default function TemplateActions( {
template={ template }
onClose={ onClose }
/>
<MenuItem
isDestructive
isTertiary
onClick={ () => {
<DeleteMenuItem
onRemove={ () => {
removeTemplate( template );
onRemove?.();
onClose();
} }
>
{ __( 'Delete' ) }
</MenuItem>
isTemplate={ template.type === 'wp_template' }
/>
</>
) }
{ isRevertable && (
Expand All @@ -115,3 +118,30 @@ export default function TemplateActions( {
</DropdownMenu>
);
}

function DeleteMenuItem( { onRemove, isTemplate } ) {
const [ isModalOpen, setIsModalOpen ] = useState( false );
return (
<>
<MenuItem
isDestructive
isTertiary
onClick={ () => setIsModalOpen( true ) }
>
{ __( 'Delete' ) }
</MenuItem>
<ConfirmDialog
isOpen={ isModalOpen }
onConfirm={ onRemove }
onCancel={ () => setIsModalOpen( false ) }
confirmButtonText={ __( 'Delete' ) }
>
{ isTemplate
? __( 'Are you sure you want to delete this template?' )
: __(
'Are you sure you want to delete this template part?'
) }
</ConfirmDialog>
</>
);
}