signup.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { NextPage } from "next";
  2. import { useEffect } from "react";
  3. import Layout from "../components/Layout";
  4. import useForm from "../hooks/useForm";
  5. import api from "../utils/api";
  6. const SignUp: NextPage = () => {
  7. const { submitHandler, error, success } = useForm(api.register);
  8. useEffect(() => {
  9. if (success) {
  10. console.log(success);
  11. }
  12. }, [success]);
  13. return (
  14. <Layout>
  15. <form className="form" onSubmit={submitHandler}>
  16. <div className="form-group">
  17. <label htmlFor="email" className="form-label">
  18. Email
  19. </label>
  20. <input
  21. type="email"
  22. name="email"
  23. id="email"
  24. className="form-input"
  25. placeholder="monkey@gmail.com"
  26. required
  27. />
  28. </div>
  29. <div className="form-group">
  30. <label htmlFor="password" className="form-label">
  31. Password
  32. </label>
  33. <input
  34. type="password"
  35. name="password"
  36. id="password"
  37. className="form-input"
  38. minLength={6}
  39. placeholder="••••••"
  40. required
  41. />
  42. </div>
  43. <button type="submit" className="form-button">
  44. Sign up
  45. </button>
  46. {error && (
  47. <div role="alert" className="form-alert-msg">
  48. {error.message}
  49. </div>
  50. )}
  51. </form>
  52. </Layout>
  53. );
  54. };
  55. export default SignUp;