From 399b7148df3c90a182e990af12ffbe239249b679 Mon Sep 17 00:00:00 2001 From: chip <49256163+chipanyanwu@users.noreply.github.com> Date: Sun, 13 Oct 2024 04:43:58 -0500 Subject: [PATCH] add location preference to profile page & edit profile form --- src/components/Profile/EditProfile.jsx | 22 +++++++++++++++++++++- src/components/Profile/ProfilePage.jsx | 24 ++++++++++++++++++++++-- src/hooks/useEditProfileForm.js | 6 +++++- src/utils/firestore/userProfile.js | 1 + 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/components/Profile/EditProfile.jsx b/src/components/Profile/EditProfile.jsx index 8c8893d..7f99b4c 100644 --- a/src/components/Profile/EditProfile.jsx +++ b/src/components/Profile/EditProfile.jsx @@ -10,6 +10,10 @@ import { Autocomplete, IconButton, MenuItem, + Checkbox, + FormLabel, + FormGroup, + FormControlLabel, } from '@mui/material'; import { useNavigate } from 'react-router-dom'; @@ -119,7 +123,7 @@ const EditProfile = () => { // Only include options that start with the input return options.filter((option) => option.toLowerCase().startsWith(lowercasedInput)); }} - sx={{ flex: 1, mb: 2, minWidth: 200, maxWidth: '100%' }} + sx={{ flex: 1, minWidth: 200, maxWidth: '100%' }} freeSolo /> @@ -129,6 +133,13 @@ const EditProfile = () => { {/* Description Field */} {renderTextField('Description', 'description', formData.description, handleInputChange)} + {/* Location Preference */} + Location Preference + + {renderCheckbox('In Person', 'inPerson', !!formData.inPerson, handleInputChange)} + {renderCheckbox('Online', 'online', !!formData.online, handleInputChange)} + + @@ -172,4 +183,13 @@ const renderSelectField = (label, name, options, value, onChange, error = false) ); +const renderCheckbox = (label, name, value, onChange) => ( + onChange(name, e.target.checked)} /> + } + label={label} + /> +); + export default EditProfile; diff --git a/src/components/Profile/ProfilePage.jsx b/src/components/Profile/ProfilePage.jsx index 1a97d9c..4c7e0f5 100755 --- a/src/components/Profile/ProfilePage.jsx +++ b/src/components/Profile/ProfilePage.jsx @@ -1,7 +1,7 @@ import React, { useState } from 'react'; import useUserProfile from '@data/useUserProfile'; -import { Email, Phone, School, CalendarToday, ListAlt } from '@mui/icons-material'; +import { Email, Phone, Place, School, CalendarToday, ListAlt } from '@mui/icons-material'; import { Avatar, Typography, @@ -11,7 +11,9 @@ import { Card, CardContent, CircularProgress, + Checkbox, Chip, + FormControlLabel, useTheme, } from '@mui/material'; import { useParams, useNavigate } from 'react-router-dom'; @@ -60,8 +62,26 @@ export default function ProfilePage() { - + + + } + label="In Person" + /> + } + label="Online" + /> + + } + /> + + setSignOutDialogOpen(false)} /> ); diff --git a/src/hooks/useEditProfileForm.js b/src/hooks/useEditProfileForm.js index bfd36ac..f21de7a 100644 --- a/src/hooks/useEditProfileForm.js +++ b/src/hooks/useEditProfileForm.js @@ -18,6 +18,8 @@ const useEditProfileForm = (user) => { year: '', description: '', listOfCourses: '', + inPerson: false, + online: false, }); const [errors, setErrors] = useState({}); @@ -44,6 +46,8 @@ const useEditProfileForm = (user) => { major: data.major || '', year: data.year || '', description: data.description || '', + inPerson: data.locationPreference.inPerson, + online: data.locationPreference.online, }); setSelectedMajors(data.major ? data.major.split(',') : []); setSelectedCourses(data.listOfCourses || []); @@ -100,7 +104,7 @@ const useEditProfileForm = (user) => { ...formData, major: selectedMajors.join(', '), listOfCourses: selectedCourses, - //listOfCourses: formData.listOfCourses.split(',').map((course) => course.trim()), + locationPreference: { inPerson: formData.inPerson, online: formData.online }, }; await updateUserProfile(userId, updatedProfileData); return true; // Indicate success diff --git a/src/utils/firestore/userProfile.js b/src/utils/firestore/userProfile.js index 900a7f6..1f6b29a 100644 --- a/src/utils/firestore/userProfile.js +++ b/src/utils/firestore/userProfile.js @@ -34,6 +34,7 @@ export const checkUserProfile = async (user) => { major: '', year: '', open: true, + locationPreference: { inPerson: true, online: true }, listOfCourses: [], description: '', incomingMatches: [],