Skip to content
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

Redesigned the Add/Edit Student Modal #511

Merged
merged 23 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
36a0709
Changed the styling of the Add/Edit student Modal to reflect figma de…
namanhboi Apr 9, 2024
a494b8a
ran prettier
namanhboi Apr 9, 2024
c8cc7ce
Changed the styling of the Add/Edit student Modal to reflect figma de…
namanhboi Apr 9, 2024
f100f38
ran prettier
namanhboi Apr 9, 2024
116c24d
Changed font color to black in add student modal to follow WCAG guide…
namanhboi Sep 24, 2024
17a41c1
Merge branch 'nd433/redesignStudentModal' of github.com:cornell-dti/c…
namanhboi Sep 24, 2024
9e7cdaa
outdated packages causing code to not compile, will look into this later
namanhboi Sep 28, 2024
7c7f525
outdated packages causing code to not compile, will look into this later
namanhboi Sep 28, 2024
22331f3
Merge branch 'master' into nd433/redesignStudentModal
namanhboi Oct 2, 2024
8bf08c5
resolved conflicts iwith master branch
namanhboi Oct 2, 2024
f9c1fac
Merge branch 'dka34/select' of github.com:cornell-dti/carriage-web in…
namanhboi Oct 5, 2024
26aa357
Merge branch 'dka34/select' of github.com:cornell-dti/carriage-web in…
namanhboi Oct 5, 2024
5e55b4d
Merge branch 'master' into nd433/redesignStudentModal
namanhboi Oct 5, 2024
5fe087b
experimented with react select
namanhboi Oct 5, 2024
0abe3e4
Merge branch 'master' into nd433/redesignStudentModal
namanhboi Oct 5, 2024
680ad2f
added the react-select dropdown box in add edit student modal
namanhboi Oct 9, 2024
d01470d
added some documentation
namanhboi Oct 9, 2024
6f875cc
wip need to delete data in the backend
namanhboi Oct 15, 2024
343bb26
Merge branch 'master' of https://github.com/cornell-dti/carriage-web …
Atikpui007 Oct 16, 2024
6c236a0
Ability to add multiple needs
Atikpui007 Oct 17, 2024
4916680
Prettier Fix
Atikpui007 Oct 17, 2024
2cb4259
Type check fix
Atikpui007 Oct 17, 2024
d14a875
Another prettier fix :/
Atikpui007 Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 32 additions & 67 deletions frontend/src/components/Modal/RiderModalInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import React, { useState } from 'react';
import { useForm, SubmitHandler } from 'react-hook-form';
import cn from 'classnames';
import {
Button,
Input,
Label,
SelectComponent,
} from '../FormElements/FormElements';
import { Button, Input, Label } from '../FormElements/FormElements';
import styles from './ridermodal.module.css';
import { ObjectType, Accessibility, Rider } from '../../types/index';

Expand All @@ -18,11 +13,10 @@ type ModalFormProps = {
};

