-
Notifications
You must be signed in to change notification settings - Fork 3
Edit rider info modal #690
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
anika-4444
wants to merge
4
commits into
master
Choose a base branch
from
edit-rider-info
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ const RiderModalInfo: React.FC<ModalFormProps> = ({ | |
| const [showCustomInput, setShowCustomInput] = useState(false); | ||
| const [customNeed, setCustomNeed] = useState(''); | ||
|
|
||
| // Returns a validator function so both name fields share the same logic with different labels | ||
| const makeNameValidator = | ||
| (fieldLabel: 'First name' | 'Last name') => (value: string) => { | ||
| const trimmed = value.trim(); | ||
|
|
@@ -124,6 +125,8 @@ const RiderModalInfo: React.FC<ModalFormProps> = ({ | |
| }), | ||
| }; | ||
|
|
||
| // "Add Custom Need" is a sentinel option | ||
| // intercept it to show the free-text input instead of adding it as a real need | ||
| const handleNeedsChange = ( | ||
| selectedOptions: readonly NeedOption[] | null, | ||
| { action }: any | ||
|
|
@@ -145,6 +148,7 @@ const RiderModalInfo: React.FC<ModalFormProps> = ({ | |
| if (customNeed.trim()) { | ||
| const currentNeeds = getValues('needs') || []; | ||
| const newNeed: NeedOption = { | ||
| // Normalize to UPPER_SNAKE_CASE to match the Accessibility enum format on the backend | ||
| value: customNeed.toUpperCase().replace(/\s+/g, '_'), | ||
| label: customNeed.trim(), | ||
| }; | ||
|
|
@@ -173,6 +177,7 @@ const RiderModalInfo: React.FC<ModalFormProps> = ({ | |
| const accessibility = needs.map((option) => option.value.toString()); | ||
| const normalizedPhoneNumber = normalizePhoneNumber(phoneNumber); | ||
|
|
||
| // Derive active status client-side so backend doesn't need to recalculate it on every edit | ||
| const today = new Date().toISOString().slice(0, 10); | ||
| const active = joinDate <= today && today <= endDate; | ||
|
|
||
|
|
@@ -192,12 +197,13 @@ const RiderModalInfo: React.FC<ModalFormProps> = ({ | |
| }; | ||
|
|
||
| const cancel = () => { | ||
| setFormData({}); | ||
| setFormData({}); // Clear stale data so a reopened modal doesn't submit a partial previous entry | ||
| setIsOpen(false); | ||
| }; | ||
|
|
||
| const localUserType = localStorage.getItem('userType'); | ||
| const isEditing = rider !== undefined; | ||
| // Riders editing their own profile get a restricted form — no NetID or duration fields | ||
| const isStudentEditing = isEditing && localUserType === 'Rider'; | ||
|
|
||
| const needsOptions: NeedOption[] = [ | ||
|
|
@@ -251,23 +257,24 @@ const RiderModalInfo: React.FC<ModalFormProps> = ({ | |
| )} | ||
| </div> | ||
|
|
||
| <div className={cn(styles.gridR1, styles.gridCSmall3)}> | ||
| <Label className={styles.label} htmlFor="netid"> | ||
| NetID:{' '} | ||
| </Label> | ||
| <Input | ||
| id="netid" | ||
| {...register('netid', { | ||
| required: true, | ||
| pattern: /^[a-zA-Z]+[0-9]+$/, | ||
| })} | ||
| type="text" | ||
| disabled={isStudentEditing} | ||
| className={styles.firstRow} | ||
| aria-required="true" | ||
| /> | ||
| {errors.netid && <p className={styles.error}>Invalid NetID</p>} | ||
| </div> | ||
| {!isStudentEditing && ( | ||
| <div className={cn(styles.gridR1, styles.gridCSmall3)}> | ||
| <Label className={styles.label} htmlFor="netid"> | ||
| NetID:{' '} | ||
| </Label> | ||
| <Input | ||
| id="netid" | ||
| {...register('netid', { | ||
| required: true, | ||
| pattern: /^[a-zA-Z]+[0-9]+$/, | ||
| })} | ||
| type="text" | ||
| className={styles.firstRow} | ||
| aria-required="true" | ||
| /> | ||
| {errors.netid && <p className={styles.error}>Invalid NetID</p>} | ||
| </div> | ||
| )} | ||
|
|
||
| <div className={cn(styles.gridR2, styles.gridCBig1)}> | ||
| <Label className={styles.label} htmlFor="phoneNumber"> | ||
|
|
@@ -354,55 +361,55 @@ const RiderModalInfo: React.FC<ModalFormProps> = ({ | |
| </div> | ||
| </div> | ||
|
|
||
| <div className={cn(styles.gridR3, styles.gridCAll)}> | ||
| <p>Duration</p> | ||
| <div className={styles.lastRow}> | ||
| <div> | ||
| <Label className={styles.label} htmlFor="joinDate"> | ||
| Join Date:{' '} | ||
| </Label> | ||
| <Input | ||
| id="joinDate" | ||
| {...register('joinDate', { required: true })} | ||
| type="date" | ||
| aria-required="true" | ||
| disabled={isStudentEditing} | ||
| className={styles.riderDate} | ||
| /> | ||
| {errors.joinDate && ( | ||
| <p className={styles.error}>Please enter a join date</p> | ||
| )} | ||
| </div> | ||
| <div className={styles.to}> | ||
| <p>→</p> | ||
| </div> | ||
| <div> | ||
| <Label className={styles.label} htmlFor="endDate"> | ||
| End Date:{' '} | ||
| </Label> | ||
| <Input | ||
| id="endDate" | ||
| {...register('endDate', { | ||
| required: true, | ||
| validate: (endDate) => { | ||
| const joinDate = getValues('joinDate'); | ||
| return joinDate < endDate; | ||
| }, | ||
| })} | ||
| type="date" | ||
| aria-required="true" | ||
| disabled={isStudentEditing} | ||
| className={styles.riderDate} | ||
| /> | ||
| {errors.endDate?.type === 'required' && ( | ||
| <p className={styles.error}>Please enter an end date</p> | ||
| )} | ||
| {errors.endDate?.type === 'validate' && ( | ||
| <p className={styles.error}>Invalid end time</p> | ||
| )} | ||
| {!isStudentEditing && ( | ||
|
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. Modal UI interacts well and is responsive, nice stuff! |
||
| <div className={cn(styles.gridR3, styles.gridCAll)}> | ||
| <p>Duration</p> | ||
| <div className={styles.lastRow}> | ||
| <div> | ||
| <Label className={styles.label} htmlFor="joinDate"> | ||
| Join Date:{' '} | ||
| </Label> | ||
| <Input | ||
| id="joinDate" | ||
| {...register('joinDate', { required: true })} | ||
| type="date" | ||
| aria-required="true" | ||
| className={styles.riderDate} | ||
| /> | ||
| {errors.joinDate && ( | ||
| <p className={styles.error}>Please enter a join date</p> | ||
| )} | ||
| </div> | ||
| <div className={styles.to}> | ||
| <p>→</p> | ||
| </div> | ||
| <div> | ||
| <Label className={styles.label} htmlFor="endDate"> | ||
| End Date:{' '} | ||
| </Label> | ||
| <Input | ||
| id="endDate" | ||
| {...register('endDate', { | ||
| required: true, | ||
| validate: (endDate) => { | ||
| const joinDate = getValues('joinDate'); | ||
| return joinDate < endDate; | ||
| }, | ||
| })} | ||
| type="date" | ||
| aria-required="true" | ||
| className={styles.riderDate} | ||
| /> | ||
| {errors.endDate?.type === 'required' && ( | ||
| <p className={styles.error}>Please enter an end date</p> | ||
| )} | ||
| {errors.endDate?.type === 'validate' && ( | ||
| <p className={styles.error}>Invalid end time</p> | ||
| )} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
|
|
||
| <div className={styles.buttonContainer}> | ||
|
|
@@ -415,7 +422,11 @@ const RiderModalInfo: React.FC<ModalFormProps> = ({ | |
| Cancel | ||
| </Button> | ||
| <Button type="submit" className={styles.submit}> | ||
| {isEditing ? 'Edit a Student' : 'Add a Student'} | ||
| {isStudentEditing | ||
| ? 'Save Changes' | ||
| : isEditing | ||
| ? 'Edit a Student' | ||
| : 'Add a Student'} | ||
| </Button> | ||
| </div> | ||
| </form> | ||
|
|
||
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.
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.
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.
Good work with the documentation!!!