Skip to content

Test view availability #19

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
48 changes: 47 additions & 1 deletion src/components/GroupsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ function GroupsPage() {
const [matchProfiles, setMatchProfiles] = useState([]);
const [selectedProfile, setSelectedProfile] = useState(null); // State for selected user profile
const [openProfileModal, setOpenProfileModal] = useState(false); // State for modal visibility
const [openAvailabilityModal, setOpenAvailabilityModal] = useState(false); // Modal visibility state
const [selectedTimePreferences, setSelectedTimePreferences] = useState([]); // State to store time preferences


// Combined useEffect for fetching incoming, outgoing, and current matches
useEffect(() => {
Expand Down Expand Up @@ -115,6 +118,22 @@ function GroupsPage() {
setOpenProfileModal(false);
};

const handleOpenAvailabilityModal = async (userId) => {
try {
const { profile } = await fetchUserProfile(userId); // Fetch user profile for the matched user
const fetchedTimes = profile?.timePreferences || []; // Extract time preferences
setSelectedTimePreferences(fetchedTimes); // Set the fetched time preferences in state
setOpenAvailabilityModal(true); // Open the modal
} catch (err) {
console.error('Failed to load time preferences', err);
}
};

const handleCloseAvailabilityModal = () => {
setOpenAvailabilityModal(false); // Close the modal
};


if (loading) {
return <Typography variant="h6">Loading...</Typography>;
}
Expand Down Expand Up @@ -151,6 +170,10 @@ function GroupsPage() {
variant: 'outlined',
color: 'secondary',
},
{
label: 'View Availability', // New button for viewing time preferences
onClick: () => handleOpenAvailabilityModal(profile.uid), // We'll define this function below
},
];
return <StudentCard key={index} studentUserProfile={profile} actions={actions} />;
})
Expand Down Expand Up @@ -195,7 +218,7 @@ function GroupsPage() {
label: 'Requested',
variant: 'outlined',
color: 'default',
onClick: () => {}, // No functionality
onClick: () => { }, // No functionality
},
];
return <StudentCard key={index} studentUserProfile={profile} actions={actions} />;
Expand All @@ -213,6 +236,29 @@ function GroupsPage() {
open={openProfileModal}
onClose={handleCloseProfileModal}
/>
<Modal
open={openAvailabilityModal}
onClose={handleCloseAvailabilityModal}
aria-labelledby="time-preferences-modal"
aria-describedby="time-preferences-description"
>
<Box sx={{ ...modalStyle }}>
<Typography id="time-preferences-modal" variant="h6" component="h2">
Time Preferences
</Typography>
{selectedTimePreferences.length > 0 ? (
<ul>
{selectedTimePreferences.map((time, index) => (
<li key={index}>{time}</li>
))}
</ul>
) : (
<Typography>No time preferences available.</Typography>
)}
<Button onClick={handleCloseAvailabilityModal}>Close</Button>
</Box>
</Modal>

</Box>
);
}
Expand Down
Loading