diff --git a/src/components/account/login/AccountLogin.js b/src/components/account/login/AccountLogin.js index 1dc96bd4..026f88e9 100644 --- a/src/components/account/login/AccountLogin.js +++ b/src/components/account/login/AccountLogin.js @@ -68,7 +68,7 @@ export const AccountLogin = ({ history }) => { const { meta } = await dispatch(setLogin(loginForm)); if (meta.requestStatus === 'fulfilled') { - if (loginForm?.userId === 'dos-gmp') { + if (loginForm?.userId === 'GMPATC') { history.push('/flight/Approvals/new'); } else { history.push('/control'); diff --git a/src/redux/features/account/auth/authSlice.ts b/src/redux/features/account/auth/authSlice.ts index 79f6707e..b8f5cc1e 100644 --- a/src/redux/features/account/auth/authSlice.ts +++ b/src/redux/features/account/auth/authSlice.ts @@ -53,7 +53,13 @@ const authSlice = createSlice({ extraReducers: builder => { builder .addCase(setLogin.fulfilled, (state, action) => { + const { user } = action.payload as { + isLogin: boolean; + user?: ICheckAuthencationRs; + }; + state.isLogin = true; + if (user) localStorage.setItem('cptAuthCode', user.cptAuthCode); }) .addCase(setLogin.pending, (state, action) => { state.isLogin = false; @@ -77,6 +83,7 @@ const authSlice = createSlice({ cookieStorage.removeCookie(COOKIE_REFRESH_TOKEN); localStorage.removeItem('dronGroupId'); localStorage.removeItem('dronGroupNm'); + localStorage.removeItem('cptAuthCode'); state.isLogin = false; state.user = initAuth.user; }) diff --git a/src/redux/features/account/auth/authThunk.ts b/src/redux/features/account/auth/authThunk.ts index da3d1069..7e3dcb99 100644 --- a/src/redux/features/account/auth/authThunk.ts +++ b/src/redux/features/account/auth/authThunk.ts @@ -53,6 +53,12 @@ export const setLogin = createAsyncThunk( cookieStorage.setCookie(COOKIE_REFRESH_TOKEN, data.refreshToken); thunkAPI.dispatch(checkCookie()); + + const decodedToken = decode(data.accessToken); + const { data: user }: { data: ICheckAuthencationRs } = await axios.get( + `api/acnt/jwt/profile/${decodedToken.cstmrSno}` + ); + return { isLogin: true, user }; } catch (error: any) { thunkAPI.dispatch( openModal({ diff --git a/src/router/hoc/ResolveRoutes.tsx b/src/router/hoc/ResolveRoutes.tsx index b2043662..d9b150ee 100644 --- a/src/router/hoc/ResolveRoutes.tsx +++ b/src/router/hoc/ResolveRoutes.tsx @@ -8,12 +8,15 @@ import { useLayout } from '@hooks/useLayout'; import { useRouterTransition } from '@hooks/useRouterTransition'; import LayoutWrapper from '@layouts/components/layout-wrapper'; import { IRoute } from '../routes/type'; -import { Routes } from '../routes'; +import { Routes, GimpoControlRoutes } from '../routes'; import authenticationCheck from './authenticationCheck'; +import { useSelector } from '@src/redux/store'; +import { shallowEqual } from 'react-redux'; export default function ResolveRoutes() { const [layout, setLayout] = useLayout(); const [transition, setTransition] = useRouterTransition(); + const user = useSelector(state => state.authState.user, shallowEqual); const DefaultLayout = layout === 'horizontal' ? 'HorizontalLayout' : 'VerticalLayout'; @@ -29,8 +32,14 @@ export default function ResolveRoutes() { const LayoutRoutes: IRoute[] = []; const LayoutPaths: string[] = []; - if (Routes) { - Routes.filter(route => { + const cptAuthCode = localStorage.getItem('cptAuthCode'); + + let Router = Routes; + if (cptAuthCode === 'DF0002' || user?.cptAuthCode === 'DF0002') + Router = GimpoControlRoutes; + + if (Router) { + Router.filter(route => { if ( route.layout === layout || (route.layout === undefined && DefaultLayout === layout) @@ -41,6 +50,19 @@ export default function ResolveRoutes() { }); } + // console.log(router, ' ====router'); + // if (router) { + // router?.filter(route => { + // if ( + // route.layout === layout || + // (route.layout === undefined && DefaultLayout === layout) + // ) { + // LayoutRoutes.push(route); + // LayoutPaths.push(route.path); + // } + // }); + // } + return { LayoutRoutes, LayoutPaths }; }; diff --git a/src/router/hoc/authenticationCheck.tsx b/src/router/hoc/authenticationCheck.tsx index fae18962..930ecab4 100644 --- a/src/router/hoc/authenticationCheck.tsx +++ b/src/router/hoc/authenticationCheck.tsx @@ -31,7 +31,7 @@ export default function (SpecificComponent: ReactNode, option: IOption) { props: IProps ) => JSX.Element; - useLayoutEffect(() => { + useEffect(() => { if (user?.cptAuthCode === 'DF0002') { const pathname = history.location.pathname; @@ -61,9 +61,14 @@ export default function (SpecificComponent: ReactNode, option: IOption) { } } else { if (!authRoute) { - localStorage.setItem('topMenuCd', '/'); - dispatch(clientDispatchTopMenu('/')); - props.history.replace('/main/dashboard'); + const cptAuthCode = localStorage.getItem('cptAuthCode'); + if (cptAuthCode === 'DF0002') { + props.history.replace('/flight/Approvals/new'); + } else { + localStorage.setItem('topMenuCd', '/'); + dispatch(clientDispatchTopMenu('/')); + props.history.replace('/main/dashboard'); + } } } setIsRender(true); diff --git a/src/router/index.tsx b/src/router/index.tsx index e3965e05..a247ab73 100644 --- a/src/router/index.tsx +++ b/src/router/index.tsx @@ -25,7 +25,16 @@ export default function Router() { exact path='/' render={() => { - return ; + const cptAuthCode = localStorage.getItem('cptAuthCode'); + return ( + + ); }} /> diff --git a/src/router/routes/index.js b/src/router/routes/index.js index df7579ed..1ca304f6 100644 --- a/src/router/routes/index.js +++ b/src/router/routes/index.js @@ -25,7 +25,7 @@ const Routes = [ ...RouteLaance, ...RouterCstmrService, ...RouteStatistics, - ...RouteFlight, + // ...RouteFlight, { path: '/home', component: lazy(() => import('../../views/Home')) @@ -229,4 +229,31 @@ const Routes = [ } ]; -export { DefaultRoute, TemplateTitle, Routes }; +const GimpoControlRoutes = [ + { + path: '/flight/approvals/new', + component: lazy(() => import('../../views/flight/NewFlightView')), + layout: 'BlankLayout', + meta: { + authRoute: true + } + }, + { + path: '/rightMenu', + component: lazy(() => import('../../views/rightMenuView')), + layout: 'BlankLayout', + meta: { + authRoute: true + } + }, + { + path: '/account/login', + component: lazy(() => import('../../views/account/AccountLoginView')), + layout: 'BlankLayout', + meta: { + authRoute: false + } + } +]; + +export { DefaultRoute, TemplateTitle, Routes, GimpoControlRoutes };