diff --git a/src/hooks/useLayoutType.js b/src/hooks/useLayoutType.js new file mode 100644 index 0000000..a717435 --- /dev/null +++ b/src/hooks/useLayoutType.js @@ -0,0 +1,17 @@ +import { useMediaQuery } from '@mui/material'; +import { useEffect, useState } from 'react'; + +export default function useLayoutType() { + const [layoutType, setLayoutType] = useState('desktop'); + const isMediaQueryRuleActive = useMediaQuery('(max-width:800px)'); + + useEffect(() => { + if (isMediaQueryRuleActive) { + setLayoutType('mobile'); + } else { + setLayoutType('desktop'); + } + }, [isMediaQueryRuleActive]); + + return layoutType; +} diff --git a/src/index.css b/src/index.css index 20c8d70..6c59b99 100644 --- a/src/index.css +++ b/src/index.css @@ -3,6 +3,7 @@ body { font-family: 'Fira Code', monospace; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; + height: 100vh; } code { diff --git a/src/screens/Login.js b/src/screens/Login.js deleted file mode 100644 index 943edde..0000000 --- a/src/screens/Login.js +++ /dev/null @@ -1,122 +0,0 @@ -import { Fragment, useState } from 'react'; -import { - Box, - Button, - Container, - Link, - Paper, - Stack, - TextField, -} from '@mui/material'; -import { useAuthState } from '../context/auth'; - -import LoadingIndicator from '../components/LoadingIndicator'; -import SnackbarIndicator from '../components/SnackbarIndicator'; - -import logoImage from '../assets/if-salas-logo.svg'; - -function Login() { - const { login, isPending, isError, error } = useAuthState(); - const [email, setEmail] = useState(''); - const [password, setPassword] = useState(''); - - const isSubmitable = email.length !== 0 && password.length !== 0; - - const onTryLogin = () => { - isSubmitable && login(email, password); - }; - - return ( - - - - - Logotipo -

A plataforma de ensino de código aberto.

-
-
- -

Login

-

Bem-vindo de volta. Faça o login digitando os dados abaixo.

- - setEmail(e.target.value)} - /> - setPassword(e.target.value)} - /> - - Esqueci minha senha - Cadastre-se - -
-
- - -
- ); -} - -const paper = { - width: '950px', - height: '500px', - display: 'flex', - justifyContent: 'center', - color: 'white', - textAlign: 'center', -}; - -const baseBox = { - width: '100%', - height: '100%', - display: 'flex', - justifyContent: 'center', - flexDirection: 'column', -}; - -const boxLogo = { - ...baseBox, - backgroundColor: 'secondary.main', -}; - -const boxForm = { - ...baseBox, - '> h1, p ': { - paddingLeft: '70px', - paddingRight: '70px', - textAlign: 'initial', - }, - '> h1': { - color: 'primary.black', - margin: 0, - }, - '> p': { - color: 'primary.lightGray', - }, -}; - -const stack = { - padding: '0 70px', -}; - -export default Login; diff --git a/src/screens/Login/View.js b/src/screens/Login/View.js new file mode 100644 index 0000000..1d5f084 --- /dev/null +++ b/src/screens/Login/View.js @@ -0,0 +1,88 @@ +import { Fragment } from 'react'; +import { + Box, + Button, + Container, + Link, + Paper, + Stack, + TextField, +} from '@mui/material'; + +import SnackbarIndicator from '../../components/SnackbarIndicator'; +import LoadingIndicator from '../../components/LoadingIndicator'; + +import logoImage from '../../assets/if-salas-logo.svg'; + +import styles from './styles'; + +function View({ + email, + password, + onChangeEmail, + onChangePassword, + isSubmitable, + onTryLogin, + isPending, + isError, + error, + layoutType, +}) { + const { paper, boxLogo, boxForm } = styles[layoutType]; + + return ( + + + + + Logotipo +

A plataforma de ensino de código aberto.

+
+
+ +

Login

+

Bem-vindo de volta. Faça o login digitando os dados abaixo.

+ + onChangeEmail(e.target.value)} + /> + onChangePassword(e.target.value)} + /> + + Esqueci minha senha + Cadastre-se + +
+
+ + +
+ ); +} + +export default View; diff --git a/src/screens/Login/index.js b/src/screens/Login/index.js new file mode 100644 index 0000000..8054883 --- /dev/null +++ b/src/screens/Login/index.js @@ -0,0 +1,35 @@ +import { useState } from 'react'; +import { useAuthState } from '../../context/auth'; +import useLayoutType from '../../hooks/useLayoutType'; + +import View from './View'; + +function Login() { + const { login, isPending, isError, error } = useAuthState(); + const layoutType = useLayoutType(); + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + + const isSubmitable = email.length !== 0 && password.length !== 0; + + const onTryLogin = () => { + isSubmitable && login(email, password); + }; + + return ( + + ); +} + +export default Login; diff --git a/src/screens/Login/styles.js b/src/screens/Login/styles.js new file mode 100644 index 0000000..4cd9073 --- /dev/null +++ b/src/screens/Login/styles.js @@ -0,0 +1,71 @@ +const desktopPaper = { + width: '950px', + height: '500px', + display: 'flex', + justifyContent: 'center', + color: 'white', + textAlign: 'center', +}; + +const mobilePaper = { + ...desktopPaper, + flexDirection: 'column', + height: '700px', + marginLeft: '10px', + marginRight: '10px', +}; + +const baseBox = { + width: '100%', + height: '100%', + display: 'flex', + justifyContent: 'center', + flexDirection: 'column', + padding: '0 70px', +}; + +const desktopBoxLogo = { + ...baseBox, + backgroundColor: 'secondary.main', +}; + +const mobileBoxLogo = { + ...desktopBoxLogo, + height: '45%', + padding: '0', +}; + +const desktopBoxForm = { + ...baseBox, + '> h1, p ': { + textAlign: 'initial', + }, + '> h1': { + color: 'primary.black', + margin: 0, + }, + '> p': { + color: 'primary.lightGray', + }, +}; + +const mobileBoxForm = { + ...desktopBoxForm, + padding: '0 15px', + width: 'fit-content', +}; + +const desktop = { + paper: desktopPaper, + boxLogo: desktopBoxLogo, + boxForm: desktopBoxForm, +}; + +const mobile = { + paper: mobilePaper, + boxLogo: mobileBoxLogo, + boxForm: mobileBoxForm, +}; + +const styles = { desktop, mobile }; +export default styles;