fixed bug

This commit is contained in:
AmirHossein Mahmoodi
2025-03-08 16:11:04 +03:30
parent ea0e3e17c3
commit cac9b243b9
3 changed files with 21 additions and 12 deletions

View File

@@ -128,8 +128,8 @@ const OperatorList = () => {
props.dependencyFieldValue.value === ""
? "empty"
: loadingSubItemsList
? "loading"
: props.filterParameters.value
? "loading"
: props.filterParameters.value
}
columnSelectOption={getColumnSelectOptions}
/>
@@ -282,7 +282,7 @@ const OperatorList = () => {
grow: false,
size: 100,
},
]
],
},
{
accessorFn: (row) => moment(row.created_at).locale("fa").format("HH:mm | yyyy/MM/DD"),

View File

@@ -378,7 +378,7 @@ const SupervisorList = () => {
grow: false,
size: 100,
},
]
],
},
{
accessorFn: (row) => moment(row.created_at).locale("fa").format("HH:mm | yyyy/MM/DD"),

View File

@@ -5,14 +5,25 @@ import isArrayEmpty from "@/core/utils/isArrayEmpty";
import useDataTable from "@/lib/hooks/useDataTable";
import useRequest from "@/lib/hooks/useRequest";
import { useMaterialReactTable } from "material-react-table";
import { useCallback, useEffect, useState } from "react";
import { useCallback, useEffect, useReducer, useState } from "react";
import useSWR from "swr";
import { FA_DATATABLE_LOCALIZATION } from "./localization/fa/datatable";
import DataTable_Paper from "./table/Paper";
const rowSelectionReducer = (state, action) => {
switch (action.type) {
case "TOGGLE_ROW":
return { [action.payload]: true };
case "RESET":
return {};
default:
return state;
}
};
const DataTable_Main = (props) => {
const request = useRequest();
const [rowSelection, setRowSelection] = useState({});
const [rowSelection, dispatchRowSelection] = useReducer(rowSelectionReducer, {});
const { filterData, sortData, setSortData, hideData } = useDataTable();
const {
need_filter,
@@ -75,7 +86,8 @@ const DataTable_Main = (props) => {
});
useEffect(() => {
setRowSelection({});
if (!isValidating) return;
dispatchRowSelection({ type: "RESET" });
}, [isValidating]);
const table = useMaterialReactTable({
@@ -83,11 +95,8 @@ const DataTable_Main = (props) => {
columns,
data: data ?? [],
muiTableBodyRowProps: ({ row }) => ({
onClick: () =>
setRowSelection((prev) => ({
[row.id]: true,
})),
selected: rowSelection[row.id],
onClick: () => dispatchRowSelection({ type: "TOGGLE_ROW", payload: row.id }),
selected: !!rowSelection[row.id],
}),
initialState: {
density: "compact",