Skip to content

Commit 641f6bb

Browse files
authored
Merge pull request #54 from nicolelim02/feat/users
Fix linting issues
2 parents 3a9e8c0 + e1b04e1 commit 641f6bb

File tree

4 files changed

+116
-91
lines changed

4 files changed

+116
-91
lines changed

frontend/src/components/EditProfileModal/index.tsx

Lines changed: 66 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@ import {
1111
TextField,
1212
Typography,
1313
} from "@mui/material";
14-
import DeleteIcon from '@mui/icons-material/Delete';
14+
import DeleteIcon from "@mui/icons-material/Delete";
1515
import { useForm } from "react-hook-form";
1616
import { useProfile } from "../../contexts/ProfileContext";
17-
import { bioValidator, nameValidator, profilePictureValidator } from "../../utils/validators";
18-
import { FAILED_PROFILE_UPDATE_MESSAGE, PROFILE_PIC_MAX_SIZE_ERROR_MESSAGE, USE_AUTH_ERROR_MESSAGE, USE_PROFILE_ERROR_MESSAGE } from "../../utils/constants";
17+
import {
18+
bioValidator,
19+
nameValidator,
20+
profilePictureValidator,
21+
} from "../../utils/validators";
22+
import {
23+
FAILED_PROFILE_UPDATE_MESSAGE,
24+
PROFILE_PIC_MAX_SIZE_ERROR_MESSAGE,
25+
USE_AUTH_ERROR_MESSAGE,
26+
USE_PROFILE_ERROR_MESSAGE,
27+
} from "../../utils/constants";
1928
import { useRef, useState } from "react";
2029
import { Restore } from "@mui/icons-material";
2130
import { toast } from "react-toastify";
@@ -35,7 +44,14 @@ const StyledForm = styled("form")(({ theme }) => ({
3544
}));
3645

3746
const EditProfileModal: React.FC<EditProfileModalProps> = (props) => {
38-
const { open, onClose, currProfilePictureUrl, currFirstName, currLastName, currBiography } = props;
47+
const {
48+
open,
49+
onClose,
50+
currProfilePictureUrl,
51+
currFirstName,
52+
currLastName,
53+
currBiography,
54+
} = props;
3955

4056
const {
4157
register,
@@ -77,12 +93,16 @@ const EditProfileModal: React.FC<EditProfileModalProps> = (props) => {
7793
const { setUser } = auth;
7894

7995
// profile pic functionality referenced and adapted from https://dreamix.eu/insights/uploading-files-with-react-hook-form/
80-
const [picPreview, setPicPreview] = useState<string | null>(currProfilePictureUrl || null);
96+
const [picPreview, setPicPreview] = useState<string | null>(
97+
currProfilePictureUrl || null
98+
);
8199
const hiddenFileInputRef = useRef<HTMLInputElement | null>(null);
82-
const { ref: registerRef, ...rest } = register("profilePic", { validate: profilePictureValidator });
100+
const { ref: registerRef, ...rest } = register("profilePic", {
101+
validate: profilePictureValidator,
102+
});
83103
const onClickUpload = () => {
84104
hiddenFileInputRef.current?.click();
85-
}
105+
};
86106
const handleImageChange = (event: React.ChangeEvent<HTMLInputElement>) => {
87107
const file = event.target.files?.[0];
88108
if (file) {
@@ -93,33 +113,35 @@ const EditProfileModal: React.FC<EditProfileModalProps> = (props) => {
93113
setValue("profilePictureUrl", "", { shouldDirty: true });
94114
}
95115
}
96-
}
116+
};
97117

98118
const onClickReset = () => {
99119
if (getFieldState("profilePic").isDirty) {
100120
setValue("profilePic", null, { shouldValidate: true, shouldDirty: true });
101121
if (hiddenFileInputRef.current) {
102-
hiddenFileInputRef.current.value = '';
122+
hiddenFileInputRef.current.value = "";
103123
}
104124
}
105125
if (getFieldState("profilePictureUrl").isDirty) {
106-
setValue("profilePictureUrl", currProfilePictureUrl || "", { shouldDirty: true })
126+
setValue("profilePictureUrl", currProfilePictureUrl || "", {
127+
shouldDirty: true,
128+
});
107129
}
108130
setPicPreview(currProfilePictureUrl || "");
109-
}
131+
};
110132

