Skip to content

Commit 16d8670

Browse files
authored
refactor: use useConfirm @primer hook (#2313)
Signed-off-by: Adam Setch <[email protected]>
1 parent 731bbcf commit 16d8670

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed
Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,42 @@
1-
import { type FC, useCallback, useContext, useState } from 'react';
1+
import { type FC, useContext } from 'react';
22

3-
import { Button, Dialog, Stack, Text } from '@primer/react';
3+
import { Button, Stack, useConfirm } from '@primer/react';
44

55
import { AppContext } from '../../context/App';
6+
import { rendererLogInfo } from '../../utils/logger';
67

78
export const SettingsReset: FC = () => {
89
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+
};
1529

1630
return (
1731
<Stack align="center">
1832
<Button
1933
data-testid="settings-reset"
20-
onClick={() => setIsOpen(!isOpen)}
34+
onClick={handleReset}
2135
sx={{ width: '200px' }}
2236
variant="danger"
2337
>
2438
Reset Settings
2539
</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-
)}
4940
</Stack>
5041
);
5142
};

0 commit comments

Comments
 (0)