diff --git a/resources/scripts/TransitionRouter.tsx b/resources/scripts/TransitionRouter.tsx new file mode 100644 index 000000000..dc0ec7a95 --- /dev/null +++ b/resources/scripts/TransitionRouter.tsx @@ -0,0 +1,36 @@ +import React from 'react'; +import { Route, Switch } from 'react-router'; +import { CSSTransition, TransitionGroup } from 'react-transition-group'; +import { BrowserRouter } from 'react-router-dom'; + +type Props = Readonly<{ + basename: string; + children: React.ReactNode; +}>; + +export default ({ basename, children }: Props) => ( + + ( + + +
+ + {children} + +

+ © 2015 - 2019  + + Pterodactyl Software + +

+
+
+
+ )} + /> +
+); diff --git a/resources/scripts/components/auth/LoginCheckpointContainer.tsx b/resources/scripts/components/auth/LoginCheckpointContainer.tsx index e3a0857fb..b3c508076 100644 --- a/resources/scripts/components/auth/LoginCheckpointContainer.tsx +++ b/resources/scripts/components/auth/LoginCheckpointContainer.tsx @@ -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) => 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) => { diff --git a/resources/scripts/components/auth/LoginContainer.tsx b/resources/scripts/components/auth/LoginContainer.tsx index b5d61d344..7a33b7dcc 100644 --- a/resources/scripts/components/auth/LoginContainer.tsx +++ b/resources/scripts/components/auth/LoginContainer.tsx @@ -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) => actions.flashes); diff --git a/resources/scripts/routers/AccountRouter.tsx b/resources/scripts/routers/AccountRouter.tsx index d70a6b343..7c5166285 100644 --- a/resources/scripts/routers/AccountRouter.tsx +++ b/resources/scripts/routers/AccountRouter.tsx @@ -1,36 +1,11 @@ import * as React from 'react'; -import { BrowserRouter, Route, Switch } from 'react-router-dom'; -import { CSSTransition, TransitionGroup } from 'react-transition-group'; +import { Route } from 'react-router-dom'; import DesignElements from '@/components/account/DesignElements'; +import TransitionRouter from '@/TransitionRouter'; -export default class AccountRouter extends React.PureComponent { - render () { - return ( - - ( - - -
- - - - -

- © 2015 - 2019  - - Pterodactyl Software - -

-
-
-
- )} - /> -
- ); - } -} +export default () => ( + + + + +); diff --git a/resources/scripts/routers/AuthenticationRouter.tsx b/resources/scripts/routers/AuthenticationRouter.tsx index 8d5ed492f..5a36a16e6 100644 --- a/resources/scripts/routers/AuthenticationRouter.tsx +++ b/resources/scripts/routers/AuthenticationRouter.tsx @@ -1,42 +1,19 @@ -import * as React from 'react'; -import { BrowserRouter, Route, Switch } from 'react-router-dom'; +import React from 'react'; +import { Route } from 'react-router-dom'; import LoginContainer from '@/components/auth/LoginContainer'; -import { CSSTransition, TransitionGroup } from 'react-transition-group'; import ForgotPasswordContainer from '@/components/auth/ForgotPasswordContainer'; import ResetPasswordContainer from '@/components/auth/ResetPasswordContainer'; +import TransitionRouter from '@/TransitionRouter'; import LoginCheckpointContainer from '@/components/auth/LoginCheckpointContainer'; -export default class AuthenticationRouter extends React.PureComponent { - render () { - return ( - - ( - - -
- - - - - - - -

- © 2015 - 2019  - - Pterodactyl Software - -

-
-
-
- )} - /> -
- ); - } -} +export default () => ( + +
+ + + + + +
+
+);