Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(profile): Add location preference to profile #4

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/components/Profile/EditProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import {
Autocomplete,
IconButton,
MenuItem,
Checkbox,
FormLabel,
FormGroup,
FormControlLabel,
} from '@mui/material';
import { useNavigate } from 'react-router-dom';

Expand Down Expand Up @@ -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
/>

Expand All @@ -129,6 +133,13 @@ const EditProfile = () => {
{/* Description Field */}
{renderTextField('Description', 'description', formData.description, handleInputChange)}

{/* 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)}
</FormGroup>

<Button variant="contained" color="primary" type="submit" disabled={!isFormValid}>
Save Profile
</Button>
Expand Down Expand Up @@ -172,4 +183,13 @@ const renderSelectField = (label, name, options, value, onChange, error = false)
</TextField>
);

const renderCheckbox = (label, name, value, onChange) => (
<FormControlLabel
control={
<Checkbox name={name} checked={value} onChange={(e) => onChange(name, e.target.checked)} />
}
label={label}
/>
);

export default EditProfile;
24 changes: 22 additions & 2 deletions src/components/Profile/ProfilePage.jsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -11,7 +11,9 @@ import {
Card,
CardContent,
CircularProgress,
Checkbox,
Chip,
FormControlLabel,
useTheme,
} from '@mui/material';
import { useParams, useNavigate } from 'react-router-dom';
Expand Down Expand Up @@ -60,8 +62,26 @@ export default function ProfilePage() {
</Typography>
</InfoSection>

<ActionButtons onEditClick={handleEditClick} onSignOutClick={handleSignOutDialogOpen} />
<InfoSection title="Preferences">
<ContentBox
icon={Place}
title="Location"
content={
<>
<FormControlLabel
control={<Checkbox disabled checked={profileData?.locationPreference.inPerson} />}
label="In Person"
/>
<FormControlLabel
control={<Checkbox disabled checked={profileData?.locationPreference.online} />}
label="Online"
/>
</>
}
/>
</InfoSection>

<ActionButtons onEditClick={handleEditClick} onSignOutClick={handleSignOutDialogOpen} />
<SignOutDialog open={signOutDialogOpen} onClose={() => setSignOutDialogOpen(false)} />
</Box>
);
Expand Down
6 changes: 5 additions & 1 deletion src/hooks/useEditProfileForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const useEditProfileForm = (user) => {
year: '',
description: '',
listOfCourses: '',
inPerson: false,
online: false,
});

const [errors, setErrors] = useState({});
Expand All @@ -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 || []);
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/utils/firestore/userProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const checkUserProfile = async (user) => {
major: '',
year: '',
open: true,
locationPreference: { inPerson: true, online: true },
listOfCourses: [],
description: '',
incomingMatches: [],
Expand Down
Loading