base select options
This commit is contained in:
@@ -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 (
|
||||
<Controller
|
||||
control={control}
|
||||
name={"item_id"}
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
<SelectBox
|
||||
value={field.value}
|
||||
label="موضوع"
|
||||
selectors={itemsList}
|
||||
isLoading={loadingItemsList}
|
||||
schema={{ name: "name", value: "id" }}
|
||||
error={errorItemsList}
|
||||
helperText={error?.message}
|
||||
onChange={() => {
|
||||
field.onChange;
|
||||
setValue("sub_item_id", "");
|
||||
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
export default ItemSelectField
|
||||
@@ -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 (
|
||||
<Controller
|
||||
control={control}
|
||||
name={"sub_item_id"}
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
<SelectBox
|
||||
value={field.value}
|
||||
label="اقدام انجام شده"
|
||||
selectors={subItemsList}
|
||||
isLoading={loadingSubItemsList}
|
||||
schema={{ name: "name", value: "id" }}
|
||||
error={errorSubItemsList}
|
||||
helperText={error?.message}
|
||||
onChange={field.onChange}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
export default SubItemSelectField;
|
||||
@@ -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 }) => {
|
||||
<Stack>
|
||||
<Grid container spacing={2}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<Controller
|
||||
control={control}
|
||||
name={"explanation"}
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
<PersianTextField
|
||||
value={field.value}
|
||||
variant="outlined"
|
||||
name="explanation"
|
||||
onChange={field.onChange}
|
||||
label="موضوع"
|
||||
placeholder={"موضوع را وارد کنید"}
|
||||
fullWidth
|
||||
size="small"
|
||||
error={error}
|
||||
helperText={error?.message}
|
||||
InputLabelProps={{ shrink: true }}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<ItemSelectField control={control} watch={watch} setValue={setValue} />
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SubItemSelectField control={control} watch={watch} />
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<Controller
|
||||
|
||||
@@ -93,6 +93,8 @@ const Create = ({ mutate }) => {
|
||||
defaultValues={{
|
||||
explanation: "",
|
||||
category_id: "",
|
||||
item_id: null,
|
||||
sub_item_id: null,
|
||||
road_observed_id: "",
|
||||
rahdaran: [],
|
||||
requested_machines: [],
|
||||
|
||||
Reference in New Issue
Block a user