type FormData = {
firstName: string;
lastName: string;
name: string;
netid: string;
phoneNumber: string;
needs: string;
needs: Accessibility[];
address: string;
joinDate: string;
endDate: string;
Expand All @@ -36,27 +30,24 @@ const RiderModalInfo: React.FC<ModalFormProps> = ({
rider,
}) => {
const {
control,
register,
formState: { errors },
handleSubmit,
getValues,
} = useForm<FormData>({
defaultValues: {
firstName: rider?.firstName ?? '',
lastName: rider?.lastName ?? '',
name: (rider?.firstName ?? '') + (rider?.lastName ?? ''),
netid: rider?.email.split('@')[0] ?? '',
phoneNumber: rider?.phoneNumber ?? '',
needs: rider?.accessibility ?? '',
needs: [],
address: rider?.address ?? '',
joinDate: rider?.joinDate ?? '',
endDate: rider?.endDate ?? '',
},
});

const beforeSubmit: SubmitHandler<FormData> = ({
firstName,
lastName,
name,
netid,
phoneNumber,
needs,
Expand All @@ -66,7 +57,12 @@ const RiderModalInfo: React.FC<ModalFormProps> = ({
}) => {
const email = netid ? `${netid}@cornell.edu` : undefined;
const accessibility = needs;
onSubmit({
const nameParts = name.trim().split(/\s+/);
const firstName =
nameParts.length > 1 ? nameParts.slice(0, -1).join(' ') : nameParts[0];
const lastName = nameParts.length > 1 ? nameParts.slice(-1)[0] : '';

const payload = {
firstName,
lastName,
email,
Expand All @@ -75,7 +71,11 @@ const RiderModalInfo: React.FC<ModalFormProps> = ({
address,
joinDate,
endDate,
});
};

console.log('Form payload:', payload);

onSubmit(payload);
};

const cancel = () => {
Expand All @@ -92,32 +92,19 @@ const RiderModalInfo: React.FC<ModalFormProps> = ({
<form onSubmit={handleSubmit(beforeSubmit)} className={styles.form}>
<div className={cn(styles.inputContainer, styles.rideTime)}>
<div className={cn(styles.gridR1, styles.gridCSmall1)}>
<Label className={styles.label} htmlFor="firstName">
First Name:{' '}
<Label className={styles.label} htmlFor="name">
Name:{' '}
</Label>
<Input
id="firstName"
{...register('firstName', { required: true })}
id="name"
type="text"
{...register('name', {
required: true,
})}
aria-required="true"
className={styles.firstRow}
/>
{errors.firstName && (
<p className={styles.error}>First name cannot be empty</p>
)}
<Label className={styles.label} htmlFor="lastName">
Last Name:{' '}
</Label>
<Input
id="lastName"
{...register('lastName', { required: true })}
type="text"
className={styles.firstRow}
aria-required="true"
/>
{errors.lastName && (
<p className={styles.error}>Last name cannot be empty</p>
)}
{errors.name && <p className={styles.error}>Name cannot be empty</p>}
</div>
<div className={cn(styles.gridR1, styles.gridCSmall2)}>
<Label className={styles.label} htmlFor="netid">
Expand Down Expand Up @@ -156,51 +143,29 @@ const RiderModalInfo: React.FC<ModalFormProps> = ({
<p className={styles.error}>Phone number is not valid</p>
)}
</div>

{/* Replacing SelectComponent with native <select> */}
<div className={cn(styles.gridR2, styles.gridCBig1)}>
<Label className={styles.label} htmlFor="needs">
Needs:{' '}
</Label>
<select
id="needs"
{...register('needs', { required: true })}
aria-required="true"
onChange={(e) => setNeedsOption(e.target.value)}
multiple
className={styles.firstRow}
>
{Object.values(Accessibility).map((value, index) => (
<option key={index} value={value}>
{Object.entries(Accessibility).map(([key, value]) => (
<option key={key} value={value}>
{value}
</option>
))}
</select>
{needsOption === 'Other' && (
<Input
id="otherNeeds"
{...register('otherNeeds')}
type="text"
placeholder="Please Specify Needs"
/>
)}
{errors.needs?.type === 'validate' && (
<p className={styles.error}>
Invalid needs. You can enter 'Assistant', 'Crutches', or
'Wheelchair'
</p>
{errors.needs && (
<p className={styles.error}>Please select at least one need</p>
)}
</div>

<div className={cn(styles.gridR2, styles.gridCBig2)}>
<SelectComponent<FormData>
name="needs"
datalist={Object.entries(Accessibility).map(([key, value]) => ({
id: key,
name: value,
}))}
isSearchable={true}
control={control}
isMulti={true}
rules={{ required: 'Rider name is required' }}
/>
</div>
<div className={cn(styles.gridR2, styles.gridCBig2)}>
<Label className={styles.label} htmlFor="address">
Address:{' '}
Expand Down
58 changes: 49 additions & 9 deletions frontend/src/components/Modal/ridermodal.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,63 @@
margin-bottom: 1.5rem;
}

.inputContainer input[type='text'],
.inputContainer input[type='tel'],
.inputContainer input[type='date'],
.inputContainer select {
border: 1px solid #808080;
width: 100%;
border-radius: 6px;
height: 1.75rem; /* Adjust height as needed */
font-size: 1rem; /* Adjust font size as needed */
/* Add any other relevant styling here */
}

.inputContainer input[type='text'],
.inputContainer input[type='tel'],
.inputContainer input[type='date'],
.inputContainer select {
border: 1px solid #808080;
width: 100%;
border-radius: 6px;
height: 1.75rem; /* Adjust height as needed */
font-size: 1rem; /* Adjust font size as needed */
/* Add any other relevant styling here */
}

.rideTime {
display: grid;
grid-template-columns: repeat(6, 1fr);
grid-template-columns: repeat(10, 1fr);
grid-template-columns: repeat(10, 1fr);
grid-template-rows: repeat(3, 1fr);
column-gap: 1rem;
row-gap: 1rem;
column-gap: 2rem;
row-gap: 2rem;
column-gap: 2rem;
row-gap: 2rem;
}

.gridCSmall1 {
grid-column: 1 / span 2;
grid-column: 1 / 5;
grid-column: 1 / 5;
}

.gridCSmall2 {
grid-column: 3 / span 2;
grid-column: 5 / 7;
grid-column: 5 / 7;
}

.gridCSmall3 {
grid-column: 5 / span 2;
grid-column: 7 / 11;
grid-column: 7 / 11;
}

.gridCBig1 {
grid-column: 1 / span 3;
grid-column: 1 / 5;
grid-column: 1 / 5;
}
.gridCBig2 {
grid-column: 4 / span 3;
grid-column: 5 / 11;
grid-column: 5 / 11;
}
.gridCAll {
grid-column: 1 / span 6;
Expand Down Expand Up @@ -72,10 +104,13 @@

.riderDate {
font-size: 1rem !important;
color: #808080;
color: #808080;
}

.firstRow {
max-width: 90%;
max-width: 100%;
max-width: 100%;
}

.lastRow {
Expand Down Expand Up @@ -109,6 +144,11 @@
cursor: pointer;
}

.label {
font-size: smaller;
color: #000000;
}

@media screen and (max-width: 1092px) {
.form {
display: block;
Expand Down
16 changes: 11 additions & 5 deletions frontend/src/components/UserDetail/PastRides.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { Row, Table } from '../TableComponents/TableComponents';
import { Ride } from '../../types';
import styles from './userDetail.module.css';

type pastRideProps = {
type PastRideProps = {
isStudent: boolean;
rides: Ride[];
};

const PastRides = ({ isStudent, rides }: pastRideProps) => {
const PastRides = ({ isStudent, rides }: PastRideProps) => {
const colSizes = [1, 1, 1, 1, 1];
const headers = [
isStudent ? 'Date' : 'Name',
Expand Down Expand Up @@ -38,15 +38,21 @@ const PastRides = ({ isStudent, rides }: pastRideProps) => {
.toLowerCase();
const { rider } = ride;
const name = `${rider.firstName} ${rider.lastName}`;
const needs = rider.accessibility || '';

// Convert accessibility array to string
const needs =
rider.accessibility && rider.accessibility.length > 0
? rider.accessibility.join(', ')
: 'None';

const pickupLocation = ride.startLocation.name;
const pickupTag = ride.startLocation.tag;
const dropoffLocation = ride.endLocation.name;
const dropoffTag = ride.endLocation.tag;

const valueNameDate = isStudent ? date : name;
const valueDateTime = isStudent
? `${startTime}${' - '}${endTime}`
? `${startTime} - ${endTime}`
: date;
const valuePickup = { data: pickupLocation, tag: pickupTag };
const valueDropoff = { data: dropoffLocation, tag: dropoffTag };
Expand All @@ -56,7 +62,7 @@ const PastRides = ({ isStudent, rides }: pastRideProps) => {
valueDateTime,
valuePickup,
valueDropoff,
needs,
needs, // Now needs is a string
];

return <Row data={inputValues} colSizes={colSizes} key={index} />;
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/components/UserTables/RidesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ const RidesTable = ({ rides, hasButtons }: RidesTableProps) => {
});
const { rider } = ride;
const riderName = rider ? `${rider.firstName} ${rider.lastName}` : '';
const needs = rider ? rider.accessibility || '' : '';

// Convert accessibility array to string
const needs =
rider && rider.accessibility && rider.accessibility.length > 0
? rider.accessibility.join(', ')
: 'None';

const pickupLocation = ride.startLocation.name;
const pickupTag = ride.startLocation.tag;
const dropoffLocation = ride.endLocation.name;
Expand Down
Loading
Loading