diff --git a/app/components/CalendarModalButton.tsx b/app/components/CalendarModalButton.tsx index 6e9bb95..f997346 100644 --- a/app/components/CalendarModalButton.tsx +++ b/app/components/CalendarModalButton.tsx @@ -17,6 +17,13 @@ import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; import { DatePicker } from '@mui/x-date-pickers/DatePicker'; +import Alert from '@mui/material/Alert'; +import IconButton from '@mui/material/IconButton'; +import Collapse from '@mui/material/Collapse'; +import CloseIcon from '@mui/icons-material/Close'; + + + const style = { position: 'absolute' as 'absolute', top: '50%', @@ -72,17 +79,46 @@ const initialFormData = { const CalendarModalButton: FC = ({callback}) => { const [open, setOpen] = useState(false); const handleOpen = () => setOpen(true); - const handleClose = () => setOpen(false); + const handleClose = () => { + setFormData(initialFormData); + setOpen(false); + } const [startDate, setStartDate] = useState(new Date()); const [endDate, setEndDate] = useState(new Date()); const [formData, setFormData] = useState(initialFormData); + // For Date/Time (Add Shift) validation + const [timeError, setTimeError] = useState(true); + + // Allows for the update of the validation to happen in real-time despite asynchronosity of formdata + useEffect(() => { + validateTime(); + }, [formData]); + + // Handle form input change const handleInputChange = (e) => { const { name, value } = e.target; setFormData((prevData) => ({ ...prevData, [name]: value })); }; + + const validateTime = () => { + let startingDate = new Date(formData.startDate); + let endingDate = new Date(formData.endDate); + + startingDate.setHours(formData.startTime) + endingDate.setHours(formData.endTime) + + let timeDifference = endingDate.getTime() - startingDate.getTime(); + + // Invalid time combination is if end time occurs before start time: + if (timeDifference <= 0) { + setTimeError(true); + } else { + setTimeError(false); + } + } // Handle form submission (IN PROGRESS) const handleSubmit = async (e) => { @@ -174,148 +210,162 @@ const CalendarModalButton: FC = ({callback}) => { -
- - - - - - Start Time: - - - {/* Start Date */} - - setStartDate(new Date(newValue))} - sx={{ marginRight: '10px',width: '180px' }} - /> - - - - - - - End Time: - - -
- setEndDate(new Date(newValue))} - sx={{ marginRight: '10px',width: '180px' }} - /> -
-
- - -
- - - Assigned Employee: - - - - - - Phone Line: - - - - - - - - {/* ASSIGN SHIFT CONFIRMATION BUTTON (where we post shift) */} - - - - -
-
-
-
+ {/* Start Date */} + + { + setStartDate(new Date(newValue)); + handleInputChange({ target: { name: 'startDate', value: newValue } }); + }} + sx={{ marginRight: '10px',width: '180px' }} + /> + + + + + + + End Time: + + +
+ { + setEndDate(new Date(newValue)); + handleInputChange({ target: { name: 'endDate', value: newValue } }); + }} + sx={{ marginRight: '10px',width: '180px' }} + /> +
+
+ + +
+ + + Assigned Employee: + + + + + + Phone Line: + + + + + + + + {/* ASSIGN SHIFT CONFIRMATION BUTTON (where we post shift) */} + + + + + + + +