add dropdown that allows viewing meetings for other team members, or all team members at once
This commit is contained in:
parent
62d120afb7
commit
f282d0d96c
@ -2,15 +2,15 @@ import { Calendar, momentLocalizer, Views } from "react-big-calendar";
|
|||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
|
|
||||||
import "react-big-calendar/lib/css/react-big-calendar.css";
|
import "react-big-calendar/lib/css/react-big-calendar.css";
|
||||||
import { Divider, Toolbar } from "@mui/material";
|
import { Divider, FormControl, InputLabel, MenuItem, Select, SelectChangeEvent, Toolbar, Typography } from "@mui/material";
|
||||||
import { selectUserUpcomingMeetings } from "../../redux/slices/meetingsAndUserStatusSlice";
|
import { selectMeetings } from "../../redux/slices/meetingsAndUserStatusSlice";
|
||||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||||
import { selectMe } from "../../redux/slices/usersSlice";
|
import { selectMe, selectTeam, selectUser, selectUsers } from "../../redux/slices/usersSlice";
|
||||||
import { open } from "../../redux/slices/meetingDetailsOpenSlice";
|
import { open } from "../../redux/slices/meetingDetailsOpenSlice";
|
||||||
import DetailedMeeting from "../../api-bodies/DetailedMeeting";
|
import DetailedMeeting from "../../api-bodies/DetailedMeeting";
|
||||||
|
import { useState } from "react";
|
||||||
|
import UserLite from "../../api-bodies/UserLite";
|
||||||
|
|
||||||
// TODO: per user calendar
|
|
||||||
// TODO: full view (all teammates)
|
|
||||||
// TODO: match the styles and themes
|
// TODO: match the styles and themes
|
||||||
|
|
||||||
// A superset of DetailedMeeting; contains fields required for the calendar to work
|
// A superset of DetailedMeeting; contains fields required for the calendar to work
|
||||||
@ -28,12 +28,25 @@ interface CalendarEvent {
|
|||||||
end: Date;
|
end: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CalendarPage: React.FC = () => {
|
enum CalendarTaskView {
|
||||||
|
ViewAll = "VIEWALL"
|
||||||
|
}
|
||||||
|
|
||||||
|
const CalendarPage: React.FC = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const currentUserUuid = useAppSelector(selectMe); // TODO: per-user
|
|
||||||
const meetings = useAppSelector((state) =>
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
selectUserUpcomingMeetings(state, currentUserUuid)
|
const currentUserUuid: string = useAppSelector(selectMe)!;
|
||||||
|
const currentUser: UserLite = useAppSelector((state) =>
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
selectUser(state, currentUserUuid)!
|
||||||
|
);
|
||||||
|
const teamUuids: string[] = useAppSelector(selectTeam);
|
||||||
|
const team: UserLite[] = useAppSelector((state) =>
|
||||||
|
selectUsers(state, teamUuids)
|
||||||
|
);
|
||||||
|
const meetings: CalendarEvent[] = useAppSelector((state) =>
|
||||||
|
selectMeetings(state)
|
||||||
).map(m =>
|
).map(m =>
|
||||||
({
|
({
|
||||||
meetingId: m.meetingId,
|
meetingId: m.meetingId,
|
||||||
@ -51,6 +64,9 @@ const CalendarPage: React.FC = () => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const [selectedUserUuid, setSelectedUserUuid] = useState(currentUserUuid);
|
||||||
|
|
||||||
|
// turns calendar event back into DetailedMeeting then opens meeting view
|
||||||
const handleSelectEvent = (event: CalendarEvent) => {
|
const handleSelectEvent = (event: CalendarEvent) => {
|
||||||
const meeting: DetailedMeeting = {
|
const meeting: DetailedMeeting = {
|
||||||
meetingId: event.meetingId,
|
meetingId: event.meetingId,
|
||||||
@ -65,12 +81,48 @@ const CalendarPage: React.FC = () => {
|
|||||||
dispatch(open(meeting));
|
dispatch(open(meeting));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// dropdown selection event
|
||||||
|
const handleUserChange = (event: SelectChangeEvent) => {
|
||||||
|
setSelectedUserUuid(event.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
// filter the meetings based on the uuid
|
||||||
|
const getUserMeetings = (uuid: string): CalendarEvent[] => {
|
||||||
|
if (uuid == CalendarTaskView.ViewAll) { // "View all team member meetings" option
|
||||||
|
return meetings;
|
||||||
|
} else {
|
||||||
|
return meetings.filter(meeting => meeting.registrantIds.includes(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Toolbar />
|
<Toolbar />
|
||||||
|
|
||||||
|
<FormControl variant="filled" fullWidth>
|
||||||
|
<InputLabel id="calendar-user-select-label">
|
||||||
|
<Typography color="black">User</Typography>
|
||||||
|
</InputLabel>
|
||||||
|
<Select
|
||||||
|
labelId="calendar-user-select-label"
|
||||||
|
id="calendar-user-select"
|
||||||
|
value={selectedUserUuid}
|
||||||
|
label="User"
|
||||||
|
onChange={handleUserChange}
|
||||||
|
>
|
||||||
|
<MenuItem value={CalendarTaskView.ViewAll}>View all team member meetings</MenuItem>
|
||||||
|
<MenuItem value={currentUserUuid}>{currentUser.name + " (Me)"}</MenuItem>
|
||||||
|
{team.map(user => (
|
||||||
|
<MenuItem key={user.uuid} value={user.uuid}>{user.name}</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
<Divider sx={{ my: 1 }} />
|
<Divider sx={{ my: 1 }} />
|
||||||
|
|
||||||
<Calendar
|
<Calendar
|
||||||
events={meetings}
|
events={getUserMeetings(selectedUserUuid)}
|
||||||
views={["month", "week", "day"]}
|
views={["month", "week", "day"]}
|
||||||
defaultView={Views.WEEK}
|
defaultView={Views.WEEK}
|
||||||
onSelectEvent={handleSelectEvent}
|
onSelectEvent={handleSelectEvent}
|
||||||
|
|||||||
Reference in New Issue
Block a user