1
-
2
- import React , { ChangeEvent , ReactElement , useState } from "react" ;
3
- import { Button , Container , Form , Row } from "react-bootstrap" ;
1
+ import React , { ReactElement , useState } from "react" ;
2
+ import { Alert , Button , Container , Row } from "react-bootstrap" ;
3
+ import { changeUserInformation } from "../../../background/api/userInformations" ;
4
+ import UserInformationInput , { UserInformationInterface } from "./UserInformationInput" ;
4
5
import { useSelector } from "react-redux" ;
5
6
import { RootState } from "../../../background/redux/store" ;
6
- import { changeUserInformation } from "../../../background/api/userInformations" ;
7
- import { notMinStrLength } from "../../../background/methods/checkInput" ;
8
7
9
8
10
9
export default function Profile ( ) : ReactElement {
11
- return ( < p > Hi</ p > ) ;
12
- }
13
- /*
14
10
const [ isEditing , setIsEditing ] = useState < boolean > ( false ) ;
15
- const [username, setUsername] = useState<string>("");
16
- const [password, setPassword] = useState<string>("");
17
- const [passwordConfirmation, setPasswordConfirmation] = useState<string>("");
18
- const [passwordInformationLength, setPasswordInformationLength] = useState<boolean>(false);
19
- const [passwordInformationLowercase, setPasswordInformationLowercase] = useState<boolean>(false);
20
- const [passwordInformationUppercase, setPasswordInformationUppercase] = useState<boolean>(false);
21
- const [passwordInformationNumber, setPasswordInformationNumber] = useState<boolean>(false);
22
- const [passwordsMatch, setPasswordsMatch] = useState<boolean>(true);
11
+ const user = useSelector ( ( state : RootState ) => state . user ) ;
12
+ const [ newUser , setNewUser ] = useState < UserInformationInterface > ( {
13
+ username : "" ,
14
+ password : "" ,
15
+ passwordConfirmation : ""
16
+ } )
23
17
const [ alertMessage , setAlertMessage ] = useState < string > ( "Error 404: No Message found." ) ;
24
18
const [ alertVariant , setAlertColor ] = useState < "primary" | "secondary" | "success" | "danger" | "warning" | "info" | "light" | "dark" > ( "success" ) ;
25
19
const [ alertVisibility , setAlertVisibility ] = useState < boolean > ( false ) ;
26
20
27
- function handleEditModeChange(): void {
28
- if (isEditing) {
29
- let newUser = JSON.parse(JSON.stringify(user))
30
- let usernameInput = document.getElementById("editProfileForm-Username")
31
- if (usernameInput) {
32
- console.log((usernameInput as HTMLInputElement).value)
33
- newUser.username = (usernameInput as HTMLInputElement).value
34
- console.log(changeUserInformation(newUser))
35
- }
36
- } else {
37
- console.log("[PROFILE] changedEditMode")
38
- setIsEditing(!isEditing)
21
+ const handleAlertVisibility = ( duration : number , color : "primary" | "secondary" | "success" | "danger" | "warning" | "info" | "light" | "dark" , message : string ) => {
22
+ if ( ! alertVisibility ) {
23
+ setAlertMessage ( message ) ;
24
+ setAlertColor ( color ) ;
25
+ setAlertVisibility ( true ) ;
26
+ setTimeout ( ( ) => {
27
+ setAlertVisibility ( false ) ;
28
+ } , duration ) ;
39
29
}
40
30
}
41
31
42
- function EditProfile(): ReactElement {
32
+ function handleEditModeChange ( ) : void {
33
+ console . log ( "[PROFILE] changedEditMode" )
34
+ setIsEditing ( ! isEditing )
35
+ }
36
+
37
+ const handleSubmit = async ( ) => {
38
+ console . log ( "[PROFILE] handleSubmit" )
39
+ console . log ( changeUserInformation ( newUser ) )
40
+ }
41
+
42
+ /*function EditProfile(): ReactElement {
43
43
return (
44
44
<Form>
45
45
<Form.Group controlId="editProfileForm-Username">
@@ -59,6 +59,19 @@ export default function Profile(): ReactElement {
59
59
</Form.Group>
60
60
</Form>
61
61
)
62
+ }*/
63
+
64
+ function EditProfile ( ) : ReactElement {
65
+ return (
66
+ < >
67
+ < UserInformationInput triggerAlert = { handleAlertVisibility } submitFunction = { handleSubmit }
68
+ newUser = { newUser } setNewUser = { setNewUser } />
69
+ < Alert variant = { alertVariant } onClose = { ( ) => setAlertVisibility ( false ) } show = { alertVisibility }
70
+ dismissible >
71
+ < p > { alertMessage } </ p >
72
+ </ Alert >
73
+ </ >
74
+ )
62
75
}
63
76
64
77
function DisplayProfile ( ) : ReactElement {
@@ -94,4 +107,4 @@ export default function Profile(): ReactElement {
94
107
95
108
</ Container >
96
109
) ;
97
- }*/
110
+ }
0 commit comments