Skip to content

Commit

Permalink
React-Select Integration and Ride Modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Atikpui007 committed Oct 5, 2024
1 parent 71e5dbc commit 8318ad8
Show file tree
Hide file tree
Showing 10 changed files with 505 additions and 178 deletions.
217 changes: 217 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
"react-router-dom": "^6.26.2",
"react-router-hash-link": "^2.4.3",
"react-scripts": "^5.0.1",
"react-select": "^5.8.1",
"reactjs-popup": "^2.0.6"
},
"scripts": {
"start": "react-scripts --openssl-legacy-provider start",
"start": "react-scripts start",
"build": "react-scripts build",
"tsc": "../node_modules/.bin/tsc --noEmit false",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
Expand Down Expand Up @@ -71,4 +72,4 @@
"eslint-plugin-react-hooks": "^4.6.0",
"prettier": "2.8.8"
}
}
}
18 changes: 9 additions & 9 deletions frontend/src/components/FormElements/FormElements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { SelectHTMLAttributes } from 'react';
import cn from 'classnames';
import styles from './formelements.module.css';
import Select, { ActionMeta, Props as SelectProps } from 'react-select';
import { Control, RegisterOptions, useController } from 'react-hook-form';
import { Control, RegisterOptions, useController, Path, FieldValues } from 'react-hook-form';

type LabelType = React.DetailedHTMLProps<
React.LabelHTMLAttributes<HTMLLabelElement>,
Expand Down Expand Up @@ -86,25 +86,25 @@ type SelectOption = {
label: string;
};

type SelectComponentProps = SelectProps & {
control: Control;
name: string;
type SelectComponentProps<TFieldValues extends FieldValues> = SelectProps & {
control: Control<TFieldValues>;
name: Path<TFieldValues>;
datalist: Option[];
className?: string;
rules?: RegisterOptions;
rules?: RegisterOptions<TFieldValues>;
};

export const SelectComponent: React.FC<SelectComponentProps> = ({
export const SelectComponent = <TFieldValues extends FieldValues>({
control,
name,
datalist,
className,
rules,
...rest
}) => {
}: SelectComponentProps<TFieldValues>) => {
const {
field: { onChange, value, ref, ...inputProps },
} = useController({
} = useController<TFieldValues>({
name,
control,
rules,
Expand Down Expand Up @@ -132,4 +132,4 @@ export const SelectComponent: React.FC<SelectComponentProps> = ({
{...rest}
/>
);
};
};
22 changes: 21 additions & 1 deletion frontend/src/components/Modal/RiderModalInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React, { useState } from 'react';
import { useForm, SubmitHandler } from 'react-hook-form';
import cn from 'classnames';
import { Button, Input, Label } from '../FormElements/FormElements';
import {
Button,
Input,
Label,
SelectComponent,
} from '../FormElements/FormElements';
import styles from './ridermodal.module.css';
import { ObjectType, Accessibility, Rider } from '../../types/index';

Expand Down Expand Up @@ -31,6 +36,7 @@ const RiderModalInfo: React.FC<ModalFormProps> = ({
rider,
}) => {
const {
control,
register,
formState: { errors },
handleSubmit,
Expand Down Expand Up @@ -181,6 +187,20 @@ const RiderModalInfo: React.FC<ModalFormProps> = ({
</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
Loading

0 comments on commit 8318ad8

Please sign in to comment.