Ingen beskrivning
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SignupForm.js 7.2KB

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