homeflowjs 0.9.34 → 0.9.35

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.
package/.eslintrc.js CHANGED
@@ -4,6 +4,7 @@ module.exports = {
4
4
  fetch: 'readonly',
5
5
  Homeflow: 'readonly',
6
6
  document: 'readonly',
7
+ location: 'readonly',
7
8
  FormData: 'readonly',
8
9
  window: 'readonly',
9
10
  describe: 'readonly',
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-cycle */
1
2
  import UserActionTypes from './user.types';
2
3
  import { fetchSavedProperties, setSavedProperties } from './properties.actions';
3
4
  import { fetchSavedSearches, setSavedSearches } from './search.actions';
@@ -153,11 +154,15 @@ export const signOutUser = () => (dispatch) => (
153
154
  fetch('/session', {
154
155
  method: 'DELETE',
155
156
  })
156
- .then(() => {
157
- dispatch(setCurrentUser(INITIAL_USER_DATA));
158
- dispatch(setLocalUser(INITIAL_USER_DATA));
159
- dispatch(setUserCredentials({ email: '', password: '' }));
160
- dispatch(setSavedProperties([]));
161
- dispatch(setSavedSearches([]));
157
+ .then((response) => {
158
+ if (response.ok) {
159
+ dispatch(setCurrentUser(INITIAL_USER_DATA));
160
+ dispatch(setLocalUser(INITIAL_USER_DATA));
161
+ dispatch(setUserCredentials({ email: '', password: '' }));
162
+ dispatch(setSavedProperties([]));
163
+ dispatch(setSavedSearches([]));
164
+ }
165
+
166
+ return response.ok;
162
167
  })
163
168
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "0.9.34",
3
+ "version": "0.9.35",
4
4
  "description": "JavaScript toolkit for Homeflow themes",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,23 +1,39 @@
1
1
  import React from 'react';
2
+ import { useHistory } from 'react-router-dom';
2
3
  import { connect } from 'react-redux';
3
4
  import PropTypes from 'prop-types';
4
5
 
5
6
  import { signOutUser } from '../../actions/user.actions';
6
7
  import notify from '../../app/notify';
7
8
 
8
- const SignOutButton = ({ signOutUser, children, ...otherProps }) => (
9
- <button
10
- type="button"
11
- onClick={(e) => {
12
- e.preventDefault();
13
- signOutUser()
14
- .then(() => notify('You have been signed out', 'success'));
15
- }}
16
- {...otherProps}
17
- >
18
- {children}
19
- </button>
20
- );
9
+ const SignOutButton = ({
10
+ signOutUser, pushHistory, reload, children, ...otherProps
11
+ }) => {
12
+ const history = useHistory();
13
+ const handleClick = (e) => {
14
+ e.preventDefault();
15
+ signOutUser()
16
+ .then((success) => {
17
+ if (success) {
18
+ notify('You have been signed out', 'success');
19
+ if (pushHistory) history.push('/');
20
+ if (reload) location.reload(false);
21
+ } else {
22
+ notify('There was an error signing out', 'error');
23
+ }
24
+ });
25
+ };
26
+
27
+ return (
28
+ <button
29
+ type="button"
30
+ onClick={(e) => handleClick(e)}
31
+ {...otherProps}
32
+ >
33
+ {children}
34
+ </button>
35
+ );
36
+ };
21
37
 
22
38
  SignOutButton.propTypes = {
23
39
  signOutUser: PropTypes.func.isRequired,
@@ -25,6 +41,13 @@ SignOutButton.propTypes = {
25
41
  PropTypes.element,
26
42
  PropTypes.string,
27
43
  ]).isRequired,
44
+ pushHistory: PropTypes.bool,
45
+ reload: PropTypes.bool,
46
+ };
47
+
48
+ SignOutButton.defaultProps = {
49
+ pushHistory: false,
50
+ reload: false,
28
51
  };
29
52
 
30
53
  const mapDispatchToProps = {