@@ -21,15 +21,17 @@ export const ProfileEdit = (): JSX.Element => {
21
21
const nav : NavigateFunction = useNavigate ( ) ;
22
22
23
23
const session : Session = React . useContext ( SessionContext ) ;
24
+ const [ showDelete , setShowDelete ] = React . useState < boolean > ( false ) ;
24
25
let user : User = session . user ;
25
26
26
27
// Form
27
28
const { register, handleSubmit, watch, reset, formState : { errors } } = useForm < Inputs > ( ) ;
28
29
29
30
React . useEffect ( ( ) => {
31
+ // console.log(user)
30
32
if ( "username" in user ) {
31
- console . log ( "User:" , { ...session . user , graduating_year : session . user . graduating_year ! . toString ( ) } ) ;
32
- reset ( { ...session . user , graduating_year : session . user . graduating_year ! . toString ( ) } ) ;
33
+ // console.log("User:", { ...session.user, graduating_year: session.user.graduating_year? .toString() });
34
+ reset ( { ...session . user , graduating_year : session . user . graduating_year ? .toString ( ) } ) ;
33
35
}
34
36
} , [ session . user ] ) ;
35
37
@@ -42,6 +44,15 @@ export const ProfileEdit = (): JSX.Element => {
42
44
} ) ;
43
45
}
44
46
47
+ const deleteUser = ( ) => {
48
+ session . request ( 'post' , `${ Routes . USER } /me/delete` ) . then ( ( res ) => {
49
+ if ( res . status === 200 ) {
50
+ session . refreshUser ( ) ;
51
+ nav ( `/user/${ user . username } ` )
52
+ }
53
+ } )
54
+ }
55
+
45
56
// console.log(watch("graduating_year")) // watch input value by passing the name of it
46
57
// console.log(user.timezone);
47
58
@@ -955,13 +966,13 @@ export const ProfileEdit = (): JSX.Element => {
955
966
956
967
< div className = "field" >
957
968
< div className = "label" > < label htmlFor = "id_first_name" > First name:</ label > </ div >
958
- < span > < input { ...register ( "first_name" ) } type = "text" name = "first_name" value = "Jimmy" maxLength = { 150 } id = "id_first_name" /> < div data-lastpass-icon-root = "true" style = { { position : "relative" , height : "0px" , width : "0px" , float : "left" } } > < template > < svg width = "24" height = "24" viewBox = "0 0 24 24" fill = "none" data-lastpass-icon = "true" style = { { position : "absolute" , cursor : "pointer" , height : "22px" , maxHeight : "22px" , width : "22px" , maxWidth : "22px" , top : "11.5px" , left : "154px" , zIndex : "auto" , color : "rgb(215, 64, 58)" } } > < rect x = "0.680176" y = "0.763062" width = "22.6392" height = "22.4737" rx = "4" fill = "currentColor" > </ rect > < path fill-rule = "evenodd" clip-rule = "evenodd" d = "M19.7935 7.9516C19.7935 7.64414 20.0427 7.3949 20.3502 7.3949C20.6576 7.3949 20.9069 7.64414 20.9069 7.9516V16.0487C20.9069 16.3562 20.6576 16.6054 20.3502 16.6054C20.0427 16.6054 19.7935 16.3562 19.7935 16.0487V7.9516Z" fill = "white" > </ path > < path fill-rule = "evenodd" clip-rule = "evenodd" d = "M4.76288 13.6577C5.68525 13.6577 6.43298 12.9154 6.43298 11.9998C6.43298 11.0842 5.68525 10.3419 4.76288 10.3419C3.8405 10.3419 3.09277 11.0842 3.09277 11.9998C3.09277 12.9154 3.8405 13.6577 4.76288 13.6577Z" fill = "white" > </ path > < path fill-rule = "evenodd" clip-rule = "evenodd" d = "M10.3298 13.6577C11.2521 13.6577 11.9999 12.9154 11.9999 11.9998C11.9999 11.0842 11.2521 10.3419 10.3298 10.3419C9.4074 10.3419 8.65967 11.0842 8.65967 11.9998C8.65967 12.9154 9.4074 13.6577 10.3298 13.6577Z" fill = "white" > </ path > < path fill-rule = "evenodd" clip-rule = "evenodd" d = "M15.8964 13.6577C16.8188 13.6577 17.5665 12.9154 17.5665 11.9998C17.5665 11.0842 16.8188 10.3419 15.8964 10.3419C14.974 10.3419 14.2263 11.0842 14.2263 11.9998C14.2263 12.9154 14.974 13.6577 15.8964 13.6577Z" fill = "white" > </ path > </ svg > </ template > </ div > </ span >
969
+ < span > < input { ...register ( "first_name" ) } type = "text" name = "first_name" value = { `${ user ?. first_name } ` } maxLength = { 150 } id = "id_first_name" /> < div data-lastpass-icon-root = "true" style = { { position : "relative" , height : "0px" , width : "0px" , float : "left" } } > < template > < svg width = "24" height = "24" viewBox = "0 0 24 24" fill = "none" data-lastpass-icon = "true" style = { { position : "absolute" , cursor : "pointer" , height : "22px" , maxHeight : "22px" , width : "22px" , maxWidth : "22px" , top : "11.5px" , left : "154px" , zIndex : "auto" , color : "rgb(215, 64, 58)" } } > < rect x = "0.680176" y = "0.763062" width = "22.6392" height = "22.4737" rx = "4" fill = "currentColor" > </ rect > < path fill-rule = "evenodd" clip-rule = "evenodd" d = "M19.7935 7.9516C19.7935 7.64414 20.0427 7.3949 20.3502 7.3949C20.6576 7.3949 20.9069 7.64414 20.9069 7.9516V16.0487C20.9069 16.3562 20.6576 16.6054 20.3502 16.6054C20.0427 16.6054 19.7935 16.3562 19.7935 16.0487V7.9516Z" fill = "white" > </ path > < path fill-rule = "evenodd" clip-rule = "evenodd" d = "M4.76288 13.6577C5.68525 13.6577 6.43298 12.9154 6.43298 11.9998C6.43298 11.0842 5.68525 10.3419 4.76288 10.3419C3.8405 10.3419 3.09277 11.0842 3.09277 11.9998C3.09277 12.9154 3.8405 13.6577 4.76288 13.6577Z" fill = "white" > </ path > < path fill-rule = "evenodd" clip-rule = "evenodd" d = "M10.3298 13.6577C11.2521 13.6577 11.9999 12.9154 11.9999 11.9998C11.9999 11.0842 11.2521 10.3419 10.3298 10.3419C9.4074 10.3419 8.65967 11.0842 8.65967 11.9998C8.65967 12.9154 9.4074 13.6577 10.3298 13.6577Z" fill = "white" > </ path > < path fill-rule = "evenodd" clip-rule = "evenodd" d = "M15.8964 13.6577C16.8188 13.6577 17.5665 12.9154 17.5665 11.9998C17.5665 11.0842 16.8188 10.3419 15.8964 10.3419C14.974 10.3419 14.2263 11.0842 14.2263 11.9998C14.2263 12.9154 14.974 13.6577 15.8964 13.6577Z" fill = "white" > </ path > </ svg > </ template > </ div > </ span >
959
970
</ div >
960
971
961
972
962
973
< div className = "field" >
963
974
< div className = "label" > < label htmlFor = "id_last_name" > Last name:</ label > </ div >
964
- < span > < input { ...register ( "last_name" ) } type = "text" name = "last_name" value = "Liu" maxLength = { 150 } id = "id_last_name" /> < div data-lastpass-icon-root = "true" style = { { position : "relative" , height : "0px" , width : "0px" , float : "left" } } > < template > < svg width = "24" height = "24" viewBox = "0 0 24 24" fill = "none" data-lastpass-icon = "true" style = { { position : "absolute" , cursor : "pointer" , height : "22px" , maxHeight : "22px" , width : "22px" , maxWidth : "22px" , top : "11.5px" , left : "154px" , zIndex : "auto" , color : "rgb(215, 64, 58)" } } > < rect x = "0.680176" y = "0.763062" width = "22.6392" height = "22.4737" rx = "4" fill = "currentColor" > </ rect > < path fill-rule = "evenodd" clip-rule = "evenodd" d = "M19.7935 7.9516C19.7935 7.64414 20.0427 7.3949 20.3502 7.3949C20.6576 7.3949 20.9069 7.64414 20.9069 7.9516V16.0487C20.9069 16.3562 20.6576 16.6054 20.3502 16.6054C20.0427 16.6054 19.7935 16.3562 19.7935 16.0487V7.9516Z" fill = "white" > </ path > < path fill-rule = "evenodd" clip-rule = "evenodd" d = "M4.76288 13.6577C5.68525 13.6577 6.43298 12.9154 6.43298 11.9998C6.43298 11.0842 5.68525 10.3419 4.76288 10.3419C3.8405 10.3419 3.09277 11.0842 3.09277 11.9998C3.09277 12.9154 3.8405 13.6577 4.76288 13.6577Z" fill = "white" > </ path > < path fill-rule = "evenodd" clip-rule = "evenodd" d = "M10.3298 13.6577C11.2521 13.6577 11.9999 12.9154 11.9999 11.9998C11.9999 11.0842 11.2521 10.3419 10.3298 10.3419C9.4074 10.3419 8.65967 11.0842 8.65967 11.9998C8.65967 12.9154 9.4074 13.6577 10.3298 13.6577Z" fill = "white" > </ path > < path fill-rule = "evenodd" clip-rule = "evenodd" d = "M15.8964 13.6577C16.8188 13.6577 17.5665 12.9154 17.5665 11.9998C17.5665 11.0842 16.8188 10.3419 15.8964 10.3419C14.974 10.3419 14.2263 11.0842 14.2263 11.9998C14.2263 12.9154 14.974 13.6577 15.8964 13.6577Z" fill = "white" > </ path > </ svg > </ template > </ div > </ span >
975
+ < span > < input { ...register ( "last_name" ) } type = "text" name = "last_name" value = { `${ user ?. last_name } ` } maxLength = { 150 } id = "id_last_name" /> < div data-lastpass-icon-root = "true" style = { { position : "relative" , height : "0px" , width : "0px" , float : "left" } } > < template > < svg width = "24" height = "24" viewBox = "0 0 24 24" fill = "none" data-lastpass-icon = "true" style = { { position : "absolute" , cursor : "pointer" , height : "22px" , maxHeight : "22px" , width : "22px" , maxWidth : "22px" , top : "11.5px" , left : "154px" , zIndex : "auto" , color : "rgb(215, 64, 58)" } } > < rect x = "0.680176" y = "0.763062" width = "22.6392" height = "22.4737" rx = "4" fill = "currentColor" > </ rect > < path fill-rule = "evenodd" clip-rule = "evenodd" d = "M19.7935 7.9516C19.7935 7.64414 20.0427 7.3949 20.3502 7.3949C20.6576 7.3949 20.9069 7.64414 20.9069 7.9516V16.0487C20.9069 16.3562 20.6576 16.6054 20.3502 16.6054C20.0427 16.6054 19.7935 16.3562 19.7935 16.0487V7.9516Z" fill = "white" > </ path > < path fill-rule = "evenodd" clip-rule = "evenodd" d = "M4.76288 13.6577C5.68525 13.6577 6.43298 12.9154 6.43298 11.9998C6.43298 11.0842 5.68525 10.3419 4.76288 10.3419C3.8405 10.3419 3.09277 11.0842 3.09277 11.9998C3.09277 12.9154 3.8405 13.6577 4.76288 13.6577Z" fill = "white" > </ path > < path fill-rule = "evenodd" clip-rule = "evenodd" d = "M10.3298 13.6577C11.2521 13.6577 11.9999 12.9154 11.9999 11.9998C11.9999 11.0842 11.2521 10.3419 10.3298 10.3419C9.4074 10.3419 8.65967 11.0842 8.65967 11.9998C8.65967 12.9154 9.4074 13.6577 10.3298 13.6577Z" fill = "white" > </ path > < path fill-rule = "evenodd" clip-rule = "evenodd" d = "M15.8964 13.6577C16.8188 13.6577 17.5665 12.9154 17.5665 11.9998C17.5665 11.0842 16.8188 10.3419 15.8964 10.3419C14.974 10.3419 14.2263 11.0842 14.2263 11.9998C14.2263 12.9154 14.974 13.6577 15.8964 13.6577Z" fill = "white" > </ path > </ svg > </ template > </ div > </ span >
965
976
</ div >
966
977
967
978
@@ -983,10 +994,25 @@ export const ProfileEdit = (): JSX.Element => {
983
994
<!-- </span> -->
984
995
<!-- </div> --> */ }
985
996
< div style = { { display : "flex" , alignItems : "center" , "gap" : "3px" } } >
986
- < button type = "submit" className = "btn" > Submit</ button >
987
- < NavLink to = { `/user/${ user . username } ` } className = "btn" role = "button" aria-pressed = "true" > Cancel</ NavLink >
997
+ < button type = "submit" className = "btn btn-primary " > Submit</ button >
998
+ < NavLink to = { `/user/${ user . username } ` } className = "btn btn-primary " role = "button" aria-pressed = "true" > Cancel</ NavLink >
988
999
</ div >
989
1000
</ form >
1001
+ < br />
1002
+ { ! session . user . is_deleted && < div className = "delete-container" >
1003
+ < h2 className = "delete-title" > Danger Zone</ h2 >
1004
+ < button className = "delete btn-small btn-primary" style = { { width : "100%" } } onClick = { ( ) => setShowDelete ( true ) } > Delete User</ button >
1005
+ </ div > }
1006
+
1007
+ < div className = "delete-confirmation" style = { { display : "flex" , flexDirection : "column" , justifyContent : "center" , visibility : showDelete ? "visible" : "hidden" , opacity : showDelete ? "100%" : "0%" } } >
1008
+ < div className = "delete-box" style = { { display : "flex" , flexDirection : "column" } } >
1009
+ < h3 > Are you sure you want to delete this user?</ h3 >
1010
+ < span style = { { display : "flex" , flexDirection : "row" , justifyContent : "right" } } >
1011
+ < button className = "delete btn-small btn-primary" onClick = { deleteUser } > YES</ button >
1012
+ < button className = "btn btn-small btn-primary" onClick = { ( ) => setShowDelete ( false ) } > No</ button >
1013
+ </ span >
1014
+ </ div >
1015
+ </ div >
990
1016
</ div >
991
1017
</ >
992
1018
) ;
0 commit comments