|
1 | | -import { type FC, useCallback, useContext, useState } from 'react'; |
| 1 | +import { type FC, useContext } from 'react'; |
2 | 2 |
|
3 | | -import { Button, Dialog, Stack, Text } from '@primer/react'; |
| 3 | +import { Button, Stack, useConfirm } from '@primer/react'; |
4 | 4 |
|
5 | 5 | import { AppContext } from '../../context/App'; |
| 6 | +import { rendererLogInfo } from '../../utils/logger'; |
6 | 7 |
|
7 | 8 | export const SettingsReset: FC = () => { |
8 | 9 | const { resetSettings } = useContext(AppContext); |
9 | | - const [isOpen, setIsOpen] = useState(false); |
10 | | - const onDialogClose = useCallback(() => setIsOpen(false), []); |
11 | | - const onDialogProceed = useCallback(() => { |
12 | | - resetSettings(); |
13 | | - setIsOpen(false); |
14 | | - }, [resetSettings]); |
| 10 | + |
| 11 | + const confirm = useConfirm(); |
| 12 | + |
| 13 | + const handleReset = async () => { |
| 14 | + const confirmed = await confirm({ |
| 15 | + title: 'Reset settings?', |
| 16 | + content: |
| 17 | + 'Please confirm that you want to reset all settings to the Gitify defaults', |
| 18 | + |
| 19 | + confirmButtonContent: 'Reset', |
| 20 | + cancelButtonContent: 'Cancel', |
| 21 | + confirmButtonType: 'danger', |
| 22 | + }); |
| 23 | + |
| 24 | + if (confirmed) { |
| 25 | + resetSettings(); |
| 26 | + rendererLogInfo('settingsReset', 'Settings have been reset to defaults'); |
| 27 | + } |
| 28 | + }; |
15 | 29 |
|
16 | 30 | return ( |
17 | 31 | <Stack align="center"> |
18 | 32 | <Button |
19 | 33 | data-testid="settings-reset" |
20 | | - onClick={() => setIsOpen(!isOpen)} |
| 34 | + onClick={handleReset} |
21 | 35 | sx={{ width: '200px' }} |
22 | 36 | variant="danger" |
23 | 37 | > |
24 | 38 | Reset Settings |
25 | 39 | </Button> |
26 | | - {isOpen && ( |
27 | | - <Dialog |
28 | | - data-testid="reset-dialog" |
29 | | - footerButtons={[ |
30 | | - { |
31 | | - buttonType: 'default', |
32 | | - content: 'Cancel', |
33 | | - onClick: onDialogClose, |
34 | | - }, |
35 | | - { |
36 | | - buttonType: 'danger', |
37 | | - content: 'Reset', |
38 | | - onClick: onDialogProceed, |
39 | | - }, |
40 | | - ]} |
41 | | - onClose={onDialogClose} |
42 | | - title="Reset Settings" |
43 | | - width="large" |
44 | | - > |
45 | | - Please confirm that you want to reset all settings to the{' '} |
46 | | - <Text as="strong">Gitify defaults</Text> |
47 | | - </Dialog> |
48 | | - )} |
49 | 40 | </Stack> |
50 | 41 | ); |
51 | 42 | }; |
0 commit comments