Skip to content

Commit

Permalink
Added icon on tabs in step4
Browse files Browse the repository at this point in the history
  • Loading branch information
bulhakovolexii committed Apr 26, 2024
1 parent 5b61de5 commit 56c65e4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
49 changes: 44 additions & 5 deletions app/components/steps/Step4.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
"use client";

import {
CancelRounded,
CheckCircleOutlineRounded,
CheckCircleRounded,
} from "@mui/icons-material";
import {
Box,
FormControl,
FormHelperText,
Icon,
InputLabel,
MenuItem,
Select,
Stack,
Tab,
Tabs,
Typography,
Zoom,
} from "@mui/material";
import { useEffect, useState } from "react";
import { Controller, useFormContext } from "react-hook-form";
Expand All @@ -31,15 +38,19 @@ const floorTypes = [
export default function Step4() {
const {
control,
formState: { submitCount },
formState: { isSubmitting, submitCount },
getFieldState,
} = useFormContext();
const [tab, setTab] = useState("ceiling");
const [floorTabIsInvalid, setFloorTabIsInvalid] = useState(null);
const [ceilingTabIsInvalid, setCeilingTabIsInvalid] = useState(null);

useEffect(() => {
const floorTabIsInvalid = getFieldState("floor.type").invalid;
const ceilingTabIsInvalid = getFieldState("ceiling.type").invalid;
setFloorTabIsInvalid(getFieldState("floor.type").invalid);
setCeilingTabIsInvalid(getFieldState("ceiling.type").invalid);
}, [isSubmitting]);

useEffect(() => {
if (!floorTabIsInvalid) {
setTab("ceiling");
} else if (!ceilingTabIsInvalid) {
Expand All @@ -60,8 +71,36 @@ export default function Step4() {
variant="fullWidth"
sx={{ borderBottom: 1, borderColor: "divider" }}
>
<Tab label="Дах" value="ceiling" />
<Tab label="Підлога" value="floor" />
<Tab
label="Дах"
value="ceiling"
sx={{ minHeight: "42px" }}
iconPosition="start"
icon={
ceilingTabIsInvalid ? (
<Zoom in={true}>
<CancelRounded color="error" />
</Zoom>
) : (
<CheckCircleRounded color="primary" />
)
}
/>
<Tab
label="Підлога"
value="floor"
sx={{ minHeight: "42px" }}
iconPosition="start"
icon={
floorTabIsInvalid ? (
<Zoom in={true}>
<CancelRounded color="error" />
</Zoom>
) : (
<CheckCircleRounded color="primary" />
)
}
/>
</Tabs>
<Box hidden={tab !== "ceiling"}>
<Controller
Expand Down
2 changes: 1 addition & 1 deletion app/questionnaire/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const steps = [
{
id: 3,
label: "Підлога та дах",
fields: ["ceiling.type", "floor.type"],
fields: ["ceiling.type", "ceiling.layers", "floor.type", "floor.layers"],
},
];

Expand Down

0 comments on commit 56c65e4

Please sign in to comment.