Feature/user management
This commit is contained in:
10
src/core/utils/DataTableFilterDataStructure.js
Normal file
10
src/core/utils/DataTableFilterDataStructure.js
Normal file
@@ -0,0 +1,10 @@
|
||||
export default function DataTableFilterDataStructure(filterData, isValueEmpty) {
|
||||
return Object.values(filterData)
|
||||
.filter((filter) => !isValueEmpty(filter.value))
|
||||
.map(({ filterMode, id, datatype, value }) => ({
|
||||
id: id.replace(/__/g, "."),
|
||||
fn: filterMode,
|
||||
datatype,
|
||||
value,
|
||||
}));
|
||||
}
|
||||
9
src/core/utils/flattenArrayOfObjects.js
Normal file
9
src/core/utils/flattenArrayOfObjects.js
Normal file
@@ -0,0 +1,9 @@
|
||||
export const flattenArrayOfObjects = (array, key) => {
|
||||
return array.reduce((acc, obj) => {
|
||||
acc.push(obj);
|
||||
if (Array.isArray(obj[key])) {
|
||||
acc.push(...flattenArrayOfObjects(obj[key], key));
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
};
|
||||
12
src/core/utils/flattenObjectOfObjects.js
Normal file
12
src/core/utils/flattenObjectOfObjects.js
Normal file
@@ -0,0 +1,12 @@
|
||||
export const flattenObjectOfObjects = (obj, res = {}) => {
|
||||
for (let key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
if (typeof obj[key] === "object" && obj[key] !== null) {
|
||||
flattenObjectOfObjects(obj[key], res);
|
||||
} else {
|
||||
res[key] = obj[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
};
|
||||
6
src/core/utils/isArrayEmpty.js
Normal file
6
src/core/utils/isArrayEmpty.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export default function isArrayEmpty(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return value.length === 0 || value.every((v) => v === "");
|
||||
}
|
||||
return value === "" || value === null || value === undefined;
|
||||
}
|
||||
30
src/core/utils/nationalCodeValidation.js
Normal file
30
src/core/utils/nationalCodeValidation.js
Normal file
@@ -0,0 +1,30 @@
|
||||
function validateNationalCode(code) {
|
||||
const invalidCodes = [
|
||||
"1111111111",
|
||||
"2222222222",
|
||||
"3333333333",
|
||||
"4444444444",
|
||||
"5555555555",
|
||||
"6666666666",
|
||||
"7777777777",
|
||||
"8888888888",
|
||||
"9999999999",
|
||||
];
|
||||
if (invalidCodes.includes(code)) return false;
|
||||
|
||||
const L = code.length;
|
||||
if (L < 8 || parseInt(code, 10) === 0) return false;
|
||||
|
||||
code = code.padStart(10, "0");
|
||||
if (parseInt(code.substr(3, 6), 10) === 0) return false;
|
||||
|
||||
const c = parseInt(code.charAt(9), 10);
|
||||
let s = 0;
|
||||
for (let i = 0; i < 9; i++) {
|
||||
s += parseInt(code.charAt(i), 10) * (10 - i);
|
||||
}
|
||||
s = s % 11;
|
||||
return (s < 2 && c === s) || (s >= 2 && c === 11 - s);
|
||||
}
|
||||
|
||||
export default validateNationalCode;
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Settings } from "@mui/icons-material";
|
||||
import SpaceDashboardIcon from "@mui/icons-material/SpaceDashboard";
|
||||
|
||||
export const pageMenu = [
|
||||
@@ -9,4 +10,20 @@ export const pageMenu = [
|
||||
icon: <SpaceDashboardIcon sx={{ width: "inherit", height: "inherit" }} />,
|
||||
permissions: ["all"],
|
||||
},
|
||||
{
|
||||
id: "systemManagment",
|
||||
label: "مدیریت سامانه",
|
||||
type: "menu",
|
||||
icon: <Settings sx={{ width: "inherit", height: "inherit" }} />,
|
||||
hasSubitems: true,
|
||||
Subitems: [
|
||||
{
|
||||
id: "systemManagment-users",
|
||||
label: "کاربران",
|
||||
type: "page",
|
||||
route: "/dashboard/users",
|
||||
permissions: ["manage_users"],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -6,8 +6,14 @@ export const GET_USER_LOGIN_ROUTE = api + "/auth/login";
|
||||
export const GET_USER_LOGOUT_ROUTE = api + "/auth/logout";
|
||||
export const GET_PERMISSIONS_ROUTE = api + "/profile/permissions";
|
||||
export const GET_SIDEBAR_BADGE_ROUTE = "";
|
||||
export const GET_PROVINCE_LISTS = api + "/provinces/list";
|
||||
export const GET_ROLE_LISTS = api + "/roles/list";
|
||||
|
||||
export const GET_CATEGORY = api + "/categories/list";
|
||||
|
||||
export const GET_CALLER_HISTORY = api + "/calls/list";
|
||||
export const CALL_ACTION = api + "/calls";
|
||||
|
||||
export const GET_USER_LIST = api + "/users";
|
||||
export const CREATE_USER = api + "/users";
|
||||
export const DELETE_USER = api + "/users";
|
||||
export const UPDATE_USER = api + "/users";
|
||||
|
||||
@@ -11,7 +11,6 @@ const theme = createTheme({
|
||||
primary: {
|
||||
main: "#1b4332",
|
||||
contrastText: "#FFFFFF",
|
||||
|
||||
},
|
||||
secondary: {
|
||||
main: "#1B4043",
|
||||
|
||||
149
src/core/utils/utils.js
Normal file
149
src/core/utils/utils.js
Normal file
@@ -0,0 +1,149 @@
|
||||
import { alpha, darken } from "@mui/material";
|
||||
|
||||
export const parseCSSVarId = (id) => id.replace(/[^a-zA-Z0-9]/g, "_");
|
||||
|
||||
export const parseFromValuesOrFunc = (fn, arg) =>
|
||||
fn instanceof Function ? fn(arg) : fn;
|
||||
|
||||
export const getCommonToolbarStyles = ({ table }) => ({
|
||||
alignItems: "flex-start",
|
||||
backgroundColor: table.options.mrtTheme.baseBackgroundColor,
|
||||
display: "grid",
|
||||
flexWrap: "wrap-reverse",
|
||||
minHeight: "3.5rem",
|
||||
overflow: "hidden",
|
||||
position: "relative",
|
||||
transition: "all 150ms ease-in-out",
|
||||
zIndex: 1,
|
||||
});
|
||||
|
||||
export const getCommonTooltipProps = (placement) => ({
|
||||
disableInteractive: true,
|
||||
enterDelay: 500,
|
||||
enterNextDelay: 500,
|
||||
placement,
|
||||
});
|
||||
|
||||
export const flipIconStyles = (theme) =>
|
||||
theme.direction === "rtl"
|
||||
? { style: { transform: "scaleX(-1)" } }
|
||||
: undefined;
|
||||
|
||||
export const getCommonPinnedCellStyles = ({ column, table, theme }) => {
|
||||
const { baseBackgroundColor } = table.options.mrtTheme;
|
||||
const isPinned = column?.getIsPinned();
|
||||
|
||||
return {
|
||||
'&[data-pinned="true"]': {
|
||||
"&:before": {
|
||||
backgroundColor: alpha(
|
||||
darken(
|
||||
baseBackgroundColor,
|
||||
theme.palette.mode === "dark" ? 0.05 : 0.01,
|
||||
),
|
||||
0.97,
|
||||
),
|
||||
boxShadow: column
|
||||
? isPinned === "left" && column.getIsLastColumn(isPinned)
|
||||
? `-4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset`
|
||||
: isPinned === "right" && column.getIsFirstColumn(isPinned)
|
||||
? `4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset`
|
||||
: undefined
|
||||
: undefined,
|
||||
...commonCellBeforeAfterStyles,
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const getCommonMRTCellStyles = ({
|
||||
column,
|
||||
header,
|
||||
table,
|
||||
tableCellProps,
|
||||
theme,
|
||||
}) => {
|
||||
const {
|
||||
getState,
|
||||
options: { enableColumnVirtualization, layoutMode },
|
||||
} = table;
|
||||
const { draggingColumn } = getState();
|
||||
const { columnDef } = column;
|
||||
const { columnDefType } = columnDef;
|
||||
|
||||
const isColumnPinned =
|
||||
columnDef.columnDefType !== "group" && column.getIsPinned();
|
||||
|
||||
const widthStyles = {
|
||||
minWidth: `max(calc(var(--${header ? "header" : "col"}-${parseCSSVarId(
|
||||
header?.id ?? column.id,
|
||||
)}-size) * 1px), ${columnDef.minSize ?? 30}px)`,
|
||||
width: `calc(var(--${header ? "header" : "col"}-${parseCSSVarId(header?.id ?? column.id)}-size) * 1px)`,
|
||||
};
|
||||
|
||||
if (layoutMode === "grid") {
|
||||
widthStyles.flex = `${
|
||||
[0, false].includes(columnDef.grow)
|
||||
? 0
|
||||
: `var(--${header ? "header" : "col"}-${parseCSSVarId(header?.id ?? column.id)}-size)`
|
||||
} 0 auto`;
|
||||
} else if (layoutMode === "grid-no-grow") {
|
||||
widthStyles.flex = `${+(columnDef.grow || 0)} 0 auto`;
|
||||
}
|
||||
|
||||
const pinnedStyles = isColumnPinned
|
||||
? {
|
||||
...getCommonPinnedCellStyles({ column, table, theme }),
|
||||
left:
|
||||
isColumnPinned === "left"
|
||||
? `${column.getStart("left")}px`
|
||||
: undefined,
|
||||
opacity: 0.97,
|
||||
position: "sticky",
|
||||
right:
|
||||
isColumnPinned === "right"
|
||||
? `${column.getAfter("right")}px`
|
||||
: undefined,
|
||||
}
|
||||
: {};
|
||||
|
||||
return {
|
||||
backgroundColor: "inherit",
|
||||
backgroundImage: "inherit",
|
||||
display: layoutMode?.startsWith("grid") ? "flex" : undefined,
|
||||
justifyContent:
|
||||
columnDefType === "group"
|
||||
? "center"
|
||||
: layoutMode?.startsWith("grid")
|
||||
? tableCellProps.align
|
||||
: undefined,
|
||||
opacity:
|
||||
table.getState().draggingColumn?.id === column.id ||
|
||||
table.getState().hoveredColumn?.id === column.id
|
||||
? 0.5
|
||||
: 1,
|
||||
position: "relative",
|
||||
transition: enableColumnVirtualization
|
||||
? "none"
|
||||
: `padding 150ms ease-in-out`,
|
||||
zIndex:
|
||||
column.getIsResizing() || draggingColumn?.id === column.id
|
||||
? 2
|
||||
: columnDefType !== "group" && isColumnPinned
|
||||
? 1
|
||||
: 0,
|
||||
...pinnedStyles,
|
||||
...widthStyles,
|
||||
...parseFromValuesOrFunc(tableCellProps?.sx, theme),
|
||||
};
|
||||
};
|
||||
|
||||
export const commonCellBeforeAfterStyles = {
|
||||
content: '""',
|
||||
height: "100%",
|
||||
left: 0,
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
width: "100%",
|
||||
zIndex: -1,
|
||||
};
|
||||
Reference in New Issue
Block a user