homeflowjs 1.0.27 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,11 +42,13 @@ const useRecaptcha = ({
42
42
  };
43
43
 
44
44
  const onResetRecaptcha = useCallback(() => {
45
- window.grecaptcha.reset(stateWidget);
46
- const currentRecaptchaContainer = document.getElementById(RECAPTCHA_CONTAINER_ID);
45
+ if (stateWidget !== null) {
46
+ window.grecaptcha.reset(stateWidget);
47
+ const currentRecaptchaContainer = document.getElementById(RECAPTCHA_CONTAINER_ID);
47
48
 
48
- if (currentRecaptchaContainer) {
49
- currentRecaptchaContainer.remove();
49
+ if (currentRecaptchaContainer) {
50
+ currentRecaptchaContainer.remove();
51
+ }
50
52
  }
51
53
  }, [stateWidget]);
52
54
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "sideEffects": [
5
5
  "modal/**/*",
6
6
  "user/default-profile/**/*",
@@ -1,6 +1,8 @@
1
- import React, { useState } from 'react';
1
+ import React, { useCallback, useState, useRef, useEffect } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
 
4
+ import { useRecaptcha } from '../../hooks';
5
+
4
6
  import notify from '../../app/notify';
5
7
 
6
8
  const ForgottenPasswordForm = ({
@@ -10,8 +12,8 @@ const ForgottenPasswordForm = ({
10
12
  honeypot,
11
13
  honeypotClass,
12
14
  }) => {
15
+ const formRef = useRef(null);
13
16
  const [email, setEmail] = useState('');
14
- const [honeypotInput, setHoneypotInput] = useState('');
15
17
  const [success, setSuccess] = useState(false);
16
18
 
17
19
  const fallbackHoneypotStyles = {
@@ -25,13 +27,13 @@ const ForgottenPasswordForm = ({
25
27
  color: 'transparent',
26
28
  };
27
29
 
28
- const handleSubmit = (e) => {
29
- e.preventDefault();
30
-
31
- const formData = new FormData();
32
- if (honeypotInput !== '') return window.location.href = '/';
30
+ const onRecaptchaSubmit = useCallback((recaptchaData) => {
31
+ const formData = new FormData(formRef.current);
32
+ const honeypot = formData.get("body");
33
33
 
34
- formData.append('email', email);
34
+ if (honeypot && honeypot !== '') {
35
+ return window.location.href = '/';
36
+ }
35
37
 
36
38
  fetch('/reset_passwords', {
37
39
  method: 'POST',
@@ -49,7 +51,28 @@ const ForgottenPasswordForm = ({
49
51
  { duration: 8000 },
50
52
  );
51
53
  });
52
- };
54
+ }, []);
55
+
56
+ const { onRecaptchaRender, onResetRecaptcha } = useRecaptcha({
57
+ formID: 'reset-pwd',
58
+ formRef,
59
+ onRecaptchaSubmit,
60
+ shouldKickGAEvent: false,
61
+ });
62
+
63
+ useEffect(() => {
64
+ if (success) {
65
+ onResetRecaptcha()
66
+ }
67
+ }, [success])
68
+
69
+ const onFormSubmit = (e) => {
70
+ e.preventDefault();
71
+
72
+ if (formRef.current.checkValidity()) {
73
+ onRecaptchaRender();
74
+ }
75
+ }
53
76
 
54
77
  if (success) {
55
78
  return (
@@ -58,7 +81,11 @@ const ForgottenPasswordForm = ({
58
81
  }
59
82
 
60
83
  return (
61
- <form className="forgotten-password-form" onSubmit={handleSubmit}>
84
+ <form
85
+ ref={formRef}
86
+ className="forgotten-password-form"
87
+ onSubmit={onFormSubmit}
88
+ >
62
89
  {honeypot && (
63
90
  <input
64
91
  className={honeypotClass || null}
@@ -66,8 +93,6 @@ const ForgottenPasswordForm = ({
66
93
  type="text"
67
94
  id="body"
68
95
  name="body"
69
- value={honeypotInput}
70
- onChange={(e) => setHoneypotInput(e.target.value)}
71
96
  />
72
97
  )}
73
98