build and format
This commit is contained in:
@@ -19,9 +19,7 @@ const ViolationsDialog = ({ open, setOpen, mutate, row }) => {
|
||||
<Close />
|
||||
</IconButton>
|
||||
<DialogTitle>تخلفات</DialogTitle>
|
||||
{open && (
|
||||
<ViolationsList setOpen={setOpen} />
|
||||
)}
|
||||
{open && <ViolationsList setOpen={setOpen} />}
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import MissionCorrection from "./MissionCorrection";
|
||||
|
||||
export default function RowActions({row, mutate}) {
|
||||
export default function RowActions({ row, mutate }) {
|
||||
return (
|
||||
<>
|
||||
<MissionCorrection row={row} mutate={mutate} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@ import { GET_MACHINES_TABLE_LIST } from "@/core/utils/routes";
|
||||
import { useAuth } from "@/lib/contexts/auth";
|
||||
|
||||
const statusTypes = [
|
||||
{id : 1, name_fa : "آماده"},
|
||||
{id : 2, name_fa : "رزرو"},
|
||||
{id : 3, name_fa : "در ماموریت"},
|
||||
{id : 4, name_fa : "خارج از رده"},
|
||||
{id : 5, name_fa : "در تعمیر"},
|
||||
{id : 6, name_fa : "فروخته شده"},
|
||||
{id : 7, name_fa : "نیاز به تعمیر"},
|
||||
]
|
||||
{ id: 1, name_fa: "آماده" },
|
||||
{ id: 2, name_fa: "رزرو" },
|
||||
{ id: 3, name_fa: "در ماموریت" },
|
||||
{ id: 4, name_fa: "خارج از رده" },
|
||||
{ id: 5, name_fa: "در تعمیر" },
|
||||
{ id: 6, name_fa: "فروخته شده" },
|
||||
{ id: 7, name_fa: "نیاز به تعمیر" },
|
||||
];
|
||||
|
||||
const MachinesList = ({ machineType, setMachine, setOpenMachinesDialog }) => {
|
||||
const {
|
||||
@@ -61,7 +61,7 @@ const MachinesList = ({ machineType, setMachine, setOpenMachinesDialog }) => {
|
||||
},
|
||||
Cell: ({ row }) => {
|
||||
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;
|
||||
},
|
||||
},
|
||||
|
||||
@@ -12,163 +12,158 @@ import CustomSelectByDependency from "@/core/components/DataTable/filter/fieldsT
|
||||
import useCities from "@/lib/hooks/useCities";
|
||||
|
||||
const ViolationsList = () => {
|
||||
const columns = useMemo(
|
||||
() => {
|
||||
const dynamicColumns = {
|
||||
header: "استان",
|
||||
id: "province_id",
|
||||
const columns = useMemo(() => {
|
||||
const dynamicColumns = {
|
||||
header: "استان",
|
||||
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,
|
||||
datatype: "numeric",
|
||||
filterMode: "equals",
|
||||
sortDescFirst: true,
|
||||
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) => {
|
||||
const { provinces, errorProvinces, loadingProvinces } = useProvinces();
|
||||
const { cityList, loadingCityList, errorCityList } = useCities(props.dependencyFieldValue.value);
|
||||
|
||||
const getColumnSelectOptions = useMemo(() => {
|
||||
if (loadingProvinces) {
|
||||
if (props.dependencyFieldValue.value === "") {
|
||||
return [{ value: "empty", label: "ابتدا استان را انتخاب کنید" }];
|
||||
}
|
||||
if (loadingCityList) {
|
||||
return [{ value: "loading", label: "در حال بارگذاری..." }];
|
||||
}
|
||||
if (errorProvinces) {
|
||||
if (errorCityList) {
|
||||
return [{ value: "error", label: "خطا در بارگذاری" }];
|
||||
}
|
||||
return [
|
||||
{ value: "", label: "کل کشور" },
|
||||
...provinces.map((province) => ({
|
||||
value: province.id,
|
||||
label: province.name_fa,
|
||||
{ value: "", label: "کل ادارات" },
|
||||
...cityList.map((edare) => ({
|
||||
value: edare.id,
|
||||
label: edare.name_fa,
|
||||
})),
|
||||
];
|
||||
}, [provinces, errorProvinces, loadingProvinces]);
|
||||
}, [cityList, loadingCityList, errorCityList]);
|
||||
return (
|
||||
<CustomSelectByDependency
|
||||
{...props}
|
||||
value={loadingProvinces ? "loading" : props.filterParameters.value}
|
||||
value={
|
||||
props.dependencyFieldValue?.value === ""
|
||||
? "empty"
|
||||
: loadingCityList
|
||||
? "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,
|
||||
datatype: "numeric",
|
||||
filterMode: "equals",
|
||||
sortDescFirst: true,
|
||||
grow: false,
|
||||
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) => {
|
||||
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"),
|
||||
},
|
||||
];
|
||||
},
|
||||
[]
|
||||
);
|
||||
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 (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user