Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

UpdateAvatar.js 3.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { ErrorMessage, Field, Form, Formik } from "formik";
  2. import * as Yup from "yup";
  3. const initialValues = {
  4. fullName: "",
  5. photo: "",
  6. };
  7. const UpdateAvatarSchema = Yup.object().shape({
  8. fullName: Yup.string().required("Full Name is required"),
  9. photo: Yup.string().required("Photo required"),
  10. });
  11. function UpdateAvatar() {
  12. return (
  13. <>
  14. <Formik
  15. initialValues={initialValues}
  16. validationSchema={UpdateAvatarSchema}
  17. onSubmit={(fields) => {
  18. alert(
  19. "SUCCESS!! :-)\n\n" + JSON.stringify(fields, null, 4)
  20. );
  21. }}
  22. >
  23. {({ errors, status, touched }) => (
  24. <Form>
  25. <div className="row">
  26. <div className="col-12 mb-3">
  27. <label className="form-label">Full Name</label>
  28. <Field
  29. name="fullName"
  30. type="text"
  31. className={
  32. "form-control" +
  33. (errors.fullName && touched.fullName
  34. ? " is-invalid"
  35. : "")
  36. }
  37. />
  38. <ErrorMessage
  39. name="fullName"
  40. component="div"
  41. className="invalid-feedback"
  42. />
  43. </div>
  44. <div className="col-xxl-12">
  45. <div className="d-flex align-items-center mb-3">
  46. <img
  47. className="me-3 rounded-circle me-0 me-sm-3"
  48. src="images/profile/3.png"
  49. width="55"
  50. height="55"
  51. alt=""
  52. />
  53. <div className="media-body">
  54. <h4 className="mb-0">Jannatul Maowa</h4>
  55. <p className="mb-0">
  56. Max file size is 20mb
  57. </p>
  58. </div>
  59. </div>
  60. </div>
  61. <div className="col-12">
  62. <Field
  63. name="photo"
  64. type="file"
  65. className={
  66. (errors.photo && touched.photo
  67. ? " is-invalid"
  68. : "")
  69. }
  70. />
  71. <ErrorMessage
  72. name="photo"
  73. component="div"
  74. className="invalid-feedback"
  75. />
  76. </div>
  77. </div>
  78. <div className="mt-3">
  79. <button
  80. type="submit"
  81. className="btn btn-primary mr-2"
  82. >
  83. Save
  84. </button>
  85. </div>
  86. </Form>
  87. )}
  88. </Formik>
  89. </>
  90. );
  91. }
  92. export default UpdateAvatar;