-
Notifications
You must be signed in to change notification settings - Fork 91
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
feat: Added complaint button, hidden as an easter egg 'complaint'. #791
Changes from all commits
ef84f83
41607a6
61dc27e
c54eaf4
2958356
316a8f4
0e98a9d
f8dab1c
94715df
13023c7
b5e1761
457fe41
f8b6fb4
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 | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,194 @@ | ||||||
import { useState, ChangeEvent, useEffect } from 'react' | ||||||
import { | ||||||
Box, | ||||||
Button, | ||||||
FormControl, | ||||||
InputLabel, | ||||||
MenuItem, | ||||||
Modal, | ||||||
Select, | ||||||
TextField, | ||||||
SelectChangeEvent, | ||||||
CircularProgress, | ||||||
} from '@mui/material' | ||||||
import { useTranslation } from 'react-i18next' | ||||||
import { SiriRideWithRelatedPydanticModel } from 'open-bus-stride-client' | ||||||
import { Point } from 'src/pages/timeBasedMap' | ||||||
import { getSiriRideWithRelated } from 'src/api/siriService' | ||||||
|
||||||
interface ComplaintModalProps { | ||||||
modalOpen: boolean | ||||||
setModalOpen: (open: boolean) => void | ||||||
position: Point | ||||||
} | ||||||
|
||||||
const ComplaintModal = ({ modalOpen, setModalOpen, position }: ComplaintModalProps) => { | ||||||
const { t, i18n } = useTranslation() | ||||||
const [siriRide, setSiriRide] = useState<SiriRideWithRelatedPydanticModel | undefined>() | ||||||
const [isLoading, setIsLoading] = useState(false) | ||||||
const [complaintData, setComplaintData] = useState({ | ||||||
firstName: '', | ||||||
lastName: '', | ||||||
id: '', | ||||||
email: '', | ||||||
phone: '', | ||||||
complaintType: '', | ||||||
description: '', | ||||||
}) | ||||||
|
||||||
useEffect(() => { | ||||||
setIsLoading(true) | ||||||
getSiriRideWithRelated( | ||||||
position.point!.siri_route__id.toString(), | ||||||
position.point!.siri_ride__vehicle_ref.toString(), | ||||||
position.point!.siri_route__line_ref.toString(), | ||||||
) | ||||||
.then((siriRideRes: SiriRideWithRelatedPydanticModel) => setSiriRide(siriRideRes)) | ||||||
.finally(() => setIsLoading(false)) | ||||||
}, [position]) | ||||||
|
||||||
const modalStyle = { | ||||||
position: 'absolute' as const, | ||||||
top: '50%', | ||||||
left: '50%', | ||||||
transform: 'translate(-50%, -50%)', | ||||||
width: 400, | ||||||
bgcolor: 'background.paper', | ||||||
border: '2px solid #000', | ||||||
boxShadow: 24, | ||||||
p: 4, | ||||||
textAlign: i18n.language === 'he' ? 'left' : 'right', | ||||||
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. something feels weird about this condition, are you sure it works as intended? |
||||||
} as const | ||||||
|
||||||
const handleInputChange = (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => { | ||||||
const { name, value } = e.target | ||||||
setComplaintData((prevData) => ({ ...prevData, [name]: value })) | ||||||
} | ||||||
|
||||||
const handleSelectChange = (e: SelectChangeEvent<string>) => { | ||||||
const { name, value } = e.target | ||||||
setComplaintData((prevData) => ({ ...prevData, [name]: value }) as const) | ||||||
} | ||||||
const handleSubmit = () => { | ||||||
const complaintPayload = { | ||||||
userData: complaintData, | ||||||
databusData: { | ||||||
operator: siriRide?.gtfsRideGtfsRouteId, | ||||||
...position, | ||||||
}, | ||||||
} | ||||||
console.log(complaintPayload) | ||||||
// Handle the form submission, e.g., send it to an API | ||||||
setModalOpen(false) | ||||||
} | ||||||
|
||||||
return ( | ||||||
<div> | ||||||
{isLoading || !siriRide ? ( | ||||||
<div className="loading"> | ||||||
<span>{t('loading_routes')}</span> | ||||||
<CircularProgress /> | ||||||
</div> | ||||||
) : ( | ||||||
<Modal | ||||||
open={modalOpen} | ||||||
onClose={() => setModalOpen(false)} | ||||||
aria-labelledby="modal-modal-title" | ||||||
aria-describedby="modal-modal-description"> | ||||||
<Box className="modal" sx={modalStyle}> | ||||||
<h2>{t('complaint')}</h2> | ||||||
<form> | ||||||
<TextField | ||||||
label={t('first_name')} | ||||||
name="firstName" | ||||||
value={complaintData.firstName} | ||||||
onChange={handleInputChange} | ||||||
fullWidth | ||||||
margin="normal" | ||||||
/> | ||||||
<TextField | ||||||
label={t('last_name')} | ||||||
name="lastName" | ||||||
value={complaintData.lastName} | ||||||
onChange={handleInputChange} | ||||||
fullWidth | ||||||
margin="normal" | ||||||
/> | ||||||
<TextField | ||||||
label={t('id')} | ||||||
name="id" | ||||||
value={complaintData.id} | ||||||
onChange={handleInputChange} | ||||||
fullWidth | ||||||
margin="normal" | ||||||
/> | ||||||
<TextField | ||||||
label={t('email')} | ||||||
name="email" | ||||||
value={complaintData.email} | ||||||
onChange={handleInputChange} | ||||||
fullWidth | ||||||
margin="normal" | ||||||
/> | ||||||
Comment on lines
+125
to
+132
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. if you'll add |
||||||
<TextField | ||||||
label={t('phone')} | ||||||
name="phone" | ||||||
value={complaintData.phone} | ||||||
onChange={handleInputChange} | ||||||
fullWidth | ||||||
margin="normal" | ||||||
/> | ||||||
<FormControl fullWidth margin="normal"> | ||||||
<InputLabel>{t('complaint_type')}</InputLabel> | ||||||
<Select | ||||||
name="complaintType" | ||||||
value={complaintData.complaintType} | ||||||
onChange={handleSelectChange} | ||||||
sx={{ textAlign: i18n.language === 'he' ? 'left' : 'right' }}> | ||||||
<MenuItem value="other">{t('other')}</MenuItem> | ||||||
<MenuItem value="no_stop">{t('no_stop')}</MenuItem> | ||||||
<MenuItem value="no_ride">{t('no_ride')}</MenuItem> | ||||||
<MenuItem value="delay">{t('delay')}</MenuItem> | ||||||
<MenuItem value="overcrowded">{t('overcrowded')}</MenuItem> | ||||||
<MenuItem value="driver_behavior">{t('driver_behavior')}</MenuItem> | ||||||
<MenuItem value="early">{t('early')}</MenuItem> | ||||||
<MenuItem value="cleanliness">{t('cleanliness')}</MenuItem> | ||||||
<MenuItem value="fine_appeal">{t('fine_appeal')}</MenuItem> | ||||||
<MenuItem value="route_change">{t('route_change')}</MenuItem> | ||||||
<MenuItem value="line_switch">{t('line_switch')}</MenuItem> | ||||||
<MenuItem value="station_signs">{t('station_signs')}</MenuItem> | ||||||
</Select> | ||||||
</FormControl> | ||||||
<TextField | ||||||
label={t('description')} | ||||||
name="description" | ||||||
value={complaintData.description} | ||||||
onChange={handleInputChange} | ||||||
multiline | ||||||
rows={4} | ||||||
fullWidth | ||||||
margin="normal" | ||||||
/> | ||||||
<Button | ||||||
variant="contained" | ||||||
color="primary" | ||||||
onClick={handleSubmit} | ||||||
style={{ marginTop: '16px', borderRadius: '50px' }}> | ||||||
{t('submit_complaint')} | ||||||
</Button> | ||||||
</form> | ||||||
<Button | ||||||
variant="contained" | ||||||
color="success" | ||||||
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. this button will lead the user to cancel their complaint and potentially loose everything they typed
Suggested change
|
||||||
onClick={() => setModalOpen(false)} | ||||||
style={{ marginTop: '16px', borderRadius: '50px' }}> | ||||||
{t('close_complaint')} | ||||||
</Button> | ||||||
</Box> | ||||||
</Modal> | ||||||
)} | ||||||
</div> | ||||||
) | ||||||
} | ||||||
|
||||||
export default ComplaintModal |
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.