1- import { Button , ButtonGroup , Text } from "@chakra-ui/react"
21import { useMutation , useQueryClient } from "@tanstack/react-query"
3- import { useState } from "react"
42import { 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"
76import {
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"
1817import useAuth from "@/hooks/useAuth"
1918import useCustomToast from "@/hooks/useCustomToast"
2019import { handleError } from "@/utils"
2120
2221const 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