-
Notifications
You must be signed in to change notification settings - Fork 3
Implement email service #600
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
selenaliu1
wants to merge
16
commits into
master
Choose a base branch
from
sl2663/emailservice
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3338484
implement nodemailer
selenaliu1 9ce8237
update package-lock.json
selenaliu1 3c2decf
merge sso changes
selenaliu1 5f862f4
Merge branch 'master' of github.com:cornell-dti/carriage-web into sl2…
selenaliu1 0a9425f
add requested vs cancelled state and guards, misc fixes: removed stat…
selenaliu1 efbc152
standardize cancel/reject ride confirmation dialog across student and…
selenaliu1 82c5c9d
remove unwanted file
selenaliu1 93fb1e0
separate email service from notification logic, scheduled with modifi…
selenaliu1 128cbf1
prettier
selenaliu1 b1d6bee
Merge branch 'master' of github.com:cornell-dti/carriage-web into sl2…
selenaliu1 bab9ed4
Merge branch 'master' of github.com:cornell-dti/carriage-web into sl2…
selenaliu1 d5a0cea
Merge branch 'master' of github.com:cornell-dti/carriage-web into sl2…
selenaliu1 82b235b
Merge branch 'master' of github.com:cornell-dti/carriage-web into sl2…
selenaliu1 5f0a80a
code review
selenaliu1 18423aa
prettier
selenaliu1 4c99f7e
Merge branch 'master' into sl2663/emailservice
mjaydenkim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
148 changes: 148 additions & 0 deletions
148
frontend/src/components/Modal/CancelRideConfirmationDialog.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| import React from 'react'; | ||
| import { | ||
| Dialog, | ||
| DialogTitle, | ||
| DialogContent, | ||
| DialogActions, | ||
| Button, | ||
| Typography, | ||
| Box, | ||
| } from '@mui/material'; | ||
| import { RideType, SchedulingState } from '../../types'; | ||
| import { UserRole } from '../../util/rideValidation'; | ||
| import axios from '../../util/axios'; | ||
| import { useToast, ToastStatus } from '../../context/toastContext'; | ||
| import { useRides } from '../../context/RidesContext'; | ||
|
|
||
| interface CancelRideConfirmationDialogProps { | ||
| open: boolean; | ||
| onClose: () => void; | ||
| ride: RideType; | ||
| userRole?: UserRole; | ||
| onSuccess?: () => void; | ||
| } | ||
|
|
||
| const CancelRideConfirmationDialog: React.FC< | ||
| CancelRideConfirmationDialogProps | ||
| > = ({ open, onClose, ride, userRole: propUserRole, onSuccess }) => { | ||
| const { showToast } = useToast(); | ||
| const { refreshRides } = useRides(); | ||
|
|
||
| // Get user role from localStorage if not provided as prop | ||
| const getUserRole = (): UserRole => { | ||
| if (propUserRole) return propUserRole; | ||
| const userType = localStorage.getItem('userType'); | ||
| if (userType === 'Admin') return 'admin'; | ||
| if (userType === 'Driver') return 'driver'; | ||
| if (userType === 'Rider') return 'rider'; | ||
| return 'rider'; | ||
| }; | ||
|
|
||
| const userRole = getUserRole(); | ||
|
|
||
| const handleCancelConfirm = async () => { | ||
| // Check for recurring rides (not supported yet) | ||
| if (ride.isRecurring) { | ||
| showToast('Recurring ride deletion not supported yet', ToastStatus.ERROR); | ||
| return; | ||
| } | ||
|
|
||
| // Only admins can reject rides; riders can only cancel | ||
| // If ride has no driver (unscheduled) AND user is admin, reject it | ||
| if (!ride.driver && userRole === 'admin') { | ||
| try { | ||
| // Set schedulingState to REJECTED | ||
| await axios.put(`/api/rides/${ride.id}`, { | ||
| schedulingState: SchedulingState.REJECTED, | ||
| }); | ||
|
|
||
| // Close the cancel confirmation modal | ||
| onClose(); | ||
|
|
||
| // Refresh the rides data | ||
| refreshRides(); | ||
|
|
||
| // Show success message | ||
| showToast('Ride Rejected', ToastStatus.SUCCESS); | ||
| onSuccess?.(); | ||
| } catch (error) { | ||
| console.error('Failed to reject ride:', error); | ||
| showToast('Failed to reject ride', ToastStatus.ERROR); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| // All other cases: call DELETE endpoint | ||
| // Backend will handle: | ||
| // - If unscheduled ride + user is rider: physically delete the ride | ||
| // - If scheduled ride (has driver) + user is admin: set status to CANCELLED | ||
| try { | ||
| await axios.delete(`/api/rides/${ride.id}`); | ||
|
|
||
| // Close the cancel confirmation modal | ||
| onClose(); | ||
|
|
||
| // Refresh the rides data | ||
| refreshRides(); | ||
|
|
||
| // Show success message | ||
| showToast('Ride Cancelled', ToastStatus.SUCCESS); | ||
| onSuccess?.(); | ||
| } catch (error) { | ||
| console.error('Failed to cancel ride:', error); | ||
| showToast('Failed to cancel ride', ToastStatus.ERROR); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog open={open} onClose={onClose} fullWidth maxWidth="xs"> | ||
| <DialogTitle> | ||
| {!ride.driver && userRole === 'admin' ? 'Reject Ride' : 'Cancel Ride'} | ||
| </DialogTitle> | ||
| <DialogContent> | ||
| <Typography> | ||
| {!ride.driver && userRole === 'admin' | ||
| ? 'Are you sure you want to reject this ride? This will mark the ride as rejected and notify the rider.' | ||
| : 'Are you sure you want to cancel this ride? This action cannot be undone.'} | ||
| </Typography> | ||
| <Box sx={{ mt: 2, p: 2, backgroundColor: 'grey.50', borderRadius: 1 }}> | ||
| <Typography variant="body2" color="textSecondary"> | ||
| Ride Summary | ||
| </Typography> | ||
| <Typography variant="body2"> | ||
| {new Date(ride.startTime).toLocaleDateString()} at{' '} | ||
| {new Date(ride.startTime).toLocaleTimeString([], { | ||
| hour: '2-digit', | ||
| minute: '2-digit', | ||
| })} | ||
| </Typography> | ||
| {ride.riders && ride.riders.length > 0 && ( | ||
| <Typography variant="body2"> | ||
| Rider:{' '} | ||
| {ride.riders | ||
| .map((rider) => rider.firstName + ' ' + rider.lastName) | ||
| .join(', ')} | ||
| </Typography> | ||
| )} | ||
| {ride.driver && ( | ||
| <Typography variant="body2"> | ||
| Driver: {ride.driver?.firstName + ' ' + ride.driver?.lastName} | ||
| </Typography> | ||
| )} | ||
| <Typography variant="body2"> | ||
| From: {ride.startLocation.name} | ||
| </Typography> | ||
| <Typography variant="body2">To: {ride.endLocation.name}</Typography> | ||
| </Box> | ||
| </DialogContent> | ||
| <DialogActions> | ||
| <Button onClick={onClose}>Keep Ride</Button> | ||
| <Button onClick={handleCancelConfirm} variant="contained" color="error"> | ||
| {!ride.driver && userRole === 'admin' ? 'Reject Ride' : 'Cancel Ride'} | ||
| </Button> | ||
| </DialogActions> | ||
| </Dialog> | ||
| ); | ||
| }; | ||
|
|
||
| export default CancelRideConfirmationDialog; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.