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

Commit edf50bb

Browse files
committed
Fixed Rerender problems
1 parent 3840c7a commit edf50bb

File tree

3 files changed

+14
-27
lines changed

3 files changed

+14
-27
lines changed

src/components/pages/User/Profile.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ import {RootState} from "../../../background/redux/store";
99
export default function Profile(): ReactElement {
1010
const [isEditing, setIsEditing] = useState<boolean>(false);
1111
const user = useSelector((state: RootState) => state.user);
12-
const [newUser, setNewUser] = useState<UserInformationInterface>({
13-
username: "",
14-
password: "",
15-
passwordConfirmation: ""
16-
})
1712
const [alertMessage, setAlertMessage] = useState<string>("Error 404: No Message found.");
1813
const [alertVariant, setAlertColor] = useState<"primary" | "secondary" | "success" | "danger" | "warning" | "info" | "light" | "dark">("success");
1914
const [alertVisibility, setAlertVisibility] = useState<boolean>(false);
@@ -34,7 +29,7 @@ export default function Profile(): ReactElement {
3429
setIsEditing(!isEditing)
3530
}
3631

37-
const handleSubmit = () => {
32+
const handleSubmit = async (newUser:UserInformationInterface) => {
3833
console.log("[PROFILE] handleSubmit")
3934
//console.log(changeUserInformation(newUser))
4035
changeEditMode()
@@ -65,8 +60,7 @@ export default function Profile(): ReactElement {
6560
function EditProfile(): ReactElement {
6661
return (
6762
<>
68-
<UserInformationInput triggerAlert={handleAlertVisibility} submitFunction={handleSubmit}
69-
newUser={newUser} setNewUser={setNewUser}/>
63+
<UserInformationInput triggerAlert={handleAlertVisibility} submitFunction={handleSubmit}/>
7064
<Alert variant={alertVariant} onClose={() => setAlertVisibility(false)} show={alertVisibility}
7165
dismissible>
7266
<p>{alertMessage}</p>

src/components/pages/User/Registration.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ export default function Registration(): ReactElement {
1313
const [alertVariant, setAlertColor] = useState<"primary" | "secondary" | "success" | "danger" | "warning" | "info" | "light" | "dark">("success");
1414
const [alertVisibility, setAlertVisibility] = useState<boolean>(false);
1515

16-
const [newUser, setNewUser] = useState<UserInformationInterface>({
17-
username: "",
18-
password: "",
19-
passwordConfirmation: ""
20-
})
16+
// const [newUser, setNewUser] = useState<UserInformationInterface>({
17+
// username: "",
18+
// password: "",
19+
// passwordConfirmation: ""
20+
// })
2121

2222
const registrationContainer = document.getElementById("registrationContainer")
2323
const logoSubmit = document.getElementById("logoSubmit")
@@ -40,7 +40,7 @@ export default function Registration(): ReactElement {
4040
repositionSubmitLogo()
4141
}, [registrationContainer, logoSubmit])
4242

43-
const handleSubmit = async () => {
43+
const handleSubmit = async (newUser:UserInformationInterface) => {
4444
console.log("[REGISTRATION] handleSubmit")
4545
if (!newUser.username) {
4646
handleAlertVisibility(DEFAULT_ALERT_DURATION, "danger", "Error: Please choose an username.")
@@ -76,8 +76,7 @@ export default function Registration(): ReactElement {
7676
<Row>
7777
<Col md={{span: 6, offset: 3}}>
7878
<h1>Create new account</h1>
79-
<UserInformationInput triggerAlert={handleAlertVisibility} submitFunction={handleSubmit}
80-
newUser={newUser} setNewUser={setNewUser}/>
79+
<UserInformationInput triggerAlert={handleAlertVisibility} submitFunction={handleSubmit}/>
8180
<Alert variant={alertVariant} onClose={() => setAlertVisibility(false)} show={alertVisibility}
8281
dismissible>
8382
<p>{alertMessage}</p>

src/components/pages/User/UserInformationInput.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ export interface UserInformationInterface {
2424

2525
type Props = {
2626
triggerAlert(duration: number, color: "primary" | "secondary" | "success" | "danger" | "warning" | "info" | "light" | "dark", message: string): void,
27-
submitFunction(): void,
28-
newUser: UserInformationInterface,
29-
setNewUser: Dispatch<SetStateAction<UserInformationInterface>> }
27+
submitFunction(newUser:UserInformationInterface): void
28+
}
3029

3130
export default function UserInformationInput(props: Props): ReactElement {
32-
const {triggerAlert, submitFunction, newUser, setNewUser} = props;
31+
let {triggerAlert, submitFunction} = props;
3332
const [username, setUsername] = useState<string>("");
3433
const [password, setPassword] = useState<string>("");
3534
const [passwordConfirmation, setPasswordConfirmation] = useState<string>("");
@@ -47,12 +46,6 @@ export default function UserInformationInput(props: Props): ReactElement {
4746
reviewPasswordMatch()
4847
}, [reviewPasswordMatch])
4948

50-
useEffect(() => {
51-
//TODO: [UserInformationInput.tsx] without submitted submitFunction triggers on site load
52-
console.log("[UserInformationInput] in submit useEffect")
53-
submitFunction();
54-
}, [newUser])
55-
5649
const makePasswordInputFitRules = (input: string): [string, boolean] => {
5750
input = deleteSpaces(input);
5851
if (biggerMaxStrLength(input, MAX_PASSWORD_LENGTH)) {
@@ -92,7 +85,8 @@ export default function UserInformationInput(props: Props): ReactElement {
9285
event.preventDefault();
9386
console.log("[UserInformationInput] handleSubmit")
9487
reviewPasswordMatch();
95-
setNewUser({username: username, password: password, passwordConfirmation: passwordConfirmation})
88+
let newUser = {username: username, password: password, passwordConfirmation: passwordConfirmation}
89+
submitFunction(newUser)
9690
}
9791

9892
return (

0 commit comments

Comments
 (0)