-
Notifications
You must be signed in to change notification settings - Fork 3
Fix time validation, standardize request modals #609
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
Changes from all commits
4988761
0921772
3003214
ad77f3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ import AdminPanelSettingsIcon from '@mui/icons-material/AdminPanelSettings'; | |
| import CloseIcon from '@mui/icons-material/Close'; | ||
| import { RideType, Status, SchedulingState } from '../../types'; | ||
| import { useRideEdit } from './RideEditContext'; | ||
| import { validateRideTimes, TimeValidationError } from './TimeValidation'; | ||
| import { | ||
| canUpdateStatus, | ||
| canCancelRide, | ||
|
|
@@ -92,6 +93,8 @@ const RideActions: React.FC<RideActionsProps> = ({ | |
| const [selectedStatus, setSelectedStatus] = useState<Status | null>(null); | ||
| const [updating, setUpdating] = useState(false); | ||
| const [saving, setSaving] = useState(false); | ||
| const [timeErrorOpen, setTimeErrorOpen] = useState(false); | ||
| const [timeErrors, setTimeErrors] = useState<TimeValidationError[]>([]); | ||
|
|
||
| const ride = editedRide!; // We know this exists from the context | ||
| const rideCompleted = ride.status === Status.COMPLETED; | ||
|
|
@@ -159,6 +162,24 @@ const RideActions: React.FC<RideActionsProps> = ({ | |
| }; | ||
|
|
||
| const handleSave = async () => { | ||
| // Validate times before saving; show modal with errors if invalid | ||
| const allowPastTimes = false; | ||
| const timeValidation = validateRideTimes( | ||
| ride.startTime, | ||
| ride.endTime, | ||
| { | ||
| allowPastTimes, | ||
| maxDurationHours: 24, | ||
| minDurationMinutes: 5, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How was 5 minutes chosen as the minimum? We might want to just make this 0 or 1 so we never get in the way on minimums. |
||
| } | ||
| ); | ||
|
|
||
| if (!timeValidation.isValid) { | ||
| setTimeErrors(timeValidation.errors); | ||
| setTimeErrorOpen(true); | ||
| return; | ||
| } | ||
|
|
||
| setSaving(true); | ||
| try { | ||
| const success = await saveChanges(); | ||
|
|
@@ -527,6 +548,34 @@ const RideActions: React.FC<RideActionsProps> = ({ | |
| </DialogActions> | ||
| </Dialog> | ||
|
|
||
| {/* Time Validation Errors Modal */} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might have missed when this was already discussed, but what was the reasoning behind a modal specifically for these validation errors? Wouldn't something inline on the layout be a little more clear, to avoid stacking modals on top of modals, or are we switching due to layout shift and consistency issues? Either way it might be useful if the PR summary had justification behind this consideration. |
||
| <Dialog | ||
| open={timeErrorOpen} | ||
| onClose={() => setTimeErrorOpen(false)} | ||
| fullWidth | ||
| maxWidth="sm" | ||
| > | ||
| <DialogTitle>Cannot Save – Please Fix Time Settings</DialogTitle> | ||
| <DialogContent> | ||
| <Typography variant="body2" color="textSecondary" gutterBottom> | ||
| The following issues were found: | ||
| </Typography> | ||
| <List> | ||
| {timeErrors.map((err, idx) => ( | ||
| <ListItem key={idx}> | ||
| <ListItemIcon> | ||
| <ReportIcon color="error" /> | ||
| </ListItemIcon> | ||
| <ListItemText primary={err.message} /> | ||
| </ListItem> | ||
| ))} | ||
| </List> | ||
| </DialogContent> | ||
| <DialogActions> | ||
| <Button onClick={() => setTimeErrorOpen(false)}>Close</Button> | ||
| </DialogActions> | ||
| </Dialog> | ||
|
|
||
| {/* Contact Admin Modal */} | ||
| <Dialog | ||
| open={contactAdminOpen} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,7 +153,7 @@ export const RideEditProvider: React.FC<RideEditProviderProps> = ({ | |
| editedRide.startTime, | ||
| editedRide.endTime, | ||
| { | ||
| allowPastTimes: !isNewRide(editedRide), | ||
| allowPastTimes: false, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am I misreading something, or does this change mean past rides can never be edited? Does this effectively freeze past rides in place? |
||
| maxDurationHours: 24, | ||
| minDurationMinutes: 5, | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do
timeErrorOpenandtimeErrorsneed to be independent pieces of state? Can one be derived with auseMemo?