PluginProbe
Code Snippets / 3.6.6
Code Snippets v3.6.6
3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 3.0.1 All 64 releases
code-snippets / js / components / SnippetForm / buttons / DeleteButton.tsx

DeleteButton.tsx in Code Snippets 3.6.6, at js/components/SnippetForm/buttons/DeleteButton.tsx

51 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { addQueryArgs } from '@wordpress/url'
2 import React, { useState } from 'react'
3 import { __ } from '@wordpress/i18n'
4 import { Button } from '../../common/Button'
5 import { ConfirmDialog } from '../../common/ConfirmDialog'
6 import { useSnippetsAPI } from '../../../hooks/useSnippets'
7 import { useSnippetForm } from '../../../hooks/useSnippetForm'
8
9 export const DeleteButton: React.FC = () => {
10 const api = useSnippetsAPI()
11 const { snippet, setIsWorking, isWorking, handleRequestError } = useSnippetForm()
12 const [isDialogOpen, setIsDialogOpen] = useState(false)
13
14 return (
15 <>
16 <Button
17 name="delete_snippet"
18 onClick={() => setIsDialogOpen(true)}
19 disabled={isWorking}
20 >
21 {__('Delete', 'code-snippets')}
22 </Button>
23
24 <ConfirmDialog
25 open={isDialogOpen}
26 title={__('Permanently delete?', 'code-snippets')}
27 confirmLabel={__('Delete', 'code-snippets')}
28 confirmButtonClassName="is-destructive"
29 onCancel={() => setIsDialogOpen(false)}
30 onConfirm={() => {
31 setIsDialogOpen(false)
32 setIsWorking(true)
33
34 api.delete(snippet)
35 .then(() => {
36 setIsWorking(false)
37 window.location.replace(addQueryArgs(window.CODE_SNIPPETS?.urls.manage, { result: 'deleted' }))
38 })
39 .catch((error: unknown) => handleRequestError(error, __('Could not delete snippet.', 'code-snippets')))
40 }}
41 >
42 <p>
43 {__('You are about to permanently delete this snippet.', 'code-snippets')}{' '}
44 {__('Are you sure?', 'code-snippets')}
45 </p>
46 <p><strong>{__('This action cannot be undone.', 'code-snippets')}</strong></p>
47 </ConfirmDialog>
48 </>
49 )
50 }
51