diff --git a/ui/src/Pages/LoginPage/InitialSetupPage.tsx b/ui/src/Pages/LoginPage/InitialSetupPage.tsx index 6f879d20..852527d9 100644 --- a/ui/src/Pages/LoginPage/InitialSetupPage.tsx +++ b/ui/src/Pages/LoginPage/InitialSetupPage.tsx @@ -1,13 +1,15 @@ -import React, { useState } from 'react' +import React from 'react' import { gql, useQuery, useMutation } from '@apollo/client' import { Redirect } from 'react-router-dom' -import { Button, Form, Message, Header } from 'semantic-ui-react' import { Container } from './loginUtilities' import { checkInitialSetupQuery, login } from './loginUtilities' import { authToken } from '../../helpers/authentication' import { useTranslation } from 'react-i18next' import { CheckInitialSetup } from './__generated__/CheckInitialSetup' +import { useForm } from 'react-hook-form' +import { Submit, TextField } from '../../primitives/form/Input' +import MessageBox from '../../primitives/form/MessageBox' const initialSetupMutation = gql` mutation InitialSetup( @@ -27,14 +29,26 @@ const initialSetupMutation = gql` } ` +type InitialSetupFormData = { + username: string + password: string + rootPath: string +} + const InitialSetupPage = () => { const { t } = useTranslation() - const [state, setState] = useState({ - username: '', - password: '', - rootPath: '', - }) + const { + register, + handleSubmit, + formState: { errors: formErrors }, + } = useForm() + + // const [state, setState] = useState({ + // username: '', + // password: '', + // rootPath: '', + // }) if (authToken()) { return @@ -48,41 +62,37 @@ const InitialSetupPage = () => { ) - const [ - authorize, - { loading: authorizeLoading, data: authorizationData }, - ] = useMutation(initialSetupMutation, { - onCompleted: data => { - const { success, token } = data.initialSetupWizard + const [authorize, { loading: authorizeLoading, data: authorizationData }] = + useMutation(initialSetupMutation, { + onCompleted: data => { + const { success, token } = data.initialSetupWizard - if (success) { - login(token) - } - }, - }) - - const handleChange = ( - event: React.ChangeEvent, - key: string - ) => { - const value = event.target.value - setState(prevState => ({ - ...prevState, - [key]: value, - })) - } - - const signIn = (event: React.FormEvent) => { - event.preventDefault() - - authorize({ - variables: { - username: state.username, - password: state.password, - rootPath: state.rootPath, + if (success) { + login(token) + } }, }) - } + + // const handleChange = ( + // event: React.ChangeEvent, + // key: string + // ) => { + // const value = event.target.value + // setState(prevState => ({ + // ...prevState, + // [key]: value, + // })) + // } + + const signIn = handleSubmit(data => { + authorize({ + variables: { + username: data.username, + password: data.password, + rootPath: data.rootPath, + }, + }) + }) let errorMessage = null if (authorizationData && !authorizationData.initialSetupWizard.success) { @@ -93,49 +103,59 @@ const InitialSetupPage = () => {
{initialSetupRedirect} -
+

{t('login_page.initial_setup.title', 'Initial Setup')} -

-
- - - handleChange(e, 'username')} /> - - - - handleChange(e, 'password')} - /> - - - - handleChange(e, 'rootPath')} - /> - - - - + +
) diff --git a/ui/src/Pages/LoginPage/LoginPage.tsx b/ui/src/Pages/LoginPage/LoginPage.tsx index 7f4a9b46..a06968ad 100644 --- a/ui/src/Pages/LoginPage/LoginPage.tsx +++ b/ui/src/Pages/LoginPage/LoginPage.tsx @@ -27,7 +27,7 @@ const LogoHeader = () => { const { t } = useTranslation() return ( -
+
photoview logo

{t('login_page.welcome', 'Welcome to Photoview')} @@ -73,13 +73,13 @@ const LoginForm = () => { return (
{ /> { type="submit" disabled={loading} value={t('login_page.field.submit', 'Sign in') as string} - className="rounded-md px-8 py-2 mt-1 focus:outline-none cursor-pointer bg-gradient-to-bl from-[#FF8246] to-[#D6264D] text-white font-semibold focus:ring-2 focus:ring-red-200 disabled:cursor-default disabled:opacity-80" + className="rounded-md px-8 py-2 mt-2 focus:outline-none cursor-pointer bg-gradient-to-bl from-[#FF8246] to-[#D6264D] text-white font-semibold focus:ring-2 focus:ring-red-200 disabled:cursor-default disabled:opacity-80" /> background == 'white' ? 'bg-white' : 'bg-gray-50' ) +type SubmitProps = ButtonProps & { + children: string +} + export const Submit = ({ className, variant, background, + children, ...props -}: ButtonProps & React.ButtonHTMLAttributes) => ( +}: SubmitProps & React.ButtonHTMLAttributes) => ( )