This is just a technology testing project based on Create React App and TailwindCSS
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

83 Zeilen
2.9KB

  1. import React, { useEffect } from 'react'
  2. import PropTypes from 'prop-types'
  3. import { Formik, Form } from 'formik'
  4. import { Persist } from 'formik-persist'
  5. import * as Yup from 'yup'
  6. import FormikControl from '../FormikControls'
  7. import ButtonPrimary from '../controls/ButtonPrimary'
  8. import ButtonSecondary from '../controls/ButtonSecondary'
  9. import { FormLogin } from './FormLogin'
  10. import { SubmitFormResult } from '../SubmitFormResult';
  11. export const FormPasswordRecovery = (props) => {
  12. const { setPopupTitle, setPopupContent, setPopupOpened, close } = props
  13. useEffect(() => {
  14. if (setPopupTitle) { setPopupTitle('Forgotten password recovery') }
  15. })
  16. const initialValues = {
  17. email: '',
  18. }
  19. const validationSchema = Yup.object({
  20. email: Yup.string()
  21. .required('Required')
  22. .email('Must be a valid email address'),
  23. })
  24. const onSubmit = values => {
  25. setPopupOpened(false)
  26. setTimeout(() => {
  27. setPopupContent(<SubmitFormResult setPopupTitle={setPopupTitle} data={values} />)
  28. setPopupOpened(true)
  29. }, 200);
  30. }
  31. const goLogin = () => {
  32. setPopupOpened(false)
  33. setTimeout(() => {
  34. setPopupContent(<FormLogin setPopupTitle={setPopupTitle} setPopupContent={setPopupContent} setPopupOpened={setPopupOpened} close={close} />)
  35. setPopupOpened(true)
  36. }, 200);
  37. }
  38. return (
  39. <Formik
  40. initialValues={initialValues}
  41. validationSchema={validationSchema}
  42. onSubmit={onSubmit}
  43. >
  44. {formik => {
  45. return (
  46. <div className="overflow-y-auto max-h-screen-80">
  47. <Form className="password-recovery-form">
  48. <div className="p-3">
  49. <FormikControl
  50. control='string'
  51. name='email'
  52. label='Email'
  53. placeholder='Enter email'
  54. />
  55. </div>
  56. <div className="px-2 pt-4 pb-1 mb-0 bg-primary-200 border-t sm:rounded-b-lg">
  57. <ButtonPrimary type="submit" text="Recover" disabled={!formik.isValid || !formik.dirty} />
  58. <div className="my-3">
  59. <ButtonSecondary type="button" text="Go to Sign In" action={goLogin} />
  60. </div>
  61. </div>
  62. <Persist name="password-recovery-form" isSessionStorage />
  63. </Form>
  64. </div>
  65. )
  66. }}
  67. </Formik>
  68. )
  69. }
  70. FormPasswordRecovery.propTypes = {
  71. setPopupTitle: PropTypes.func,
  72. setPopupContent: PropTypes.func,
  73. setPopupOpened: PropTypes.func,
  74. close: PropTypes.func,
  75. }