|
|
@ -1,5 +1,5 @@ |
|
|
|
import { ReactNode, useEffect, useLayoutEffect, useState } from 'react'; |
|
|
|
import { ReactNode, useEffect, useLayoutEffect, useState } from 'react'; |
|
|
|
import { RouteComponentProps } from 'react-router-dom'; |
|
|
|
import { RouteComponentProps, useHistory } from 'react-router-dom'; |
|
|
|
import { useSelector, useDispatch } from '@src/redux/store'; |
|
|
|
import { useSelector, useDispatch } from '@src/redux/store'; |
|
|
|
import { checkToken } from '@src/redux/features/account/auth/authThunk'; |
|
|
|
import { checkToken } from '@src/redux/features/account/auth/authThunk'; |
|
|
|
import { ICheckAuthencationRs } from '@src/redux/features/account/auth/authState'; |
|
|
|
import { ICheckAuthencationRs } from '@src/redux/features/account/auth/authState'; |
|
|
@ -23,6 +23,7 @@ interface IProps extends RouteComponentProps { |
|
|
|
export default function (SpecificComponent: ReactNode, option: IOption) { |
|
|
|
export default function (SpecificComponent: ReactNode, option: IOption) { |
|
|
|
function AuthenticationCheck(props: RouteComponentProps) { |
|
|
|
function AuthenticationCheck(props: RouteComponentProps) { |
|
|
|
const dispatch = useDispatch(); |
|
|
|
const dispatch = useDispatch(); |
|
|
|
|
|
|
|
const history = useHistory(); |
|
|
|
const { user } = useSelector(state => state.authState); |
|
|
|
const { user } = useSelector(state => state.authState); |
|
|
|
const [isRender, setIsRender] = useState<boolean>(false); |
|
|
|
const [isRender, setIsRender] = useState<boolean>(false); |
|
|
|
|
|
|
|
|
|
|
@ -60,6 +61,17 @@ export default function (SpecificComponent: ReactNode, option: IOption) { |
|
|
|
}; |
|
|
|
}; |
|
|
|
}, []); |
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useLayoutEffect(() => { |
|
|
|
|
|
|
|
if (user?.cptAuthCode === 'DF0002') { |
|
|
|
|
|
|
|
const pathname = history.location.pathname; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pathname != '/flight/Approvals/new') { |
|
|
|
|
|
|
|
props.history.replace('/flight/Approvals/new'); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, [user]); |
|
|
|
|
|
|
|
|
|
|
|
return <>{isRender ? <Component {...props} user={user} /> : null}</>; |
|
|
|
return <>{isRender ? <Component {...props} user={user} /> : null}</>; |
|
|
|
} |
|
|
|
} |
|
|
|
return AuthenticationCheck; |
|
|
|
return AuthenticationCheck; |
|
|
|