Make the transition based router be grouped more cleanly.

This commit is contained in:
Dane Everitt 2019-06-22 17:45:32 -07:00
parent d22747b0b1
commit f34593e777
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 65 additions and 79 deletions

View file

@ -1,23 +1,23 @@
import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import { Link, RouteComponentProps } from 'react-router-dom';
import loginCheckpoint from '@/api/auth/loginCheckpoint';
import { httpErrorToHuman } from '@/api/http';
import LoginFormContainer from '@/components/auth/LoginFormContainer';
import { Actions, useStoreActions } from 'easy-peasy';
import { ApplicationState } from '@/state/types';
import useRouter from 'use-react-router';
import { StaticContext } from 'react-router';
import FlashMessageRender from '@/components/FlashMessageRender';
export default () => {
export default ({ history, location: { state } }: RouteComponentProps<{}, StaticContext, { token?: string }>) => {
const [ code, setCode ] = useState('');
const [ isLoading, setIsLoading ] = useState(false);
const { clearFlashes, addFlash } = useStoreActions((actions: Actions<ApplicationState>) => actions.flashes);
const { history, location: { state } } = useRouter<{}, StaticContext, { token?: string }>();
if (!state || !state.token) {
return history.replace('/login');
history.replace('/login');
return null;
}
const onChangeHandler = (e: React.ChangeEvent<HTMLInputElement>) => {

View file

@ -1,18 +1,16 @@
import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import { Link, RouteComponentProps } from 'react-router-dom';
import login from '@/api/auth/login';
import { httpErrorToHuman } from '@/api/http';
import LoginFormContainer from '@/components/auth/LoginFormContainer';
import FlashMessageRender from '@/components/FlashMessageRender';
import { Actions, useStoreActions } from 'easy-peasy';
import { ApplicationState } from '@/state/types';
import useRouter from 'use-react-router';
export default () => {
export default ({ history }: RouteComponentProps) => {
const [ username, setUsername ] = useState('');
const [ password, setPassword ] = useState('');
const [ isLoading, setLoading ] = useState(false);
const { history } = useRouter();
const { clearFlashes, addFlash } = useStoreActions((actions: Actions<ApplicationState>) => actions.flashes);