import { addQueryArgs } from '@wordpress/url' import React, { useState } from 'react' import { __ } from '@wordpress/i18n' import { Button } from '../../common/Button' import { ConfirmDialog } from '../../common/ConfirmDialog' import { useSnippetsAPI } from '../../../hooks/useSnippets' import { useSnippetForm } from '../../../hooks/useSnippetForm' export const DeleteButton: React.FC = () => { const api = useSnippetsAPI() const { snippet, setIsWorking, isWorking, handleRequestError } = useSnippetForm() const [isDialogOpen, setIsDialogOpen] = useState(false) return ( <> setIsDialogOpen(false)} onConfirm={() => { setIsDialogOpen(false) setIsWorking(true) api.delete(snippet) .then(() => { setIsWorking(false) window.location.replace(addQueryArgs(window.CODE_SNIPPETS?.urls.manage, { result: 'deleted' })) }) .catch((error: unknown) => handleRequestError(error, __('Could not delete snippet.', 'code-snippets'))) }} >

{__('You are about to permanently delete this snippet.', 'code-snippets')}{' '} {__('Are you sure?', 'code-snippets')}

{__('This action cannot be undone.', 'code-snippets')}

) }