111-
const onClickDelete = () => {
133+
const onClickDelete = () => {
112134
if (getFieldState("profilePic").isDirty) {
113135
setValue("profilePic", null, { shouldValidate: true, shouldDirty: true });
114136
if (hiddenFileInputRef.current) {
115-
hiddenFileInputRef.current.value = '';
137+
hiddenFileInputRef.current.value = "";
116138
}
117139
}
118140
if (currProfilePictureUrl) {
119141
setValue("profilePictureUrl", "", { shouldDirty: true });
120142
}
121143
setPicPreview(null);
122-
}
144+
};
123145

124146
return (
125147
<Dialog open={open} onClose={onClose}>
@@ -151,7 +173,7 @@ const EditProfileModal: React.FC<EditProfileModalProps> = (props) => {
151173
profilePictureUrl: url_data.profilePictureUrl,
152174
createdAt: user.createdAt,
153175
isAdmin: user.isAdmin,
154-
}
176+
};
155177
setUser(updatedUser);
156178
}
157179
});
@@ -179,24 +201,26 @@ const EditProfileModal: React.FC<EditProfileModalProps> = (props) => {
179201
profilePictureUrl: url_data.profilePictureUrl,
180202
createdAt: user.createdAt,
181203
isAdmin: user.isAdmin,
182-
}
204+
};
183205
setUser(updatedUser);
184206
}
185207
});
186208
onClose();
187209
}
188210
})}
189211
>
190-
<Stack
191-
direction="row"
212+
<Stack
213+
direction="row"
192214
spacing={2}
193215
display="flex"
194216
alignItems="center"
195-
sx={(theme) => ({ marginBottom: theme.spacing(2) })}>
196-
{!picPreview
197-
? <Avatar sx={{ width: 56, height: 56 }} />
198-
: <Avatar src={picPreview} sx={{ width: 56, height: 56 }} />
199-
}
217+
sx={(theme) => ({ marginBottom: theme.spacing(2) })}
218+
>
219+
{!picPreview ? (
220+
<Avatar sx={{ width: 56, height: 56 }} />
221+
) : (
222+
<Avatar src={picPreview} sx={{ width: 56, height: 56 }} />
223+
)}
200224
{/* input referenced from https://dreamix.eu/insights/uploading-files-with-react-hook-form/ */}
201225
<input
202226
type="file"
@@ -209,35 +233,32 @@ const EditProfileModal: React.FC<EditProfileModalProps> = (props) => {
209233
}}
210234
onChange={handleImageChange}
211235
/>
212-
<Button
236+
<Button
213237
size="small"
214238
variant="outlined"
215239
onClick={onClickUpload}
216-
sx={{height: 30}}>
217-
Upload
240+
sx={{ height: 30 }}
241+
>
242+
Upload
218243
</Button>
219-
<IconButton
220-
onClick={onClickReset}>
221-
<Restore color="success"/>
244+
<IconButton onClick={onClickReset}>
245+
<Restore color="success" />
222246
</IconButton>
223-
<IconButton
224-
onClick={onClickDelete}>
225-
<DeleteIcon color="error"/>
247+
<IconButton onClick={onClickDelete}>
248+
<DeleteIcon color="error" />
226249
</IconButton>
227250
</Stack>
228-
{!!errors.profilePic
229-
? <Typography
230-
color="error"
231-
sx={{fontSize: 13,
232-
marginBottom: 2}}>
233-
{errors.profilePic.message}
234-
</Typography>
235-
: <Typography
236-
sx={{fontSize: 13,
237-
marginBottom: 2,
238-
color: "#808080"}}>
239-
{PROFILE_PIC_MAX_SIZE_ERROR_MESSAGE}
240-
</Typography>}
251+
{errors.profilePic ? (
252+
<Typography color="error" sx={{ fontSize: 13, marginBottom: 2 }}>
253+
{errors.profilePic.message}
254+
</Typography>
255+
) : (
256+
<Typography
257+
sx={{ fontSize: 13, marginBottom: 2, color: "#808080" }}
258+
>
259+
{PROFILE_PIC_MAX_SIZE_ERROR_MESSAGE}
260+
</Typography>
261+
)}
241262
<TextField
242263
fullWidth
243264
required

