feat: redirect to register page if no users exist

fixes #130
This commit is contained in:
Jordan Knott
2021-10-06 14:20:36 -05:00
parent eab33bfd9a
commit 8b1de30204
8 changed files with 73 additions and 41 deletions

View File

@ -21,14 +21,7 @@ import {
SubTitle,
} from './Styles';
const Confirm = ({ onConfirmUser, hasConfirmToken }: ConfirmProps) => {
const [hasFailed, setFailed] = useState(false);
const setHasFailed = () => {
setFailed(true);
};
useEffect(() => {
onConfirmUser(setHasFailed);
});
const Confirm = ({ hasFailed, hasConfirmToken }: ConfirmProps) => {
return (
<Wrapper>
<Column>

View File

@ -1,8 +1,8 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import AccessAccount from 'shared/undraw/AccessAccount';
import { User, Lock, Taskcafe } from 'shared/icons';
import { useForm } from 'react-hook-form';
import { useHistory } from 'react-router';
import LoadingSpinner from 'shared/components/LoadingSpinner';
import {
Form,
@ -25,6 +25,7 @@ import {
const Login = ({ onSubmit }: LoginProps) => {
const [isComplete, setComplete] = useState(true);
const [showRegistration, setShowRegistration] = useState(false);
const {
register,
handleSubmit,
@ -35,6 +36,17 @@ const Login = ({ onSubmit }: LoginProps) => {
setComplete(false);
onSubmit(data, setComplete, setError);
};
const history = useHistory();
useEffect(() => {
fetch('/settings').then(async (x) => {
const { isConfigured, allowPublicRegistration } = await x.json();
if (!isConfigured) {
history.push('/register');
} else if (allowPublicRegistration) {
setShowRegistration(true);
}
});
}, []);
return (
<Wrapper>
<Column>
@ -68,7 +80,7 @@ const Login = ({ onSubmit }: LoginProps) => {
{errors.password && <FormError>{errors.password.message}</FormError>}
<ActionButtons>
<RegisterButton variant="outline">Register</RegisterButton>
{showRegistration ? <RegisterButton variant="outline">Register</RegisterButton> : <div />}
{!isComplete && <LoadingSpinner size="32px" thickness="2px" borderSize="48px" />}
<LoginButton type="submit" disabled={!isComplete}>
Login