1
1
import { InformationCircleIcon } from "@heroicons/react/outline" ;
2
+ import { TrashIcon } from "@heroicons/react/solid" ;
2
3
import crypto from "crypto" ;
3
4
import { GetServerSidePropsContext } from "next" ;
5
+ import { signOut } from "next-auth/react" ;
4
6
import { useRouter } from "next/router" ;
5
7
import { ComponentProps , FormEvent , RefObject , useEffect , useMemo , useRef , useState } from "react" ;
6
8
import Select from "react-select" ;
@@ -17,10 +19,11 @@ import prisma from "@lib/prisma";
17
19
import { trpc } from "@lib/trpc" ;
18
20
import { inferSSRProps } from "@lib/types/inferSSRProps" ;
19
21
20
- import { Dialog , DialogClose , DialogContent } from "@components/Dialog" ;
22
+ import { Dialog , DialogClose , DialogContent , DialogTrigger } from "@components/Dialog" ;
21
23
import ImageUploader from "@components/ImageUploader" ;
22
24
import SettingsShell from "@components/SettingsShell" ;
23
25
import Shell from "@components/Shell" ;
26
+ import ConfirmationDialogContent from "@components/dialog/ConfirmationDialogContent" ;
24
27
import { TextField } from "@components/form/fields" ;
25
28
import { Alert } from "@components/ui/Alert" ;
26
29
import Avatar from "@components/ui/Avatar" ;
@@ -112,6 +115,19 @@ function SettingsView(props: ComponentProps<typeof Settings> & { localeProp: str
112
115
} ,
113
116
} ) ;
114
117
118
+ const deleteAccount = async ( ) => {
119
+ await fetch ( "/api/user/me" , {
120
+ method : "DELETE" ,
121
+ headers : {
122
+ "Content-Type" : "application/json" ,
123
+ } ,
124
+ } ) . catch ( ( e ) => {
125
+ console . error ( `Error Removing user: ${ props . user . id } , email: ${ props . user . email } :` , e ) ;
126
+ } ) ;
127
+ // signout;
128
+ signOut ( { callbackUrl : "/auth/logout" } ) ;
129
+ } ;
130
+
115
131
const localeOptions = useMemo ( ( ) => {
116
132
return ( router . locales || [ ] ) . map ( ( locale ) => ( {
117
133
value : locale ,
@@ -409,6 +425,34 @@ function SettingsView(props: ComponentProps<typeof Settings> & { localeProp: str
409
425
</ div >
410
426
</ div >
411
427
</ div >
428
+ < h3 className = "font-bold leading-6 text-red-700 mt-7 text-md" > { t ( "danger_zone" ) } </ h3 >
429
+ < div >
430
+ < div className = "relative flex items-start" >
431
+ < Dialog >
432
+ < DialogTrigger asChild >
433
+ < Button
434
+ type = "button"
435
+ color = "warn"
436
+ StartIcon = { TrashIcon }
437
+ className = "text-red-700 border-2 border-red-700"
438
+ data-testid = "delete-account" >
439
+ { t ( "delete_account" ) }
440
+ </ Button >
441
+ </ DialogTrigger >
442
+ < ConfirmationDialogContent
443
+ variety = "danger"
444
+ title = { t ( "delete_account" ) }
445
+ confirmBtn = {
446
+ < Button color = "warn" data-testid = "delete-account-confirm" >
447
+ { t ( "confirm_delete_account" ) }
448
+ </ Button >
449
+ }
450
+ onConfirm = { ( ) => deleteAccount ( ) } >
451
+ { t ( "delete_account_confirmation_message" ) }
452
+ </ ConfirmationDialogContent >
453
+ </ Dialog >
454
+ </ div >
455
+ </ div >
412
456
</ div >
413
457
</ div >
414
458
< hr className = "mt-8" />
@@ -460,6 +504,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
460
504
theme : true ,
461
505
plan : true ,
462
506
brandColor : true ,
507
+ metadata : true ,
463
508
} ,
464
509
} ) ;
465
510
0 commit comments