Skip to content

Commit 9e477eb

Browse files
committed
Merge branch 'development' of https://github.com/ruiqi7/peer-prep into feature/user-authentication
# Conflicts: # frontend/src/components/ChangePasswordModal/index.tsx
2 parents 771237b + 163191e commit 9e477eb

File tree

3 files changed

+21
-38
lines changed

3 files changed

+21
-38
lines changed

frontend/src/components/ChangePasswordModal/index.tsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { passwordValidator } from "../../utils/validators";
1313
import PasswordTextField from "../PasswordTextField";
1414
import {
1515
PASSWORD_MISMATCH_ERROR_MESSAGE,
16+
PASSWORD_REQUIRED_ERROR_MESSAGE,
1617
USE_PROFILE_ERROR_MESSAGE,
1718
} from "../../utils/constants";
1819

@@ -33,7 +34,6 @@ const ChangePasswordModal: React.FC<ChangePasswordModalProps> = (props) => {
3334
formState: { errors, dirtyFields, isDirty, isValid },
3435
watch,
3536
trigger,
36-
reset,
3737
} = useForm<{
3838
oldPassword: string;
3939
newPassword: string;
@@ -51,14 +51,7 @@ const ChangePasswordModal: React.FC<ChangePasswordModalProps> = (props) => {
5151
const { updatePassword } = profile;
5252

5353
return (
54-
<Dialog
55-
fullWidth
56-
open={open}
57-
onClose={() => {
58-
onClose();
59-
reset();
60-
}}
61-
>
54+
<Dialog fullWidth open={open} onClose={onClose}>
6255
<DialogTitle fontSize={24} sx={{ paddingBottom: 0 }}>
6356
Change password
6457
</DialogTitle>
@@ -71,7 +64,6 @@ const ChangePasswordModal: React.FC<ChangePasswordModalProps> = (props) => {
7164
newPassword: data.newPassword,
7265
});
7366
onClose();
74-
reset();
7567
})}
7668
>
7769
<PasswordTextField
@@ -82,7 +74,10 @@ const ChangePasswordModal: React.FC<ChangePasswordModalProps> = (props) => {
8274
sx={(theme) => ({ marginTop: theme.spacing(1) })}
8375
{...register("oldPassword", {
8476
setValueAs: (value: string) => value.trim(),
77+
required: PASSWORD_REQUIRED_ERROR_MESSAGE,
8578
})}
79+
error={!!errors.oldPassword}
80+
helperText={errors.oldPassword?.message}
8681
/>
8782
<PasswordTextField
8883
displayTooltip
@@ -133,10 +128,7 @@ const ChangePasswordModal: React.FC<ChangePasswordModalProps> = (props) => {
133128
fullWidth
134129
variant="contained"
135130
color="secondary"
136-
onClick={() => {
137-
onClose();
138-
reset();
139-
}}
131+
onClick={onClose}
140132
>
141133
Cancel
142134
</Button>

frontend/src/components/EditProfileModal/index.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const EditProfileModal: React.FC<EditProfileModalProps> = (props) => {
3232
register,
3333
formState: { errors, isValid, isDirty },
3434
handleSubmit,
35-
reset,
3635
} = useForm<{
3736
firstName: string;
3837
lastName: string;
@@ -55,13 +54,7 @@ const EditProfileModal: React.FC<EditProfileModalProps> = (props) => {
5554
const { updateProfile } = profile;
5655

5756
return (
58-
<Dialog
59-
open={open}
60-
onClose={() => {
61-
onClose();
62-
reset();
63-
}}
64-
>
57+
<Dialog open={open} onClose={onClose}>
6558
<DialogTitle fontSize={24} sx={{ paddingBottom: 0 }}>
6659
Edit profile
6760
</DialogTitle>
@@ -71,7 +64,6 @@ const EditProfileModal: React.FC<EditProfileModalProps> = (props) => {
7164
onSubmit={handleSubmit((data) => {
7265
updateProfile(data);
7366
onClose();
74-
reset();
7567
})}
7668
>
7769
<TextField
@@ -120,10 +112,7 @@ const EditProfileModal: React.FC<EditProfileModalProps> = (props) => {
120112
fullWidth
121113
variant="contained"
122114
color="secondary"
123-
onClick={() => {
124-
onClose();
125-
reset();
126-
}}
115+
onClick={onClose}
127116
>
128117
Cancel
129118
</Button>

frontend/src/pages/Profile/index.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,19 @@ const ProfilePage: React.FC = () => {
105105
<Box sx={(theme) => ({ flex: 3, paddingLeft: theme.spacing(4) })}>
106106
<Typography variant="h4">Questions attempted</Typography>
107107
</Box>
108-
<EditProfileModal
109-
open={editProfileOpen}
110-
onClose={() => setEditProfileModalOpen(false)}
111-
currFirstName={user.firstName}
112-
currLastName={user.lastName}
113-
currBiography={user.biography}
114-
/>
115-
<ChangePasswordModal
116-
open={passwordModalOpen}
117-
onClose={() => setPasswordModalOpen(false)}
118-
/>
108+
{editProfileOpen &&
109+
<EditProfileModal
110+
open={editProfileOpen}
111+
onClose={() => setEditProfileModalOpen(false)}
112+
currFirstName={user.firstName}
113+
currLastName={user.lastName}
114+
currBiography={user.biography}
115+
/>}
116+
{passwordModalOpen &&
117+
<ChangePasswordModal
118+
open={passwordModalOpen}
119+
onClose={() => setPasswordModalOpen(false)}
120+
/>}
119121
</Box>
120122
</AppMargin>
121123
);

0 commit comments

Comments
 (0)