Skip to content
Snippets Groups Projects
Verified Commit 0fdc3b8c authored by Defendi Alberto's avatar Defendi Alberto
Browse files

New attributes into reservation.

parent 0fbc90d3
No related branches found
No related tags found
2 merge requests!69Possibility to insert a reservation and new docs.,!64Pass state to avoid controlled component.
export type Location = { export type LocationType = {
address: string; address: string;
}; };
export type TripStageType = {
location: Location;
number: number;
estimatedBeAt: Date;
};
export type InsertReservationProps = { export type InsertReservationProps = {
senior: number | undefined; senior: number | undefined;
insertedBy: number; insertedBy: number;
tripStages: string[]; tripStages: TripStageType[];
driverShift: string; driverShift: string | null;
number: number;
estimatedBeAt: Date; estimatedBeAt: Date;
}; };
/* eslint-disable react/jsx-props-no-spreading */ /* eslint-disable react/jsx-props-no-spreading */
import React, { FC, useState } from 'react'; import React, { FC, useState } from 'react';
import { Button, TextField } from '@material-ui/core'; import { Button, TextField, Typography } from '@material-ui/core';
import { Control, Controller } from 'react-hook-form'; import { Control, Controller } from 'react-hook-form';
import { InsertReservationProps } from './InsertReservationProps'; import { InputField } from 'components/Auth/InputField/InputField';
import {
InsertReservationProps,
TripStageType,
} from './InsertReservationProps';
type TripStageProps = { type TripStageProps = {
control: Control<InsertReservationProps>; control: Control<InsertReservationProps>;
...@@ -14,8 +18,9 @@ type TripStageProps = { ...@@ -14,8 +18,9 @@ type TripStageProps = {
// https://codesandbox.io/s/usefieldarray-virtual-input-v9wyw // https://codesandbox.io/s/usefieldarray-virtual-input-v9wyw
// https://codesandbox.io/s/react-hook-form-usefieldarray-7bpmk // https://codesandbox.io/s/react-hook-form-usefieldarray-7bpmk
export const TripStage: FC<TripStageProps> = ({ control }: TripStageProps) => { export const TripStage: FC<TripStageProps> = ({ control }: TripStageProps) => {
const [stage, setStage] = useState<string[]>([]); const [stage, setStage] = useState<string[]>(['']);
const [value, setValue] = useState<string>(''); const [value, setValue] = useState<string>('');
console.log(control);
const addStage = (): void => { const addStage = (): void => {
setStage([...stage, value]); setStage([...stage, value]);
...@@ -24,12 +29,23 @@ export const TripStage: FC<TripStageProps> = ({ control }: TripStageProps) => { ...@@ -24,12 +29,23 @@ export const TripStage: FC<TripStageProps> = ({ control }: TripStageProps) => {
return ( return (
<> <>
{stage.map((field, index) => ( {stage.map((field, index) => (
<Controller <>
as={<TextField />} <Typography variant="h3" component="h3">
name={`tripStages[${index}].address`} Stage {index}
control={control} </Typography>
defaultValue={field} <Controller
/> as={<TextField variant="outlined" fullWidth label="Location" />}
name={`tripStages[${index}].address`}
control={control}
defaultValue={field}
/>
<InputField
name={`tripStages[${index}].estimatedBeAt`}
label="Predicted time"
type="date"
control={control}
/>
</>
))} ))}
<Button variant="outlined" onClick={addStage} type="button"> <Button variant="outlined" onClick={addStage} type="button">
Add stage Add stage
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment