formatting
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import React, {useState} from "react";
|
||||
import {useForm} from "react-hook-form";
|
||||
import {yupResolver} from "@hookform/resolvers/yup";
|
||||
import {array, mixed, number, object, string} from "yup";
|
||||
import {useTheme} from "@emotion/react";
|
||||
import {Box, Button, DialogActions, DialogContent, Tab, Tabs, useMediaQuery} from "@mui/material";
|
||||
import React, { useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { yupResolver } from "@hookform/resolvers/yup";
|
||||
import { array, mixed, number, object, string } from "yup";
|
||||
import { useTheme } from "@emotion/react";
|
||||
import { Box, Button, DialogActions, DialogContent, Tab, Tabs, useMediaQuery } from "@mui/material";
|
||||
import StyledForm from "@/core/components/StyledForm";
|
||||
import InsertDriveFileIcon from "@mui/icons-material/InsertDriveFile";
|
||||
import FileCopyIcon from "@mui/icons-material/FileCopy";
|
||||
@@ -16,7 +16,7 @@ import GetSubItemsForm from "@/components/dashboard/roadItems/operator/Actions/C
|
||||
import GetItemInfo from "@/components/dashboard/roadItems/operator/Actions/Create/Forms/GetItemInfo";
|
||||
|
||||
function TabPanel(props) {
|
||||
const {children, value, index} = props;
|
||||
const { children, value, index } = props;
|
||||
return (
|
||||
<div role="tabpanel" hidden={value !== index}>
|
||||
{value === index && <Box>{children}</Box>}
|
||||
@@ -30,26 +30,28 @@ const validationSchema = object({
|
||||
amount: string().required("وارد کردن مقدار الزامیست!"),
|
||||
cmms_machines: array().required("وارد کردن کد خودرو الزامیست!"),
|
||||
rahdaran_id: array().required("وارد کردن کد راهداران الزامیست!").min(1, "حداقل یک کد راهدار باید وارد شود!"), // بررسی حداقل یک آیتم,
|
||||
activity_time: string()
|
||||
.test("activity-time-conditional", "لطفا زمان فعالیت را انتخاب کنید!", function (value) {
|
||||
const {is_gasht} = this.options.context; // دسترسی به context
|
||||
activity_time: string().test("activity-time-conditional", "لطفا زمان فعالیت را انتخاب کنید!", function (value) {
|
||||
const { is_gasht } = this.options.context; // دسترسی به context
|
||||
if (is_gasht) {
|
||||
return true; // اگر is_gasht true باشد، این فیلد نیاز به اعتبارسنجی ندارد
|
||||
}
|
||||
return !!value; // در غیر این صورت مقدار فیلد باید وجود داشته باشد
|
||||
}),
|
||||
activity_date: string().test(
|
||||
"activity-date-conditional",
|
||||
"لطفاً تاریخ شروع فعالیت را انتخاب کنید!",
|
||||
function (value) {
|
||||
const { is_gasht } = this.options.context; // دسترسی به context
|
||||
if (is_gasht) {
|
||||
return true; // اگر is_gasht true باشد، این فیلد نیاز به اعتبارسنجی ندارد
|
||||
}
|
||||
return !!value; // در غیر این صورت مقدار فیلد باید وجود داشته باشد
|
||||
}),
|
||||
activity_date: string()
|
||||
.test("activity-date-conditional", "لطفاً تاریخ شروع فعالیت را انتخاب کنید!", function (value) {
|
||||
const {is_gasht} = this.options.context; // دسترسی به context
|
||||
if (is_gasht) {
|
||||
return true; // اگر is_gasht true باشد، این فیلد نیاز به اعتبارسنجی ندارد
|
||||
}
|
||||
return !!value; // در غیر این صورت مقدار فیلد باید وجود داشته باشد
|
||||
}),
|
||||
}
|
||||
),
|
||||
before_image: mixed()
|
||||
.nullable()
|
||||
.test("before-image-required", "لطفا عکس قبل از اقدام را بارگذاری کنید!", function (value) {
|
||||
const {subItemsList} = this.options.context;
|
||||
const { subItemsList } = this.options.context;
|
||||
const needsImage = subItemsList?.needs_image === 1;
|
||||
if (needsImage) {
|
||||
return !!value;
|
||||
@@ -59,7 +61,7 @@ const validationSchema = object({
|
||||
after_image: mixed()
|
||||
.nullable()
|
||||
.test("after-image-required", "لطفا عکس بعد از اقدام را بارگذاری کنید!", function (value) {
|
||||
const {subItemsList} = this.options.context;
|
||||
const { subItemsList } = this.options.context;
|
||||
const needsImage = subItemsList?.needs_image === 1;
|
||||
if (needsImage) {
|
||||
return !!value;
|
||||
@@ -72,7 +74,7 @@ const validationSchema = object({
|
||||
})
|
||||
.required("لطفاً نقطه شروع را مشخص کنید!"),
|
||||
end_point: mixed().test("end-point-required", "لطفاً نقطه پایان را مشخص کنید!", function (value) {
|
||||
const {subItemsList} = this.options.context;
|
||||
const { subItemsList } = this.options.context;
|
||||
const needsEndPoint = subItemsList?.needs_end_point === 1;
|
||||
if (needsEndPoint) {
|
||||
return !!value; // چک میکند که مقدار موجود است
|
||||
@@ -81,7 +83,7 @@ const validationSchema = object({
|
||||
}),
|
||||
});
|
||||
|
||||
const CreateFormContent = ({setOpen, onSubmit, is_gasht = false}) => {
|
||||
const CreateFormContent = ({ setOpen, onSubmit, is_gasht = false }) => {
|
||||
const defaultValues = {
|
||||
item_id: null,
|
||||
sub_item_id: null,
|
||||
@@ -92,7 +94,7 @@ const CreateFormContent = ({setOpen, onSubmit, is_gasht = false}) => {
|
||||
rahdaran_id: null,
|
||||
start_point: "",
|
||||
end_point: "",
|
||||
...(!is_gasht && {activity_time: "", activity_date: ""}),
|
||||
...(!is_gasht && { activity_time: "", activity_date: "" }),
|
||||
};
|
||||
|
||||
const [tabState, setTabState] = useState(0);
|
||||
@@ -138,15 +140,15 @@ const CreateFormContent = ({setOpen, onSubmit, is_gasht = false}) => {
|
||||
handleSubmit,
|
||||
setValue,
|
||||
resetField,
|
||||
formState: {errors, isSubmitting},
|
||||
formState: { errors, isSubmitting },
|
||||
} = useForm({
|
||||
defaultValues,
|
||||
resolver: yupResolver(validationSchema),
|
||||
mode: "onBlur",
|
||||
context: {subItemsList, is_gasht},
|
||||
context: { subItemsList, is_gasht },
|
||||
});
|
||||
const onSubmitBase = (data) => {
|
||||
let result = {...data};
|
||||
let result = { ...data };
|
||||
|
||||
if (result.before_image === null) {
|
||||
delete result.before_image;
|
||||
@@ -192,7 +194,7 @@ const CreateFormContent = ({setOpen, onSubmit, is_gasht = false}) => {
|
||||
},
|
||||
});
|
||||
};
|
||||
console.log(errors)
|
||||
console.log(errors);
|
||||
|
||||
return (
|
||||
<StyledForm onSubmit={handleSubmit(onSubmitBase)} id="road_items">
|
||||
@@ -208,12 +210,12 @@ const CreateFormContent = ({setOpen, onSubmit, is_gasht = false}) => {
|
||||
backgroundColor: "#efefef",
|
||||
}}
|
||||
>
|
||||
<Tab icon={<InsertDriveFileIcon/>} label="انتخاب آیتم"/>
|
||||
<Tab disabled={tabState === 0} icon={<FileCopyIcon/>} label="انتخاب موضوع مشاهده شده"/>
|
||||
<Tab disabled={tabState === 0 || tabState === 1} icon={<InfoIcon/>} label="اطلاعات فعالیت"/>
|
||||
<Tab icon={<InsertDriveFileIcon />} label="انتخاب آیتم" />
|
||||
<Tab disabled={tabState === 0} icon={<FileCopyIcon />} label="انتخاب موضوع مشاهده شده" />
|
||||
<Tab disabled={tabState === 0 || tabState === 1} icon={<InfoIcon />} label="اطلاعات فعالیت" />
|
||||
</Tabs>
|
||||
<DialogContent dividers sx={{overflowY: "auto", maxHeight: "70vh"}}>
|
||||
<Box sx={{flex: 1}}>
|
||||
<DialogContent dividers sx={{ overflowY: "auto", maxHeight: "70vh" }}>
|
||||
<Box sx={{ flex: 1 }}>
|
||||
<TabPanel value={tabState} index={0}>
|
||||
<GetItemsForm
|
||||
setItemsList={setItemsList}
|
||||
@@ -247,13 +249,13 @@ const CreateFormContent = ({setOpen, onSubmit, is_gasht = false}) => {
|
||||
</TabPanel>
|
||||
</Box>
|
||||
</DialogContent>
|
||||
<DialogActions sx={{alignItems: "center", justifyContent: "center"}}>
|
||||
<DialogActions sx={{ alignItems: "center", justifyContent: "center" }}>
|
||||
<Button
|
||||
onClick={handlePrev}
|
||||
variant="outlined"
|
||||
color="error"
|
||||
size="large"
|
||||
startIcon={tabState === 0 ? <ExitToAppIcon/> : <KeyboardDoubleArrowRightIcon/>}
|
||||
startIcon={tabState === 0 ? <ExitToAppIcon /> : <KeyboardDoubleArrowRightIcon />}
|
||||
>
|
||||
{tabState === 0 ? "بستن" : "مرحله قبل"}
|
||||
</Button>
|
||||
@@ -264,7 +266,7 @@ const CreateFormContent = ({setOpen, onSubmit, is_gasht = false}) => {
|
||||
disabled={isSubmitting}
|
||||
type={"submit"}
|
||||
form="road_items"
|
||||
endIcon={<BeenhereIcon/>}
|
||||
endIcon={<BeenhereIcon />}
|
||||
>
|
||||
{isSubmitting ? "در حال ثبت فعالیت" : "ثبت فعالیت"}
|
||||
</Button>
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import {Grid, Stack} from "@mui/material";
|
||||
import { Grid, Stack } from "@mui/material";
|
||||
import ImageUpload from "./ImageUpload";
|
||||
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
||||
import MuiTimePicker from "@/core/components/MuiTimePicker";
|
||||
import MapInfoTwoMarker from "@/core/components/MapInfoTwoMarker";
|
||||
import MapInfoOneMarker from "@/core/components/MapInfoOneMarker";
|
||||
import {Controller} from "react-hook-form";
|
||||
import { Controller } from "react-hook-form";
|
||||
import CarCode from "@/core/components/CarCode";
|
||||
import RahdarCode from "@/core/components/RahdarCode";
|
||||
import PreviousStatesInfo from "./PreviousStatesInfo";
|
||||
import NumberField from "@/core/components/NumberField";
|
||||
|
||||
const GetItemInfo = ({register, itemsList, subItemsList, control, setValue, errors, watch, getValues, is_gasht}) => {
|
||||
const GetItemInfo = ({ register, itemsList, subItemsList, control, setValue, errors, watch, getValues, is_gasht }) => {
|
||||
return (
|
||||
<Stack spacing={2}>
|
||||
<Stack>
|
||||
<PreviousStatesInfo itemsList={itemsList} subItemsList={subItemsList}/>
|
||||
<PreviousStatesInfo itemsList={itemsList} subItemsList={subItemsList} />
|
||||
</Stack>
|
||||
<Stack>
|
||||
<NumberField
|
||||
@@ -45,7 +45,7 @@ const GetItemInfo = ({register, itemsList, subItemsList, control, setValue, erro
|
||||
<Stack>
|
||||
<Controller
|
||||
control={control}
|
||||
render={({field, fieldState: {error}}) => {
|
||||
render={({ field, fieldState: { error } }) => {
|
||||
return (
|
||||
<CarCode
|
||||
carCode={field.value || []}
|
||||
@@ -61,7 +61,7 @@ const GetItemInfo = ({register, itemsList, subItemsList, control, setValue, erro
|
||||
<Stack>
|
||||
<Controller
|
||||
control={control}
|
||||
render={({field, fieldState: {error}}) => {
|
||||
render={({ field, fieldState: { error } }) => {
|
||||
return (
|
||||
<RahdarCode
|
||||
rahdarsCode={field.value || []}
|
||||
@@ -75,7 +75,7 @@ const GetItemInfo = ({register, itemsList, subItemsList, control, setValue, erro
|
||||
</Stack>
|
||||
<Stack>
|
||||
{subItemsList.needs_image ? (
|
||||
<ImageUpload setValue={setValue} control={control} errors={errors} getValues={getValues}/>
|
||||
<ImageUpload setValue={setValue} control={control} errors={errors} getValues={getValues} />
|
||||
) : null}
|
||||
</Stack>
|
||||
{!is_gasht ? (
|
||||
@@ -106,9 +106,9 @@ const GetItemInfo = ({register, itemsList, subItemsList, control, setValue, erro
|
||||
) : null}
|
||||
<Stack>
|
||||
{subItemsList?.needs_end_point === 1 ? (
|
||||
<MapInfoTwoMarker setValue={setValue} errors={errors}/>
|
||||
<MapInfoTwoMarker setValue={setValue} errors={errors} />
|
||||
) : (
|
||||
<MapInfoOneMarker setValue={setValue} errors={errors}/>
|
||||
<MapInfoOneMarker setValue={setValue} errors={errors} />
|
||||
)}
|
||||
</Stack>
|
||||
</Stack>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {FormControl, FormHelperText, Grid} from "@mui/material";
|
||||
import { FormControl, FormHelperText, Grid } from "@mui/material";
|
||||
import UploadSystem from "@/core/components/UploadSystem";
|
||||
import {Controller} from "react-hook-form";
|
||||
import React, {useEffect, useState} from "react";
|
||||
import { Controller } from "react-hook-form";
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
const ImageUpload = ({control, setValue, errors, getValues, beforeImage = null, afterImage = null}) => {
|
||||
const ImageUpload = ({ control, setValue, errors, getValues, beforeImage = null, afterImage = null }) => {
|
||||
const [beforeImg, setBeforeImg] = useState(beforeImage ? beforeImage : null);
|
||||
const [beforeFileType, setBeforeFileType] = useState(beforeImage ? "image/" : null);
|
||||
const [beforeFileName, setBeforeFileName] = useState(null);
|
||||
@@ -73,7 +73,7 @@ const ImageUpload = ({control, setValue, errors, getValues, beforeImage = null,
|
||||
<Controller
|
||||
name="before_image"
|
||||
control={control}
|
||||
render={({field: {value, onChange}}) => {
|
||||
render={({ field: { value, onChange } }) => {
|
||||
return (
|
||||
<FormControl
|
||||
error={errors.before_image}
|
||||
@@ -84,7 +84,7 @@ const ImageUpload = ({control, setValue, errors, getValues, beforeImage = null,
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
<FormHelperText sx={{fontSize: "large"}} id="before_image">
|
||||
<FormHelperText sx={{ fontSize: "large" }} id="before_image">
|
||||
عکس قبل از اقدام
|
||||
</FormHelperText>
|
||||
<UploadSystem
|
||||
@@ -109,7 +109,7 @@ const ImageUpload = ({control, setValue, errors, getValues, beforeImage = null,
|
||||
<Controller
|
||||
name="after_image"
|
||||
control={control}
|
||||
render={({field: {value, onChange}}) => {
|
||||
render={({ field: { value, onChange } }) => {
|
||||
return (
|
||||
<FormControl
|
||||
error={errors.before_image}
|
||||
@@ -120,7 +120,7 @@ const ImageUpload = ({control, setValue, errors, getValues, beforeImage = null,
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
<FormHelperText sx={{fontSize: "large"}} id="before_image">
|
||||
<FormHelperText sx={{ fontSize: "large" }} id="before_image">
|
||||
عکس بعد از اقدام
|
||||
</FormHelperText>
|
||||
<UploadSystem
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
import {LinearProgress, Typography} from "@mui/material";
|
||||
import { LinearProgress, Typography } from "@mui/material";
|
||||
import React from "react";
|
||||
import useRoadItemGetISubtems from "@/lib/hooks/useRoadItemGetISubtems";
|
||||
import EditFormCreate from "@/components/dashboard/roadItems/operator/RowActions/EditForm/EditFormCreate";
|
||||
|
||||
const EditFormContent = ({setOpenEditDialog, onSubmit, defaultData}) => {
|
||||
const {subItemsList, loadingSubItemsList, errorSubItemsList} = useRoadItemGetISubtems(defaultData?.item_id);
|
||||
const EditFormContent = ({ setOpenEditDialog, onSubmit, defaultData }) => {
|
||||
const { subItemsList, loadingSubItemsList, errorSubItemsList } = useRoadItemGetISubtems(defaultData?.item_id);
|
||||
const subItem = subItemsList.find((SubItem) => SubItem.sub_item === defaultData?.sub_item_id);
|
||||
|
||||
const defaultValues = {
|
||||
before_image: defaultData?.before_image || null,
|
||||
after_image: defaultData?.after_image || null,
|
||||
amount: defaultData?.amount || null,
|
||||
start_point: defaultData?.start_point || {lat: "", lng: ""},
|
||||
end_point: defaultData?.end_point || {lat: "", lng: ""},
|
||||
start_point: defaultData?.start_point || { lat: "", lng: "" },
|
||||
end_point: defaultData?.end_point || { lat: "", lng: "" },
|
||||
cmms_machines: defaultData?.cmms_machines || null,
|
||||
rahdaran_id: defaultData?.rahdaran_id || null,
|
||||
};
|
||||
|
||||
const onSubmitBase = (data) => {
|
||||
let result = {...data};
|
||||
let result = { ...data };
|
||||
if (result.before_image === null) {
|
||||
delete result.before_image;
|
||||
delete data.before_image;
|
||||
@@ -73,7 +73,7 @@ const EditFormContent = ({setOpenEditDialog, onSubmit, defaultData}) => {
|
||||
خطا در دریافت اطلاعات!!!
|
||||
</Typography>
|
||||
) : loadingSubItemsList ? (
|
||||
<LinearProgress/>
|
||||
<LinearProgress />
|
||||
) : (
|
||||
<EditFormCreate
|
||||
onSubmitBase={onSubmitBase}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import {Button, DialogActions, DialogContent, Stack} from "@mui/material";
|
||||
import { Button, DialogActions, DialogContent, Stack } from "@mui/material";
|
||||
import ImageUpload from "@/components/dashboard/roadItems/operator/Actions/Create/Forms/ImageUpload";
|
||||
import NumberField from "@/core/components/NumberField";
|
||||
import {Controller, useForm} from "react-hook-form";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import CarCode from "@/core/components/CarCode";
|
||||
import RahdarCode from "@/core/components/RahdarCode";
|
||||
import MapInfoTwoMarker from "@/core/components/MapInfoTwoMarker";
|
||||
import MapInfoOneMarker from "@/core/components/MapInfoOneMarker";
|
||||
import StyledForm from "@/core/components/StyledForm";
|
||||
import React from "react";
|
||||
import {yupResolver} from "@hookform/resolvers/yup";
|
||||
import {array, mixed, object, string} from "yup";
|
||||
import { yupResolver } from "@hookform/resolvers/yup";
|
||||
import { array, mixed, object, string } from "yup";
|
||||
|
||||
const validationSchema = object({
|
||||
amount: string().required("وارد کردن مقدار الزامیست!"),
|
||||
@@ -18,7 +18,7 @@ const validationSchema = object({
|
||||
before_image: mixed()
|
||||
.nullable()
|
||||
.test("before-image-required", "لطفا عکس قبل از اقدام را بارگذاری کنید!", function (value) {
|
||||
const {subItem} = this.options.context;
|
||||
const { subItem } = this.options.context;
|
||||
const needsImage = subItem?.needs_image === 1;
|
||||
if (needsImage) {
|
||||
return !!value;
|
||||
@@ -28,7 +28,7 @@ const validationSchema = object({
|
||||
after_image: mixed()
|
||||
.nullable()
|
||||
.test("after-image-required", "لطفا عکس بعد از اقدام را بارگذاری کنید!", function (value) {
|
||||
const {subItem} = this.options.context;
|
||||
const { subItem } = this.options.context;
|
||||
const needsImage = subItem?.needs_image === 1;
|
||||
if (needsImage) {
|
||||
return !!value;
|
||||
@@ -41,7 +41,7 @@ const validationSchema = object({
|
||||
})
|
||||
.required("لطفاً نقطه شروع را مشخص کنید!"),
|
||||
end_point: mixed().test("end-point-required", "لطفاً نقطه پایان را مشخص کنید!", function (value) {
|
||||
const {subItem} = this.options.context;
|
||||
const { subItem } = this.options.context;
|
||||
const needsEndPoint = subItem?.needs_end_point === 1;
|
||||
if (needsEndPoint) {
|
||||
return !!value;
|
||||
@@ -50,7 +50,7 @@ const validationSchema = object({
|
||||
}),
|
||||
});
|
||||
|
||||
const EditFormCreate = ({defaultData, subItem, onSubmitBase, defaultValues, setOpenEditDialog}) => {
|
||||
const EditFormCreate = ({ defaultData, subItem, onSubmitBase, defaultValues, setOpenEditDialog }) => {
|
||||
const {
|
||||
control,
|
||||
getValues,
|
||||
@@ -58,17 +58,17 @@ const EditFormCreate = ({defaultData, subItem, onSubmitBase, defaultValues, setO
|
||||
register,
|
||||
handleSubmit,
|
||||
setValue,
|
||||
formState: {errors, isSubmitting},
|
||||
formState: { errors, isSubmitting },
|
||||
} = useForm({
|
||||
defaultValues,
|
||||
resolver: yupResolver(validationSchema),
|
||||
mode: "onBlur",
|
||||
context: {subItem},
|
||||
context: { subItem },
|
||||
});
|
||||
|
||||
return (
|
||||
<StyledForm onSubmit={handleSubmit(onSubmitBase)} id="edit_road_items">
|
||||
<DialogContent sx={{overflowY: "auto", maxHeight: "70vh"}}>
|
||||
<DialogContent sx={{ overflowY: "auto", maxHeight: "70vh" }}>
|
||||
<Stack spacing={2}>
|
||||
<Stack>
|
||||
{subItem.needs_image === 1 ? (
|
||||
@@ -111,7 +111,7 @@ const EditFormCreate = ({defaultData, subItem, onSubmitBase, defaultValues, setO
|
||||
<Stack>
|
||||
<Controller
|
||||
control={control}
|
||||
render={({field, fieldState: {error}}) => {
|
||||
render={({ field, fieldState: { error } }) => {
|
||||
return (
|
||||
<CarCode
|
||||
carCode={field.value || []}
|
||||
@@ -128,7 +128,7 @@ const EditFormCreate = ({defaultData, subItem, onSubmitBase, defaultValues, setO
|
||||
<Stack>
|
||||
<Controller
|
||||
control={control}
|
||||
render={({field, fieldState: {error}}) => {
|
||||
render={({ field, fieldState: { error } }) => {
|
||||
return (
|
||||
<RahdarCode
|
||||
rahdarsCode={field.value || []}
|
||||
@@ -162,8 +162,13 @@ const EditFormCreate = ({defaultData, subItem, onSubmitBase, defaultValues, setO
|
||||
<Button onClick={() => setOpenEditDialog(false)} variant="outlined" color="primary" autoFocus>
|
||||
بستن
|
||||
</Button>
|
||||
<Button form="edit_road_items" disabled={isSubmitting} type={"submit"} variant="contained"
|
||||
color="primary">
|
||||
<Button
|
||||
form="edit_road_items"
|
||||
disabled={isSubmitting}
|
||||
type={"submit"}
|
||||
variant="contained"
|
||||
color="primary"
|
||||
>
|
||||
{isSubmitting ? "در حال ویرایش" : "ویرایش"}
|
||||
</Button>
|
||||
</DialogActions>
|
||||
|
||||
Reference in New Issue
Block a user