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 { Button, DialogActions, DialogContent, Stack } from "@mui/material";
import { Controller, useForm } from "react-hook-form"; 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 * as yup from "yup";
import StyledForm from "@/core/components/StyledForm";
const schema = yup.object().shape({ const schema = yup.object().shape({
machinesId: yup.object().required("کد خودرو الزامی است."), machinesId: yup.object().required("کد خودرو الزامی است."),
km: yup.string(),
}); });
const CreateViolationForm = ({ setOpenMachinesDialog, defaultValues, onSubmitBase }) => { const CreateViolationForm = ({ setOpenMachinesDialog, defaultValues, onSubmitBase }) => {
@@ -22,20 +24,43 @@ const CreateViolationForm = ({ setOpenMachinesDialog, defaultValues, onSubmitBas
<> <>
<StyledForm onSubmit={handleSubmit(handleOnSubmit)}> <StyledForm onSubmit={handleSubmit(handleOnSubmit)}>
<DialogContent> <DialogContent>
<Stack sx={{ minWidth: "200px" }}> <Stack alignItems="stretch" spacing={2}>
<Controller <Stack sx={{ minWidth: "200px" }}>
control={control} <Controller
render={({ field, fieldState: { error } }) => { control={control}
return ( render={({ field, fieldState: { error } }) => {
<CarCode return (
carCode={field.value} <CarCode
setCarCode={(value) => field.onChange(value)} carCode={field.value}
error={error} 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> </Stack>
</DialogContent> </DialogContent>
<DialogActions sx={{ alignItems: "center", justifyContent: "end" }}> <DialogActions sx={{ alignItems: "center", justifyContent: "end" }}>

View File

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

View File

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