merging to develop
This commit is contained in:
@@ -8,4 +8,7 @@ NEXT_PUBLIC_SECONDARY_MAIN = "#FF4E00"
|
|||||||
|
|
||||||
NEXT_PUBLIC_BASE_URL = "https://loan.witel.ir"
|
NEXT_PUBLIC_BASE_URL = "https://loan.witel.ir"
|
||||||
|
|
||||||
|
#["NEXT_PUBLIC_HAS_WIDGET" , "NEXT_PUBLIC_HAS_NOTIFICATION"]
|
||||||
|
NEXT_PUBLIC_HAS_VALUE=["NEXT_PUBLIC_HAS_NOTIFICATION"]
|
||||||
|
|
||||||
NODE_ENV = "development"
|
NODE_ENV = "development"
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
"typography_your_login_is_valid_and_you_do_not_need_to_login_again": "شما دسترسی لازم به این صفحه را دارید نیاز به ورود مجدد نیست.",
|
"typography_your_login_is_valid_and_you_do_not_need_to_login_again": "شما دسترسی لازم به این صفحه را دارید نیاز به ورود مجدد نیست.",
|
||||||
"typography_your_access_to_this_page_has_expired_Please_login_again": "دسترسی شما منقضی شده است لطفا دوباره ورود نمایید.",
|
"typography_your_access_to_this_page_has_expired_Please_login_again": "دسترسی شما منقضی شده است لطفا دوباره ورود نمایید.",
|
||||||
"typography_redirect_to": "درحال رفتن به صفحه",
|
"typography_redirect_to": "درحال رفتن به صفحه",
|
||||||
"typography_routing_previuos_page": "صفحه قبل...",
|
"typography_routing_previuos_page": " قبل...",
|
||||||
"typography_routing_dashbaord_page": "داشبورد..."
|
"typography_routing_dashbaord_page": "داشبورد..."
|
||||||
},
|
},
|
||||||
"Permission": {
|
"Permission": {
|
||||||
|
|||||||
33
src/core/components/Middleware/RolePermissionComponent.jsx
Normal file
33
src/core/components/Middleware/RolePermissionComponent.jsx
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { Button, Typography } from "@mui/material";
|
||||||
|
import {useTranslations} from "next-intl";
|
||||||
|
import {NextLinkComposed} from "@/core/components/LinkRouting";
|
||||||
|
import Message from "@/core/components/Messages";
|
||||||
|
|
||||||
|
const RolePermissionComponent = () => {
|
||||||
|
const t = useTranslations();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Message
|
||||||
|
text={
|
||||||
|
<Typography sx={{ textAlign: "center" }}>
|
||||||
|
{t("Permission.typography_you_dont_have_access")}
|
||||||
|
</Typography>
|
||||||
|
}
|
||||||
|
actions={
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
component={NextLinkComposed}
|
||||||
|
to={{
|
||||||
|
pathname: "/dashboard",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("Permission.button_back_dashboard")}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RolePermissionComponent;
|
||||||
36
src/core/components/Middleware/WithAuthComponent.jsx
Normal file
36
src/core/components/Middleware/WithAuthComponent.jsx
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { Button, Typography } from "@mui/material";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
import Message from "@/core/components/Messages";
|
||||||
|
import { NextLinkComposed } from "@/core/components/LinkRouting";
|
||||||
|
import {useTranslations} from "next-intl";
|
||||||
|
|
||||||
|
const WithAuthComponent = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const t = useTranslations();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Message
|
||||||
|
text={
|
||||||
|
<Typography sx={{ textAlign: "center" }}>
|
||||||
|
{t("Authorization.typography_your_access_to_this_page_has_expired_Please_login_again")}
|
||||||
|
</Typography>
|
||||||
|
}
|
||||||
|
actions={
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
component={NextLinkComposed}
|
||||||
|
to={{
|
||||||
|
pathname: "/login-expert",
|
||||||
|
query: {back_url: encodeURIComponent(router.asPath)},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("login")}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default WithAuthComponent;
|
||||||
25
src/core/components/Middleware/WithoutAuthComponent.jsx
Normal file
25
src/core/components/Middleware/WithoutAuthComponent.jsx
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import {Stack, Typography} from "@mui/material";
|
||||||
|
import Message from "@/core/components/Messages";
|
||||||
|
import {useTranslations} from "next-intl";
|
||||||
|
const WithoutAuthComponent = ({ backUrlDecodedPath }) => {
|
||||||
|
const t = useTranslations();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Message
|
||||||
|
text={
|
||||||
|
<Stack alignItems="center" spacing={2}>
|
||||||
|
<Typography sx={{ textAlign: "center" }}>
|
||||||
|
{t("Authorization.typography_your_login_is_valid_and_you_do_not_need_to_login_again")}
|
||||||
|
</Typography>
|
||||||
|
<Typography>
|
||||||
|
{t("Authorization.typography_redirect_to")}{" "}
|
||||||
|
{backUrlDecodedPath
|
||||||
|
? t("Authorization.typography_routing_previuos_page")
|
||||||
|
: t("Authorization.typography_routing_dashbaord_page")}
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default WithoutAuthComponent;
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
import useSWR from 'swr'
|
import useSWR from 'swr'
|
||||||
import {GET_SIDEBAR_NOTIFICATION} from "@/core/data/apiRoutes";
|
import {GET_SIDEBAR_NOTIFICATION} from "@/core/data/apiRoutes";
|
||||||
import useRequest from "@/lib/app/hooks/useRequest";
|
import useRequest from "@/lib/app/hooks/useRequest";
|
||||||
|
const GLOBAL_HAS_VALUE = process.env.NEXT_PUBLIC_HAS_VALUE;
|
||||||
|
const hasPermissionsValue = GLOBAL_HAS_VALUE ? JSON.parse(GLOBAL_HAS_VALUE) : [];
|
||||||
|
const isNotificationEnabled = hasPermissionsValue.includes("NEXT_PUBLIC_HAS_NOTIFICATION");
|
||||||
|
|
||||||
const useNotification = () => {
|
const useNotification = () => {
|
||||||
|
|
||||||
const requestServer = useRequest({auth: true, notification: false})
|
const requestServer = useRequest({auth: true, notification: false})
|
||||||
|
|
||||||
//swr config
|
//swr config
|
||||||
@@ -13,7 +17,7 @@ const useNotification = () => {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
const {data, mutate} = useSWR(GET_SIDEBAR_NOTIFICATION, fetcher)
|
const {data, mutate} = useSWR( isNotificationEnabled ? GET_SIDEBAR_NOTIFICATION : '', fetcher , {keepPreviousData:true})
|
||||||
const notification_count = data
|
const notification_count = data
|
||||||
//swr config
|
//swr config
|
||||||
|
|
||||||
|
|||||||
@@ -1,43 +1,14 @@
|
|||||||
import {NextLinkComposed} from "@/core/components/LinkRouting";
|
|
||||||
import Message from "@/core/components/Messages";
|
|
||||||
import useUser from "@/lib/app/hooks/useUser";
|
import useUser from "@/lib/app/hooks/useUser";
|
||||||
import {Button, Typography} from "@mui/material";
|
import RolePermissionComponent from "@/core/components/Middleware/RolePermissionComponent";
|
||||||
import {useTranslations} from "next-intl";
|
|
||||||
|
|
||||||
const RolePermissionMiddleware = ({children, requiredPermissions}) => {
|
const RolePermissionMiddleware = ({children, requiredPermissions}) => {
|
||||||
const {user} = useUser();
|
const {user} = useUser();
|
||||||
const t = useTranslations();
|
|
||||||
|
|
||||||
const hasPermission = requiredPermissions.some((permission) =>
|
const hasPermission = requiredPermissions.some((permission) =>
|
||||||
user?.permissions?.includes(permission)
|
user?.permissions?.includes(permission)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!hasPermission) {
|
return !hasPermission ? <RolePermissionComponent /> : <>{children}</>;
|
||||||
return (
|
|
||||||
<Message
|
|
||||||
text={
|
|
||||||
<Typography sx={{textAlign: "center"}}>
|
|
||||||
{t("Permission.typography_you_dont_have_access")}
|
|
||||||
</Typography>
|
|
||||||
}
|
|
||||||
actions={
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
component={NextLinkComposed}
|
|
||||||
to={{
|
|
||||||
pathname: "/dashboard",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("Permission.button_back_dashboard")}
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return <>{children}</>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default RolePermissionMiddleware;
|
export default RolePermissionMiddleware;
|
||||||
|
|||||||
@@ -1,42 +1,10 @@
|
|||||||
import {NextLinkComposed} from "@/core/components/LinkRouting";
|
|
||||||
import Message from "@/core/components/Messages";
|
|
||||||
import useUser from "@/lib/app/hooks/useUser";
|
import useUser from "@/lib/app/hooks/useUser";
|
||||||
import {Button, Typography} from "@mui/material";
|
import WithAuthComponent from "@/core/components/Middleware/WithAuthComponent";
|
||||||
import {useTranslations} from "next-intl";
|
|
||||||
import {useRouter} from "next/router";
|
|
||||||
|
|
||||||
const WithAuthMiddleware = ({children}) => {
|
const WithAuthMiddleware = ({children}) => {
|
||||||
const {isAuth} = useUser();
|
const {isAuth} = useUser();
|
||||||
const t = useTranslations();
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
if (!isAuth)
|
return isAuth ? <>{children}</> : <WithAuthComponent />;
|
||||||
return (
|
|
||||||
<Message
|
|
||||||
text={
|
|
||||||
<Typography sx={{textAlign: "center"}}>
|
|
||||||
{t(
|
|
||||||
"Authorization.typography_your_access_to_this_page_has_expired_Please_login_again"
|
|
||||||
)}
|
|
||||||
</Typography>
|
|
||||||
}
|
|
||||||
actions={
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
component={NextLinkComposed}
|
|
||||||
to={{
|
|
||||||
pathname: "/login-expert",
|
|
||||||
query: {back_url: encodeURIComponent(router.asPath)},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("login")}
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
return <>{children}</>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default WithAuthMiddleware;
|
export default WithAuthMiddleware;
|
||||||
|
|||||||
@@ -1,19 +1,14 @@
|
|||||||
import Message from "@/core/components/Messages";
|
|
||||||
import useUser from "@/lib/app/hooks/useUser";
|
import useUser from "@/lib/app/hooks/useUser";
|
||||||
import {Stack, Typography} from "@mui/material";
|
|
||||||
import {useTranslations} from "next-intl";
|
|
||||||
import {useSearchParams} from "next/navigation";
|
|
||||||
import {useRouter} from "next/router";
|
import {useRouter} from "next/router";
|
||||||
import {useEffect} from "react";
|
import {useEffect} from "react";
|
||||||
|
import WithoutAuthComponent from "@/core/components/Middleware/WithoutAuthComponent";
|
||||||
|
|
||||||
const WithoutAuthMiddleware = ({children}) => {
|
const WithoutAuthMiddleware = ({children}) => {
|
||||||
|
|
||||||
const {isAuth} = useUser();
|
const {isAuth} = useUser();
|
||||||
const t = useTranslations();
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
// gettin url query
|
const backUrlDecodedPath = router.query?.back_url;
|
||||||
const searchParams = useSearchParams();
|
|
||||||
const backUrlDecodedPath = searchParams.get("back_url");
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isAuth) return;
|
if (!isAuth) return;
|
||||||
@@ -30,27 +25,11 @@ const WithoutAuthMiddleware = ({children}) => {
|
|||||||
};
|
};
|
||||||
}, [isAuth]);
|
}, [isAuth]);
|
||||||
|
|
||||||
if (isAuth)
|
return isAuth ? (
|
||||||
return (
|
<WithoutAuthComponent backUrlDecodedPath={backUrlDecodedPath} />
|
||||||
<Message
|
) : (
|
||||||
text={
|
<>{children}</>
|
||||||
<Stack alignItems="center" spacing={2}>
|
);
|
||||||
<Typography sx={{textAlign: "center"}}>
|
|
||||||
{t(
|
|
||||||
"Authorization.typography_your_login_is_valid_and_you_do_not_need_to_login_again"
|
|
||||||
)}
|
|
||||||
</Typography>
|
|
||||||
<Typography>
|
|
||||||
{t("Authorization.typography_redirect_to")}{" "}
|
|
||||||
{backUrlDecodedPath
|
|
||||||
? t("Authorization.typography_routing_previuos_page")
|
|
||||||
: t("Authorization.typography_routing_dashbaord_page")}
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
return <>{children}</>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default WithoutAuthMiddleware;
|
export default WithoutAuthMiddleware;
|
||||||
|
|||||||
Reference in New Issue
Block a user