diff --git a/app/components/AutocomlpleteWithModal.jsx b/app/components/AutocomlpleteWithModal.jsx new file mode 100644 index 0000000..08a4e0f --- /dev/null +++ b/app/components/AutocomlpleteWithModal.jsx @@ -0,0 +1,43 @@ +export default function AutoocompleteWithModal({ children }) { + return ( + { + const { onChange, value, ref } = field; + return ( + { + return city.name; + }} + groupBy={(city) => city.region} + value={ + value + ? cities.find((city) => { + return value === city.name; + }) ?? null + : null + } + onChange={(event, newValue) => { + onChange(newValue ? newValue.name : null); + }} + renderInput={(params) => ( + + )} + /> + ); + }} + /> + ) +} \ No newline at end of file diff --git a/app/components/LayerForm.jsx b/app/components/LayerForm.jsx new file mode 100644 index 0000000..e69de29 diff --git a/app/components/steps/Step3.jsx b/app/components/steps/Step3.jsx index 22ef91e..06e4219 100644 --- a/app/components/steps/Step3.jsx +++ b/app/components/steps/Step3.jsx @@ -122,7 +122,6 @@ export default function Step3() { onChange={(e) => onChange(e.target.value)} inputRef={ref} inputProps={{ inputMode: "numeric", min: 1, step: 1 }} - InputProps={{ endAdornment: "м", sx: { gap: 1 } }} variant="filled" fullWidth label="Кількість поверхів" diff --git a/app/components/steps/Step4.jsx b/app/components/steps/Step4.jsx index 9102ae6..a8974da 100644 --- a/app/components/steps/Step4.jsx +++ b/app/components/steps/Step4.jsx @@ -2,14 +2,12 @@ import { CancelRounded, - CheckCircleOutlineRounded, CheckCircleRounded, } from "@mui/icons-material"; import { Box, FormControl, FormHelperText, - Icon, InputLabel, MenuItem, Select, @@ -21,6 +19,8 @@ import { } from "@mui/material"; import { useEffect, useState } from "react"; import { Controller, useFormContext } from "react-hook-form"; +import AutocompleteWithModal from "../AutocomlpleteWithModal"; +import LayerForm from "../LayerForm"; const ceilingTypes = [ "Суміщене покриття", @@ -38,17 +38,18 @@ const floorTypes = [ export default function Step4() { const { control, - formState: { isSubmitting, submitCount }, - getFieldState, + formState, } = useFormContext(); const [tab, setTab] = useState("ceiling"); const [floorTabIsInvalid, setFloorTabIsInvalid] = useState(null); const [ceilingTabIsInvalid, setCeilingTabIsInvalid] = useState(null); useEffect(() => { - setFloorTabIsInvalid(getFieldState("floor.type").invalid); - setCeilingTabIsInvalid(getFieldState("ceiling.type").invalid); - }, [isSubmitting]); + const ceilingErrors = !!formState.errors?.ceiling?.type || !!formState.errors?.ceiling?.layers + const floorErrors = !!formState.errors?.floor?.type || !!formState.errors?.floor?.layers + setCeilingTabIsInvalid(ceilingErrors); + setFloorTabIsInvalid(floorErrors); + }, [formState]); useEffect(() => { if (!floorTabIsInvalid) { @@ -56,7 +57,7 @@ export default function Step4() { } else if (!ceilingTabIsInvalid) { setTab("floor"); } - }, [submitCount]); + }, [formState.isSubmitting]); const handleChangeTab = (event, newTab) => { setTab(newTab); @@ -79,10 +80,10 @@ export default function Step4() { icon={ ceilingTabIsInvalid ? ( - + ) : ( - + ) } /> @@ -94,10 +95,10 @@ export default function Step4() { icon={ floorTabIsInvalid ? ( - + ) : ( - + ) } /> @@ -134,6 +135,15 @@ export default function Step4() { ); }} /> + {/* + + */}