homeflowjs 1.0.37 → 1.0.38

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.
@@ -54,7 +54,7 @@ export const setUserCredentials = (payload) => ({
54
54
  payload,
55
55
  });
56
56
 
57
- export const createUser = (payload) => (dispatch, getState) => {
57
+ export const createUser = (payload, recaptchaData = {}) => (dispatch, getState) => {
58
58
  const { user: { localUser }, app: { authenticityToken } } = getState();
59
59
 
60
60
  return fetch('/user.ljson', {
@@ -63,6 +63,7 @@ export const createUser = (payload) => (dispatch, getState) => {
63
63
  body: JSON.stringify({
64
64
  client: payload,
65
65
  authenticity_token: authenticityToken,
66
+ ...recaptchaData,
66
67
  }),
67
68
  })
68
69
  .then(async (response) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "1.0.37",
3
+ "version": "1.0.38",
4
4
  "sideEffects": [
5
5
  "modal/**/*",
6
6
  "user/default-profile/**/*",
@@ -73,6 +73,6 @@
73
73
  "jest": "^26.6.0",
74
74
  "msw": "^0.28.1",
75
75
  "react-autosuggest": "^10.0.2",
76
- "redux-mock-store": "^1.5.4"
76
+ "redux-mock-store": "^1.5.5"
77
77
  }
78
78
  }
@@ -1,11 +1,13 @@
1
1
  import React from 'react';
2
- import { render, screen, waitFor, cleanup } from '@testing-library/react';
3
- import userEvent from '@testing-library/user-event'
2
+ import { Provider } from 'react-redux';
3
+ import { HashRouter } from 'react-router-dom';
4
+ import { fireEvent, render } from '@testing-library/react';
5
+ import userEvent from '@testing-library/user-event';
4
6
  import { rest } from 'msw';
5
7
  import { setupServer } from 'msw/node';
8
+ import configureStore from 'redux-mock-store';
6
9
 
7
- import withHomeflowState, { resetStore } from '../../../app/with-homeflow-state';
8
- import store from '../../../store';
10
+ import withHomeflowState, { resetStore } from '../../../app/with-homeflow-state';
9
11
  import SignInForm from './sign-in-form.component';
10
12
  import UserProfileModal from '../user-profile/user-profile-modal.component';
11
13
 
@@ -57,7 +59,9 @@ describe('SignInForm Component', () => {
57
59
  });
58
60
 
59
61
  it('reports successful sign in', async () => {
60
- const { findByText, findAllByText, getByText, getAllByText } = render(withHomeflowState(UserProfileModal));
62
+ const {
63
+ findByText, findAllByText, getByText, getAllByText,
64
+ } = render(withHomeflowState(UserProfileModal));
61
65
 
62
66
  await findByText('Register or Sign in');
63
67
  userEvent.click(getByText('Register or Sign in'));
@@ -71,7 +75,7 @@ describe('SignInForm Component', () => {
71
75
  const { findByText, getByText } = render(withHomeflowState(SignInForm));
72
76
 
73
77
  server.use(
74
- rest.post('/session', (req, res, ctx) => res(ctx.status(401))),
78
+ rest.post('/session', (req, res, ctx) => res(ctx.status(401))),
75
79
  );
76
80
  jest.spyOn(console, 'error').mockImplementation(() => {});
77
81
 
@@ -81,7 +85,9 @@ describe('SignInForm Component', () => {
81
85
  });
82
86
 
83
87
  it('reports succesful sign out', async () => {
84
- const { findByText, findAllByText, getByText, getAllByText } = render(withHomeflowState(UserProfileModal));
88
+ const {
89
+ findByText, findAllByText, getByText, getAllByText,
90
+ } = render(withHomeflowState(UserProfileModal));
85
91
 
86
92
  await findByText('Register or Sign in');
87
93
  userEvent.click(getByText('Register or Sign in'));
@@ -98,7 +104,7 @@ describe('SignInForm Component', () => {
98
104
 
99
105
  it('clears sign-in credentials on sign-out', async () => {
100
106
  const {
101
- findByText, findAllByText, getAllByLabelText, getByText, getAllByText
107
+ findByText, findAllByText, getAllByLabelText, getByText, getAllByText,
102
108
  } = render(withHomeflowState(UserProfileModal));
103
109
 
104
110
  await findByText('Register or Sign in');
@@ -121,29 +127,34 @@ describe('SignInForm Component', () => {
121
127
  });
122
128
 
123
129
  it('populates new user data in profile edit page afte user registration', async () => {
124
- const {
125
- findByText, findAllByText, findByRole, getByLabelText, getAllByLabelText, getByRole, getByText, getAllByText
126
- } = render(withHomeflowState(UserProfileModal));
127
-
128
- await findByText('Register or Sign in');
129
- userEvent.click(getByText('Register or Sign in'));
130
- await findByText('Welcome, Guest.');
131
- userEvent.type(getByLabelText('First name'), user.first_name);
132
- userEvent.type(getByLabelText('Last name'), user.last_name);
133
- userEvent.type(getAllByLabelText('Email')[0], user.email);
134
- userEvent.type(getByLabelText('Phone'), user.pohne);
135
- userEvent.type(getAllByLabelText('Password')[0], 'password');
136
- userEvent.type(getByLabelText('Confirm password'), 'password');
137
- userEvent.click(getByRole('button', { name: 'Register' }));
130
+ const mockStore = configureStore([]);
131
+ const store = mockStore({
132
+ user: { currentUser: user, localUser: user },
133
+ app: { loading: { user: false }},
134
+ properties: { savedProperties: [] },
135
+ search: { savedSearches: [] },
136
+ });
137
+
138
+ const { findByText, getByDisplayValue } = render(
139
+ <Provider store={store}>
140
+ <HashRouter>
141
+ <UserProfileModal />
142
+ </HashRouter>
143
+ </Provider>,
144
+ );
138
145
 
139
- await findByText('Welcome, Test.');
140
- userEvent.click(getByText('Edit your profile'));
146
+ expect(findByText(`Welcome, ${user.first_name}`)).toBeTruthy();
147
+ expect(findByText(`${user.first_name} ${user.last_name}`)).toBeTruthy();
148
+ expect(findByText(user.email)).toBeTruthy();
149
+ expect(findByText(user.tel_home)).toBeTruthy();
150
+ expect(findByText('Edit your profile')).toBeTruthy();
141
151
 
142
- await findByRole('heading', { name: 'Edit Your Profile' });
152
+ const button = await findByText('Edit your profile');
153
+ fireEvent.click(button);
143
154
 
144
- expect(getByLabelText('First name')).toHaveValue(user.first_name);
145
- expect(getByLabelText('Last name')).toHaveValue(user.last_name);
146
- expect(getByLabelText('Email')).toHaveValue(user.email);
147
- expect(getByLabelText('Phone')).toHaveValue(user.tel_home);
155
+ getByDisplayValue(user.first_name);
156
+ getByDisplayValue(user.last_name);
157
+ getByDisplayValue(user.tel_home);
158
+ getByDisplayValue(user.email);
148
159
  });
149
160
  });
@@ -1,6 +1,7 @@
1
- import React from 'react';
1
+ import React, { useEffect, useRef, useState } from 'react';
2
2
  import { connect } from 'react-redux';
3
3
  import PropTypes from 'prop-types';
4
+ import { useRecaptcha } from '../../hooks';
4
5
 
5
6
  import { setLocalUser, createUser } from '../../actions/user.actions';
6
7
  import { setLoading } from '../../actions/app.actions';
@@ -19,6 +20,9 @@ const UserRegisterForm = (props) => {
19
20
  ...otherProps
20
21
  } = props;
21
22
 
23
+ const formRef = useRef(null);
24
+ const [isRequestCompleted, setIsRequestCompleted] = useState(null);
25
+
22
26
  const validateForm = () => {
23
27
  if (localUser.password === localUser.password_confirmation) return true;
24
28
 
@@ -26,9 +30,8 @@ const UserRegisterForm = (props) => {
26
30
  return false;
27
31
  };
28
32
 
29
- const handleSubmit = (e) => {
30
- e.preventDefault();
31
- const { body } = Object.fromEntries(new FormData(e.target));
33
+ const onRecaptchaSubmit = (recaptchaData) => {
34
+ const { body } = Object.fromEntries(new FormData(formRef.current));
32
35
  const formData = {
33
36
  ...localUser,
34
37
  body,
@@ -39,37 +42,61 @@ const UserRegisterForm = (props) => {
39
42
  ...localUser.marketing_preferences, opt_in_marketing_statement: marketingStatement,
40
43
  };
41
44
 
45
+ createUser(userParams)
46
+ .then(() => {
47
+ setLoading({ userRegister: false });
48
+ notify('You have been successfully registered!', 'success');
49
+
50
+ if (redirectHash) {
51
+ window.location.hash = redirectHash;
52
+ }
53
+ })
54
+ .catch(() => {
55
+ if (userParams?.body) {
56
+ window.location.href = '/';
57
+ } else if(errors?.password){
58
+ // this could be used for any kind of errors but we only need it for password errors right now
59
+ errors.password.forEach((error) => notify(error, 'error', { duration: 8000 }))
60
+ } else {
61
+ notify(
62
+ 'Sorry, something went wrong. You may already have an account with this email address, if so, please try signing in instead of registering.',
63
+ 'error',
64
+ { duration: 8000 },
65
+ );
66
+ }
67
+ })
68
+ .finally(setIsRequestCompleted((prevState) => !prevState))
69
+ }
70
+
71
+ const { onRecaptchaRender, onResetRecaptcha } = useRecaptcha({
72
+ formID: 'registration-form',
73
+ formRef,
74
+ onRecaptchaSubmit,
75
+ });
76
+
77
+ const handleSubmit = (e) => {
78
+ e.preventDefault();
79
+
42
80
  if (validateForm()) {
43
81
  setLoading({ userRegister: true });
44
-
45
- createUser(userParams)
46
- .then(() => {
47
- setLoading({ userRegister: false });
48
- notify('You have been successfully registered!', 'success');
49
-
50
- if (redirectHash) {
51
- window.location.hash = redirectHash;
52
- }
53
- })
54
- .catch((errors) => {
55
- if (userParams?.body) {
56
- window.location.href = '/';
57
- } else if(errors?.password){
58
- // this could be used for any kind of errors but we only need it for password errors right now
59
- errors.password.forEach((error) => notify(error, 'error', { duration: 8000 }))
60
- } else {
61
- notify(
62
- 'Sorry, something went wrong. You may already have an account with this email address, if so, please try signing in instead of registering.',
63
- 'error',
64
- { duration: 8000 },
65
- );
66
- }
67
- });
82
+ setIsRequestCompleted(false);
83
+ onRecaptchaRender();
68
84
  }
69
85
  };
70
86
 
87
+ useEffect(() => {
88
+ if(isRequestCompleted) {
89
+ onResetRecaptcha();
90
+ }
91
+ }, [isRequestCompleted])
92
+
93
+
71
94
  return (
72
- <form onSubmit={handleSubmit} {...otherProps}>
95
+ <form
96
+ onSubmit={handleSubmit}
97
+ ref={formRef}
98
+ {...otherProps}
99
+ >
73
100
  <input
74
101
  type="text"
75
102
  name="body"