homeflowjs 0.10.11 → 0.10.13
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/index.js
CHANGED
@@ -7,6 +7,7 @@ import notify from './app/notify';
|
|
7
7
|
import Loader from './shared/loader.component';
|
8
8
|
import AuthenticityTokenField from './shared/authenticity-token-field.component';
|
9
9
|
import { uniqueKey } from './utils';
|
10
|
+
import SingleLocationMap from './shared/single-location-map';
|
10
11
|
|
11
12
|
export {
|
12
13
|
withHomeflowState,
|
@@ -18,4 +19,5 @@ export {
|
|
18
19
|
Loader,
|
19
20
|
AuthenticityTokenField,
|
20
21
|
uniqueKey,
|
22
|
+
SingleLocationMap,
|
21
23
|
};
|
package/package.json
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import {
|
3
|
+
MapContainer, TileLayer,
|
4
|
+
} from 'react-leaflet';
|
5
|
+
import PropTypes from 'prop-types';
|
6
|
+
|
7
|
+
const SingleLocationMap = ({
|
8
|
+
lat, lng, zoomLvl, ...otherProps
|
9
|
+
}) => {
|
10
|
+
if (!lat || !lng) return null;
|
11
|
+
|
12
|
+
return (
|
13
|
+
<MapContainer
|
14
|
+
center={[lat, lng]}
|
15
|
+
zoom={zoomLvl}
|
16
|
+
scrollWheelZoom={false}
|
17
|
+
{...otherProps}
|
18
|
+
>
|
19
|
+
<TileLayer
|
20
|
+
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
21
|
+
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
22
|
+
/>
|
23
|
+
</MapContainer>
|
24
|
+
);
|
25
|
+
};
|
26
|
+
|
27
|
+
SingleLocationMap.propTypes = {
|
28
|
+
lat: PropTypes.number.isRequired,
|
29
|
+
lng: PropTypes.number.isRequired,
|
30
|
+
zoomLvl: PropTypes.number,
|
31
|
+
};
|
32
|
+
|
33
|
+
SingleLocationMap.defaultProps = {
|
34
|
+
zoomLvl: 12,
|
35
|
+
};
|
36
|
+
|
37
|
+
export default SingleLocationMap;
|
@@ -21,22 +21,45 @@ const MarketingPreferencesForm = ({ buttonClass, buttonSpanClass, strict }) => {
|
|
21
21
|
const handleSubmit = (e) => {
|
22
22
|
e.preventDefault();
|
23
23
|
|
24
|
-
if (!user
|
24
|
+
if (!user?.user_id) {
|
25
25
|
notify('Please sign in to update your preferences', 'error');
|
26
26
|
return;
|
27
27
|
}
|
28
28
|
|
29
|
-
|
29
|
+
/**
|
30
|
+
* cms created users don't have marketing_preference_id
|
31
|
+
* associated to them. To update marketing preferences
|
32
|
+
* we can use any of those 2 endpoints depending on the
|
33
|
+
* data we pass. Ideally this should get fixed by BE at some point.
|
34
|
+
*/
|
35
|
+
const url = user?.marketing_preference_id
|
36
|
+
? `/marketing_preferences/${user.marketing_preference_id}`
|
37
|
+
: `/custom_marketing_preferences/${user.user_id}`;
|
38
|
+
|
39
|
+
const optInAtAndUrl = {
|
40
|
+
opt_in_marketing_at: optInMarketing ? 'optin' : 'optout',
|
41
|
+
opt_in_marketing_url: document.URL,
|
42
|
+
};
|
43
|
+
|
44
|
+
const body = {
|
45
|
+
user_id: user.user_id,
|
46
|
+
...(!user.marketing_preference_id ? ({
|
47
|
+
marketing_preferences: {
|
48
|
+
is_opted_in_to_marketing: optInMarketing,
|
49
|
+
...optInAtAndUrl,
|
50
|
+
},
|
51
|
+
}) : ({
|
52
|
+
...optInAtAndUrl,
|
53
|
+
})),
|
54
|
+
};
|
55
|
+
|
56
|
+
fetch(url, {
|
30
57
|
method: 'POST',
|
31
58
|
headers: {
|
32
59
|
'Content-Type': 'application/json',
|
33
60
|
'X-Http-Method-Override': 'put',
|
34
61
|
},
|
35
|
-
body: JSON.stringify(
|
36
|
-
opt_in_marketing_at: optInMarketing ? 'optin' : 'optout',
|
37
|
-
opt_in_marketing_url: document.URL,
|
38
|
-
user_id: user.user_id,
|
39
|
-
}),
|
62
|
+
body: JSON.stringify(body),
|
40
63
|
}).then((res) => {
|
41
64
|
if (res.ok && (res.status === 200 || res.status === 204)) {
|
42
65
|
dispatch(setCurrentUser({
|