diff --git a/src/pages/login/Page.tsx b/src/pages/login/Page.tsx new file mode 100644 index 0000000..29a430e --- /dev/null +++ b/src/pages/login/Page.tsx @@ -0,0 +1,115 @@ +import { IonButtons, IonContent, IonHeader, IonMenuButton, IonPage, IonTitle, IonToolbar } from '@ionic/react'; +import { useParams } from 'react-router'; +import ExploreContainer from '../components/ExploreContainer'; +import './Page.css'; + +const Page: React.FC = () => { + const history = useHistory(); + const [email, setEmail] = useState("eve.holt@reqres.in"); + const [password, setPassword] = useState("cityslicka"); + const [iserror, setIserror] = useState(false); + const [message, setMessage] = useState(""); + + const { name } = useParams<{ name: string; }>(); + + const handleLogin = () => { + // validação de inputs + if (!email) { + setMessage("Por favor, informe um e-mail válido"); + setIserror(true); + return; + } + + if (validateEmail(email) === false) { + setMessage("E-mail inválido"); + setIserror(true); + return; + } + + if (!password || password.length < 6) { + setMessage("Por favor, digite a sua senha"); + setIserror(true); + return; + } + + const loginData = { + email: email, + password: password, + }; + + const api = axios.create({ + baseURL: `https://reqres.in/api`, + }); + + api.post("/login", loginData) + .then((res) => { + // login bem-sucedido + history.push("/dashboard/" + email); + }) + .catch((error) => { + setMessage("Falha na autenticação! Por favor, crie uma conta"); + setIserror(true); + }); + }; + + return ( + + + + + + + {name} + + + + + + + + + + + + + Login + + + + + + + Email + setEmail(e.detail.value!)} + > + + + + + + + +

+ Clicando no botão de "LOGIN", você concorda com a nossa política de termos e serviços +

+ + Login + +

+ Ainda não possui uma conta? Cadastre-se aqui! +

+
+
+ +
+
+ ); +}; + +export default Page;