Skip to content

Commit 77781a3

Browse files
committed
♻️ Refactor DeleteAccount components
1 parent f3557ea commit 77781a3

2 files changed

Lines changed: 34 additions & 60 deletions

File tree

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
import { Container, Heading, Text } from "@chakra-ui/react"
2-
31
import DeleteConfirmation from "./DeleteConfirmation"
42

53
const DeleteAccount = () => {
64
return (
7-
<Container maxW="full">
8-
<Heading size="sm" py={4}>
9-
Delete Account
10-
</Heading>
11-
<Text>
12-
Permanently delete your data and everything associated with your
13-
account.
14-
</Text>
5+
<div className="max-w-md mt-4 rounded-lg border border-destructive/50 p-4">
6+
<h3 className="font-semibold text-destructive">Delete Account</h3>
7+
<p className="mt-1 text-sm text-muted-foreground">
8+
Permanently delete your account and all associated data.
9+
</p>
1510
<DeleteConfirmation />
16-
</Container>
11+
</div>
1712
)
1813
}
14+
1915
export default DeleteAccount

frontend/src/components/UserSettings/DeleteConfirmation.tsx

Lines changed: 27 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
import { Button, ButtonGroup, Text } from "@chakra-ui/react"
21
import { useMutation, useQueryClient } from "@tanstack/react-query"
3-
import { useState } from "react"
42
import { useForm } from "react-hook-form"
53

6-
import { type ApiError, UsersService } from "@/client"
4+
import { UsersService } from "@/client"
5+
import { Button } from "@/components/ui/button"
76
import {
8-
DialogActionTrigger,
9-
DialogBody,
10-
DialogCloseTrigger,
7+
Dialog,
8+
DialogClose,
119
DialogContent,
10+
DialogDescription,
1211
DialogFooter,
1312
DialogHeader,
14-
DialogRoot,
1513
DialogTitle,
1614
DialogTrigger,
1715
} from "@/components/ui/dialog"
16+
import { LoadingButton } from "@/components/ui/loading-button"
1817
import useAuth from "@/hooks/useAuth"
1918
import useCustomToast from "@/hooks/useCustomToast"
2019
import { handleError } from "@/utils"
2120

2221
const DeleteConfirmation = () => {
23-
const [isOpen, setIsOpen] = useState(false)
2422
const queryClient = useQueryClient()
25-
const { showSuccessToast } = useCustomToast()
23+
const { showSuccessToast, showErrorToast } = useCustomToast()
2624
const {
2725
handleSubmit,
2826
formState: { isSubmitting },
@@ -33,12 +31,9 @@ const DeleteConfirmation = () => {
3331
mutationFn: () => UsersService.deleteUserMe(),
3432
onSuccess: () => {
3533
showSuccessToast("Your account has been successfully deleted")
36-
setIsOpen(false)
3734
logout()
3835
},
39-
onError: (err: ApiError) => {
40-
handleError(err)
41-
},
36+
onError: handleError.bind(showErrorToast),
4237
onSettled: () => {
4338
queryClient.invalidateQueries({ queryKey: ["currentUser"] })
4439
},
@@ -49,58 +44,41 @@ const DeleteConfirmation = () => {
4944
}
5045

5146
return (
52-
<DialogRoot
53-
size={{ base: "xs", md: "md" }}
54-
role="alertdialog"
55-
placement="center"
56-
open={isOpen}
57-
onOpenChange={({ open }) => setIsOpen(open)}
58-
>
47+
<Dialog>
5948
<DialogTrigger asChild>
60-
<Button variant="solid" colorPalette="red" mt={4}>
61-
Delete
49+
<Button variant="destructive" className="mt-3">
50+
Delete Account
6251
</Button>
6352
</DialogTrigger>
64-
6553
<DialogContent>
6654
<form onSubmit={handleSubmit(onSubmit)}>
67-
<DialogCloseTrigger />
6855
<DialogHeader>
6956
<DialogTitle>Confirmation Required</DialogTitle>
70-
</DialogHeader>
71-
<DialogBody>
72-
<Text mb={4}>
57+
<DialogDescription>
7358
All your account data will be{" "}
7459
<strong>permanently deleted.</strong> If you are sure, please
7560
click <strong>"Confirm"</strong> to proceed. This action cannot be
7661
undone.
77-
</Text>
78-
</DialogBody>
62+
</DialogDescription>
63+
</DialogHeader>
7964

80-
<DialogFooter gap={2}>
81-
<ButtonGroup>
82-
<DialogActionTrigger asChild>
83-
<Button
84-
variant="subtle"
85-
colorPalette="gray"
86-
disabled={isSubmitting}
87-
>
88-
Cancel
89-
</Button>
90-
</DialogActionTrigger>
91-
<Button
92-
variant="solid"
93-
colorPalette="red"
94-
type="submit"
95-
loading={isSubmitting}
96-
>
97-
Delete
65+
<DialogFooter className="mt-4">
66+
<DialogClose asChild>
67+
<Button variant="outline" disabled={isSubmitting}>
68+
Cancel
9869
</Button>
99-
</ButtonGroup>
70+
</DialogClose>
71+
<LoadingButton
72+
variant="destructive"
73+
type="submit"
74+
loading={isSubmitting}
75+
>
76+
Delete
77+
</LoadingButton>
10078
</DialogFooter>
10179
</form>
10280
</DialogContent>
103-
</DialogRoot>
81+
</Dialog>
10482
)
10583
}
10684

0 commit comments

Comments
 (0)