Add missing register fields and some improvements

This commit is contained in:
Leonardo Murça 2022-09-06 21:36:58 -03:00
parent 5085c05623
commit 0b8cbaad41
4 changed files with 34 additions and 10 deletions

View file

@ -27,7 +27,7 @@ function AuthenticatedApp() {
<Toolbar <Toolbar
title={ title={
<p style={{ fontSize: layoutType === 'desktop' ? '30px' : '20px' }}> <p style={{ fontSize: layoutType === 'desktop' ? '30px' : '20px' }}>
Olá, <strong>{state.user.name}</strong> 👋 Olá, <strong>{state.user.firstName}</strong> 👋
</p> </p>
} }
layoutType={layoutType} layoutType={layoutType}
@ -52,6 +52,7 @@ function AuthenticatedApp() {
<Route path=":id" element={<Assignment />} /> <Route path=":id" element={<Assignment />} />
</Route> </Route>
<Route path="/login" element={<Navigate to="/home" />} /> <Route path="/login" element={<Navigate to="/home" />} />
<Route path="/register" element={<Navigate to="/home" />} />
<Route path="/" element={<Navigate to="/home" />} /> <Route path="/" element={<Navigate to="/home" />} />
</Routes> </Routes>
</Container> </Container>

View file

@ -72,7 +72,7 @@ function View({
Entrar Entrar
</Button> </Button>
<Link href="#">Esqueci minha senha</Link> <Link href="#">Esqueci minha senha</Link>
<Link href="#">Cadastre-se</Link> <Link href="register">Cadastre-se</Link>
</Stack> </Stack>
</Box> </Box>
</Paper> </Paper>

View file

@ -2,6 +2,7 @@ import { Fragment } from 'react';
import { import {
Box, Box,
Button, Button,
Checkbox,
Container, Container,
FormControl, FormControl,
InputLabel, InputLabel,
@ -11,7 +12,9 @@ import {
Select, Select,
Stack, Stack,
TextField, TextField,
Typography,
} from '@mui/material'; } from '@mui/material';
import dayjs from 'dayjs';
import SnackbarIndicator from '../../components/SnackbarIndicator'; import SnackbarIndicator from '../../components/SnackbarIndicator';
import LoadingIndicator from '../../components/LoadingIndicator'; import LoadingIndicator from '../../components/LoadingIndicator';
@ -19,7 +22,6 @@ import LoadingIndicator from '../../components/LoadingIndicator';
import logoImage from '../../assets/if-salas-logo.svg'; import logoImage from '../../assets/if-salas-logo.svg';
import styles from './styles'; import styles from './styles';
import dayjs from 'dayjs';
function View({ function View({
isPending, isPending,
@ -28,11 +30,11 @@ function View({
layoutType, layoutType,
data, data,
onChangeInput, onChangeInput,
onChangeCheckbox,
onTryRegister, onTryRegister,
}) { }) {
const { paper, boxLogo, boxForm, logoContainer } = styles[layoutType]; const { paper, boxLogo, boxForm, logoContainer } = styles[layoutType];
const currentYear = dayjs().year(); const currentYear = dayjs().year();
console.log(currentYear);
return ( return (
<Fragment> <Fragment>
@ -144,15 +146,29 @@ function View({
value={data.password} value={data.password}
onChange={onChangeInput} onChange={onChangeInput}
/> />
<Stack flexDirection="row" alignItems="center">
<Checkbox
name="termsAgreed"
value={data.termsAgreed}
onChange={onChangeCheckbox}
/>
<Typography sx={{ color: '#595959' }} variant="body1">
Eu li e aceito os <Link href="#">termos de uso. </Link>
</Typography>
</Stack>
<Button <Button
// disabled={!isSubmitable}
onClick={onTryRegister} onClick={onTryRegister}
variant="contained" variant="contained"
disabled={!data.termsAgreed}
> >
Entrar Criar conta
</Button> </Button>
<Link href="#">Esqueci minha senha</Link>
<Link href="#">Cadastre-se</Link> <Stack alignItems="center">
<Typography sx={{ color: '#595959' }} variant="body1">
possui uma conta? Então <Link href="login">faça login.</Link>
</Typography>
</Stack>
</Stack> </Stack>
</Box> </Box>
<Box sx={boxLogo}> <Box sx={boxLogo}>

View file

@ -1,4 +1,3 @@
import { Button } from '@mui/material';
import { useState } from 'react'; import { useState } from 'react';
import { useAuthState } from '../../context/auth'; import { useAuthState } from '../../context/auth';
import { useDocumentTitle } from '../../hooks/useDocumentTitle'; import { useDocumentTitle } from '../../hooks/useDocumentTitle';
@ -7,7 +6,7 @@ import useLayoutType from '../../hooks/useLayoutType';
import View from './View'; import View from './View';
function Register() { function Register() {
useDocumentTitle('Entrar'); useDocumentTitle('Criar conta');
const { register, isPending, isError, error } = useAuthState(); const { register, isPending, isError, error } = useAuthState();
const layoutType = useLayoutType(); const layoutType = useLayoutType();
const [data, setData] = useState({ const [data, setData] = useState({
@ -33,6 +32,13 @@ function Register() {
setData(prev => ({ ...prev, [name]: value })); setData(prev => ({ ...prev, [name]: value }));
}; };
const onChangeCheckbox = e => {
const name = e.target.name;
const value = e.target.checked;
setData(prev => ({ ...prev, [name]: value }));
};
return ( return (
<View <View
isPending={isPending} isPending={isPending}
@ -41,6 +47,7 @@ function Register() {
layoutType={layoutType} layoutType={layoutType}
data={data} data={data}
onChangeInput={onChangeInput} onChangeInput={onChangeInput}
onChangeCheckbox={onChangeCheckbox}
onTryRegister={onTryRegister} onTryRegister={onTryRegister}
/> />
); );