Skip to content

Commit

Permalink
fix: validation for courses as mandatory in profile. (#13)
Browse files Browse the repository at this point in the history
Set courseList in hook and output as errors.courseList to component for
validation.
  • Loading branch information
ZL-Asica authored Oct 18, 2024
1 parent 87b8d32 commit ef7cc9d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/components/Profile/EditProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ const EditProfile = () => {
<TextField
{...params}
label="Courses"
error={!!errors.courses}
helperText={errors.courses && 'Please select your course(s)'}
error={errors.coursesList}
helperText={errors.coursesList && 'Please select your course(s)'}
margin="normal"
fullWidth
/>
Expand All @@ -138,8 +138,8 @@ const EditProfile = () => {
{/* Location Preference */}
<FormLabel component="legend">Location Preference</FormLabel>
<FormGroup row sx={{ mb: 2 }}>
{renderCheckbox('In Person', 'inPerson', !!formData.inPerson, handleInputChange)}
{renderCheckbox('Online', 'online', !!formData.online, handleInputChange)}
{renderCheckbox('In Person', 'inPerson', formData.inPerson, handleInputChange)}
{renderCheckbox('Online', 'online', formData.online, handleInputChange)}
</FormGroup>

<Button variant="contained" color="primary" type="submit" disabled={!isFormValid}>
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useEditProfileForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const useEditProfileForm = (user) => {
});
setSelectedMajors(data.major ? data.major.split(',') : []);
setSelectedCourses(data.listOfCourses || []);
setFirstTimeUser(Boolean(data.major && data.year));
setFirstTimeUser(!!(data.major && data.year));
}
} catch (error) {
console.error('Error fetching profile, majors, and courses:', error);
Expand Down Expand Up @@ -79,7 +79,7 @@ const useEditProfileForm = (user) => {
email: !/^\S+@\S+\.\S+$/.test(formData.email),
phoneNumber: formData.phoneNumber.replace(/\D/g, '').length !== 10,
major: selectedMajors.length === 0,
listClasses: selectedCourses.length === 0,
coursesList: selectedCourses.length === 0,
year: !formData.year,
};
setErrors(newErrors);
Expand Down

0 comments on commit ef7cc9d

Please sign in to comment.