PasswordResetRequestForm.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import React, { FC, useState, useCallback } from 'react';
  2. import { useTranslation } from 'next-i18next';
  3. import Link from 'next/link';
  4. import { toastSuccess, toastError } from '~/client/util/apiNotification';
  5. import { apiv3Post } from '~/client/util/apiv3-client';
  6. const PasswordResetRequestForm: FC = () => {
  7. const { t } = useTranslation();
  8. const [email, setEmail] = useState('');
  9. const changeEmail = useCallback((inputValue) => {
  10. setEmail(inputValue);
  11. }, []);
  12. const sendPasswordResetRequestMail = useCallback(async(e) => {
  13. e.preventDefault();
  14. if (email === '') {
  15. toastError('err', t('forgot_password.email_is_required'));
  16. return;
  17. }
  18. try {
  19. await apiv3Post('/forgot-password', { email });
  20. toastSuccess(t('forgot_password.success_to_send_email'));
  21. }
  22. catch (err) {
  23. toastError(err);
  24. }
  25. }, [t, email]);
  26. return (
  27. <form onSubmit={sendPasswordResetRequestMail}>
  28. <h3>{ t('forgot_password.password_reset_request_desc') }</h3>
  29. <div className="form-group">
  30. <div className="input-group">
  31. <input name="email" placeholder="E-mail Address" className="form-control" type="email" onChange={e => changeEmail(e.target.value)} />
  32. </div>
  33. </div>
  34. <div className="form-group">
  35. <button
  36. className="btn btn-lg btn-primary btn-block"
  37. type="submit"
  38. >
  39. {t('forgot_password.send')}
  40. </button>
  41. </div>
  42. <Link href='/login' prefetch={false}>
  43. <a>
  44. <i className="icon-login mr-1" />{t('forgot_password.return_to_login')}
  45. </a>
  46. </Link>
  47. </form>
  48. );
  49. };
  50. export default PasswordResetRequestForm;