| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import { NextPage } from "next";
- import { useContext, useEffect } from "react";
- import Layout from "../components/Layout";
- import { UserContext } from "../context/UserContext";
- import useForm from "../hooks/useForm";
- import api from "../utils/api";
- const Login: NextPage = () => {
- const context = useContext(UserContext);
- const { error, submitHandler, success } = useForm(api.login);
- useEffect(() => {
- if (success && context) {
- console.log(success.message, success.result, context);
- }
- }, [success, context]);
- return (
- <Layout>
- <form className="form" onSubmit={submitHandler}>
- <div className="form-group">
- <label htmlFor="email" className="form-label">
- Email
- </label>
- <input
- type="email"
- name="email"
- id="email"
- className="form-input"
- placeholder="monkey@gmail.com"
- required
- />
- </div>
- <div className="form-group">
- <label htmlFor="password" className="form-label">
- Password
- </label>
- <input
- type="password"
- name="password"
- id="password"
- className="form-input"
- placeholder="••••••"
- required
- />
- </div>
- <button type="submit" className="form-button">
- Log in
- </button>
- {error && (
- <div role="alert" className="form-alert-msg">
- {error.message}
- </div>
- )}
- </form>
- </Layout>
- );
- };
- export default Login;
|