@@ -3,6 +3,8 @@ import {Alert, Button, Container, Row} from "react-bootstrap";
3
3
import UserInformationInput , { UserInformationInterface } from "./UserInformationInput" ;
4
4
import { useSelector } from "react-redux" ;
5
5
import { RootState } from "../../../background/redux/store" ;
6
+ import { DEFAULT_ALERT_DURATION } from "../../../background/constants" ;
7
+ import { changeUserInformation } from "../../../background/api/userInformation" ;
6
8
7
9
8
10
export default function Profile ( ) : ReactElement {
@@ -30,8 +32,25 @@ export default function Profile(): ReactElement {
30
32
31
33
const handleSubmit = async ( newUser : UserInformationInterface ) => {
32
34
console . log ( "[PROFILE] handleSubmit" )
33
- //console.log(changeUserInformation(newUser))
34
- changeEditMode ( )
35
+
36
+ if ( ! newUser . username ) {
37
+ handleAlertVisibility ( DEFAULT_ALERT_DURATION , "danger" , "Error: Please choose an username." )
38
+ // } else if (newUser.password !== newUser.passwordConfirmation) {
39
+ // handleAlertVisibility(DEFAULT_ALERT_DURATION, "danger", "Error: Password and password confirmation must match.")
40
+ // } else if (newUser.password.match(/\d/) == null || newUser.password.match(/[a-z]/) == null || newUser.password.match(/[A-Z]/) == null || notMinStrLength(newUser.password, MIN_PASSWORD_LENGTH)) {
41
+ // handleAlertVisibility(DEFAULT_ALERT_DURATION, "danger", "Error: Please pay attention to the notes below the input fields.")
42
+ } else {
43
+ // console.log("Hello there ", {...user, username: newUser.username})
44
+ // console.log("General Kenobi ", newUser)
45
+ await changeUserInformation ( { ...user , username : newUser . username } )
46
+ . then ( res => {
47
+ changeEditMode ( )
48
+ handleAlertVisibility ( DEFAULT_ALERT_DURATION , "success" , "Worked: " + ( res ) ) ;
49
+ } )
50
+ . catch ( err => {
51
+ handleAlertVisibility ( DEFAULT_ALERT_DURATION , "danger" , "Error: " + ( err . outputMessage ? err . outputMessage : ( err . httpStatus + " " + err . httpMessage ) ) )
52
+ } )
53
+ }
35
54
}
36
55
37
56
/*function EditProfile(): ReactElement {
@@ -82,7 +101,7 @@ export default function Profile(): ReactElement {
82
101
< dt > Username</ dt >
83
102
< dd > { user . username } </ dd >
84
103
< dt > Groups</ dt >
85
- < dd > { user . groups . map ( ( value : number ) => {
104
+ < dd > { user . groups ? .map ( ( value : number ) => {
86
105
return value + " "
87
106
} ) }
88
107
</ dd >
@@ -98,12 +117,14 @@ export default function Profile(): ReactElement {
98
117
< h1 className = "mr-1 h4" >
99
118
My Profile
100
119
</ h1 >
101
- { isEditing ? < > </ > : < Button onClick = { changeEditMode }
102
- disabled = { isEditing } > { isEditing ? "Editing" : "Edit Information" } </ Button > }
120
+ < Button
121
+ onClick = { changeEditMode }
122
+ >
123
+ { isEditing ? "Cancel" : "Edit" }
124
+ </ Button >
103
125
</ Row >
104
126
</ Container >
105
127
{ isEditing ? < EditProfile /> : < DisplayProfile /> }
106
-
107
128
</ Container >
108
129
) ;
109
130
}
0 commit comments