Feature/migration
This commit is contained in:
15
src/core/utils/cacheRtl.js
Normal file
15
src/core/utils/cacheRtl.js
Normal file
@@ -0,0 +1,15 @@
|
||||
"use client";
|
||||
import createCache from "@emotion/cache";
|
||||
import { CacheProvider } from "@emotion/react";
|
||||
import { prefixer } from "stylis";
|
||||
import rtlPlugin from "stylis-plugin-rtl";
|
||||
|
||||
// Create rtl cache
|
||||
export const rtlCache = createCache({
|
||||
key: "mui-rtl",
|
||||
stylisPlugins: [prefixer, rtlPlugin],
|
||||
});
|
||||
|
||||
export function Rtl(props) {
|
||||
return <CacheProvider value={rtlCache}>{props.children}</CacheProvider>;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
import createCache from "@emotion/cache";
|
||||
import {prefixer} from "stylis";
|
||||
import stylisRTLPlugin from "stylis-plugin-rtl";
|
||||
|
||||
const isBrowser = typeof document !== "undefined";
|
||||
|
||||
export const createEmotionCacheLtr = () => {
|
||||
let insertionPoint;
|
||||
|
||||
if (isBrowser) {
|
||||
const emotionInsertionPoint = document.querySelector(
|
||||
'meta[name="emotion-insertion-point"]'
|
||||
);
|
||||
insertionPoint = emotionInsertionPoint ?? undefined;
|
||||
}
|
||||
|
||||
return createCache({
|
||||
key: "mui-style",
|
||||
insertionPoint,
|
||||
});
|
||||
};
|
||||
|
||||
export const createEmotionCacheRtl = () => {
|
||||
let insertionPoint;
|
||||
|
||||
if (isBrowser) {
|
||||
const emotionInsertionPoint = document.querySelector(
|
||||
'meta[name="emotion-insertion-point"]'
|
||||
);
|
||||
insertionPoint = emotionInsertionPoint ?? undefined;
|
||||
}
|
||||
|
||||
return createCache({
|
||||
key: "muirtl",
|
||||
stylisPlugins: [prefixer, stylisRTLPlugin],
|
||||
insertionPoint,
|
||||
});
|
||||
};
|
||||
@@ -1,65 +0,0 @@
|
||||
import Notifications from "@/core/components/notifications";
|
||||
|
||||
export const errorSetting = (dismissToastList, t, notification) => {
|
||||
if (notification) {
|
||||
dismissToastList(["pending", "warning", "error", "success"])
|
||||
}
|
||||
}
|
||||
export const errorRequest = (dismissToastList, t, notification) => {
|
||||
if (notification) {
|
||||
dismissToastList(["pending", "warning", "error", "success"])
|
||||
}
|
||||
}
|
||||
|
||||
export const errorResponse = (pushToastList, dismissToastList, response, clearToken, t, notification) => {
|
||||
if (notification) {
|
||||
dismissToastList(["pending", "warning", "error", "success"])
|
||||
}
|
||||
if (isServerError(response.status)) {
|
||||
errorServer(pushToastList, response, t, notification)
|
||||
} else if (isClientError(response.status)) {
|
||||
errorClient(pushToastList, response, clearToken, t, notification)
|
||||
}
|
||||
}
|
||||
|
||||
const errorServer = (pushToastList, response, t, notification) => {
|
||||
if (notification) Notifications(pushToastList, "warning", t, response.status);
|
||||
}
|
||||
const errorClient = (pushToastList, response, clearToken, t, notification) => {
|
||||
switch (response.status) {
|
||||
case 401:
|
||||
clearToken()
|
||||
if (notification) Notifications(pushToastList, "error", t, response.status);
|
||||
break;
|
||||
case 422:
|
||||
if ('type' in response.data) {
|
||||
errorLogic(pushToastList, response, t, notification)
|
||||
break;
|
||||
}
|
||||
errorValidation(pushToastList, response, t, notification)
|
||||
break;
|
||||
case 429:
|
||||
if (notification) Notifications(pushToastList, "error", t, response.status);
|
||||
break
|
||||
default:
|
||||
if (notification) Notifications(pushToastList, "error", t, response.status);
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
const isServerError = status => status >= 500 && status <= 599;
|
||||
const isClientError = status => status >= 400 && status <= 499;
|
||||
|
||||
const errorLogic = (pushToastList, response, t, notification) => {
|
||||
if (notification) Notifications(pushToastList, "error", t, response.status, response.data.message);
|
||||
}
|
||||
const errorValidation = (pushToastList, response, t, notification) => {
|
||||
if (notification) {
|
||||
const errorsMap = Object.keys(response.data.errors)
|
||||
const errorsArray = response.data.errors
|
||||
|
||||
errorsMap.map((item, index) => {
|
||||
Notifications(pushToastList, "error", t, response.status, errorsArray[item][0]);
|
||||
})
|
||||
}
|
||||
}
|
||||
72
src/core/utils/errorResponse.js
Normal file
72
src/core/utils/errorResponse.js
Normal file
@@ -0,0 +1,72 @@
|
||||
"use client";
|
||||
import { toast } from "react-toastify";
|
||||
import {
|
||||
errorAccessDeniedToast,
|
||||
errorClientToast,
|
||||
errorLogicToast,
|
||||
errorServerToast,
|
||||
errorTooManyToast,
|
||||
errorUnauthorizedToast,
|
||||
errorValidationToast,
|
||||
} from "@/core/components/Toasts/error";
|
||||
|
||||
const isServerError = (status) => status >= 500 && status <= 599;
|
||||
const isClientError = (status) => status >= 400 && status <= 499;
|
||||
|
||||
const errorServer = (response, notification, toastContainer) => {
|
||||
if (notification) errorServerToast(toastContainer);
|
||||
};
|
||||
|
||||
const errorClient = (response, notification, toastContainer, logout) => {
|
||||
switch (response.status) {
|
||||
case 401:
|
||||
logout();
|
||||
if (notification) errorUnauthorizedToast(toastContainer);
|
||||
break;
|
||||
case 403:
|
||||
if (notification)
|
||||
errorAccessDeniedToast(response.data.message, toastContainer);
|
||||
break;
|
||||
case 422:
|
||||
if ("type" in response.data) {
|
||||
if (Array.isArray(response.data.message)) {
|
||||
response.data.message.map((item) => {
|
||||
if (notification) errorLogicToast(item, toastContainer);
|
||||
});
|
||||
} else {
|
||||
if (notification)
|
||||
errorLogicToast(response.data.message, toastContainer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (notification) {
|
||||
const errorsMap = Object.keys(response.data.errors);
|
||||
const errorsArray = response.data.errors;
|
||||
|
||||
errorsMap.map((item, index) => {
|
||||
errorValidationToast(errorsArray[item][0], toastContainer);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 429:
|
||||
if (notification) errorTooManyToast(toastContainer);
|
||||
break;
|
||||
default:
|
||||
if (notification) errorClientToast(toastContainer);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
export const errorResponse = (
|
||||
response,
|
||||
notification,
|
||||
toastContainer,
|
||||
logout,
|
||||
) => {
|
||||
if (notification) toast.dismiss({ containerId: toastContainer });
|
||||
if (isServerError(response.status)) {
|
||||
errorServer(response, notification, toastContainer);
|
||||
} else if (isClientError(response.status)) {
|
||||
errorClient(response, notification, toastContainer, logout);
|
||||
}
|
||||
};
|
||||
19
src/core/utils/filterMenuItems.js
Normal file
19
src/core/utils/filterMenuItems.js
Normal file
@@ -0,0 +1,19 @@
|
||||
export function filterMenuItems(items, _permissions = []) {
|
||||
return items.reduce((acc, item) => {
|
||||
if (item.permissions) {
|
||||
if (
|
||||
item.permissions.some((permission) => _permissions.includes(permission))
|
||||
) {
|
||||
acc.push(item);
|
||||
}
|
||||
} else if (item.hasSubitems) {
|
||||
const filteredSubItems = filterMenuItems(item.Subitems, _permissions);
|
||||
if (filteredSubItems.length > 0) {
|
||||
acc.push({ ...item, Subitems: filteredSubItems });
|
||||
}
|
||||
} else {
|
||||
acc.push(item);
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
}
|
||||
14
src/core/utils/getValueByPath.js
Normal file
14
src/core/utils/getValueByPath.js
Normal file
@@ -0,0 +1,14 @@
|
||||
export const getValueByPath = (obj, path) => {
|
||||
const keys = path.split(".");
|
||||
|
||||
let value = obj;
|
||||
|
||||
for (const key of keys) {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
value = value[key];
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
15
src/core/utils/headerMenu.js
Normal file
15
src/core/utils/headerMenu.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const api = process.env.NEXT_PUBLIC_API_URL;
|
||||
|
||||
export const headerMenu = [
|
||||
// {
|
||||
// title: "تصادفات",
|
||||
// subMenu: [
|
||||
// [
|
||||
// {
|
||||
// title: "تصادفات روزانه",
|
||||
// href: api + "/v2/daily_accidents/create",
|
||||
// },
|
||||
// ],
|
||||
// ],
|
||||
// },
|
||||
];
|
||||
12
src/core/utils/pageMenu.js
Normal file
12
src/core/utils/pageMenu.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import SpaceDashboardIcon from "@mui/icons-material/SpaceDashboard";
|
||||
|
||||
export const pageMenu = [
|
||||
{
|
||||
id: "dashboard",
|
||||
label: "پیشخوان",
|
||||
type: "page",
|
||||
route: "/dashboard",
|
||||
icon: <SpaceDashboardIcon sx={{ width: "inherit", height: "inherit" }} />,
|
||||
permissions: ["all"],
|
||||
},
|
||||
];
|
||||
12
src/core/utils/routes.js
Normal file
12
src/core/utils/routes.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const api = process.env.NEXT_PUBLIC_API_URL;
|
||||
|
||||
export const GET_USER_ROUTE = api + "/profile/info";
|
||||
export const GET_USER_LOGIN_ROUTE = api + "/auth/login";
|
||||
export const GET_USER_LOGOUT_ROUTE = api + "/auth/logout";
|
||||
export const GET_PERMISSIONS_ROUTE = "";
|
||||
export const GET_SIDEBAR_BADGE_ROUTE = "";
|
||||
|
||||
export const GET_CATEGORY = api + "/categories";
|
||||
|
||||
export const GET_CALLER_HISTORY = api + "/calls/list";
|
||||
export const CALL_ACTION = api + "/calls";
|
||||
@@ -1,8 +0,0 @@
|
||||
import Notifications from "@/core/components/notifications";
|
||||
|
||||
export const successRequest = (pushToastList, dismissToastList, response, t, options) => {
|
||||
if (options.notification && options.success.notification.show) {
|
||||
dismissToastList(["pending", "warning", "error", "success"])
|
||||
Notifications(pushToastList, "success", t, response.status);
|
||||
}
|
||||
}
|
||||
10
src/core/utils/successRequest.js
Normal file
10
src/core/utils/successRequest.js
Normal file
@@ -0,0 +1,10 @@
|
||||
"use client";
|
||||
import { toast } from "react-toastify";
|
||||
import { successToast } from "@/core/components/Toasts/success";
|
||||
|
||||
export const successRequest = (notification, toastContainer) => {
|
||||
if (notification) {
|
||||
toast.dismiss({ containerId: toastContainer });
|
||||
successToast(toastContainer);
|
||||
}
|
||||
};
|
||||
@@ -1,14 +0,0 @@
|
||||
import {createTheme} from "@mui/material/styles";
|
||||
import theme from "./theme";
|
||||
import {faIR} from "@mui/x-date-pickers/locales";
|
||||
|
||||
const themeRtl = createTheme({
|
||||
direction: "rtl",
|
||||
typography: {
|
||||
fontFamily: `IRANSansFaNum, sans-serif`,
|
||||
},
|
||||
faIR,
|
||||
...theme,
|
||||
});
|
||||
|
||||
export default themeRtl;
|
||||
31
src/core/utils/theme.js
Normal file
31
src/core/utils/theme.js
Normal file
@@ -0,0 +1,31 @@
|
||||
"use client";
|
||||
import { createTheme } from "@mui/material";
|
||||
|
||||
const theme = createTheme({
|
||||
direction: "rtl",
|
||||
typography: {
|
||||
fontFamily: `IRANSansFaNum, sans-serif`,
|
||||
fontSize: 12,
|
||||
},
|
||||
palette: {
|
||||
primary: {
|
||||
main: "#0D47A1",
|
||||
contrastText: "#fff",
|
||||
},
|
||||
secondary: {
|
||||
main: "#90A4AE",
|
||||
},
|
||||
},
|
||||
components: {
|
||||
MuiBackdrop: {
|
||||
styleOverrides: {
|
||||
root: {
|
||||
backdropFilter: "blur(2px)",
|
||||
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default theme;
|
||||
@@ -1,29 +0,0 @@
|
||||
import {colord} from "colord";
|
||||
|
||||
const theme = {
|
||||
palette: {
|
||||
primary: {
|
||||
main: process.env.NEXT_PUBLIC_PRIMARY_MAIN,
|
||||
contrastText: "#FFFFFF",
|
||||
light: colord(process.env.NEXT_PUBLIC_PRIMARY_MAIN).lighten(0.1).toHex(),
|
||||
dark: colord(process.env.NEXT_PUBLIC_PRIMARY_MAIN).darken(0.1).toHex(),
|
||||
},
|
||||
secondary: {
|
||||
main: process.env.NEXT_PUBLIC_SECONDARY_MAIN,
|
||||
contrastText: "#FFFFFF",
|
||||
light: colord(process.env.NEXT_PUBLIC_SECONDARY_MAIN).lighten(0.1).toHex(),
|
||||
dark: colord(process.env.NEXT_PUBLIC_SECONDARY_MAIN).darken(0.1).toHex(),
|
||||
},
|
||||
},
|
||||
components: {
|
||||
MuiBackdrop: {
|
||||
styleOverrides: {
|
||||
root: {
|
||||
backgroundColor: colord(process.env.NEXT_PUBLIC_PRIMARY_MAIN).darken(0.2).alpha(0.7).toHex(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default theme;
|
||||
Reference in New Issue
Block a user