|
| 1 | +import { Card, Classes, Elevation, NonIdealState, Spinner, SpinnerSize } from '@blueprintjs/core'; |
| 2 | +import classNames from 'classnames'; |
| 3 | +import React, { useEffect } from 'react'; |
| 4 | +import { useTranslation } from 'react-i18next'; |
| 5 | +import { useDispatch } from 'react-redux'; |
| 6 | +import { useLocation, useNavigate } from 'react-router'; |
| 7 | +import SessionActions from 'src/commons/application/actions/SessionActions'; |
| 8 | +import { parseQuery } from 'src/commons/utils/QueryHelper'; |
| 9 | +import classes from 'src/styles/Login.module.scss'; |
| 10 | + |
| 11 | +const LoginVscodeCallback: React.FC = () => { |
| 12 | + const navigate = useNavigate(); |
| 13 | + const dispatch = useDispatch(); |
| 14 | + const location = useLocation(); |
| 15 | + const { t } = useTranslation('login'); |
| 16 | + |
| 17 | + const { access_token: accessToken, refresh_token: refreshToken } = parseQuery(location.search); |
| 18 | + |
| 19 | + useEffect(() => { |
| 20 | + if (accessToken && refreshToken) { |
| 21 | + dispatch( |
| 22 | + SessionActions.setTokens({ |
| 23 | + accessToken: accessToken, |
| 24 | + refreshToken: refreshToken |
| 25 | + }) |
| 26 | + ); |
| 27 | + dispatch(SessionActions.fetchUserAndCourse()); |
| 28 | + navigate('/welcome'); |
| 29 | + } |
| 30 | + // eslint-disable-next-line react-hooks/exhaustive-deps |
| 31 | + }, []); |
| 32 | + |
| 33 | + return ( |
| 34 | + <div className={classNames(classes['Login'], Classes.DARK)}> |
| 35 | + <Card elevation={Elevation.FOUR}> |
| 36 | + <div> |
| 37 | + <NonIdealState |
| 38 | + description={t('Logging In')} |
| 39 | + icon={<Spinner size={SpinnerSize.LARGE} />} |
| 40 | + /> |
| 41 | + </div> |
| 42 | + </Card> |
| 43 | + </div> |
| 44 | + ); |
| 45 | +}; |
| 46 | + |
| 47 | +// react-router lazy loading |
| 48 | +// https://reactrouter.com/en/main/route/lazy |
| 49 | +export const Component = LoginVscodeCallback; |
| 50 | +Component.displayName = 'LoginVscodeCallback'; |
| 51 | + |
| 52 | +export default LoginVscodeCallback; |
0 commit comments