bigbuffet-rw/app/soapbox/features/auth-layout/index.tsx

102 lines
4.3 KiB
TypeScript
Raw Normal View History

2022-03-21 11:09:01 -07:00
import React from 'react';
import { defineMessages, useIntl } from 'react-intl';
2022-06-07 14:56:45 -07:00
import { Link, Redirect, Route, Switch, useHistory, useLocation } from 'react-router-dom';
2022-03-21 11:09:01 -07:00
import LandingGradient from 'soapbox/components/landing-gradient';
import SiteLogo from 'soapbox/components/site-logo';
2022-11-26 08:38:16 -08:00
import { useAppSelector, useFeatures, useSoapboxConfig, useOwnAccount, useInstance } from 'soapbox/hooks';
2022-03-21 11:09:01 -07:00
import { Button, Card, CardBody } from '../../components/ui';
2022-11-16 05:32:32 -08:00
import LoginPage from '../auth-login/components/login-page';
import PasswordReset from '../auth-login/components/password-reset';
import PasswordResetConfirm from '../auth-login/components/password-reset-confirm';
import RegistrationForm from '../auth-login/components/registration-form';
2022-11-15 09:23:36 -08:00
import ExternalLoginForm from '../external-login/components/external-login-form';
2022-11-15 11:00:40 -08:00
import Footer from '../public-layout/components/footer';
import RegisterInvite from '../register-invite';
2022-03-21 11:09:01 -07:00
import Verification from '../verification';
2022-11-16 05:32:32 -08:00
import EmailPassthru from '../verification/email-passthru';
2022-03-21 11:09:01 -07:00
const messages = defineMessages({
register: { id: 'auth_layout.register', defaultMessage: 'Create an account' },
});
const AuthLayout = () => {
const intl = useIntl();
const history = useHistory();
2022-06-07 14:56:45 -07:00
const { search } = useLocation();
const account = useOwnAccount();
2022-11-26 08:38:16 -08:00
const instance = useInstance();
const features = useFeatures();
const soapboxConfig = useSoapboxConfig();
2022-11-26 08:38:16 -08:00
const pepeEnabled = soapboxConfig.getIn(['extensions', 'pepe', 'enabled']) === true;
const isOpen = features.accountCreation && instance.registrations;
const pepeOpen = useAppSelector(state => state.verification.instance.get('registrations') === true);
const isLoginPage = history.location.pathname === '/login';
const shouldShowRegisterLink = (isLoginPage && (isOpen || (pepeEnabled && pepeOpen)));
return (
2022-05-09 05:27:26 -07:00
<div className='h-full'>
<LandingGradient />
<main className='relative h-full sm:flex sm:justify-center'>
<div className='w-full h-full flex flex-col sm:max-w-lg md:max-w-2xl lg:max-w-6xl'>
<header className='flex justify-between relative py-12 px-2 mb-auto'>
<div className='relative z-0 flex-1 px-2 lg:flex lg:items-center lg:justify-center lg:absolute lg:inset-0'>
<Link to='/' className='cursor-pointer'>
2022-11-26 08:38:16 -08:00
<SiteLogo alt={instance.title} className='h-7' />
</Link>
</div>
{shouldShowRegisterLink && (
<div className='relative z-10 ml-auto flex items-center'>
<Button
theme='tertiary'
icon={require('@tabler/icons/user.svg')}
to='/signup'
>
{intl.formatMessage(messages.register)}
</Button>
</div>
)}
2022-05-09 05:27:26 -07:00
</header>
<div className='flex flex-col justify-center items-center'>
<div className='pb-10 sm:mx-auto w-full sm:max-w-lg md:max-w-2xl'>
2022-05-09 05:27:26 -07:00
<Card variant='rounded' size='xl'>
<CardBody>
<Switch>
{/* If already logged in, redirect home. */}
{account && <Redirect from='/login' to='/' exact />}
2022-05-09 05:27:26 -07:00
<Route exact path='/verify' component={Verification} />
<Route exact path='/verify/email/:token' component={EmailPassthru} />
<Route exact path='/login/external' component={ExternalLoginForm} />
<Route exact path='/login/add' component={LoginPage} />
2022-05-09 05:27:26 -07:00
<Route exact path='/login' component={LoginPage} />
<Route exact path='/signup' component={RegistrationForm} />
<Route exact path='/reset-password' component={PasswordReset} />
<Route exact path='/edit-password' component={PasswordResetConfirm} />
<Route path='/invite/:token' component={RegisterInvite} />
2022-05-09 05:27:26 -07:00
<Redirect from='/auth/password/new' to='/reset-password' />
2022-06-07 14:56:45 -07:00
<Redirect from='/auth/password/edit' to={`/edit-password${search}`} />
2022-05-09 05:27:26 -07:00
</Switch>
</CardBody>
</Card>
</div>
</div>
<div className='mt-auto'>
<Footer />
</div>
2022-03-21 11:09:01 -07:00
</div>
</main>
</div>
);
};
2022-03-21 11:09:01 -07:00
export default AuthLayout;