暫無描述
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.

Preferences.js 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import { ErrorMessage, Field, Form, Formik } from "formik";
  2. import * as Yup from "yup";
  3. const initialValues = {
  4. language: "",
  5. currency: "",
  6. theme: "",
  7. timeZone: "",
  8. };
  9. const PreferencesSchema = Yup.object().shape({
  10. language: Yup.string().required("Language is required"),
  11. currency: Yup.string().required("Currency is required"),
  12. theme: Yup.string().required("Theme is required"),
  13. timeZone: Yup.string().required("Timezone is required"),
  14. });
  15. function Preferences() {
  16. return (
  17. <>
  18. <Formik
  19. initialValues={initialValues}
  20. validationSchema={PreferencesSchema}
  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-xxl-6 col-xl-6 col-lg-6 mb-3">
  31. <label className="form-label">
  32. Language Default
  33. </label>
  34. <Field
  35. name="language"
  36. as="select"
  37. className={
  38. "form-control" +
  39. (errors.language && touched.language
  40. ? " is-invalid"
  41. : "")
  42. }
  43. >
  44. <option value="Bangladesh">
  45. Bangladesh
  46. </option>
  47. <option value="United States">
  48. United States
  49. </option>
  50. <option value="United Kingdom">
  51. United Kingdom
  52. </option>
  53. </Field>
  54. <ErrorMessage
  55. name="language"
  56. component="div"
  57. className="invalid-feedback"
  58. />
  59. </div>
  60. <div className="col-xxl-6 col-xl-6 col-lg-6 mb-3">
  61. <label className="form-label">Currency</label>
  62. <Field
  63. name="currency"
  64. as="select"
  65. className={
  66. "form-control" +
  67. (errors.currency && touched.currency
  68. ? " is-invalid"
  69. : "")
  70. }
  71. >
  72. <option value="">USD</option>
  73. <option value="">Euro</option>
  74. <option value="">BDT</option>
  75. </Field>
  76. <ErrorMessage
  77. name="currency"
  78. component="div"
  79. className="invalid-feedback"
  80. />
  81. </div>
  82. <div className="col-xxl-6 col-xl-6 col-lg-6 mb-3">
  83. <label className="form-label">Theme</label>
  84. <Field
  85. name="theme"
  86. as="select"
  87. className={
  88. "form-control" +
  89. (errors.theme && touched.theme
  90. ? " is-invalid"
  91. : "")
  92. }
  93. >
  94. <option value="">Light</option>
  95. <option value="">Dark</option>
  96. <option value="">Blue</option>
  97. </Field>
  98. <ErrorMessage
  99. name="theme"
  100. component="div"
  101. className="invalid-feedback"
  102. />
  103. </div>
  104. <div className="col-xxl-6 col-xl-6 col-lg-6 mb-3">
  105. <label className="form-label">Time Zone</label>
  106. <Field
  107. name="timeZone"
  108. as="select"
  109. className={
  110. "form-control" +
  111. (errors.timeZone && touched.timeZone
  112. ? " is-invalid"
  113. : "")
  114. }
  115. >
  116. <option>
  117. (GMT-12:00) International Date Line West
  118. </option>
  119. <option>
  120. (GMT-11:00) Midway Island, Samoa
  121. </option>
  122. <option>(GMT-10:00) Hawaii</option>
  123. <option>(GMT-09:00) Alaska</option>
  124. <option>
  125. (GMT-08:00) Pacific Time (US & Canada)
  126. </option>
  127. </Field>
  128. <ErrorMessage
  129. name="timeZone"
  130. component="div"
  131. className="invalid-feedback"
  132. />
  133. </div>
  134. </div>
  135. <div className="mt-3">
  136. <button
  137. type="submit"
  138. className="btn btn-primary mr-2"
  139. >
  140. Save
  141. </button>
  142. </div>
  143. </Form>
  144. )}
  145. </Formik>
  146. </>
  147. );
  148. }
  149. export default Preferences;