Feature/amiriis missions
This commit is contained in:
@@ -1,179 +1,179 @@
|
||||
import { createContext, useEffect, useState } from "react";
|
||||
import { toast } from "react-toastify";
|
||||
import useTableSetting from "@/lib/hooks/useTableSetting";
|
||||
import { flattenArrayOfObjects } from "@/core/utils/flattenArrayOfObjects";
|
||||
import AskForKeepData from "@/core/components/NotificationDesign/AskForKeepData";
|
||||
import { LinearProgress } from "@mui/material";
|
||||
|
||||
export const DataTableContext = createContext();
|
||||
|
||||
const DataTableProvider = ({ children, user_id, page_name, table_name, columns, initialSort = [] }) => {
|
||||
const { settingStore } = useTableSetting();
|
||||
const [isInitStates, setInitStates] = useState(false);
|
||||
const flatColumns = flattenArrayOfObjects(columns, "columns");
|
||||
const [initFilter, setInitFilter] = useState({});
|
||||
const [filterData, setFilterData] = useState({});
|
||||
const [initSort, setInitSort] = useState(initialSort || []);
|
||||
const [sortData, setSortData] = useState(initialSort || []);
|
||||
const [initHide, setInitHide] = useState({});
|
||||
const [hideData, setHideData] = useState({});
|
||||
const [isDirty, setIsDirty] = useState(false);
|
||||
const [isAnyDirty, setIsAnyDirty] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let hasAnyConflict = false;
|
||||
const hasConflict =
|
||||
JSON.stringify(hideData) !== JSON.stringify(initHide) ||
|
||||
JSON.stringify(sortData) !== JSON.stringify(initSort) ||
|
||||
JSON.stringify(filterData) !== JSON.stringify(initFilter);
|
||||
|
||||
const CheckFilterValues = Object.values(filterData).every((innerObject) => {
|
||||
if (innerObject.datatype === "date" && innerObject.filterMode === "between") {
|
||||
return (
|
||||
Array.isArray(innerObject.value) &&
|
||||
innerObject.value.length === 2 &&
|
||||
innerObject.value.every((v) => v === "")
|
||||
);
|
||||
} else {
|
||||
return innerObject.value === "";
|
||||
}
|
||||
});
|
||||
const flattenObject = (obj) => {
|
||||
let result = {};
|
||||
for (const key in obj) {
|
||||
if (typeof obj[key] === "object" && obj[key] !== null) {
|
||||
Object.assign(result, flattenObject(obj[key])); // باز کردن اشیای تودرتو
|
||||
} else {
|
||||
result[key] = obj[key];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
// تبدیل آبجکت به آبجکت فلت شده
|
||||
const flatHideData = flattenObject(hideData);
|
||||
|
||||
const CheckHideValues = Object.values(flatHideData).every((value) => value === true);
|
||||
hasAnyConflict =
|
||||
!CheckHideValues || JSON.stringify(sortData) !== JSON.stringify(initialSort) || !CheckFilterValues;
|
||||
|
||||
setIsDirty(hasConflict);
|
||||
setIsAnyDirty(hasAnyConflict);
|
||||
}, [hideData, sortData, filterData, initHide, initSort, initFilter]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!settingStore) return;
|
||||
const filterValues = flatColumns.reduce((acc, column) => {
|
||||
if (!column.enableColumnFilter) return acc;
|
||||
const storeFilter = settingStore?.[user_id]?.[page_name]?.[table_name]?.["filters"]?.find(
|
||||
(filter) => filter.id === column.id
|
||||
);
|
||||
if (column.datatype === "array") {
|
||||
acc[column.id] = {
|
||||
id: column.id,
|
||||
value: storeFilter?.value || [],
|
||||
filterMode: storeFilter?.filterMode || column.filterMode,
|
||||
datatype: column.datatype,
|
||||
};
|
||||
} else if (column.filterMode === "between") {
|
||||
acc[column.id] = {
|
||||
id: column.id,
|
||||
value: storeFilter?.value || ["", ""],
|
||||
filterMode: storeFilter?.filterMode || column.filterMode,
|
||||
datatype: column.datatype,
|
||||
};
|
||||
} else {
|
||||
acc[column.id] = {
|
||||
id: column.id,
|
||||
value: storeFilter?.value || "",
|
||||
filterMode: storeFilter?.filterMode || column.filterMode,
|
||||
datatype: column.datatype,
|
||||
};
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const getHideValues = (columns) => {
|
||||
return columns.reduce((acc, column) => {
|
||||
const columnId = column.id;
|
||||
const storeHide = settingStore?.[user_id]?.[page_name]?.[table_name]?.["hides"]?.[columnId];
|
||||
if (column.columns && column.columns.length > 0) {
|
||||
acc[columnId] = getHideValues(column.columns);
|
||||
} else {
|
||||
acc[columnId] = storeHide !== undefined ? storeHide : true;
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
|
||||
const hideValues = getHideValues(columns);
|
||||
setHideData(hideValues);
|
||||
setInitHide(hideValues);
|
||||
setFilterData(filterValues);
|
||||
setInitFilter(filterValues);
|
||||
setSortData(settingStore?.[user_id]?.[page_name]?.[table_name]?.["sorts"] || initialSort);
|
||||
setInitSort(settingStore?.[user_id]?.[page_name]?.[table_name]?.["sorts"] || initialSort);
|
||||
setInitStates(true);
|
||||
}, [settingStore]);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
JSON.stringify(initFilter) !== JSON.stringify(filterData) ||
|
||||
JSON.stringify(initSort) !== JSON.stringify(sortData) ||
|
||||
JSON.stringify(initHide) !== JSON.stringify(hideData)
|
||||
) {
|
||||
if (!toast.isActive("keep_data", "filtering")) {
|
||||
toast(
|
||||
<AskForKeepData
|
||||
filterData={filterData}
|
||||
sortData={sortData}
|
||||
hideData={hideData}
|
||||
user_id={user_id}
|
||||
page_name={page_name}
|
||||
table_name={table_name}
|
||||
columns={flatColumns}
|
||||
/>,
|
||||
{
|
||||
containerId: "filtering",
|
||||
toastId: "keep_data",
|
||||
className: "filter-toast",
|
||||
position: "bottom-left",
|
||||
draggable: true,
|
||||
autoClose: false,
|
||||
}
|
||||
);
|
||||
} else {
|
||||
toast.update("keep_data", {
|
||||
containerId: "filtering",
|
||||
toastId: "keep_data",
|
||||
render: (
|
||||
<AskForKeepData
|
||||
filterData={filterData}
|
||||
sortData={sortData}
|
||||
hideData={hideData}
|
||||
user_id={user_id}
|
||||
page_name={page_name}
|
||||
table_name={table_name}
|
||||
columns={flatColumns}
|
||||
/>
|
||||
),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
toast.dismiss({ containerId: "datatable" });
|
||||
}
|
||||
}, [filterData, sortData, hideData]);
|
||||
|
||||
if (!isInitStates) return <LinearProgress sx={{ borderRadius: 2 }} />;
|
||||
|
||||
return (
|
||||
<DataTableContext.Provider
|
||||
value={{ filterData, setFilterData, sortData, setSortData, hideData, setHideData, isDirty, isAnyDirty }}
|
||||
>
|
||||
{children}
|
||||
</DataTableContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default DataTableProvider;
|
||||
import { createContext, useEffect, useState } from "react";
|
||||
import { toast } from "react-toastify";
|
||||
import useTableSetting from "@/lib/hooks/useTableSetting";
|
||||
import { flattenArrayOfObjects } from "@/core/utils/flattenArrayOfObjects";
|
||||
import AskForKeepData from "@/core/components/NotificationDesign/AskForKeepData";
|
||||
import { LinearProgress } from "@mui/material";
|
||||
|
||||
export const DataTableContext = createContext();
|
||||
|
||||
const DataTableProvider = ({ children, user_id, page_name, table_name, columns, initialSort = [] }) => {
|
||||
const { settingStore } = useTableSetting();
|
||||
const [isInitStates, setInitStates] = useState(false);
|
||||
const flatColumns = flattenArrayOfObjects(columns, "columns");
|
||||
const [initFilter, setInitFilter] = useState({});
|
||||
const [filterData, setFilterData] = useState({});
|
||||
const [initSort, setInitSort] = useState(initialSort || []);
|
||||
const [sortData, setSortData] = useState(initialSort || []);
|
||||
const [initHide, setInitHide] = useState({});
|
||||
const [hideData, setHideData] = useState({});
|
||||
const [isDirty, setIsDirty] = useState(false);
|
||||
const [isAnyDirty, setIsAnyDirty] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let hasAnyConflict = false;
|
||||
const hasConflict =
|
||||
JSON.stringify(hideData) !== JSON.stringify(initHide) ||
|
||||
JSON.stringify(sortData) !== JSON.stringify(initSort) ||
|
||||
JSON.stringify(filterData) !== JSON.stringify(initFilter);
|
||||
|
||||
const CheckFilterValues = Object.values(filterData).every((innerObject) => {
|
||||
if (innerObject.datatype === "date" && innerObject.filterMode === "between") {
|
||||
return (
|
||||
Array.isArray(innerObject.value) &&
|
||||
innerObject.value.length === 2 &&
|
||||
innerObject.value.every((v) => v === "")
|
||||
);
|
||||
} else {
|
||||
return innerObject.value === "";
|
||||
}
|
||||
});
|
||||
const flattenObject = (obj) => {
|
||||
let result = {};
|
||||
for (const key in obj) {
|
||||
if (typeof obj[key] === "object" && obj[key] !== null) {
|
||||
Object.assign(result, flattenObject(obj[key])); // باز کردن اشیای تودرتو
|
||||
} else {
|
||||
result[key] = obj[key];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
// تبدیل آبجکت به آبجکت فلت شده
|
||||
const flatHideData = flattenObject(hideData);
|
||||
|
||||
const CheckHideValues = Object.values(flatHideData).every((value) => value === true);
|
||||
hasAnyConflict =
|
||||
!CheckHideValues || JSON.stringify(sortData) !== JSON.stringify(initialSort) || !CheckFilterValues;
|
||||
|
||||
setIsDirty(hasConflict);
|
||||
setIsAnyDirty(hasAnyConflict);
|
||||
}, [hideData, sortData, filterData, initHide, initSort, initFilter]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!settingStore) return;
|
||||
const filterValues = flatColumns.reduce((acc, column) => {
|
||||
if (!column.enableColumnFilter) return acc;
|
||||
const storeFilter = settingStore?.[user_id]?.[page_name]?.[table_name]?.["filters"]?.find(
|
||||
(filter) => filter.id === column.id
|
||||
);
|
||||
if (column.datatype === "array") {
|
||||
acc[column.id] = {
|
||||
id: column.id,
|
||||
value: storeFilter?.value || [],
|
||||
filterMode: storeFilter?.filterMode || column.filterMode,
|
||||
datatype: column.datatype,
|
||||
};
|
||||
} else if (column.filterMode === "between") {
|
||||
acc[column.id] = {
|
||||
id: column.id,
|
||||
value: storeFilter?.value || ["", ""],
|
||||
filterMode: storeFilter?.filterMode || column.filterMode,
|
||||
datatype: column.datatype,
|
||||
};
|
||||
} else {
|
||||
acc[column.id] = {
|
||||
id: column.id,
|
||||
value: storeFilter?.value || "",
|
||||
filterMode: storeFilter?.filterMode || column.filterMode,
|
||||
datatype: column.datatype,
|
||||
};
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const getHideValues = (columns) => {
|
||||
return columns.reduce((acc, column) => {
|
||||
const columnId = column.id;
|
||||
const storeHide = settingStore?.[user_id]?.[page_name]?.[table_name]?.["hides"]?.[columnId];
|
||||
if (column.columns && column.columns.length > 0) {
|
||||
acc[columnId] = getHideValues(column.columns);
|
||||
} else {
|
||||
acc[columnId] = storeHide !== undefined ? storeHide : true;
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
|
||||
const hideValues = getHideValues(columns);
|
||||
setHideData(hideValues);
|
||||
setInitHide(hideValues);
|
||||
setFilterData(filterValues);
|
||||
setInitFilter(filterValues);
|
||||
setSortData(settingStore?.[user_id]?.[page_name]?.[table_name]?.["sorts"] || initialSort);
|
||||
setInitSort(settingStore?.[user_id]?.[page_name]?.[table_name]?.["sorts"] || initialSort);
|
||||
setInitStates(true);
|
||||
}, [settingStore]);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
JSON.stringify(initFilter) !== JSON.stringify(filterData) ||
|
||||
JSON.stringify(initSort) !== JSON.stringify(sortData) ||
|
||||
JSON.stringify(initHide) !== JSON.stringify(hideData)
|
||||
) {
|
||||
if (!toast.isActive("keep_data", "filtering")) {
|
||||
toast(
|
||||
<AskForKeepData
|
||||
filterData={filterData}
|
||||
sortData={sortData}
|
||||
hideData={hideData}
|
||||
user_id={user_id}
|
||||
page_name={page_name}
|
||||
table_name={table_name}
|
||||
columns={flatColumns}
|
||||
/>,
|
||||
{
|
||||
containerId: "filtering",
|
||||
toastId: "keep_data",
|
||||
className: "filter-toast",
|
||||
position: "bottom-left",
|
||||
draggable: true,
|
||||
autoClose: false,
|
||||
}
|
||||
);
|
||||
} else {
|
||||
toast.update("keep_data", {
|
||||
containerId: "filtering",
|
||||
toastId: "keep_data",
|
||||
render: (
|
||||
<AskForKeepData
|
||||
filterData={filterData}
|
||||
sortData={sortData}
|
||||
hideData={hideData}
|
||||
user_id={user_id}
|
||||
page_name={page_name}
|
||||
table_name={table_name}
|
||||
columns={flatColumns}
|
||||
/>
|
||||
),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
toast.dismiss({ containerId: "datatable" });
|
||||
}
|
||||
}, [filterData, sortData, hideData]);
|
||||
|
||||
if (!isInitStates) return <LinearProgress sx={{ borderRadius: 2 }} />;
|
||||
|
||||
return (
|
||||
<DataTableContext.Provider
|
||||
value={{ filterData, setFilterData, sortData, setSortData, hideData, setHideData, isDirty, isAnyDirty }}
|
||||
>
|
||||
{children}
|
||||
</DataTableContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default DataTableProvider;
|
||||
|
||||
@@ -1,94 +1,94 @@
|
||||
"use client";
|
||||
import { GET_USER_ROUTE } from "@/core/utils/routes";
|
||||
import axios from "axios";
|
||||
import { createContext, useCallback, useContext, useEffect, useReducer, useState } from "react";
|
||||
|
||||
const initAuth = {
|
||||
initAuthState: false,
|
||||
isAuth: false,
|
||||
user: {},
|
||||
};
|
||||
|
||||
const authReducer = (state, action) => {
|
||||
switch (action.type) {
|
||||
case "CLEAR_USER":
|
||||
return { ...state, user: {} };
|
||||
case "CHANGE_USER":
|
||||
return { ...state, user: action.user };
|
||||
case "CHANGE_AUTH_STATE":
|
||||
return { ...state, isAuth: action.isAuth };
|
||||
case "CHANGE_INIT_AUTH":
|
||||
return { ...state, initAuthState: action.initAuthState };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
const AuthContext = createContext();
|
||||
|
||||
export const AuthProvider = ({ children }) => {
|
||||
const [errorState, setErrorState] = useState({ status: null, message: "" });
|
||||
const [state, dispatch] = useReducer(authReducer, initAuth);
|
||||
|
||||
const clearUser = useCallback(() => {
|
||||
dispatch({ type: "CLEAR_USER" });
|
||||
}, []);
|
||||
|
||||
const changeUser = useCallback((user) => {
|
||||
dispatch({ type: "CHANGE_USER", user });
|
||||
}, []);
|
||||
|
||||
const changeAuthState = useCallback((isAuth) => {
|
||||
dispatch({ type: "CHANGE_AUTH_STATE", isAuth });
|
||||
}, []);
|
||||
|
||||
const changeInitAuth = useCallback((initAuthState) => {
|
||||
dispatch({ type: "CHANGE_INIT_AUTH", initAuthState });
|
||||
}, []);
|
||||
|
||||
const logout = () => {
|
||||
clearUser();
|
||||
changeAuthState(false);
|
||||
changeInitAuth(true);
|
||||
};
|
||||
|
||||
const getUser = useCallback(async () => {
|
||||
try {
|
||||
const { data } = await axios.get(GET_USER_ROUTE, { withCredentials: true });
|
||||
changeUser(data.data);
|
||||
changeAuthState(true);
|
||||
changeInitAuth(true);
|
||||
setErrorState(false);
|
||||
} catch (error) {
|
||||
if (error.response && error.response.status === 401) {
|
||||
clearUser();
|
||||
changeAuthState(false);
|
||||
changeInitAuth(true);
|
||||
return;
|
||||
}
|
||||
let status = error.response && error.response.status ? error.response.status : "نامشخص";
|
||||
setErrorState({ status, message: " مشکلی در احراز هویت رخ داده است . دقایقی بعد امتحان کنید!!!" });
|
||||
}
|
||||
}, [clearUser, changeUser, changeAuthState, changeInitAuth]);
|
||||
|
||||
useEffect(() => {
|
||||
getUser();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<AuthContext.Provider
|
||||
value={{
|
||||
user: state.user,
|
||||
isAuth: state.isAuth,
|
||||
initAuthState: state.initAuthState,
|
||||
getUser,
|
||||
logout,
|
||||
errorState,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useAuth = () => useContext(AuthContext);
|
||||
"use client";
|
||||
import { GET_USER_ROUTE } from "@/core/utils/routes";
|
||||
import axios from "axios";
|
||||
import { createContext, useCallback, useContext, useEffect, useReducer, useState } from "react";
|
||||
|
||||
const initAuth = {
|
||||
initAuthState: false,
|
||||
isAuth: false,
|
||||
user: {},
|
||||
};
|
||||
|
||||
const authReducer = (state, action) => {
|
||||
switch (action.type) {
|
||||
case "CLEAR_USER":
|
||||
return { ...state, user: {} };
|
||||
case "CHANGE_USER":
|
||||
return { ...state, user: action.user };
|
||||
case "CHANGE_AUTH_STATE":
|
||||
return { ...state, isAuth: action.isAuth };
|
||||
case "CHANGE_INIT_AUTH":
|
||||
return { ...state, initAuthState: action.initAuthState };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
const AuthContext = createContext();
|
||||
|
||||
export const AuthProvider = ({ children }) => {
|
||||
const [errorState, setErrorState] = useState({ status: null, message: "" });
|
||||
const [state, dispatch] = useReducer(authReducer, initAuth);
|
||||
|
||||
const clearUser = useCallback(() => {
|
||||
dispatch({ type: "CLEAR_USER" });
|
||||
}, []);
|
||||
|
||||
const changeUser = useCallback((user) => {
|
||||
dispatch({ type: "CHANGE_USER", user });
|
||||
}, []);
|
||||
|
||||
const changeAuthState = useCallback((isAuth) => {
|
||||
dispatch({ type: "CHANGE_AUTH_STATE", isAuth });
|
||||
}, []);
|
||||
|
||||
const changeInitAuth = useCallback((initAuthState) => {
|
||||
dispatch({ type: "CHANGE_INIT_AUTH", initAuthState });
|
||||
}, []);
|
||||
|
||||
const logout = () => {
|
||||
clearUser();
|
||||
changeAuthState(false);
|
||||
changeInitAuth(true);
|
||||
};
|
||||
|
||||
const getUser = useCallback(async () => {
|
||||
try {
|
||||
const { data } = await axios.get(GET_USER_ROUTE, { withCredentials: true });
|
||||
changeUser(data.data);
|
||||
changeAuthState(true);
|
||||
changeInitAuth(true);
|
||||
setErrorState(false);
|
||||
} catch (error) {
|
||||
if (error.response && error.response.status === 401) {
|
||||
clearUser();
|
||||
changeAuthState(false);
|
||||
changeInitAuth(true);
|
||||
return;
|
||||
}
|
||||
let status = error.response && error.response.status ? error.response.status : "نامشخص";
|
||||
setErrorState({ status, message: " مشکلی در احراز هویت رخ داده است . دقایقی بعد امتحان کنید!!!" });
|
||||
}
|
||||
}, [clearUser, changeUser, changeAuthState, changeInitAuth]);
|
||||
|
||||
useEffect(() => {
|
||||
getUser();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<AuthContext.Provider
|
||||
value={{
|
||||
user: state.user,
|
||||
isAuth: state.isAuth,
|
||||
initAuthState: state.initAuthState,
|
||||
getUser,
|
||||
logout,
|
||||
errorState,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useAuth = () => useContext(AuthContext);
|
||||
|
||||
@@ -1,134 +1,134 @@
|
||||
"use client";
|
||||
|
||||
import { createContext, useCallback, useEffect, useState } from "react";
|
||||
import LZString from "lz-string";
|
||||
|
||||
export const TableSettingContext = createContext();
|
||||
|
||||
const decompressData = (compressedData) => {
|
||||
try {
|
||||
const decompressed = LZString.decompressFromUTF16(compressedData);
|
||||
if (decompressed === null) {
|
||||
localStorage.removeItem("_setting-app");
|
||||
return null;
|
||||
} else {
|
||||
return JSON.parse(decompressed);
|
||||
}
|
||||
} catch (error) {
|
||||
localStorage.removeItem("_setting-app");
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const TableSettingProvider = ({ children }) => {
|
||||
const [settingStore, setSettingStore] = useState({});
|
||||
|
||||
useEffect(() => {
|
||||
const compressedData = localStorage.getItem("_setting-app");
|
||||
|
||||
const data = compressedData ? decompressData(compressedData) : null;
|
||||
if (data) {
|
||||
setSettingStore(data);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const hideAction = useCallback((user_id, page_name, table_name, settingValue) => {
|
||||
clearAction(user_id, page_name, table_name, "hides");
|
||||
updateSettingStorage(user_id, page_name, table_name, "hides", settingValue);
|
||||
}, []);
|
||||
|
||||
const sortAction = useCallback((user_id, page_name, table_name, settingValue) => {
|
||||
updateSettingStorage(user_id, page_name, table_name, "sorts", settingValue);
|
||||
}, []);
|
||||
|
||||
const filterAction = (user_id, page_name, table_name, settingValue) => {
|
||||
updateSettingStorage(user_id, page_name, table_name, "filters", settingValue);
|
||||
};
|
||||
|
||||
const resetAction = (user_id, page_name, table_name) => {
|
||||
const compressedData = localStorage.getItem("_setting-app");
|
||||
const prevLocalStorage = compressedData ? decompressData(compressedData) : {};
|
||||
|
||||
const userSettings = prevLocalStorage[user_id] || {};
|
||||
const pageSettings = userSettings[page_name] || {};
|
||||
delete pageSettings[table_name];
|
||||
|
||||
const resetData = {
|
||||
...prevLocalStorage,
|
||||
[user_id]: {
|
||||
...userSettings,
|
||||
[page_name]: {
|
||||
...pageSettings,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
localStorage.setItem("_setting-app", LZString.compressToUTF16(JSON.stringify(resetData)));
|
||||
setSettingStore(resetData);
|
||||
};
|
||||
|
||||
const updateSettingStorage = (user_id, page_name, table_name, settingType, settingValue) => {
|
||||
const compressedData = localStorage.getItem("_setting-app");
|
||||
const prevLocalStorage = compressedData ? decompressData(compressedData) : {};
|
||||
|
||||
const userSettings = prevLocalStorage[user_id] || {};
|
||||
const pageSettings = userSettings[page_name] || {};
|
||||
const tableSettings = pageSettings[table_name] || {};
|
||||
|
||||
let newSettings;
|
||||
if (settingType === "sorts" || settingType === "filters") {
|
||||
newSettings = [...settingValue];
|
||||
} else {
|
||||
newSettings = { ...(tableSettings[settingType] || {}), ...settingValue };
|
||||
}
|
||||
|
||||
const updatedLocalStorage = {
|
||||
...prevLocalStorage,
|
||||
[user_id]: {
|
||||
...userSettings,
|
||||
[page_name]: {
|
||||
...pageSettings,
|
||||
[table_name]: {
|
||||
...tableSettings,
|
||||
[settingType]: Array.isArray(settingValue) ? [...newSettings] : { ...newSettings },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
localStorage.setItem("_setting-app", LZString.compressToUTF16(JSON.stringify(updatedLocalStorage)));
|
||||
setSettingStore(updatedLocalStorage);
|
||||
};
|
||||
|
||||
const clearAction = (user_id, page_name, table_name, key) => {
|
||||
const compressedData = localStorage.getItem("_setting-app");
|
||||
const prevLocalStorage = compressedData ? decompressData(compressedData) : {};
|
||||
|
||||
const userSettings = prevLocalStorage[user_id] || {};
|
||||
const pageSettings = userSettings[page_name] || {};
|
||||
const tableSettings = pageSettings[table_name] || {};
|
||||
|
||||
const updatedSettings = {
|
||||
...prevLocalStorage,
|
||||
[user_id]: {
|
||||
...userSettings,
|
||||
[page_name]: {
|
||||
...pageSettings,
|
||||
[table_name]: {
|
||||
...tableSettings,
|
||||
[key]: Array.isArray(tableSettings[key]) ? [] : {},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
localStorage.setItem("_setting-app", LZString.compressToUTF16(JSON.stringify(updatedSettings)));
|
||||
setSettingStore(updatedSettings);
|
||||
};
|
||||
|
||||
return (
|
||||
<TableSettingContext.Provider value={{ settingStore, hideAction, sortAction, filterAction, resetAction }}>
|
||||
{children}
|
||||
</TableSettingContext.Provider>
|
||||
);
|
||||
};
|
||||
"use client";
|
||||
|
||||
import { createContext, useCallback, useEffect, useState } from "react";
|
||||
import LZString from "lz-string";
|
||||
|
||||
export const TableSettingContext = createContext();
|
||||
|
||||
const decompressData = (compressedData) => {
|
||||
try {
|
||||
const decompressed = LZString.decompressFromUTF16(compressedData);
|
||||
if (decompressed === null) {
|
||||
localStorage.removeItem("_setting-app");
|
||||
return null;
|
||||
} else {
|
||||
return JSON.parse(decompressed);
|
||||
}
|
||||
} catch (error) {
|
||||
localStorage.removeItem("_setting-app");
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const TableSettingProvider = ({ children }) => {
|
||||
const [settingStore, setSettingStore] = useState({});
|
||||
|
||||
useEffect(() => {
|
||||
const compressedData = localStorage.getItem("_setting-app");
|
||||
|
||||
const data = compressedData ? decompressData(compressedData) : null;
|
||||
if (data) {
|
||||
setSettingStore(data);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const hideAction = useCallback((user_id, page_name, table_name, settingValue) => {
|
||||
clearAction(user_id, page_name, table_name, "hides");
|
||||
updateSettingStorage(user_id, page_name, table_name, "hides", settingValue);
|
||||
}, []);
|
||||
|
||||
const sortAction = useCallback((user_id, page_name, table_name, settingValue) => {
|
||||
updateSettingStorage(user_id, page_name, table_name, "sorts", settingValue);
|
||||
}, []);
|
||||
|
||||
const filterAction = (user_id, page_name, table_name, settingValue) => {
|
||||
updateSettingStorage(user_id, page_name, table_name, "filters", settingValue);
|
||||
};
|
||||
|
||||
const resetAction = (user_id, page_name, table_name) => {
|
||||
const compressedData = localStorage.getItem("_setting-app");
|
||||
const prevLocalStorage = compressedData ? decompressData(compressedData) : {};
|
||||
|
||||
const userSettings = prevLocalStorage[user_id] || {};
|
||||
const pageSettings = userSettings[page_name] || {};
|
||||
delete pageSettings[table_name];
|
||||
|
||||
const resetData = {
|
||||
...prevLocalStorage,
|
||||
[user_id]: {
|
||||
...userSettings,
|
||||
[page_name]: {
|
||||
...pageSettings,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
localStorage.setItem("_setting-app", LZString.compressToUTF16(JSON.stringify(resetData)));
|
||||
setSettingStore(resetData);
|
||||
};
|
||||
|
||||
const updateSettingStorage = (user_id, page_name, table_name, settingType, settingValue) => {
|
||||
const compressedData = localStorage.getItem("_setting-app");
|
||||
const prevLocalStorage = compressedData ? decompressData(compressedData) : {};
|
||||
|
||||
const userSettings = prevLocalStorage[user_id] || {};
|
||||
const pageSettings = userSettings[page_name] || {};
|
||||
const tableSettings = pageSettings[table_name] || {};
|
||||
|
||||
let newSettings;
|
||||
if (settingType === "sorts" || settingType === "filters") {
|
||||
newSettings = [...settingValue];
|
||||
} else {
|
||||
newSettings = { ...(tableSettings[settingType] || {}), ...settingValue };
|
||||
}
|
||||
|
||||
const updatedLocalStorage = {
|
||||
...prevLocalStorage,
|
||||
[user_id]: {
|
||||
...userSettings,
|
||||
[page_name]: {
|
||||
...pageSettings,
|
||||
[table_name]: {
|
||||
...tableSettings,
|
||||
[settingType]: Array.isArray(settingValue) ? [...newSettings] : { ...newSettings },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
localStorage.setItem("_setting-app", LZString.compressToUTF16(JSON.stringify(updatedLocalStorage)));
|
||||
setSettingStore(updatedLocalStorage);
|
||||
};
|
||||
|
||||
const clearAction = (user_id, page_name, table_name, key) => {
|
||||
const compressedData = localStorage.getItem("_setting-app");
|
||||
const prevLocalStorage = compressedData ? decompressData(compressedData) : {};
|
||||
|
||||
const userSettings = prevLocalStorage[user_id] || {};
|
||||
const pageSettings = userSettings[page_name] || {};
|
||||
const tableSettings = pageSettings[table_name] || {};
|
||||
|
||||
const updatedSettings = {
|
||||
...prevLocalStorage,
|
||||
[user_id]: {
|
||||
...userSettings,
|
||||
[page_name]: {
|
||||
...pageSettings,
|
||||
[table_name]: {
|
||||
...tableSettings,
|
||||
[key]: Array.isArray(tableSettings[key]) ? [] : {},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
localStorage.setItem("_setting-app", LZString.compressToUTF16(JSON.stringify(updatedSettings)));
|
||||
setSettingStore(updatedSettings);
|
||||
};
|
||||
|
||||
return (
|
||||
<TableSettingContext.Provider value={{ settingStore, hideAction, sortAction, filterAction, resetAction }}>
|
||||
{children}
|
||||
</TableSettingContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { GET_AZMAYESH_TYPE_LIST } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const useAzmayesh = () => {
|
||||
const requestServer = useRequest();
|
||||
const [azmayeshes, setAzmayeshes] = useState([]);
|
||||
const [loadingAzmayeshes, setLoadingAzmayeshes] = useState(true);
|
||||
const [errorAzmayeshes, setErrorAzmayeshes] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchTests = async () => {
|
||||
try {
|
||||
const response = await requestServer(`${GET_AZMAYESH_TYPE_LIST}`);
|
||||
setAzmayeshes(response.data.data);
|
||||
setLoadingAzmayeshes(false);
|
||||
} catch (e) {
|
||||
console.error("Error fetching tests types:", e);
|
||||
setErrorAzmayeshes(e);
|
||||
setLoadingAzmayeshes(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchTests();
|
||||
}, []);
|
||||
|
||||
return { azmayeshes, loadingAzmayeshes, errorAzmayeshes };
|
||||
};
|
||||
|
||||
export default useAzmayesh;
|
||||
import { useEffect, useState } from "react";
|
||||
import { GET_AZMAYESH_TYPE_LIST } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const useAzmayesh = () => {
|
||||
const requestServer = useRequest();
|
||||
const [azmayeshes, setAzmayeshes] = useState([]);
|
||||
const [loadingAzmayeshes, setLoadingAzmayeshes] = useState(true);
|
||||
const [errorAzmayeshes, setErrorAzmayeshes] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchTests = async () => {
|
||||
try {
|
||||
const response = await requestServer(`${GET_AZMAYESH_TYPE_LIST}`);
|
||||
setAzmayeshes(response.data.data);
|
||||
setLoadingAzmayeshes(false);
|
||||
} catch (e) {
|
||||
console.error("Error fetching tests types:", e);
|
||||
setErrorAzmayeshes(e);
|
||||
setLoadingAzmayeshes(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchTests();
|
||||
}, []);
|
||||
|
||||
return { azmayeshes, loadingAzmayeshes, errorAzmayeshes };
|
||||
};
|
||||
|
||||
export default useAzmayesh;
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
import { useEffect, useReducer } from "react";
|
||||
import { GET_CITY_LISTS } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
const ACTIONS = {
|
||||
LOADING: "loading",
|
||||
SUCCESS: "success",
|
||||
ERROR: "error",
|
||||
RESET: "reset",
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
data: [],
|
||||
loading: true,
|
||||
error: null,
|
||||
};
|
||||
function reducer(state, action) {
|
||||
switch (action.type) {
|
||||
case ACTIONS.LOADING:
|
||||
return { ...state, loading: true, error: null };
|
||||
case ACTIONS.SUCCESS:
|
||||
return { ...state, loading: false, data: action.payload };
|
||||
case ACTIONS.ERROR:
|
||||
return { ...state, loading: false, error: action.payload };
|
||||
case ACTIONS.RESET:
|
||||
return { ...initialState, loading: false };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
const useCities = (id) => {
|
||||
const requestServer = useRequest();
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
|
||||
useEffect(() => {
|
||||
if (!id) {
|
||||
dispatch({ type: ACTIONS.RESET });
|
||||
return;
|
||||
}
|
||||
const fetchCityLists = async () => {
|
||||
dispatch({ type: ACTIONS.LOADING });
|
||||
try {
|
||||
const response = await requestServer(`${GET_CITY_LISTS}/${id}`);
|
||||
dispatch({ type: ACTIONS.SUCCESS, payload: response.data.data });
|
||||
} catch (error) {
|
||||
dispatch({ type: ACTIONS.ERROR, payload: error });
|
||||
}
|
||||
};
|
||||
|
||||
fetchCityLists();
|
||||
}, [id]);
|
||||
|
||||
return {
|
||||
cityList: state.data,
|
||||
loadingCityList: state.loading,
|
||||
errorCityList: state.error,
|
||||
};
|
||||
};
|
||||
|
||||
export default useCities;
|
||||
import { useEffect, useReducer } from "react";
|
||||
import { GET_CITY_LISTS } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
const ACTIONS = {
|
||||
LOADING: "loading",
|
||||
SUCCESS: "success",
|
||||
ERROR: "error",
|
||||
RESET: "reset",
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
data: [],
|
||||
loading: true,
|
||||
error: null,
|
||||
};
|
||||
function reducer(state, action) {
|
||||
switch (action.type) {
|
||||
case ACTIONS.LOADING:
|
||||
return { ...state, loading: true, error: null };
|
||||
case ACTIONS.SUCCESS:
|
||||
return { ...state, loading: false, data: action.payload };
|
||||
case ACTIONS.ERROR:
|
||||
return { ...state, loading: false, error: action.payload };
|
||||
case ACTIONS.RESET:
|
||||
return { ...initialState, loading: false };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
const useCities = (id) => {
|
||||
const requestServer = useRequest();
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
|
||||
useEffect(() => {
|
||||
if (!id) {
|
||||
dispatch({ type: ACTIONS.RESET });
|
||||
return;
|
||||
}
|
||||
const fetchCityLists = async () => {
|
||||
dispatch({ type: ACTIONS.LOADING });
|
||||
try {
|
||||
const response = await requestServer(`${GET_CITY_LISTS}/${id}`);
|
||||
dispatch({ type: ACTIONS.SUCCESS, payload: response.data.data });
|
||||
} catch (error) {
|
||||
dispatch({ type: ACTIONS.ERROR, payload: error });
|
||||
}
|
||||
};
|
||||
|
||||
fetchCityLists();
|
||||
}, [id]);
|
||||
|
||||
return {
|
||||
cityList: state.data,
|
||||
loadingCityList: state.loading,
|
||||
errorCityList: state.error,
|
||||
};
|
||||
};
|
||||
|
||||
export default useCities;
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { GET_DAMAGE_ITEM_LIST, GET_PROVINCE_LISTS } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const useDamageItemList = () => {
|
||||
const requestServer = useRequest();
|
||||
const [damageItemList, setDamageItemList] = useState([]);
|
||||
const [loadingDamageItemList, setLoadingDamageItemList] = useState(true);
|
||||
const [errorDamageItemList, setErrorDamageItemList] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchDamageItem = async () => {
|
||||
try {
|
||||
const response = await requestServer(`${GET_DAMAGE_ITEM_LIST}`);
|
||||
setDamageItemList(response.data.data);
|
||||
setLoadingDamageItemList(false);
|
||||
} catch (e) {
|
||||
setErrorDamageItemList(e);
|
||||
setLoadingDamageItemList(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchDamageItem();
|
||||
}, []);
|
||||
|
||||
return { damageItemList, loadingDamageItemList, errorDamageItemList };
|
||||
};
|
||||
|
||||
export default useDamageItemList;
|
||||
import { useEffect, useState } from "react";
|
||||
import { GET_DAMAGE_ITEM_LIST, GET_PROVINCE_LISTS } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const useDamageItemList = () => {
|
||||
const requestServer = useRequest();
|
||||
const [damageItemList, setDamageItemList] = useState([]);
|
||||
const [loadingDamageItemList, setLoadingDamageItemList] = useState(true);
|
||||
const [errorDamageItemList, setErrorDamageItemList] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchDamageItem = async () => {
|
||||
try {
|
||||
const response = await requestServer(`${GET_DAMAGE_ITEM_LIST}`);
|
||||
setDamageItemList(response.data.data);
|
||||
setLoadingDamageItemList(false);
|
||||
} catch (e) {
|
||||
setErrorDamageItemList(e);
|
||||
setLoadingDamageItemList(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchDamageItem();
|
||||
}, []);
|
||||
|
||||
return { damageItemList, loadingDamageItemList, errorDamageItemList };
|
||||
};
|
||||
|
||||
export default useDamageItemList;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { useContext } from "react";
|
||||
import { DataTableContext } from "@/lib/contexts/DataTable";
|
||||
|
||||
const useTableSetting = () => {
|
||||
const { filterData, setFilterData, sortData, setSortData, hideData, setHideData, isDirty, isAnyDirty } =
|
||||
useContext(DataTableContext);
|
||||
return { filterData, setFilterData, sortData, setSortData, hideData, setHideData, isDirty, isAnyDirty };
|
||||
};
|
||||
|
||||
export default useTableSetting;
|
||||
import { useContext } from "react";
|
||||
import { DataTableContext } from "@/lib/contexts/DataTable";
|
||||
|
||||
const useTableSetting = () => {
|
||||
const { filterData, setFilterData, sortData, setSortData, hideData, setHideData, isDirty, isAnyDirty } =
|
||||
useContext(DataTableContext);
|
||||
return { filterData, setFilterData, sortData, setSortData, hideData, setHideData, isDirty, isAnyDirty };
|
||||
};
|
||||
|
||||
export default useTableSetting;
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
import { useEffect, useReducer } from "react";
|
||||
import { GET_EDARAT_LISTS } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const ACTIONS = {
|
||||
LOADING: "loading",
|
||||
SUCCESS: "success",
|
||||
ERROR: "error",
|
||||
RESET: "reset",
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
data: [],
|
||||
loading: true,
|
||||
error: null,
|
||||
};
|
||||
|
||||
function reducer(state, action) {
|
||||
switch (action.type) {
|
||||
case ACTIONS.LOADING:
|
||||
return { ...state, loading: true, error: null };
|
||||
case ACTIONS.SUCCESS:
|
||||
return { ...state, loading: false, data: action.payload };
|
||||
case ACTIONS.ERROR:
|
||||
return { ...state, loading: false, error: action.payload };
|
||||
case ACTIONS.RESET:
|
||||
return { ...initialState, loading: false };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
const useEdaratLists = (id) => {
|
||||
const requestServer = useRequest({ notificationShow: false });
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
useEffect(() => {
|
||||
if (!id) {
|
||||
dispatch({ type: ACTIONS.RESET });
|
||||
return;
|
||||
}
|
||||
|
||||
const fetchEdaratLists = async () => {
|
||||
dispatch({ type: ACTIONS.LOADING });
|
||||
try {
|
||||
const response = await requestServer(`${GET_EDARAT_LISTS}/${id}`);
|
||||
dispatch({ type: ACTIONS.SUCCESS, payload: response.data.data });
|
||||
} catch (error) {
|
||||
dispatch({ type: ACTIONS.ERROR, payload: error });
|
||||
}
|
||||
};
|
||||
|
||||
fetchEdaratLists();
|
||||
}, [id]);
|
||||
|
||||
return {
|
||||
edaratList: state.data,
|
||||
loadingEdaratList: state.loading,
|
||||
errorEdaratList: state.error,
|
||||
};
|
||||
};
|
||||
|
||||
export default useEdaratLists;
|
||||
import { useEffect, useReducer } from "react";
|
||||
import { GET_EDARAT_LISTS } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const ACTIONS = {
|
||||
LOADING: "loading",
|
||||
SUCCESS: "success",
|
||||
ERROR: "error",
|
||||
RESET: "reset",
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
data: [],
|
||||
loading: true,
|
||||
error: null,
|
||||
};
|
||||
|
||||
function reducer(state, action) {
|
||||
switch (action.type) {
|
||||
case ACTIONS.LOADING:
|
||||
return { ...state, loading: true, error: null };
|
||||
case ACTIONS.SUCCESS:
|
||||
return { ...state, loading: false, data: action.payload };
|
||||
case ACTIONS.ERROR:
|
||||
return { ...state, loading: false, error: action.payload };
|
||||
case ACTIONS.RESET:
|
||||
return { ...initialState, loading: false };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
const useEdaratLists = (id) => {
|
||||
const requestServer = useRequest({ notificationShow: false });
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
useEffect(() => {
|
||||
if (!id) {
|
||||
dispatch({ type: ACTIONS.RESET });
|
||||
return;
|
||||
}
|
||||
|
||||
const fetchEdaratLists = async () => {
|
||||
dispatch({ type: ACTIONS.LOADING });
|
||||
try {
|
||||
const response = await requestServer(`${GET_EDARAT_LISTS}/${id}`);
|
||||
dispatch({ type: ACTIONS.SUCCESS, payload: response.data.data });
|
||||
} catch (error) {
|
||||
dispatch({ type: ACTIONS.ERROR, payload: error });
|
||||
}
|
||||
};
|
||||
|
||||
fetchEdaratLists();
|
||||
}, [id]);
|
||||
|
||||
return {
|
||||
edaratList: state.data,
|
||||
loadingEdaratList: state.loading,
|
||||
errorEdaratList: state.error,
|
||||
};
|
||||
};
|
||||
|
||||
export default useEdaratLists;
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { GET_PERMISSIONS_ROUTE } from "@/core/utils/routes";
|
||||
import useSWR from "swr";
|
||||
import useRequest from "./useRequest";
|
||||
|
||||
export const usePermissions = () => {
|
||||
const request = useRequest();
|
||||
|
||||
const fetcher = async (url) => {
|
||||
try {
|
||||
const response = await request(url);
|
||||
return response.data.data;
|
||||
} catch (error) {
|
||||
throw new Error();
|
||||
}
|
||||
};
|
||||
|
||||
return useSWR(GET_PERMISSIONS_ROUTE, fetcher, { keepPreviousData: true, dedupingInterval: 30000 });
|
||||
};
|
||||
import { GET_PERMISSIONS_ROUTE } from "@/core/utils/routes";
|
||||
import useSWR from "swr";
|
||||
import useRequest from "./useRequest";
|
||||
|
||||
export const usePermissions = () => {
|
||||
const request = useRequest();
|
||||
|
||||
const fetcher = async (url) => {
|
||||
try {
|
||||
const response = await request(url);
|
||||
return response.data.data;
|
||||
} catch (error) {
|
||||
throw new Error();
|
||||
}
|
||||
};
|
||||
|
||||
return useSWR(GET_PERMISSIONS_ROUTE, fetcher, { keepPreviousData: true, dedupingInterval: 30000 });
|
||||
};
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
import { useEffect } from "react";
|
||||
function usePersianInput(inputRef, onChange) {
|
||||
useEffect(() => {
|
||||
const input = inputRef.current;
|
||||
if (!input) return;
|
||||
|
||||
const handleInput = (event) => {
|
||||
const originalValue = event.target.value;
|
||||
const filteredValue = originalValue.replace(/[A-Za-z]/g, "");
|
||||
if (filteredValue !== originalValue) {
|
||||
event.target.value = filteredValue;
|
||||
if (onChange) {
|
||||
onChange(filteredValue);
|
||||
}
|
||||
} else if (onChange) {
|
||||
onChange(originalValue);
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown = (event) => {
|
||||
const controlKeys = [
|
||||
"Backspace",
|
||||
"Delete",
|
||||
"Tab",
|
||||
"Escape",
|
||||
"Enter",
|
||||
"ArrowLeft",
|
||||
"ArrowRight",
|
||||
"ArrowUp",
|
||||
"ArrowDown",
|
||||
];
|
||||
if (controlKeys.includes(event.key)) return;
|
||||
|
||||
if (/[A-Za-z]/.test(event.key)) {
|
||||
event.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
input.addEventListener("input", handleInput);
|
||||
input.addEventListener("keydown", handleKeyDown);
|
||||
|
||||
return () => {
|
||||
input.removeEventListener("input", handleInput);
|
||||
input.removeEventListener("keydown", handleKeyDown);
|
||||
};
|
||||
}, [inputRef, onChange]);
|
||||
}
|
||||
|
||||
export default usePersianInput;
|
||||
import { useEffect } from "react";
|
||||
function usePersianInput(inputRef, onChange) {
|
||||
useEffect(() => {
|
||||
const input = inputRef.current;
|
||||
if (!input) return;
|
||||
|
||||
const handleInput = (event) => {
|
||||
const originalValue = event.target.value;
|
||||
const filteredValue = originalValue.replace(/[A-Za-z]/g, "");
|
||||
if (filteredValue !== originalValue) {
|
||||
event.target.value = filteredValue;
|
||||
if (onChange) {
|
||||
onChange(filteredValue);
|
||||
}
|
||||
} else if (onChange) {
|
||||
onChange(originalValue);
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown = (event) => {
|
||||
const controlKeys = [
|
||||
"Backspace",
|
||||
"Delete",
|
||||
"Tab",
|
||||
"Escape",
|
||||
"Enter",
|
||||
"ArrowLeft",
|
||||
"ArrowRight",
|
||||
"ArrowUp",
|
||||
"ArrowDown",
|
||||
];
|
||||
if (controlKeys.includes(event.key)) return;
|
||||
|
||||
if (/[A-Za-z]/.test(event.key)) {
|
||||
event.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
input.addEventListener("input", handleInput);
|
||||
input.addEventListener("keydown", handleKeyDown);
|
||||
|
||||
return () => {
|
||||
input.removeEventListener("input", handleInput);
|
||||
input.removeEventListener("keydown", handleKeyDown);
|
||||
};
|
||||
}, [inputRef, onChange]);
|
||||
}
|
||||
|
||||
export default usePersianInput;
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import axios from "axios";
|
||||
import { GET_PREV_STATE_OPINION } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const usePrevStateOpinion = () => {
|
||||
const requestServer = useRequest();
|
||||
const [message, setMessage] = useState([]);
|
||||
const [loadingMessage, setLoadingMessage] = useState(true);
|
||||
const [errorMessage, setErrorMessage] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchStateOpnion = async () => {
|
||||
try {
|
||||
const response = await requestServer(`${GET_PREV_STATE_OPINION}`);
|
||||
setMessage(response.data.message);
|
||||
setLoadingMessage(false);
|
||||
} catch (e) {
|
||||
console.error("Error fetching state:", e);
|
||||
setErrorMessage(e);
|
||||
setLoadingMessage(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchStateOpnion();
|
||||
}, []);
|
||||
|
||||
return { message, loadingMessage, errorMessage };
|
||||
};
|
||||
|
||||
export default usePrevStateOpinion;
|
||||
import { useState, useEffect } from "react";
|
||||
import axios from "axios";
|
||||
import { GET_PREV_STATE_OPINION } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const usePrevStateOpinion = () => {
|
||||
const requestServer = useRequest();
|
||||
const [message, setMessage] = useState([]);
|
||||
const [loadingMessage, setLoadingMessage] = useState(true);
|
||||
const [errorMessage, setErrorMessage] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchStateOpnion = async () => {
|
||||
try {
|
||||
const response = await requestServer(`${GET_PREV_STATE_OPINION}`);
|
||||
setMessage(response.data.message);
|
||||
setLoadingMessage(false);
|
||||
} catch (e) {
|
||||
console.error("Error fetching state:", e);
|
||||
setErrorMessage(e);
|
||||
setLoadingMessage(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchStateOpnion();
|
||||
}, []);
|
||||
|
||||
return { message, loadingMessage, errorMessage };
|
||||
};
|
||||
|
||||
export default usePrevStateOpinion;
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { GET_PROVINCE_LISTS } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const useProvinces = () => {
|
||||
const requestServer = useRequest();
|
||||
const [provinces, setProvinces] = useState([]);
|
||||
const [loadingProvinces, setLoadingProvinces] = useState(true);
|
||||
const [errorProvinces, setErrorProvinces] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchProvinces = async () => {
|
||||
try {
|
||||
const response = await requestServer(`${GET_PROVINCE_LISTS}`);
|
||||
setProvinces(response.data.data);
|
||||
setLoadingProvinces(false);
|
||||
} catch (e) {
|
||||
setErrorProvinces(e);
|
||||
setLoadingProvinces(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchProvinces();
|
||||
}, []);
|
||||
|
||||
return { provinces, loadingProvinces, errorProvinces };
|
||||
};
|
||||
|
||||
export default useProvinces;
|
||||
import { useEffect, useState } from "react";
|
||||
import { GET_PROVINCE_LISTS } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const useProvinces = () => {
|
||||
const requestServer = useRequest();
|
||||
const [provinces, setProvinces] = useState([]);
|
||||
const [loadingProvinces, setLoadingProvinces] = useState(true);
|
||||
const [errorProvinces, setErrorProvinces] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchProvinces = async () => {
|
||||
try {
|
||||
const response = await requestServer(`${GET_PROVINCE_LISTS}`);
|
||||
setProvinces(response.data.data);
|
||||
setLoadingProvinces(false);
|
||||
} catch (e) {
|
||||
setErrorProvinces(e);
|
||||
setLoadingProvinces(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchProvinces();
|
||||
}, []);
|
||||
|
||||
return { provinces, loadingProvinces, errorProvinces };
|
||||
};
|
||||
|
||||
export default useProvinces;
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
import { errorResponse } from "@/core/utils/errorResponse";
|
||||
import { successRequest } from "@/core/utils/successRequest";
|
||||
import axios from "axios";
|
||||
import { useAuth } from "../contexts/auth";
|
||||
import { useSidebarBadge } from "./useSidebarBadge";
|
||||
|
||||
const defaultOptions = {
|
||||
data: {},
|
||||
requestOptions: {
|
||||
headers: {},
|
||||
},
|
||||
notificationShow: true,
|
||||
notificationSuccess: false,
|
||||
notificationFailed: true,
|
||||
hasSidebarUpdate: false,
|
||||
};
|
||||
|
||||
const useRequest = (initOptions) => {
|
||||
const { mutate: sidebarUpdate } = useSidebarBadge();
|
||||
const { logout } = useAuth();
|
||||
|
||||
const _options = Object.assign({}, defaultOptions, initOptions);
|
||||
|
||||
/**
|
||||
* Performs an HTTP request.
|
||||
* @param {string} url - The URL to send the request to.
|
||||
* @param {'get' | 'post' | 'put' | 'delete'} [method='get'] - HTTP method.
|
||||
* @param {object} [options] - Additional request options.
|
||||
* @returns {Promise<AxiosResponse>} - Axios response.
|
||||
*/
|
||||
return async (url = "", method = "get", options) => {
|
||||
const mergedOptions = Object.assign({}, _options, options);
|
||||
try {
|
||||
const response = await axios({
|
||||
url,
|
||||
method,
|
||||
data: method === "get" ? null : mergedOptions.data,
|
||||
withCredentials: true,
|
||||
...mergedOptions.requestOptions,
|
||||
});
|
||||
if (mergedOptions.hasSidebarUpdate) {
|
||||
if (method === "post" || method === "put" || method === "delete") sidebarUpdate();
|
||||
}
|
||||
successRequest(mergedOptions.notificationShow && mergedOptions.notificationSuccess, "request_data");
|
||||
return response;
|
||||
} catch (error) {
|
||||
if (error.response) {
|
||||
errorResponse(
|
||||
error.response,
|
||||
mergedOptions.notificationShow && mergedOptions.notificationFailed,
|
||||
"request_data",
|
||||
logout
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default useRequest;
|
||||
import { errorResponse } from "@/core/utils/errorResponse";
|
||||
import { successRequest } from "@/core/utils/successRequest";
|
||||
import axios from "axios";
|
||||
import { useAuth } from "../contexts/auth";
|
||||
import { useSidebarBadge } from "./useSidebarBadge";
|
||||
|
||||
const defaultOptions = {
|
||||
data: {},
|
||||
requestOptions: {
|
||||
headers: {},
|
||||
},
|
||||
notificationShow: true,
|
||||
notificationSuccess: false,
|
||||
notificationFailed: true,
|
||||
hasSidebarUpdate: false,
|
||||
};
|
||||
|
||||
const useRequest = (initOptions) => {
|
||||
const { mutate: sidebarUpdate } = useSidebarBadge();
|
||||
const { logout } = useAuth();
|
||||
|
||||
const _options = Object.assign({}, defaultOptions, initOptions);
|
||||
|
||||
/**
|
||||
* Performs an HTTP request.
|
||||
* @param {string} url - The URL to send the request to.
|
||||
* @param {'get' | 'post' | 'put' | 'delete'} [method='get'] - HTTP method.
|
||||
* @param {object} [options] - Additional request options.
|
||||
* @returns {Promise<AxiosResponse>} - Axios response.
|
||||
*/
|
||||
return async (url = "", method = "get", options) => {
|
||||
const mergedOptions = Object.assign({}, _options, options);
|
||||
try {
|
||||
const response = await axios({
|
||||
url,
|
||||
method,
|
||||
data: method === "get" ? null : mergedOptions.data,
|
||||
withCredentials: true,
|
||||
...mergedOptions.requestOptions,
|
||||
});
|
||||
if (mergedOptions.hasSidebarUpdate) {
|
||||
if (method === "post" || method === "put" || method === "delete") sidebarUpdate();
|
||||
}
|
||||
successRequest(mergedOptions.notificationShow && mergedOptions.notificationSuccess, "request_data");
|
||||
return response;
|
||||
} catch (error) {
|
||||
if (error.response) {
|
||||
errorResponse(
|
||||
error.response,
|
||||
mergedOptions.notificationShow && mergedOptions.notificationFailed,
|
||||
"request_data",
|
||||
logout
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default useRequest;
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
import { useEffect, useReducer } from "react";
|
||||
import { GET_ROAD_ITEMS_SUB_ITEM } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const ACTIONS = {
|
||||
LOADING: "loading",
|
||||
SUCCESS: "success",
|
||||
ERROR: "error",
|
||||
RESET: "reset",
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
data: [],
|
||||
loading: true,
|
||||
error: null,
|
||||
};
|
||||
|
||||
function reducer(state, action) {
|
||||
switch (action.type) {
|
||||
case ACTIONS.LOADING:
|
||||
return { ...state, loading: true, error: null };
|
||||
case ACTIONS.SUCCESS:
|
||||
return { ...state, loading: false, data: action.payload };
|
||||
case ACTIONS.ERROR:
|
||||
return { ...state, loading: false, error: action.payload };
|
||||
case ACTIONS.RESET:
|
||||
return { ...initialState, loading: false };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
const useRoadItemGetSubItems = (id) => {
|
||||
const requestServer = useRequest({ notificationShow: false });
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
useEffect(() => {
|
||||
if (!id) {
|
||||
dispatch({ type: ACTIONS.RESET });
|
||||
return;
|
||||
}
|
||||
|
||||
const fetchSubItems = async () => {
|
||||
dispatch({ type: ACTIONS.LOADING });
|
||||
try {
|
||||
const response = await requestServer(`${GET_ROAD_ITEMS_SUB_ITEM}/${id}`);
|
||||
dispatch({ type: ACTIONS.SUCCESS, payload: response.data.data });
|
||||
} catch (error) {
|
||||
dispatch({ type: ACTIONS.ERROR, payload: error });
|
||||
}
|
||||
};
|
||||
|
||||
fetchSubItems();
|
||||
}, [id]);
|
||||
|
||||
return {
|
||||
subItemsList: state.data,
|
||||
loadingSubItemsList: state.loading,
|
||||
errorSubItemsList: state.error,
|
||||
};
|
||||
};
|
||||
|
||||
export default useRoadItemGetSubItems;
|
||||
import { useEffect, useReducer } from "react";
|
||||
import { GET_ROAD_ITEMS_SUB_ITEM } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const ACTIONS = {
|
||||
LOADING: "loading",
|
||||
SUCCESS: "success",
|
||||
ERROR: "error",
|
||||
RESET: "reset",
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
data: [],
|
||||
loading: true,
|
||||
error: null,
|
||||
};
|
||||
|
||||
function reducer(state, action) {
|
||||
switch (action.type) {
|
||||
case ACTIONS.LOADING:
|
||||
return { ...state, loading: true, error: null };
|
||||
case ACTIONS.SUCCESS:
|
||||
return { ...state, loading: false, data: action.payload };
|
||||
case ACTIONS.ERROR:
|
||||
return { ...state, loading: false, error: action.payload };
|
||||
case ACTIONS.RESET:
|
||||
return { ...initialState, loading: false };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
const useRoadItemGetSubItems = (id) => {
|
||||
const requestServer = useRequest({ notificationShow: false });
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
useEffect(() => {
|
||||
if (!id) {
|
||||
dispatch({ type: ACTIONS.RESET });
|
||||
return;
|
||||
}
|
||||
|
||||
const fetchSubItems = async () => {
|
||||
dispatch({ type: ACTIONS.LOADING });
|
||||
try {
|
||||
const response = await requestServer(`${GET_ROAD_ITEMS_SUB_ITEM}/${id}`);
|
||||
dispatch({ type: ACTIONS.SUCCESS, payload: response.data.data });
|
||||
} catch (error) {
|
||||
dispatch({ type: ACTIONS.ERROR, payload: error });
|
||||
}
|
||||
};
|
||||
|
||||
fetchSubItems();
|
||||
}, [id]);
|
||||
|
||||
return {
|
||||
subItemsList: state.data,
|
||||
loadingSubItemsList: state.loading,
|
||||
errorSubItemsList: state.error,
|
||||
};
|
||||
};
|
||||
|
||||
export default useRoadItemGetSubItems;
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { GET_ROAD_ITEMS_ITEM } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const useRoadItemGetItems = () => {
|
||||
const requestServer = useRequest();
|
||||
const [itemsList, setItemsList] = useState([]);
|
||||
const [loadingItemsList, setLoadingItemsList] = useState(true);
|
||||
const [errorItemsList, setErrorItemsList] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchItems = async () => {
|
||||
try {
|
||||
const response = await requestServer(`${GET_ROAD_ITEMS_ITEM}`);
|
||||
setItemsList(response.data.data);
|
||||
setLoadingItemsList(false);
|
||||
setErrorItemsList(false);
|
||||
} catch (e) {
|
||||
setErrorItemsList(e);
|
||||
setLoadingItemsList(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchItems();
|
||||
}, []);
|
||||
|
||||
return { itemsList, loadingItemsList, errorItemsList };
|
||||
};
|
||||
|
||||
export default useRoadItemGetItems;
|
||||
import { useEffect, useState } from "react";
|
||||
import { GET_ROAD_ITEMS_ITEM } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
|
||||
const useRoadItemGetItems = () => {
|
||||
const requestServer = useRequest();
|
||||
const [itemsList, setItemsList] = useState([]);
|
||||
const [loadingItemsList, setLoadingItemsList] = useState(true);
|
||||
const [errorItemsList, setErrorItemsList] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchItems = async () => {
|
||||
try {
|
||||
const response = await requestServer(`${GET_ROAD_ITEMS_ITEM}`);
|
||||
setItemsList(response.data.data);
|
||||
setLoadingItemsList(false);
|
||||
setErrorItemsList(false);
|
||||
} catch (e) {
|
||||
setErrorItemsList(e);
|
||||
setLoadingItemsList(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchItems();
|
||||
}, []);
|
||||
|
||||
return { itemsList, loadingItemsList, errorItemsList };
|
||||
};
|
||||
|
||||
export default useRoadItemGetItems;
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
import { GET_SAFETY_AND_PRIVACY_ITEM } from "@/core/utils/routes";
|
||||
|
||||
const useSafetyAndPrivacyGetItems = () => {
|
||||
const requestServer = useRequest();
|
||||
const [itemsList, setItemsList] = useState([]);
|
||||
const [loadingItemsList, setLoadingItemsList] = useState(true);
|
||||
const [errorItemsList, setErrorItemsList] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchItems = async () => {
|
||||
try {
|
||||
const response = await requestServer(`${GET_SAFETY_AND_PRIVACY_ITEM}`);
|
||||
setItemsList(response.data.data);
|
||||
setLoadingItemsList(false);
|
||||
setErrorItemsList(false);
|
||||
} catch (e) {
|
||||
setErrorItemsList(e);
|
||||
setLoadingItemsList(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchItems();
|
||||
}, []);
|
||||
|
||||
return { itemsList, loadingItemsList, errorItemsList };
|
||||
};
|
||||
|
||||
export default useSafetyAndPrivacyGetItems;
|
||||
import { useEffect, useState } from "react";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
import { GET_SAFETY_AND_PRIVACY_ITEM } from "@/core/utils/routes";
|
||||
|
||||
const useSafetyAndPrivacyGetItems = () => {
|
||||
const requestServer = useRequest();
|
||||
const [itemsList, setItemsList] = useState([]);
|
||||
const [loadingItemsList, setLoadingItemsList] = useState(true);
|
||||
const [errorItemsList, setErrorItemsList] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchItems = async () => {
|
||||
try {
|
||||
const response = await requestServer(`${GET_SAFETY_AND_PRIVACY_ITEM}`);
|
||||
setItemsList(response.data.data);
|
||||
setLoadingItemsList(false);
|
||||
setErrorItemsList(false);
|
||||
} catch (e) {
|
||||
setErrorItemsList(e);
|
||||
setLoadingItemsList(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchItems();
|
||||
}, []);
|
||||
|
||||
return { itemsList, loadingItemsList, errorItemsList };
|
||||
};
|
||||
|
||||
export default useSafetyAndPrivacyGetItems;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { GET_SIDEBAR_BADGE_ROUTE } from "@/core/utils/routes";
|
||||
import axios from "axios";
|
||||
import useSWR from "swr";
|
||||
|
||||
export const useSidebarBadge = () => {
|
||||
const fetcher = async (url) => {
|
||||
try {
|
||||
const response = await axios({ url, method: "get", withCredentials: true });
|
||||
return response.data.data;
|
||||
} catch (error) {
|
||||
throw new Error();
|
||||
}
|
||||
};
|
||||
|
||||
return useSWR(GET_SIDEBAR_BADGE_ROUTE, fetcher, { keepPreviousData: true, dedupingInterval: 30000 });
|
||||
};
|
||||
import { GET_SIDEBAR_BADGE_ROUTE } from "@/core/utils/routes";
|
||||
import axios from "axios";
|
||||
import useSWR from "swr";
|
||||
|
||||
export const useSidebarBadge = () => {
|
||||
const fetcher = async (url) => {
|
||||
try {
|
||||
const response = await axios({ url, method: "get", withCredentials: true });
|
||||
return response.data.data;
|
||||
} catch (error) {
|
||||
throw new Error();
|
||||
}
|
||||
};
|
||||
|
||||
return useSWR(GET_SIDEBAR_BADGE_ROUTE, fetcher, { keepPreviousData: true, dedupingInterval: 30000 });
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useContext } from "react";
|
||||
import { TableSettingContext } from "../contexts/tableSetting";
|
||||
|
||||
const useTableSetting = () => {
|
||||
const { settingStore, hideAction, sortAction, filterAction, resetAction } = useContext(TableSettingContext);
|
||||
return { settingStore, hideAction, sortAction, filterAction, resetAction };
|
||||
};
|
||||
|
||||
export default useTableSetting;
|
||||
import { useContext } from "react";
|
||||
import { TableSettingContext } from "../contexts/tableSetting";
|
||||
|
||||
const useTableSetting = () => {
|
||||
const { settingStore, hideAction, sortAction, filterAction, resetAction } = useContext(TableSettingContext);
|
||||
return { settingStore, hideAction, sortAction, filterAction, resetAction };
|
||||
};
|
||||
|
||||
export default useTableSetting;
|
||||
|
||||
Reference in New Issue
Block a user