Skip to content

Commit 68b73b9

Browse files
authored
Merge pull request #2030 from bconti123/1724-Change-Edit-Meeting-Times-to-MUI
1724 - Add MUI Modal open/close behavior
2 parents 88ffbe2 + c82c46d commit 68b73b9

File tree

1 file changed

+53
-42
lines changed

1 file changed

+53
-42
lines changed
Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import React, { useState } from 'react';
1+
import { useState } from 'react';
22
import '../../sass/ManageProjects.scss';
33
import { useSnackbar } from '../../context/snackbarContext';
44
import EditableMeeting from './editableMeeting';
55
import { findNextOccuranceOfDay } from './utilities/findNextDayOccuranceOfDay';
66
import { addDurationToTime } from './utilities/addDurationToTime';
77
import { timeConvertFromForm } from './utilities/timeConvertFromForm';
88
import validateEventForm from './utilities/validateEventForm';
9+
import { Box, Button, Modal } from '@mui/material';
910

1011
// This component displays current meeting times for selected project and offers the option to edit those times.
1112
const EditMeetingTimes = ({
@@ -16,13 +17,15 @@ const EditMeetingTimes = ({
1617
updateRecurringEvent,
1718
}) => {
1819
const [formErrors, setFormErrors] = useState({});
20+
const open = Boolean(selectedEvent);
1921
const { showSnackbar } = useSnackbar();
20-
const handleEventUpdate = (
21-
eventID,
22-
values,
23-
startTimeOriginal,
24-
durationOriginal
25-
) => async () => {
22+
23+
const handleClose = () => {
24+
setFormErrors(null);
25+
setSelectedEvent(null);
26+
};
27+
28+
const handleEventUpdate = (eventID, values) => async () => {
2629
const errors = validateEventForm(values, projectToEdit);
2730
if (!errors) {
2831
let theUpdatedEvent = {};
@@ -60,7 +63,7 @@ const EditMeetingTimes = ({
6063
updatedDate,
6164
};
6265

63-
// Find next occurance of Day in the future
66+
// Find next occurrence of Day in the future
6467
// Assign new start time and end time
6568
const date = findNextOccuranceOfDay(values.day);
6669
const startTimeDate = timeConvertFromForm(date, values.startTime);
@@ -69,58 +72,66 @@ const EditMeetingTimes = ({
6972
// Revert timestamps to GMT
7073
const startDateTimeGMT = new Date(startTimeDate).toISOString();
7174
const endTimeGMT = new Date(endTime).toISOString();
72-
75+
7376
theUpdatedEvent = {
7477
...theUpdatedEvent,
7578
date: startDateTimeGMT,
7679
startTime: startDateTimeGMT,
7780
endTime: endTimeGMT,
78-
duration: values.duration
81+
duration: values.duration,
7982
};
8083

8184
updateRecurringEvent(theUpdatedEvent, eventID);
82-
showSnackbar("Recurring event updated", 'info')
83-
setSelectedEvent(null);
85+
showSnackbar('Recurring event updated', 'info');
86+
handleClose();
8487
}
8588
setFormErrors(errors);
8689
};
8790

8891
const handleEventDelete = (eventID) => async () => {
8992
deleteRecurringEvent(eventID);
90-
setSelectedEvent(null);
91-
showSnackbar("Recurring event deleted", 'info');
93+
showSnackbar('Recurring event deleted', 'info');
94+
handleClose();
9295
};
9396

9497
return (
95-
<div>
96-
<button
97-
type="button"
98-
className="meeting-cancel-button"
99-
onClick={() => {
100-
setFormErrors(null);
101-
setSelectedEvent(null);
98+
<Modal open={open} onClose={handleClose}>
99+
<Box
100+
className="modal-box"
101+
sx={{
102+
position: 'absolute',
103+
top: '42%',
104+
left: '50%',
105+
transform: 'translate(-50%, -50%)',
106+
width: 450,
107+
bgcolor: 'background.paper',
108+
border: '2px solid #000',
109+
boxShadow: 24,
110+
pt: 4,
111+
px: 4,
112+
pb: 0,
102113
}}
103114
>
104-
X
105-
</button>
106-
{selectedEvent && (
107-
<EditableMeeting
108-
key={selectedEvent.event_id}
109-
eventId={selectedEvent.event_id}
110-
eventName={selectedEvent.name}
111-
eventDescription={selectedEvent.description}
112-
eventType={selectedEvent.eventType}
113-
eventDayNumber={selectedEvent.dayOfTheWeekNumber}
114-
eventStartTime={selectedEvent.startTime}
115-
eventEndTime={selectedEvent.endTime}
116-
eventDuration={selectedEvent.duration}
117-
videoConferenceLink={selectedEvent.videoConferenceLink}
118-
formErrors={formErrors}
119-
handleEventUpdate={handleEventUpdate}
120-
handleEventDelete={handleEventDelete}
121-
/>
122-
)}
123-
</div>
115+
{selectedEvent && (
116+
<EditableMeeting
117+
key={selectedEvent.event_id}
118+
eventId={selectedEvent.event_id}
119+
eventName={selectedEvent.name}
120+
eventDescription={selectedEvent.description}
121+
eventType={selectedEvent.eventType}
122+
eventDayNumber={selectedEvent.dayOfTheWeekNumber}
123+
eventStartTime={selectedEvent.startTime}
124+
eventEndTime={selectedEvent.endTime}
125+
eventDuration={selectedEvent.duration}
126+
videoConferenceLink={selectedEvent.videoConferenceLink}
127+
formErrors={formErrors}
128+
handleEventUpdate={handleEventUpdate}
129+
handleEventDelete={handleEventDelete}
130+
/>
131+
)}
132+
<Button onClick={handleClose}>Close</Button>
133+
</Box>
134+
</Modal>
124135
);
125136
};
126-
export default EditMeetingTimes;
137+
export default EditMeetingTimes;

0 commit comments

Comments
 (0)