Geen omschrijving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SigninForm.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { ErrorMessage, Field, Form, Formik } from "formik";
  2. import * as Yup from "yup";
  3. import Link from "next/link";
  4. import AuthIcon from "./authselection/AuthIcon";
  5. const initialValues = {
  6. email: "",
  7. password: "",
  8. };
  9. const SigninFormSchema = Yup.object().shape({
  10. email: Yup.string().email("Email is invalid").required("Email is required"),
  11. password: Yup.string()
  12. .min(6, "Password must be at least 6 characters")
  13. .required("Password is required"),
  14. });
  15. function SigninForm() {
  16. return (
  17. <>
  18. <Formik
  19. initialValues={initialValues}
  20. validationSchema={SigninFormSchema}
  21. onSubmit={(fields) => {
  22. alert(
  23. "SUCCESS!! :-)\n\n" + JSON.stringify(fields, null, 4)
  24. );
  25. }}
  26. >
  27. {({ errors, status, touched }) => (
  28. <Form>
  29. <div className="row">
  30. <div className="col-12 mb-3 d-flex justify-content-around">
  31. <input type="radio" id="html" className="d-none" name="fav_language" value="HTML" />
  32. <label className="auth-icon-label" for="html">
  33. <AuthIcon isActive={true} title="Consumer" icon="user" />
  34. </label>
  35. <input className="d-none" type="radio" id="css" name="fav_language" value="CSS" />
  36. <label className="auth-icon-label" for="css">
  37. <AuthIcon title="Employee" icon="address-card" />
  38. </label>
  39. <input className="d-none" type="radio" id="javascript" name="fav_language" value="JavaScript" />
  40. <label className="auth-icon-label" for="javascript">
  41. <AuthIcon title="Plumber" icon="gear" />
  42. </label>
  43. </div>
  44. <div className="col-12 mb-3">
  45. <label className="form-label">Email</label>
  46. <Field
  47. name="email"
  48. type="text"
  49. className={
  50. "form-control" +
  51. (errors.email && touched.email
  52. ? " is-invalid"
  53. : "")
  54. }
  55. />
  56. <ErrorMessage
  57. name="email"
  58. component="div"
  59. className="invalid-feedback"
  60. />
  61. </div>
  62. <div className="col-12 mb-3">
  63. <label className="form-label">Password</label>
  64. <Field
  65. name="password"
  66. type="text"
  67. className={
  68. "form-control" +
  69. (errors.password && touched.password
  70. ? " is-invalid"
  71. : "")
  72. }
  73. />
  74. <ErrorMessage
  75. name="password"
  76. component="div"
  77. className="invalid-feedback"
  78. />
  79. </div>
  80. <div className="col-6">
  81. <div className="form-check">
  82. <Field
  83. type="checkbox"
  84. name="acceptTerms"
  85. className={
  86. "form-check-input "
  87. }
  88. />
  89. <label
  90. className="form-check-label"
  91. >
  92. Remember me
  93. </label>
  94. </div>
  95. </div>
  96. <div className="col-6 text-end">
  97. <Link href="/reset">
  98. <a>Forgot Password?</a>
  99. </Link>
  100. </div>
  101. </div>
  102. <div className="mt-3 d-grid gap-2">
  103. <button
  104. type="submit"
  105. className="btn btn-primary mr-2"
  106. >
  107. Sign In
  108. </button>
  109. </div>
  110. </Form>
  111. )}
  112. </Formik>
  113. </>
  114. );
  115. }
  116. export default SigninForm;