From 188c7c45af9c1712a6fd7283bba5a1f5fb6cc4a4 Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Sun, 21 Jun 2026 15:03:20 +0330 Subject: [PATCH] base select options --- .../Form/GetItemInfo/ItemSelectField.jsx | 31 +++++++++++++++++ .../Form/GetItemInfo/SubItemSelectField.jsx | 28 ++++++++++++++++ .../Actions/Create/Form/GetItemInfo/index.jsx | 33 +++++++------------ .../operator/Actions/Create/index.jsx | 2 ++ 4 files changed, 73 insertions(+), 21 deletions(-) create mode 100644 src/components/dashboard/roadMissions/operator/Actions/Create/Form/GetItemInfo/ItemSelectField.jsx create mode 100644 src/components/dashboard/roadMissions/operator/Actions/Create/Form/GetItemInfo/SubItemSelectField.jsx diff --git a/src/components/dashboard/roadMissions/operator/Actions/Create/Form/GetItemInfo/ItemSelectField.jsx b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/GetItemInfo/ItemSelectField.jsx new file mode 100644 index 0000000..44fc09f --- /dev/null +++ b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/GetItemInfo/ItemSelectField.jsx @@ -0,0 +1,31 @@ +import useRoadItemGetItems from "@/lib/hooks/useRoadItemGetItems"; +import { Controller } from "react-hook-form"; +import SelectBox from "@/core/components/SelectBox"; + +const ItemSelectField = ({ control, setValue }) => { + const { itemsList, loadingItemsList, errorItemsList } = useRoadItemGetItems(); + + return ( + ( + { + field.onChange; + setValue("sub_item_id", ""); + + }} + /> + )} + /> + ); +}; +export default ItemSelectField \ No newline at end of file diff --git a/src/components/dashboard/roadMissions/operator/Actions/Create/Form/GetItemInfo/SubItemSelectField.jsx b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/GetItemInfo/SubItemSelectField.jsx new file mode 100644 index 0000000..82d30b2 --- /dev/null +++ b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/GetItemInfo/SubItemSelectField.jsx @@ -0,0 +1,28 @@ +import useRoadItemGetSubItems from "@/lib/hooks/useRoadItemGetISubtems"; +import { Controller } from "react-hook-form"; +import SelectBox from "@/core/components/SelectBox"; + +const SubItemSelectField = ({ control, watch }) => { + const itemId = watch("item_id"); + const { subItemsList, loadingSubItemsList, errorSubItemsList } = useRoadItemGetSubItems(itemId); + + return ( + ( + + )} + /> + ); +}; +export default SubItemSelectField; \ No newline at end of file diff --git a/src/components/dashboard/roadMissions/operator/Actions/Create/Form/GetItemInfo/index.jsx b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/GetItemInfo/index.jsx index f4e66e5..a203436 100644 --- a/src/components/dashboard/roadMissions/operator/Actions/Create/Form/GetItemInfo/index.jsx +++ b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/GetItemInfo/index.jsx @@ -8,7 +8,11 @@ import { yupResolver } from "@hookform/resolvers/yup"; import { ExitToApp } from "@mui/icons-material"; import { Box, Button, DialogActions, DialogContent, Grid, Stack } from "@mui/material"; import { Controller, useForm } from "react-hook-form"; -import { array, object, string } from "yup"; +import { array, number, object, string } from "yup"; +import ItemSelectField + from "./ItemSelectField"; +import SubItemSelectField + from "./SubItemSelectField"; const validationSchema = object({ explanation: string().required("موضوع را مشخص کنید!"), @@ -25,6 +29,8 @@ const validationSchema = object({ const GetItemInfo = ({ allData, setAllData, handlePrev, setTabState }) => { const defaultValues = { + item_id: allData.item_id, + sub_item_id: allData.sub_item_id, explanation: allData.explanation, end_point: allData.end_point, region: allData.region, @@ -33,7 +39,7 @@ const GetItemInfo = ({ allData, setAllData, handlePrev, setTabState }) => { road_observed_id: allData.road_observed_id, }; - const { control, handleSubmit } = useForm({ + const { control, handleSubmit, watch, setValue } = useForm({ defaultValues, resolver: yupResolver(validationSchema), mode: "all", @@ -51,25 +57,10 @@ const GetItemInfo = ({ allData, setAllData, handlePrev, setTabState }) => { - ( - - )} - /> + + + + { defaultValues={{ explanation: "", category_id: "", + item_id: null, + sub_item_id: null, road_observed_id: "", rahdaran: [], requested_machines: [],