@@ -2,13 +2,13 @@ import { DropdownMenu, Icon, MenuGroup, MenuItem, Spinner } from '@wordpress/com
22import { sprintf } from '@wordpress/i18n' ;
33import { moreVertical , trash } from '@wordpress/icons' ;
44import { useI18n } from '@wordpress/react-i18n' ;
5- import { useCallback , useState } from 'react' ;
5+ import { useCallback , useState , useEffect } from 'react' ;
66import { WPCOM_PROFILE_URL } from '../constants' ;
77import { useAuth } from '../hooks/use-auth' ;
88import { useDeleteSnapshot } from '../hooks/use-delete-snapshot' ;
9+ import { useFetchSnapshots } from '../hooks/use-fetch-snaphsots' ;
910import { useIpcListener } from '../hooks/use-ipc-listener' ;
1011import { useOffline } from '../hooks/use-offline' ;
11- import { useSiteDetails } from '../hooks/use-site-details' ;
1212import { useSiteUsage } from '../hooks/use-site-usage' ;
1313import { cx } from '../lib/cx' ;
1414import { getIpcApi } from '../lib/get-ipc-api' ;
@@ -142,9 +142,10 @@ const SnapshotInfo = ( {
142142
143143export default function UserSettings ( ) {
144144 const { __ } = useI18n ( ) ;
145+ const [ deletedAllSnapshots , setDeletedAllSnapshots ] = useState ( false ) ;
145146 const { isAuthenticated, authenticate, logout, user } = useAuth ( ) ;
146- const { snapshots } = useSiteDetails ( ) ;
147147 const { siteLimit, siteCount, isLoading : isLoadingSiteUsage } = useSiteUsage ( ) ;
148+ const { allSnapshots, isLoading : isLoadingAllSnapshots } = useFetchSnapshots ( ) ;
148149 const { deleteAllSnapshots, loadingDeletingAllSnapshots } = useDeleteSnapshot ( {
149150 displayAlert : true ,
150151 } ) ;
@@ -161,12 +162,39 @@ export default function UserSettings() {
161162 setNeedsToOpenUserSettings ( ! needsToOpenUserSettings ) ;
162163 } ) ;
163164
165+ useEffect ( ( ) => {
166+ if ( deletedAllSnapshots && ! loadingDeletingAllSnapshots ) {
167+ setDeletedAllSnapshots ( false ) ;
168+ getIpcApi ( ) . showNotification ( {
169+ title : __ ( 'Delete Successful' ) ,
170+ body : __ ( 'All demo sites have been deleted.' ) ,
171+ } ) ;
172+ }
173+ } , [ __ , loadingDeletingAllSnapshots , deletedAllSnapshots ] ) ;
174+
164175 const onRemoveSnapshots = useCallback ( async ( ) => {
165- if ( snapshots ? .length === 0 ) {
176+ if ( ! allSnapshots || allSnapshots . length === 0 ) {
166177 return ;
167178 }
168- await deleteAllSnapshots ( snapshots ) ;
169- } , [ snapshots , deleteAllSnapshots ] ) ;
179+
180+ const CANCEL_BUTTON_INDEX = 0 ;
181+ const DELETE_BUTTON_INDEX = 1 ;
182+
183+ const { response } = await getIpcApi ( ) . showMessageBox ( {
184+ type : 'warning' ,
185+ message : __ ( 'Delete all demo sites' ) ,
186+ detail : __ (
187+ 'All demo sites that exist for your WordPress.com account, along with all posts, pages, comments, and media, will be lost.'
188+ ) ,
189+ buttons : [ __ ( 'Cancel' ) , __ ( 'Delete all' ) ] ,
190+ cancelId : CANCEL_BUTTON_INDEX ,
191+ } ) ;
192+
193+ if ( response === DELETE_BUTTON_INDEX ) {
194+ await deleteAllSnapshots ( allSnapshots ) ;
195+ setDeletedAllSnapshots ( true ) ;
196+ }
197+ } , [ allSnapshots , deleteAllSnapshots , __ ] ) ;
170198
171199 return (
172200 < >
@@ -201,8 +229,9 @@ export default function UserSettings() {
201229 isDisabled = {
202230 siteCount === 0 ||
203231 loadingDeletingAllSnapshots ||
232+ isLoadingAllSnapshots ||
204233 isLoadingSiteUsage ||
205- snapshots . length === 0 ||
234+ allSnapshots ? .length === 0 ||
206235 isOffline
207236 }
208237 siteCount = { siteCount }
0 commit comments