Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 980fb7a

Browse files
committed
Included UserInformationInput.tsx in Profile.tsx
1 parent 17c9f17 commit 980fb7a

File tree

2 files changed

+45
-32
lines changed

2 files changed

+45
-32
lines changed

src/components/Router/Router.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Error404 from "../pages/errors/Error404";
55
import Login from "../basicElements/Login";
66
import Registration from "../pages/User/Registration";
77
import FileSystem, {filesBaseUrl} from "../pages/filesytem/Filesystem";
8-
// import Profile from "../pages/User/Profile";
8+
import Profile from "../pages/User/Profile";
99

1010
export default function Router(): ReactElement {
1111

@@ -21,7 +21,7 @@ export default function Router(): ReactElement {
2121
<Redirect to={"/"}/>
2222
</Route>
2323
<Route path={"/registration"} component={Registration}/>
24-
{/*<Route path={"/profile"} component={Profile}/>*/}
24+
{<Route path={"/profile"} component={Profile}/>}
2525
<Route path={"*"} component={Error404}/>
2626
</Switch>
2727
)

src/components/pages/User/Profile.tsx

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
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";
45
import {useSelector} from "react-redux";
56
import {RootState} from "../../../background/redux/store";
6-
import {changeUserInformation} from "../../../background/api/userInformations";
7-
import {notMinStrLength} from "../../../background/methods/checkInput";
87

98

109
export default function Profile(): ReactElement {
11-
return (<p>Hi</p>);
12-
}
13-
/*
1410
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+
})
2317
const [alertMessage, setAlertMessage] = useState<string>("Error 404: No Message found.");
2418
const [alertVariant, setAlertColor] = useState<"primary" | "secondary" | "success" | "danger" | "warning" | "info" | "light" | "dark">("success");
2519
const [alertVisibility, setAlertVisibility] = useState<boolean>(false);
2620

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);
3929
}
4030
}
4131

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 {
4343
return (
4444
<Form>
4545
<Form.Group controlId="editProfileForm-Username">
@@ -59,6 +59,19 @@ export default function Profile(): ReactElement {
5959
</Form.Group>
6060
</Form>
6161
)
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+
)
6275
}
6376

6477
function DisplayProfile(): ReactElement {
@@ -94,4 +107,4 @@ export default function Profile(): ReactElement {
94107

95108
</Container>
96109
);
97-
}*/
110+
}

0 commit comments

Comments
 (0)