build and format
This commit is contained in:
@@ -19,9 +19,7 @@ const ViolationsDialog = ({ open, setOpen, mutate, row }) => {
|
|||||||
<Close />
|
<Close />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<DialogTitle>تخلفات</DialogTitle>
|
<DialogTitle>تخلفات</DialogTitle>
|
||||||
{open && (
|
{open && <ViolationsList setOpen={setOpen} />}
|
||||||
<ViolationsList setOpen={setOpen} />
|
|
||||||
)}
|
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import MissionCorrection from "./MissionCorrection";
|
import MissionCorrection from "./MissionCorrection";
|
||||||
|
|
||||||
export default function RowActions({row, mutate}) {
|
export default function RowActions({ row, mutate }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<MissionCorrection row={row} mutate={mutate} />
|
<MissionCorrection row={row} mutate={mutate} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ import { GET_MACHINES_TABLE_LIST } from "@/core/utils/routes";
|
|||||||
import { useAuth } from "@/lib/contexts/auth";
|
import { useAuth } from "@/lib/contexts/auth";
|
||||||
|
|
||||||
const statusTypes = [
|
const statusTypes = [
|
||||||
{id : 1, name_fa : "آماده"},
|
{ id: 1, name_fa: "آماده" },
|
||||||
{id : 2, name_fa : "رزرو"},
|
{ id: 2, name_fa: "رزرو" },
|
||||||
{id : 3, name_fa : "در ماموریت"},
|
{ id: 3, name_fa: "در ماموریت" },
|
||||||
{id : 4, name_fa : "خارج از رده"},
|
{ id: 4, name_fa: "خارج از رده" },
|
||||||
{id : 5, name_fa : "در تعمیر"},
|
{ id: 5, name_fa: "در تعمیر" },
|
||||||
{id : 6, name_fa : "فروخته شده"},
|
{ id: 6, name_fa: "فروخته شده" },
|
||||||
{id : 7, name_fa : "نیاز به تعمیر"},
|
{ id: 7, name_fa: "نیاز به تعمیر" },
|
||||||
]
|
];
|
||||||
|
|
||||||
const MachinesList = ({ machineType, setMachine, setOpenMachinesDialog }) => {
|
const MachinesList = ({ machineType, setMachine, setOpenMachinesDialog }) => {
|
||||||
const {
|
const {
|
||||||
@@ -61,7 +61,7 @@ const MachinesList = ({ machineType, setMachine, setOpenMachinesDialog }) => {
|
|||||||
},
|
},
|
||||||
Cell: ({ row }) => {
|
Cell: ({ row }) => {
|
||||||
const statusValue = row.original.status;
|
const statusValue = row.original.status;
|
||||||
const statusItem = statusTypes.find(item => item.id === statusValue);
|
const statusItem = statusTypes.find((item) => item.id === statusValue);
|
||||||
return statusItem ? statusItem.name_fa : statusValue;
|
return statusItem ? statusItem.name_fa : statusValue;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -12,163 +12,158 @@ import CustomSelectByDependency from "@/core/components/DataTable/filter/fieldsT
|
|||||||
import useCities from "@/lib/hooks/useCities";
|
import useCities from "@/lib/hooks/useCities";
|
||||||
|
|
||||||
const ViolationsList = () => {
|
const ViolationsList = () => {
|
||||||
const columns = useMemo(
|
const columns = useMemo(() => {
|
||||||
() => {
|
const dynamicColumns = {
|
||||||
const dynamicColumns = {
|
header: "استان",
|
||||||
header: "استان",
|
id: "province_id",
|
||||||
id: "province_id",
|
enableColumnFilter: true,
|
||||||
|
datatype: "numeric",
|
||||||
|
filterMode: "equals",
|
||||||
|
grow: false,
|
||||||
|
size: 130,
|
||||||
|
ColumnSelectComponent: (props) => {
|
||||||
|
const { provinces, errorProvinces, loadingProvinces } = useProvinces();
|
||||||
|
const getColumnSelectOptions = useMemo(() => {
|
||||||
|
if (loadingProvinces) {
|
||||||
|
return [{ value: "loading", label: "در حال بارگذاری..." }];
|
||||||
|
}
|
||||||
|
if (errorProvinces) {
|
||||||
|
return [{ value: "error", label: "خطا در بارگذاری" }];
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
{ value: "", label: "کل کشور" },
|
||||||
|
...provinces.map((province) => ({
|
||||||
|
value: province.id,
|
||||||
|
label: province.name_fa,
|
||||||
|
})),
|
||||||
|
];
|
||||||
|
}, [provinces, errorProvinces, loadingProvinces]);
|
||||||
|
return (
|
||||||
|
<CustomSelectByDependency
|
||||||
|
{...props}
|
||||||
|
value={loadingProvinces ? "loading" : props.filterParameters.value}
|
||||||
|
columnSelectOption={getColumnSelectOptions}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
Cell: ({ renderedCellValue, row }) => {
|
||||||
|
return <>{row.original.province_name}</>;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
accessorKey: "id",
|
||||||
|
header: "کد یکتا",
|
||||||
|
id: "id",
|
||||||
|
enableColumnFilter: true,
|
||||||
|
datatype: "text",
|
||||||
|
filterMode: "equals",
|
||||||
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
|
grow: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "status",
|
||||||
|
header: "وضعیت",
|
||||||
|
id: "status",
|
||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
filterMode: "equals",
|
filterMode: "equals",
|
||||||
|
sortDescFirst: true,
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 130,
|
columnSelectOption: () => {
|
||||||
|
return violationsCategoryStatus.map((category) => ({
|
||||||
|
value: category.id,
|
||||||
|
label: category.name_fa,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
Cell: ({ row }) => (row.original.type === 1 ? "خروج بدون مجوز" : "عدم تحرک"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "machine_code",
|
||||||
|
header: "کد خودرو",
|
||||||
|
id: "machine_code",
|
||||||
|
datatype: "text",
|
||||||
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
|
grow: false,
|
||||||
|
},
|
||||||
|
...[dynamicColumns],
|
||||||
|
{
|
||||||
|
header: "شهر",
|
||||||
|
id: "city_id",
|
||||||
|
enableColumnFilter: true,
|
||||||
|
datatype: "numeric",
|
||||||
|
filterMode: "equals",
|
||||||
|
dependencyId: "province_id",
|
||||||
|
grow: false,
|
||||||
|
size: 120,
|
||||||
ColumnSelectComponent: (props) => {
|
ColumnSelectComponent: (props) => {
|
||||||
const { provinces, errorProvinces, loadingProvinces } = useProvinces();
|
const { cityList, loadingCityList, errorCityList } = useCities(props.dependencyFieldValue.value);
|
||||||
|
|
||||||
const getColumnSelectOptions = useMemo(() => {
|
const getColumnSelectOptions = useMemo(() => {
|
||||||
if (loadingProvinces) {
|
if (props.dependencyFieldValue.value === "") {
|
||||||
|
return [{ value: "empty", label: "ابتدا استان را انتخاب کنید" }];
|
||||||
|
}
|
||||||
|
if (loadingCityList) {
|
||||||
return [{ value: "loading", label: "در حال بارگذاری..." }];
|
return [{ value: "loading", label: "در حال بارگذاری..." }];
|
||||||
}
|
}
|
||||||
if (errorProvinces) {
|
if (errorCityList) {
|
||||||
return [{ value: "error", label: "خطا در بارگذاری" }];
|
return [{ value: "error", label: "خطا در بارگذاری" }];
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
{ value: "", label: "کل کشور" },
|
{ value: "", label: "کل ادارات" },
|
||||||
...provinces.map((province) => ({
|
...cityList.map((edare) => ({
|
||||||
value: province.id,
|
value: edare.id,
|
||||||
label: province.name_fa,
|
label: edare.name_fa,
|
||||||
})),
|
})),
|
||||||
];
|
];
|
||||||
}, [provinces, errorProvinces, loadingProvinces]);
|
}, [cityList, loadingCityList, errorCityList]);
|
||||||
return (
|
return (
|
||||||
<CustomSelectByDependency
|
<CustomSelectByDependency
|
||||||
{...props}
|
{...props}
|
||||||
value={loadingProvinces ? "loading" : props.filterParameters.value}
|
value={
|
||||||
|
props.dependencyFieldValue?.value === ""
|
||||||
|
? "empty"
|
||||||
|
: loadingCityList
|
||||||
|
? "loading"
|
||||||
|
: props.filterParameters.value
|
||||||
|
}
|
||||||
columnSelectOption={getColumnSelectOptions}
|
columnSelectOption={getColumnSelectOptions}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
Cell: ({ renderedCellValue, row }) => {
|
Cell: ({ row }) => <>{row.original.city_name}</>,
|
||||||
return <>{row.original.province_name}</>;
|
},
|
||||||
},
|
{
|
||||||
};
|
accessorKey: "machine",
|
||||||
return [
|
header: "نام خودرو",
|
||||||
{
|
id: "machine",
|
||||||
accessorKey: "id",
|
datatype: "text",
|
||||||
header: "کد یکتا",
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
id: "id",
|
grow: false,
|
||||||
enableColumnFilter: true,
|
Cell: ({ row }) => row.original.machine?.car_name || "-",
|
||||||
datatype: "text",
|
},
|
||||||
filterMode: "equals",
|
{
|
||||||
columnFilterModeOptions: ["equals", "contains"],
|
accessorKey: "mission_id",
|
||||||
grow: false,
|
header: "کد ماموریت",
|
||||||
},
|
id: "mission_id",
|
||||||
{
|
enableColumnFilter: false,
|
||||||
accessorKey: "status",
|
datatype: "numeric",
|
||||||
header: "وضعیت",
|
filterMode: "equals",
|
||||||
id: "status",
|
grow: false,
|
||||||
enableColumnFilter: true,
|
Cell: ({ row }) => row.original.mission_id || "-",
|
||||||
datatype: "numeric",
|
},
|
||||||
filterMode: "equals",
|
{
|
||||||
sortDescFirst: true,
|
accessorKey: "request_date",
|
||||||
grow: false,
|
header: "تاریخ تخلف",
|
||||||
columnSelectOption: () => {
|
id: "request_date",
|
||||||
return violationsCategoryStatus.map((category) => ({
|
enableColumnFilter: true,
|
||||||
value: category.id,
|
datatype: "date",
|
||||||
label: category.name_fa,
|
filterMode: "between",
|
||||||
}));
|
grow: false,
|
||||||
},
|
Cell: ({ row }) => moment(row.original.request_date).locale("fa").format("YYYY/MM/DD"),
|
||||||
Cell: ({ row }) => (row.original.type === 1 ? "خروج بدون مجوز" : "عدم تحرک"),
|
},
|
||||||
},
|
];
|
||||||
{
|
}, []);
|
||||||
accessorKey: "machine_code",
|
|
||||||
header: "کد خودرو",
|
|
||||||
id: "machine_code",
|
|
||||||
datatype: "text",
|
|
||||||
columnFilterModeOptions: ["equals", "contains"],
|
|
||||||
grow: false,
|
|
||||||
},
|
|
||||||
...[dynamicColumns],
|
|
||||||
{
|
|
||||||
header: "شهر",
|
|
||||||
id: "city_id",
|
|
||||||
enableColumnFilter: true,
|
|
||||||
datatype: "numeric",
|
|
||||||
filterMode: "equals",
|
|
||||||
dependencyId: "province_id",
|
|
||||||
grow: false,
|
|
||||||
size: 120,
|
|
||||||
ColumnSelectComponent: (props) => {
|
|
||||||
const { cityList, loadingCityList, errorCityList } = useCities(
|
|
||||||
props.dependencyFieldValue.value
|
|
||||||
);
|
|
||||||
|
|
||||||
const getColumnSelectOptions = useMemo(() => {
|
|
||||||
if (props.dependencyFieldValue.value === "") {
|
|
||||||
return [{ value: "empty", label: "ابتدا استان را انتخاب کنید" }];
|
|
||||||
}
|
|
||||||
if (loadingCityList) {
|
|
||||||
return [{ value: "loading", label: "در حال بارگذاری..." }];
|
|
||||||
}
|
|
||||||
if (errorCityList) {
|
|
||||||
return [{ value: "error", label: "خطا در بارگذاری" }];
|
|
||||||
}
|
|
||||||
return [
|
|
||||||
{ value: "", label: "کل ادارات" },
|
|
||||||
...cityList.map((edare) => ({
|
|
||||||
value: edare.id,
|
|
||||||
label: edare.name_fa,
|
|
||||||
})),
|
|
||||||
];
|
|
||||||
}, [cityList, loadingCityList, errorCityList]);
|
|
||||||
return (
|
|
||||||
<CustomSelectByDependency
|
|
||||||
{...props}
|
|
||||||
value={
|
|
||||||
props.dependencyFieldValue?.value === ""
|
|
||||||
? "empty"
|
|
||||||
: loadingCityList
|
|
||||||
? "loading"
|
|
||||||
: props.filterParameters.value
|
|
||||||
}
|
|
||||||
columnSelectOption={getColumnSelectOptions}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
Cell: ({ row }) => <>{row.original.city_name}</>,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "machine",
|
|
||||||
header: "نام خودرو",
|
|
||||||
id: "machine",
|
|
||||||
datatype: "text",
|
|
||||||
columnFilterModeOptions: ["equals", "contains"],
|
|
||||||
grow: false,
|
|
||||||
Cell: ({ row }) => row.original.machine?.car_name || "-",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "mission_id",
|
|
||||||
header: "کد ماموریت",
|
|
||||||
id: "mission_id",
|
|
||||||
enableColumnFilter: false,
|
|
||||||
datatype: "numeric",
|
|
||||||
filterMode: "equals",
|
|
||||||
grow: false,
|
|
||||||
Cell: ({ row }) => row.original.mission_id || "-",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "request_date",
|
|
||||||
header: "تاریخ تخلف",
|
|
||||||
id: "request_date",
|
|
||||||
enableColumnFilter: true,
|
|
||||||
datatype: "date",
|
|
||||||
filterMode: "between",
|
|
||||||
grow: false,
|
|
||||||
Cell: ({ row }) => moment(row.original.request_date).locale("fa").format("YYYY/MM/DD"),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
},
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
Reference in New Issue
Block a user