PluginProbe
Code Snippets / 3.10.0
Code Snippets v3.10.0
4.0.0-beta.2 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 All 65 releases
code-snippets / js / components / EditorSidebar / actions / DeleteButton.tsx

DeleteButton.tsx in Code Snippets 3.10.0, at js/components/EditorSidebar/actions/DeleteButton.tsx

53 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 { useRestAPI } from '../../../hooks/useRestAPI'
5 import { Button } from '../../common/Button'
6 import { ConfirmDialog } from '../../common/ConfirmDialog'
7 import { useSnippetForm } from '../../../hooks/useSnippetForm'
8
9 export const DeleteButton: React.FC = () => {
10 const { snippetsAPI } = useRestAPI()
11 const { snippet, setIsWorking, isWorking, handleRequestError } = useSnippetForm()
12 const [isDialogOpen, setIsDialogOpen] = useState(false)
13
14 return (
15 <>
16 <Button
17 id="delete-snippet"
18 className="delete-button"
19 disabled={isWorking}
20 onClick={() => {
21 setIsDialogOpen(true)
22 }}
23 >
24 {__('Delete', 'code-snippets')}
25 </Button>
26
27 <ConfirmDialog
28 open={isDialogOpen}
29 title={__('Delete?', 'code-snippets')}
30 confirmLabel={__('Delete', 'code-snippets')}
31 confirmButtonClassName="is-destructive"
32 onCancel={() => setIsDialogOpen(false)}
33 onConfirm={() => {
34 setIsDialogOpen(false)
35 setIsWorking(true)
36
37 snippetsAPI.delete(snippet)
38 .then(() => {
39 setIsWorking(false)
40 window.location.replace(addQueryArgs(window.CODE_SNIPPETS?.urls.manage, { result: 'deleted' }))
41 })
42 .catch((error: unknown) => handleRequestError(error, __('Could not delete snippet.', 'code-snippets')))
43 }}
44 >
45 <p style={{ marginBlockStart: 0 }}>
46 {__('You are about to delete this snippet.', 'code-snippets')}{' '}
47 {__('Are you sure?', 'code-snippets')}
48 </p>
49 </ConfirmDialog>
50 </>
51 )
52 }
53