From 94e8501f387802a251c37125c8edee046df2d1ef Mon Sep 17 00:00:00 2001 From: AmirHossein Mahmoodi Date: Sat, 12 Apr 2025 13:09:52 +0000 Subject: [PATCH] Feature/add action date --- .../Form/StepThree/StepThreeContent.jsx | 50 +++++++++++++++++-- .../operator/Form/StepThree/index.jsx | 6 +-- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/components/dashboard/roadSafety/operator/Form/StepThree/StepThreeContent.jsx b/src/components/dashboard/roadSafety/operator/Form/StepThree/StepThreeContent.jsx index e3916d1..f884c13 100644 --- a/src/components/dashboard/roadSafety/operator/Form/StepThree/StepThreeContent.jsx +++ b/src/components/dashboard/roadSafety/operator/Form/StepThree/StepThreeContent.jsx @@ -2,23 +2,30 @@ import { Button, DialogActions, DialogContent, Stack } from "@mui/material"; import { Controller, useForm } from "react-hook-form"; import { yupResolver } from "@hookform/resolvers/yup"; import StyledForm from "@/core/components/StyledForm"; -import { mixed, object } from "yup"; +import { mixed, object, string } from "yup"; import ImageUpload from "./ImageUpload"; import useRequest from "@/lib/hooks/useRequest"; import { THIRD_STEP_STORE } from "@/core/utils/routes"; +import MuiDatePicker from "@/core/components/MuiDatePicker"; +import MuiTimePicker from "@/core/components/MuiTimePicker"; +import { format } from "date-fns"; const StepThreeContent = ({ setOpen, mutate, rowId }) => { const requestServer = useRequest({ notificationSuccess: true }); const defaultValues = { + action_date: "", + action_time: "", action_picture: null, }; const validationSchema = object({ + action_date: string().required("لطفا تاریخ اقدام را انتخاب کنید!"), + action_time: string().required("لطفا ساعت اقدام را انتخاب کنید!"), action_picture: mixed().nullable().required("لطفا عکس اقدام را بارگذاری کنید!"), }); const { control, handleSubmit, - formState: { isSubmitting, errors }, + formState: { isSubmitting }, } = useForm({ defaultValues, resolver: yupResolver(validationSchema), @@ -26,6 +33,7 @@ const StepThreeContent = ({ setOpen, mutate, rowId }) => { }); const onSubmit = async (data) => { const formData = new FormData(); + formData.append("action_date", `${data.action_date} ${format(new Date(data.action_time), "HH:mm")}`); formData.append("action_picture", data.action_picture); await requestServer(`${THIRD_STEP_STORE}/${rowId}`, "post", { data: formData, @@ -40,6 +48,42 @@ const StepThreeContent = ({ setOpen, mutate, rowId }) => { + + { + return ( + field.onChange(value || [])} + helperText={error ? error.message : null} + /> + ); + }} + name={"action_date"} + /> + { + return ( + field.onChange(value || null)} + helperText={error ? error.message : null} + /> + ); + }} + name={"action_time"} + /> + { بستن diff --git a/src/components/dashboard/roadSafety/operator/Form/StepThree/index.jsx b/src/components/dashboard/roadSafety/operator/Form/StepThree/index.jsx index 8602d6e..025222d 100644 --- a/src/components/dashboard/roadSafety/operator/Form/StepThree/index.jsx +++ b/src/components/dashboard/roadSafety/operator/Form/StepThree/index.jsx @@ -6,7 +6,7 @@ const StepThree = ({ mutate, rowId }) => { const [open, setOpen] = useState(false); return ( <> - + setOpen(true)}> @@ -20,10 +20,10 @@ const StepThree = ({ mutate, rowId }) => { }, }} dir="rtl" - maxWidth={"sm"} + maxWidth={"xs"} fullWidth > - بارگذاری تصویر اقدام + ثبت اقدام