import { REQUEST_MISSION_WITHOUT_PROCESS } from "@/core/utils/routes";
import useRequest from "@/lib/hooks/useRequest";
import { AddCircle, AddCircleOutline, Close } from "@mui/icons-material";
import { Button, Dialog, IconButton, useMediaQuery, useTheme } from "@mui/material";
import moment from "jalali-moment";
import { useState } from "react";
import CreateForm from "./Form";
const CreateWithoutProcess = ({ mutate }) => {
const [submitting, setSubmitting] = useState(false);
const requestServer = useRequest({ notificationSuccess: true });
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
const [open, setOpen] = useState(false);
const handleOpen = () => {
setOpen(true);
};
const submitForm = async (result) => {
setSubmitting(true);
const bound = result.bound.getLatLngs();
let area =
result.bound_type === "polygon"
? bound.map((ring) => ring.map((latlng) => [latlng.lng, latlng.lat]))[0]
: bound.map((latlng) => [latlng.lng, latlng.lat]);
// بستن polygon
if (result.bound_type === "polygon" && area.length > 0) {
const firstPoint = area[0];
area.push({ ...firstPoint });
}
await requestServer(REQUEST_MISSION_WITHOUT_PROCESS, "post", {
data: {
explanation: result.explanation,
category_id: result.category_id,
...(result.rahdaran.length != 0 ? { rahdaran: result.rahdaran.map((r) => r.id) } : {}),
zone: result.region,
end_point: result.end_point,
area: {
type: result.bound_type,
coordinates: area,
},
start_date: `${result.start_date} ${moment(result.start_time).format("HH:mm")}`,
end_date: `${result.end_date} ${moment(result.end_time).format("HH:mm")}`,
driver: result.driver.id,
machine_code: result.machine_code,
},
hasSidebarUpdate: true,
})
.then((response) => {
mutate();
setOpen(false);
})
.catch((error) => {})
.finally(() => {
setSubmitting(false);
});
};
return (
<>
{isMobile ? (
) : (
}
onClick={handleOpen}
>
ثبت ماموریت بدون فرایند
)}
>
);
};
export default CreateWithoutProcess;