Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bulhakovolexii committed May 9, 2024
1 parent b1d6c0d commit 621d900
Show file tree
Hide file tree
Showing 8 changed files with 929 additions and 26 deletions.
43 changes: 43 additions & 0 deletions app/components/AutocomlpleteWithModal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export default function AutoocompleteWithModal({ children }) {
return (
<Controller
name="city"
control={control}
rules={{
required: "Оберіть місто",
}}
render={({ field, fieldState: { error } }) => {
const { onChange, value, ref } = field;
return (
<Autocomplete
options={cities}
getOptionLabel={(city) => {
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) => (
<TextField
{...params}
label="Місто"
variant="filled"
inputRef={ref}
error={!!error}
helperText={error?.message || " "}
/>
)}
/>
);
}}
/>
)
}
Empty file added app/components/LayerForm.jsx
Empty file.
1 change: 0 additions & 1 deletion app/components/steps/Step3.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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="Кількість поверхів"
Expand Down
34 changes: 22 additions & 12 deletions app/components/steps/Step4.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import {
CancelRounded,
CheckCircleOutlineRounded,
CheckCircleRounded,
} from "@mui/icons-material";
import {
Box,
FormControl,
FormHelperText,
Icon,
InputLabel,
MenuItem,
Select,
Expand All @@ -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 = [
"Суміщене покриття",
Expand All @@ -38,25 +38,26 @@ 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) {
setTab("ceiling");
} else if (!ceilingTabIsInvalid) {
setTab("floor");
}
}, [submitCount]);
}, [formState.isSubmitting]);

const handleChangeTab = (event, newTab) => {
setTab(newTab);
Expand All @@ -79,10 +80,10 @@ export default function Step4() {
icon={
ceilingTabIsInvalid ? (
<Zoom in={true}>
<CancelRounded color="error" />
<CancelRounded color={tab === "ceiling" ? "error": "inherit"}/>
</Zoom>
) : (
<CheckCircleRounded color="primary" />
<CheckCircleRounded />
)
}
/>
Expand All @@ -94,10 +95,10 @@ export default function Step4() {
icon={
floorTabIsInvalid ? (
<Zoom in={true}>
<CancelRounded color="error" />
<CancelRounded color={tab === "floor" ? "error": "inherit"} />
</Zoom>
) : (
<CheckCircleRounded color="primary" />
<CheckCircleRounded/>
)
}
/>
Expand Down Expand Up @@ -134,6 +135,15 @@ export default function Step4() {
);
}}
/>
{/* <AutocompleteWithModal
name="ceiling.layers"
label="Шари конструкції"
optionPrefix="Шар №"
addTitlePrefix="Додати шар №"
editTitlePrefix="Редагувати шар №"
>
</AutocompleteWithModal> */}
</Box>
<Box hidden={tab !== "floor"}>
<Controller
Expand Down
22 changes: 12 additions & 10 deletions app/context/InputDataContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ const InputDataContext = createContext(undefined);

export const InputDataProvider = ({ children }) => {
const [inputData, setInputData] = useState({
// city: "Харків",
// terrain: "B",
// purpose: "Багатоквартирні будинки, гуртожитки",
// heatCapacityClass: "Середній",
// tightness: "Герметична",
// typeAndCondition: "Утеплені органічними матеріалами в задовільному стані",
// buildingWidth: "44.29",
// buildingLength: "14.49",
// floorHeight: "3",
// numbersOfFloors: "9",
city: "Харків",
terrain: "B",
purpose: "Багатоквартирні будинки, гуртожитки",
heatCapacityClass: "Середній",
tightness: "Герметична",
typeAndCondition: "Утеплені органічними матеріалами в задовільному стані",
buildingWidth: "44.29",
buildingLength: "14.49",
floorHeight: "3",
numbersOfFloors: "9",
// ceiling: { type: "Суміщене покриття" },
// floor: { type: "Технічне підпілля" },
});

const updateInputData = (newValue) => {
Expand Down
Loading

0 comments on commit 621d900

Please sign in to comment.