@@ -6,17 +6,21 @@ import {
6
6
Dialog ,
7
7
DialogContent ,
8
8
DialogDescription ,
9
+ DialogHeader ,
10
+ DialogTitle ,
9
11
} from "@/components/ui/dialog" ;
10
12
import { isValidEmail } from "@/lib/validation" ;
11
- import { DialogTitle } from "@radix-ui/react-dialog " ;
13
+ import { deleteOuterbaseUser } from "@/outerbase-cloud/api-account " ;
12
14
import { Check , Copy } from "lucide-react" ;
13
- import { useMemo , useState } from "react" ;
15
+ import { useCallback , useMemo , useState } from "react" ;
16
+ import { toast } from "sonner" ;
14
17
15
18
export default function AccountFooter ( ) {
16
- const { session } = useSession ( ) ;
19
+ const { session, logout } = useSession ( ) ;
17
20
const [ open , setOpen ] = useState ( false ) ;
18
21
const [ copied , setCopied ] = useState ( false ) ;
19
22
const [ email , setEmail ] = useState ( "" ) ;
23
+ const [ loading , setLoading ] = useState ( false ) ;
20
24
21
25
const copyToClipboard = async ( ) => {
22
26
if ( ! session ) return ;
@@ -27,16 +31,36 @@ export default function AccountFooter() {
27
31
console . error ( "Failed to copy:" , error ) ;
28
32
}
29
33
} ;
34
+
30
35
const onClose = ( ) => {
31
36
setCopied ( false ) ;
32
37
setOpen ( false ) ;
33
38
setEmail ( "" ) ;
39
+ setLoading ( false ) ;
34
40
} ;
41
+
42
+ const onDeleteOuerbaseUser = useCallback ( ( ) => {
43
+ setLoading ( true ) ;
44
+ deleteOuterbaseUser ( )
45
+ . then ( ( ) => {
46
+ onClose ( ) ;
47
+ logout ( ) ;
48
+ } )
49
+ . catch ( ( err ) => {
50
+ setLoading ( false ) ;
51
+ toast . error ( err . message ) ;
52
+ } ) ;
53
+ } , [ logout ] ) ;
54
+
35
55
const fullName = useMemo ( ( ) => {
36
56
if ( ! session ) return ;
37
57
return session ?. user . first_name + " " + session ?. user . last_name ;
38
58
} , [ session ] ) ;
39
59
60
+ const disabled = useMemo ( ( ) => {
61
+ return ! isValidEmail ( email ) || email !== session ?. user . email ;
62
+ } , [ email , session ] ) ;
63
+
40
64
return (
41
65
< >
42
66
< Dialog
@@ -48,9 +72,12 @@ export default function AccountFooter() {
48
72
} }
49
73
>
50
74
< DialogContent className = "justify-items-start" >
51
- < DialogTitle >
52
- Confirm deletion of { fullName } ' account
53
- </ DialogTitle >
75
+ < DialogHeader >
76
+ < DialogTitle >
77
+ Confirm deletion of { fullName } ' account
78
+ </ DialogTitle >
79
+ </ DialogHeader >
80
+
54
81
< DialogDescription className = "text-base" >
55
82
Deleting this account will delete all Bases and Workspaces and
56
83
revoke all connections made to your databases. All members will lose
@@ -76,9 +103,11 @@ export default function AccountFooter() {
76
103
</ Label >
77
104
< div className = "flex flex-row gap-5" >
78
105
< Button
79
- disabled = { ! isValidEmail ( email ) }
80
- onClick = { onClose }
106
+ loading = { loading }
107
+ disabled = { disabled }
108
+ onClick = { onDeleteOuerbaseUser }
81
109
variant = "destructive"
110
+ shape = "base"
82
111
title = "I understand, delete my account"
83
112
/>
84
113
< Button variant = "secondary" onClick = { onClose } title = "Cancel" />
0 commit comments