frontend/src/contexts/ProfileContext.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable react-refresh/only-export-components */
2+
13
import { createContext, useContext, useState } from "react";
24
import { userClient } from "../utils/api";
35
import {
@@ -29,7 +31,9 @@ type ProfileContextType = {
2931
editProfileOpen: boolean;
3032
passwordModalOpen: boolean;
3133
fetchUser: (userId: string) => void;
32-
uploadProfilePicture: (data: File) => Promise<{ message: string, imageUrl: string } | null>;
34+
uploadProfilePicture: (
35+
data: File
36+
) => Promise<{ message: string; imageUrl: string } | null>;
3337
updateProfile: (data: UserProfileBase) => Promise<boolean>;
3438
updatePassword: ({
3539
oldPassword,
@@ -60,38 +64,34 @@ const ProfileContextProvider: React.FC<{ children: React.ReactNode }> = ({
6064

6165
const uploadProfilePicture = async (
6266
data: File
63-
): Promise<{ message: string, imageUrl: string } | null> => {
67+
): Promise<{ message: string; imageUrl: string } | null> => {
6468
const formData = new FormData();
6569
formData.append("profilePic", data);
6670

6771
try {
6872
const res = await userClient.post("/users/images", formData, {
6973
headers: {
70-
"Content-Type": "multipart/form-data"
74+
"Content-Type": "multipart/form-data",
7175
},
7276
});
7377
return res.data;
7478
} catch {
7579
return null;
7680
}
77-
}
81+
};
7882

79-
const updateProfile = async (
80-
data: UserProfileBase
81-
): Promise<boolean> => {
83+
const updateProfile = async (data: UserProfileBase): Promise<boolean> => {
8284
const token = localStorage.getItem("token");
8385
try {
84-
const res = await userClient
85-
.patch(`/users/${user?.id}`, data,
86-
{
86+
const res = await userClient.patch(`/users/${user?.id}`, data, {
8787
headers: { Authorization: `Bearer ${token}` },
88-
})
88+
});
8989
setUser(res.data.data);
9090
toast.success(SUCCESS_PROFILE_UPDATE_MESSAGE);
9191
return true;
9292
} catch (error) {
93-
console.error('Error:', error);
94-
if(axios.isAxiosError(error)) {
93+
console.error("Error:", error);
94+
if (axios.isAxiosError(error)) {
9595
const message =
9696
error.response?.data.message || FAILED_PROFILE_UPDATE_MESSAGE;
9797
toast.error(message);

frontend/src/pages/Home/index.tsx

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
import {
2-
Autocomplete,
3-
Button,
4-
Card,
5-
FormControl,
6-
Grid2,
7-
TextField,
2+
// Autocomplete,
3+
// Button,
4+
// Card,
5+
// FormControl,
6+
// Grid2,
7+
// TextField,
88
Typography,
99
} from "@mui/material";
10-
import { useEffect, useReducer, useState } from "react";
10+
// import { useEffect, useReducer, useState } from "react";
1111

1212
import classes from "./index.module.css";
1313
import AppMargin from "../../components/AppMargin";
14-
import {
15-
complexityList,
16-
languageList,
17-
maxMatchTimeout,
18-
minMatchTimeout,
19-
} from "../../utils/constants";
20-
import reducer, {
21-
getQuestionCategories,
22-
initialState,
23-
} from "../../reducers/questionReducer";
24-
import CustomChip from "../../components/CustomChip";
14+
// import {
15+
// complexityList,
16+
// languageList,
17+
// maxMatchTimeout,
18+
// minMatchTimeout,
19+
// } from "../../utils/constants";
20+
// import reducer, {
21+
// getQuestionCategories,
22+
// initialState,
23+
// } from "../../reducers/questionReducer";
24+
// import CustomChip from "../../components/CustomChip";
2525
// import homepageImage from "/homepage_image.svg";
2626

2727
const Home: React.FC = () => {
28-
const [complexity, setComplexity] = useState<string[]>([]);
29-
const [selectedCategories, setSelectedCategories] = useState<string[]>([]);
30-
const [language, setLanguage] = useState<string[]>([]);
31-
const [timeout, setTimeout] = useState<number>(30);
28+
// const [complexity, setComplexity] = useState<string[]>([]);
29+
// const [selectedCategories, setSelectedCategories] = useState<string[]>([]);
30+
// const [language, setLanguage] = useState<string[]>([]);
31+
// const [timeout, setTimeout] = useState<number>(30);
3232

33-
const [state, dispatch] = useReducer(reducer, initialState);
33+
// const [state, dispatch] = useReducer(reducer, initialState);
3434

35-
useEffect(() => {
36-
getQuestionCategories(dispatch);
37-
}, []);
35+
// useEffect(() => {
36+
// getQuestionCategories(dispatch);
37+
// }, []);
3838

3939
return (
4040
<AppMargin
@@ -62,7 +62,8 @@ const Home: React.FC = () => {
6262
maxWidth: "80%",
6363
})}
6464
>
65-
Specify your question preferences and sit back as we find you the best match.
65+
Specify your question preferences and sit back as we find you the best
66+
match.
6667
</Typography>
6768
{/* <Box
6869
component="img"
@@ -77,7 +78,7 @@ const Home: React.FC = () => {
7778
objectFit: "contain",
7879
}}
7980
/> */}
80-
<Card
81+
{/* <Card
8182
sx={{
8283
padding: 4,
8384
width: "100%",
@@ -267,7 +268,7 @@ const Home: React.FC = () => {
267268
>
268269
Find my match!
269270
</Button>
270-
</Card>
271+
</Card> */}
271272
</AppMargin>
272273
);
273274
};

frontend/src/pages/Profile/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const ProfilePage: React.FC = () => {
4343
}
4444

4545
fetchUser(userId);
46+
// eslint-disable-next-line react-hooks/exhaustive-deps
4647
}, []);
4748

4849
if (!user) {
@@ -106,20 +107,22 @@ const ProfilePage: React.FC = () => {
106107
<Box sx={(theme) => ({ flex: 3, paddingLeft: theme.spacing(4) })}>
107108
<Typography variant="h4">Questions attempted</Typography>
108109
</Box>
109-
{editProfileOpen &&
110+
{editProfileOpen && (
110111
<EditProfileModal
111112
open={editProfileOpen}
112113
onClose={() => setEditProfileModalOpen(false)}
113114
currProfilePictureUrl={user.profilePictureUrl}
114115
currFirstName={user.firstName}
115116
currLastName={user.lastName}
116117
currBiography={user.biography}
117-
/>}
118-
{passwordModalOpen &&
118+
/>
119+
)}
120+
{passwordModalOpen && (
119121
<ChangePasswordModal
120122
open={passwordModalOpen}
121123
onClose={() => setPasswordModalOpen(false)}
122-
/>}
124+
/>
125+
)}
123126
</Box>
124127
</AppMargin>
125128
);

0 commit comments

Comments
 (0)