added car name to violations list

This commit is contained in:
2025-12-29 11:18:05 +03:30
parent f800b69756
commit 39089e1f4e
3 changed files with 53 additions and 17 deletions

View File

@@ -1,11 +1,13 @@
import CarCode from "@/core/components/CarCode";
import LtrTextField from "@/core/components/LtrTextField";
import StyledForm from "@/core/components/StyledForm";
import { yupResolver } from "@hookform/resolvers/yup";
import { Button, DialogActions, DialogContent, Stack } from "@mui/material";
import { Controller, useForm } from "react-hook-form";
import CarCode from "@/core/components/CarCode";
import { yupResolver } from "@hookform/resolvers/yup";
import * as yup from "yup";
import StyledForm from "@/core/components/StyledForm";
const schema = yup.object().shape({
machinesId: yup.object().required("کد خودرو الزامی است."),
km: yup.string(),
});
const CreateViolationForm = ({ setOpenMachinesDialog, defaultValues, onSubmitBase }) => {
@@ -22,20 +24,43 @@ const CreateViolationForm = ({ setOpenMachinesDialog, defaultValues, onSubmitBas
<>
<StyledForm onSubmit={handleSubmit(handleOnSubmit)}>
<DialogContent>
<Stack sx={{ minWidth: "200px" }}>
<Controller
control={control}
render={({ field, fieldState: { error } }) => {
return (
<CarCode
carCode={field.value}
setCarCode={(value) => field.onChange(value)}
error={error}
<Stack alignItems="stretch" spacing={2}>
<Stack sx={{ minWidth: "200px" }}>
<Controller
control={control}
render={({ field, fieldState: { error } }) => {
return (
<CarCode
carCode={field.value}
setCarCode={(value) => field.onChange(value)}
error={error}
/>
);
}}
name={"machinesId"}
/>
</Stack>
<Stack>
<Controller
control={control}
name={"km"}
render={({ field, fieldState: { error } }) => (
<LtrTextField
autoComplete="off"
type="tel"
value={field.value}
onChange={(e) => {
if (isNaN(Number(e.target.value))) return;
field.onChange(e.target.value);
}}
size="small"
fullWidth
label="کیلومتر خودرو / ساعت کار"
InputLabelProps={{ shrink: true }}
/>
);
}}
name={"machinesId"}
/>
)}
/>
</Stack>
</Stack>
</DialogContent>
<DialogActions sx={{ alignItems: "center", justifyContent: "end" }}>

View File

@@ -9,12 +9,14 @@ const ViolationForm = ({ setOpenMachinesDialog, mutate, openMachinesDialog }) =>
const defaultValues = {
machinesId: null,
km: "",
};
const submitForm = async (result) => {
await requestServer(CREATE_VIOLATION, "post", {
data: {
machine_code: result.machinesId.machine_code,
km: result.km,
},
})
.then((response) => {

View File

@@ -33,12 +33,21 @@ const ViolationsList = () => {
},
{
accessorKey: "machine_code",
header: "خودرو",
header: "کد خودرو",
id: "machine_code",
datatype: "text",
columnFilterModeOptions: ["equals", "contains"],
grow: false,
},
{
accessorKey: "machine",
header: "نام خودرو",
id: "machine",
datatype: "text",
columnFilterModeOptions: ["equals", "contains"],
grow: false,
Cell: ({ row }) => row.original.machine?.car_name || "-",
},
{
accessorKey: "mission_id",
header: "کد ماموریت",