From 6e9fa5355e05ef7c44e8bdd0b0ce9e034b3264d5 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Wed, 10 Jul 2024 15:12:53 +0400 Subject: [PATCH] add confirm dialog --- src/editor-sidebar/reset-theme.js | 134 ++++++++++++++++++------------ 1 file changed, 82 insertions(+), 52 deletions(-) diff --git a/src/editor-sidebar/reset-theme.js b/src/editor-sidebar/reset-theme.js index a23a4805..88d08821 100644 --- a/src/editor-sidebar/reset-theme.js +++ b/src/editor-sidebar/reset-theme.js @@ -5,6 +5,8 @@ import { __ } from '@wordpress/i18n'; import { useDispatch, useSelect } from '@wordpress/data'; import { store as noticesStore } from '@wordpress/notices'; import { + // eslint-disable-next-line @wordpress/no-unsafe-wp-apis + __experimentalConfirmDialog as ConfirmDialog, // eslint-disable-next-line @wordpress/no-unsafe-wp-apis __experimentalVStack as VStack, PanelBody, @@ -12,6 +14,7 @@ import { CheckboxControl, } from '@wordpress/components'; import { trash } from '@wordpress/icons'; +import { useState } from '@wordpress/element'; import { store as preferencesStore } from '@wordpress/preferences'; /** @@ -38,6 +41,7 @@ function ResetTheme() { const { set: setPreferences } = useDispatch( preferencesStore ); const { createErrorNotice } = useDispatch( noticesStore ); + const [ isConfirmDialogOpen, setIsConfirmDialogOpen ] = useState( false ); const handleTogglePreference = ( key ) => { setPreferences( PREFERENCE_SCOPE, PREFERENCE_KEY, { @@ -46,9 +50,14 @@ function ResetTheme() { } ); }; + const toggleConfirmDialog = () => { + setIsConfirmDialogOpen( ! isConfirmDialogOpen ); + }; + const handleResetTheme = async () => { try { await resetTheme( preferences ); + toggleConfirmDialog(); // eslint-disable-next-line no-alert window.alert( __( @@ -68,62 +77,83 @@ function ResetTheme() { }; return ( - - - - handleTogglePreference( 'resetStyles' ) } + <> + + { __( + 'Are you sure you want to reset the theme? This action cannot be undone.', + 'create-block-theme' + ) } + + + + + + handleTogglePreference( 'resetStyles' ) + } + /> - - handleTogglePreference( 'resetTemplates' ) - } - /> + + handleTogglePreference( 'resetTemplates' ) + } + /> - - handleTogglePreference( 'resetTemplateParts' ) - } - /> + + handleTogglePreference( 'resetTemplateParts' ) + } + /> -