CFE-1 create project from the tamplate project and config project
This commit is contained in:
38
src/core/utils/createEmotionCache.jsx
Normal file
38
src/core/utils/createEmotionCache.jsx
Normal file
@@ -0,0 +1,38 @@
|
||||
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,
|
||||
});
|
||||
};
|
||||
62
src/core/utils/errorHandler.js
Normal file
62
src/core/utils/errorHandler.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import ErrorNotification from "@/core/components/notifications/ErrorNotification";
|
||||
import WarningNotification from "@/core/components/notifications/WarningNotification";
|
||||
import {toast} from "react-toastify";
|
||||
|
||||
export const errorSetting = (t, notification) => {
|
||||
if (notification) toast.dismiss();
|
||||
}
|
||||
|
||||
export const errorRequest = (t, notification) => {
|
||||
if (notification) toast.dismiss();
|
||||
}
|
||||
|
||||
export const errorResponse = (response, clearToken, t, notification) => {
|
||||
if (notification) toast.dismiss();
|
||||
if (isServerError(response.status)) {
|
||||
errorServer(response, t, notification)
|
||||
} else if (isClientError(response.status)) {
|
||||
errorClient(response, clearToken, t, notification)
|
||||
}
|
||||
}
|
||||
|
||||
const errorServer = (response, t, notification) => {
|
||||
if (notification) WarningNotification(t, response.status);
|
||||
}
|
||||
const errorClient = (response, clearToken, t, notification) => {
|
||||
switch (response.status) {
|
||||
case 401:
|
||||
clearToken()
|
||||
if (notification) ErrorNotification(t, response.status)
|
||||
break;
|
||||
case 422:
|
||||
if ('type' in response.data) {
|
||||
errorLogic(response, t, notification)
|
||||
break;
|
||||
}
|
||||
errorValidation(response, t, notification)
|
||||
break;
|
||||
case 429:
|
||||
if (notification) ErrorNotification(t, response.status)
|
||||
break
|
||||
default:
|
||||
if (notification) ErrorNotification(t, response.status)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
const isServerError = status => status >= 500 && status <= 599;
|
||||
const isClientError = status => status >= 400 && status <= 499;
|
||||
|
||||
const errorLogic = (response, t, notification) => {
|
||||
if (notification) ErrorNotification(t, response.status)
|
||||
}
|
||||
const errorValidation = (response, t, notification) => {
|
||||
if (notification) {
|
||||
const errorsMap = Object.keys(response.data.errors)
|
||||
const errorsArray = response.data.errors
|
||||
|
||||
errorsMap.map((item, index) => {
|
||||
ErrorNotification(t, response.status, errorsArray[item][0]);
|
||||
})
|
||||
}
|
||||
}
|
||||
9
src/core/utils/succesHandler.js
Normal file
9
src/core/utils/succesHandler.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import SuccessNotification from "@/core/components/notifications/SuccessNotification";
|
||||
import {toast} from "react-toastify";
|
||||
|
||||
export const successRequest = (response, t, options) => {
|
||||
if (options.notification && options.success.notification.show) {
|
||||
toast.dismiss();
|
||||
SuccessNotification(t, response.status)
|
||||
}
|
||||
}
|
||||
14
src/core/utils/theme-rtl.jsx
Normal file
14
src/core/utils/theme-rtl.jsx
Normal file
@@ -0,0 +1,14 @@
|
||||
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;
|
||||
29
src/core/utils/theme.jsx
Normal file
29
src/core/utils/theme.jsx
Normal file
@@ -0,0 +1,29 @@
|
||||
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