@open-tender/utils 0.1.95 → 0.1.97
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/dist/.DS_Store +0 -0
- package/dist/cjs/hooks/useLoginForm.d.ts +3 -3
- package/dist/cjs/hooks/useLoginForm.js +6 -2
- package/dist/cjs/utils/constants.d.ts +1 -1
- package/dist/cjs/utils/constants.js +1 -1
- package/dist/cjs/utils/maps.d.ts +10 -14
- package/dist/cjs/utils/maps.js +22 -22
- package/dist/esm/hooks/useLoginForm.d.ts +3 -3
- package/dist/esm/hooks/useLoginForm.js +6 -2
- package/dist/esm/utils/constants.d.ts +1 -1
- package/dist/esm/utils/constants.js +1 -1
- package/dist/esm/utils/maps.d.ts +10 -14
- package/dist/esm/utils/maps.js +22 -22
- package/package.json +2 -2
package/dist/.DS_Store
ADDED
|
Binary file
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string) => void, callback?: () => void) => {
|
|
2
|
+
import { LoginData, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string) => void, callback?: () => void, showPassword?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
fields:
|
|
6
|
+
fields: import("@open-tender/types").FormFieldType[];
|
|
7
7
|
data: LoginData;
|
|
8
8
|
errors: Record<string, string>;
|
|
9
9
|
submitting: boolean;
|
|
@@ -3,13 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useLoginForm = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
-
const useLoginForm = (loading, error, login, callback) => {
|
|
6
|
+
const useLoginForm = (loading, error, login, callback, showPassword = true) => {
|
|
7
7
|
const submitRef = (0, react_1.useRef)(null);
|
|
8
8
|
const inputRef = (0, react_1.useRef)(null);
|
|
9
9
|
const [data, setData] = (0, react_1.useState)({ email: '', password: '' });
|
|
10
10
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
11
11
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
12
|
-
const
|
|
12
|
+
const toRemove = [];
|
|
13
|
+
if (!showPassword)
|
|
14
|
+
toRemove.push('password');
|
|
15
|
+
const allFields = [
|
|
13
16
|
{
|
|
14
17
|
label: 'Email',
|
|
15
18
|
name: 'email',
|
|
@@ -24,6 +27,7 @@ const useLoginForm = (loading, error, login, callback) => {
|
|
|
24
27
|
autoComplete: 'new-password'
|
|
25
28
|
}
|
|
26
29
|
];
|
|
30
|
+
const fields = allFields.filter(i => !toRemove.includes(i.name));
|
|
27
31
|
(0, react_1.useEffect)(() => {
|
|
28
32
|
var _a, _b;
|
|
29
33
|
if (loading === 'idle') {
|
package/dist/cjs/utils/maps.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { Address, RevenueCenter, RevenueCenters, ServiceType } from '@open-tender/types';
|
|
2
|
-
export interface Point {
|
|
3
|
-
lat: number;
|
|
4
|
-
lng: number;
|
|
5
|
-
}
|
|
1
|
+
import { Address, LatLng, RevenueCenter, RevenueCenters, ServiceType } from '@open-tender/types';
|
|
6
2
|
export interface GooglePlaceAddressComponent {
|
|
7
3
|
types: Array<string | 'postal_code' | 'street_number' | 'route' | 'locality' | 'sublocality_level_1' | 'administrative_area_level_1'>;
|
|
8
4
|
long_name?: string;
|
|
@@ -14,8 +10,8 @@ export declare enum GooglePlaceBusinessStatus {
|
|
|
14
10
|
CLOSED_PERMANENTLY = "CLOSED_PERMANENTLY"
|
|
15
11
|
}
|
|
16
12
|
export interface GooglePlaceAdressGeometry {
|
|
17
|
-
location:
|
|
18
|
-
viewport: Record<string,
|
|
13
|
+
location: LatLng;
|
|
14
|
+
viewport: Record<string, LatLng>;
|
|
19
15
|
}
|
|
20
16
|
export interface GooglePlace {
|
|
21
17
|
address_components: Array<GooglePlaceAddressComponent>;
|
|
@@ -48,16 +44,16 @@ export declare const makeAddress: (place: GooglePlace) => {
|
|
|
48
44
|
lng: number | null;
|
|
49
45
|
formatted_address: string;
|
|
50
46
|
};
|
|
51
|
-
export declare const getDistance: (pointA:
|
|
52
|
-
export declare const inZone: (
|
|
53
|
-
export declare const addDistance: (revenueCenters: RevenueCenters,
|
|
47
|
+
export declare const getDistance: (pointA: LatLng, pointB: LatLng, inMiles?: boolean) => number;
|
|
48
|
+
export declare const inZone: (latLng: LatLng, polygon: number[][]) => boolean;
|
|
49
|
+
export declare const addDistance: (revenueCenters: RevenueCenters, latLng: LatLng) => RevenueCenters;
|
|
54
50
|
export declare const sortRevenueCenters: (revenueCenters: RevenueCenters, isDelivery?: boolean) => RevenueCenter[];
|
|
55
51
|
export declare const calcMinDistance: (revenueCenters: RevenueCenters, maxDistance?: number) => number;
|
|
56
52
|
export declare const checkServiceType: (revenueCenter: RevenueCenter, serviceType: ServiceType) => boolean;
|
|
57
53
|
export declare const makePickupRevenueCenters: (revenueCenters: Array<RevenueCenter>, maxDistance?: number) => RevenueCenter[];
|
|
58
54
|
export declare const makeWalkinRevenueCenters: (revenueCenters: Array<RevenueCenter>, maxDistance?: number) => RevenueCenter[];
|
|
59
55
|
export declare const makeDeliveryRevenueCenters: (revenueCenters: Array<RevenueCenter>) => RevenueCenter[];
|
|
60
|
-
export declare const makePickupMesssaging: (address: Address,
|
|
56
|
+
export declare const makePickupMesssaging: (address: Address | null, latLng: LatLng | null, count: number, minDistance: number, maxDistance?: number, messages?: {
|
|
61
57
|
PICKUP: {
|
|
62
58
|
default: {
|
|
63
59
|
title: string;
|
|
@@ -106,7 +102,7 @@ export declare const makePickupMesssaging: (address: Address, geoLatLng: any, co
|
|
|
106
102
|
title: string;
|
|
107
103
|
msg: string;
|
|
108
104
|
};
|
|
109
|
-
export declare const makeWalkinMessaging: (address: Address,
|
|
105
|
+
export declare const makeWalkinMessaging: (address: Address | null, latLng: LatLng | null, count: number, minDistance: number, maxDistance?: number, messages?: {
|
|
110
106
|
PICKUP: {
|
|
111
107
|
default: {
|
|
112
108
|
title: string;
|
|
@@ -155,7 +151,7 @@ export declare const makeWalkinMessaging: (address: Address, geoLatLng: any, cou
|
|
|
155
151
|
title: string;
|
|
156
152
|
msg: string;
|
|
157
153
|
};
|
|
158
|
-
export declare const makeDeliveryMesssaging: (address: Address, count: number, messages?: {
|
|
154
|
+
export declare const makeDeliveryMesssaging: (address: Address | null, count: number, messages?: {
|
|
159
155
|
PICKUP: {
|
|
160
156
|
default: {
|
|
161
157
|
title: string;
|
|
@@ -209,7 +205,7 @@ export declare const makeDeliveryMesssaging: (address: Address, count: number, m
|
|
|
209
205
|
msg: string;
|
|
210
206
|
error: string;
|
|
211
207
|
};
|
|
212
|
-
export declare const makeDisplayedRevenueCenters: (revenueCenters:
|
|
208
|
+
export declare const makeDisplayedRevenueCenters: (revenueCenters: RevenueCenter[], serviceType: ServiceType | null, address: Address | null, latLng: LatLng | null, maxDistance: number, isGroupOrder: boolean) => {
|
|
213
209
|
title: string;
|
|
214
210
|
msg: string;
|
|
215
211
|
error: string | null;
|
package/dist/cjs/utils/maps.js
CHANGED
|
@@ -69,21 +69,21 @@ const pointInPolygon = (point, vs) => {
|
|
|
69
69
|
}
|
|
70
70
|
return inside;
|
|
71
71
|
};
|
|
72
|
-
const inZone = (
|
|
73
|
-
const point = [
|
|
72
|
+
const inZone = (latLng, polygon) => {
|
|
73
|
+
const point = [latLng.lat, latLng.lng];
|
|
74
74
|
return pointInPolygon(point, polygon);
|
|
75
75
|
};
|
|
76
76
|
exports.inZone = inZone;
|
|
77
|
-
const addDistance = (revenueCenters,
|
|
78
|
-
if (!
|
|
77
|
+
const addDistance = (revenueCenters, latLng) => {
|
|
78
|
+
if (!latLng)
|
|
79
79
|
return revenueCenters;
|
|
80
80
|
const withDistance = revenueCenters.map(i => {
|
|
81
|
-
const
|
|
81
|
+
const iLatLng = i.address.lat
|
|
82
82
|
? { lat: i.address.lat, lng: i.address.lng }
|
|
83
83
|
: null;
|
|
84
|
-
i.distance =
|
|
84
|
+
i.distance = iLatLng ? (0, exports.getDistance)(latLng, iLatLng) : 1000;
|
|
85
85
|
const { coordinates, priority } = i.delivery_zone;
|
|
86
|
-
i.inZone = coordinates ? (0, exports.inZone)(
|
|
86
|
+
i.inZone = coordinates ? (0, exports.inZone)(latLng, coordinates) : false;
|
|
87
87
|
i.priority = priority !== null && priority !== void 0 ? priority : 0;
|
|
88
88
|
return i;
|
|
89
89
|
});
|
|
@@ -140,7 +140,7 @@ const makeDeliveryRevenueCenters = (revenueCenters) => {
|
|
|
140
140
|
return sorted.filter(i => i.inZone);
|
|
141
141
|
};
|
|
142
142
|
exports.makeDeliveryRevenueCenters = makeDeliveryRevenueCenters;
|
|
143
|
-
const makePickupMesssaging = (address,
|
|
143
|
+
const makePickupMesssaging = (address, latLng, count, minDistance, maxDistance = constants_1.MAX_DISTANCE, messages = exports.LOCATIONS_MESSAGES) => {
|
|
144
144
|
if (address) {
|
|
145
145
|
if (minDistance >= maxDistance) {
|
|
146
146
|
return messages.PICKUP.addressFar;
|
|
@@ -152,7 +152,7 @@ const makePickupMesssaging = (address, geoLatLng, count, minDistance, maxDistanc
|
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
-
else if (
|
|
155
|
+
else if (latLng) {
|
|
156
156
|
if (minDistance >= maxDistance) {
|
|
157
157
|
return messages.PICKUP.geoFar;
|
|
158
158
|
}
|
|
@@ -168,8 +168,8 @@ const makePickupMesssaging = (address, geoLatLng, count, minDistance, maxDistanc
|
|
|
168
168
|
}
|
|
169
169
|
};
|
|
170
170
|
exports.makePickupMesssaging = makePickupMesssaging;
|
|
171
|
-
const makeWalkinMessaging = (address,
|
|
172
|
-
const { title, msg } = (0, exports.makePickupMesssaging)(address,
|
|
171
|
+
const makeWalkinMessaging = (address, latLng, count, minDistance, maxDistance = constants_1.MAX_DISTANCE, messages = exports.LOCATIONS_MESSAGES) => {
|
|
172
|
+
const { title, msg } = (0, exports.makePickupMesssaging)(address, latLng, count, minDistance, maxDistance, messages);
|
|
173
173
|
return {
|
|
174
174
|
title: title.replace('pickup', 'dine-in'),
|
|
175
175
|
msg: msg.replace('pickup', 'dine-in')
|
|
@@ -198,30 +198,30 @@ const makeDeliveryMesssaging = (address, count, messages = exports.LOCATIONS_MES
|
|
|
198
198
|
}
|
|
199
199
|
};
|
|
200
200
|
exports.makeDeliveryMesssaging = makeDeliveryMesssaging;
|
|
201
|
-
const makeDisplayedRevenueCenters = (revenueCenters, serviceType, address,
|
|
201
|
+
const makeDisplayedRevenueCenters = (revenueCenters, serviceType, address, latLng, maxDistance, isGroupOrder) => {
|
|
202
202
|
const filtered = isGroupOrder
|
|
203
203
|
? revenueCenters.filter(i => i.group_ordering)
|
|
204
204
|
: revenueCenters;
|
|
205
|
-
if (serviceType === '
|
|
206
|
-
const displayed = (0, exports.
|
|
207
|
-
const minDistance = (0, exports.calcMinDistance)(displayed);
|
|
205
|
+
if (serviceType === 'DELIVERY') {
|
|
206
|
+
const displayed = (0, exports.makeDeliveryRevenueCenters)(filtered);
|
|
208
207
|
const count = displayed.length;
|
|
209
|
-
const { title, msg } = (0, exports.
|
|
210
|
-
const error = null;
|
|
208
|
+
const { title, msg, error } = (0, exports.makeDeliveryMesssaging)(address, count);
|
|
211
209
|
return { title, msg, error, displayed };
|
|
212
210
|
}
|
|
213
|
-
else if (serviceType === '
|
|
214
|
-
const displayed = (0, exports.
|
|
211
|
+
else if (serviceType === 'WALKIN') {
|
|
212
|
+
const displayed = (0, exports.makeWalkinRevenueCenters)(filtered, maxDistance);
|
|
215
213
|
const minDistance = (0, exports.calcMinDistance)(displayed);
|
|
216
214
|
const count = displayed.length;
|
|
217
|
-
const { title, msg } = (0, exports.
|
|
215
|
+
const { title, msg } = (0, exports.makeWalkinMessaging)(address, latLng, count, minDistance, maxDistance);
|
|
218
216
|
const error = null;
|
|
219
217
|
return { title, msg, error, displayed };
|
|
220
218
|
}
|
|
221
219
|
else {
|
|
222
|
-
const displayed = (0, exports.
|
|
220
|
+
const displayed = (0, exports.makePickupRevenueCenters)(filtered, maxDistance);
|
|
221
|
+
const minDistance = (0, exports.calcMinDistance)(displayed);
|
|
223
222
|
const count = displayed.length;
|
|
224
|
-
const { title, msg
|
|
223
|
+
const { title, msg } = (0, exports.makePickupMesssaging)(address, latLng, count, minDistance, maxDistance);
|
|
224
|
+
const error = null;
|
|
225
225
|
return { title, msg, error, displayed };
|
|
226
226
|
}
|
|
227
227
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string) => void, callback?: () => void) => {
|
|
2
|
+
import { LoginData, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string) => void, callback?: () => void, showPassword?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
fields:
|
|
6
|
+
fields: import("@open-tender/types").FormFieldType[];
|
|
7
7
|
data: LoginData;
|
|
8
8
|
errors: Record<string, string>;
|
|
9
9
|
submitting: boolean;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { useState, useEffect, useRef } from 'react';
|
|
2
2
|
import { makeFormErrors } from '../utils';
|
|
3
|
-
export const useLoginForm = (loading, error, login, callback) => {
|
|
3
|
+
export const useLoginForm = (loading, error, login, callback, showPassword = true) => {
|
|
4
4
|
const submitRef = useRef(null);
|
|
5
5
|
const inputRef = useRef(null);
|
|
6
6
|
const [data, setData] = useState({ email: '', password: '' });
|
|
7
7
|
const [errors, setErrors] = useState({});
|
|
8
8
|
const [submitting, setSubmitting] = useState(false);
|
|
9
|
-
const
|
|
9
|
+
const toRemove = [];
|
|
10
|
+
if (!showPassword)
|
|
11
|
+
toRemove.push('password');
|
|
12
|
+
const allFields = [
|
|
10
13
|
{
|
|
11
14
|
label: 'Email',
|
|
12
15
|
name: 'email',
|
|
@@ -21,6 +24,7 @@ export const useLoginForm = (loading, error, login, callback) => {
|
|
|
21
24
|
autoComplete: 'new-password'
|
|
22
25
|
}
|
|
23
26
|
];
|
|
27
|
+
const fields = allFields.filter(i => !toRemove.includes(i.name));
|
|
24
28
|
useEffect(() => {
|
|
25
29
|
var _a, _b;
|
|
26
30
|
if (loading === 'idle') {
|
package/dist/esm/utils/maps.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { Address, RevenueCenter, RevenueCenters, ServiceType } from '@open-tender/types';
|
|
2
|
-
export interface Point {
|
|
3
|
-
lat: number;
|
|
4
|
-
lng: number;
|
|
5
|
-
}
|
|
1
|
+
import { Address, LatLng, RevenueCenter, RevenueCenters, ServiceType } from '@open-tender/types';
|
|
6
2
|
export interface GooglePlaceAddressComponent {
|
|
7
3
|
types: Array<string | 'postal_code' | 'street_number' | 'route' | 'locality' | 'sublocality_level_1' | 'administrative_area_level_1'>;
|
|
8
4
|
long_name?: string;
|
|
@@ -14,8 +10,8 @@ export declare enum GooglePlaceBusinessStatus {
|
|
|
14
10
|
CLOSED_PERMANENTLY = "CLOSED_PERMANENTLY"
|
|
15
11
|
}
|
|
16
12
|
export interface GooglePlaceAdressGeometry {
|
|
17
|
-
location:
|
|
18
|
-
viewport: Record<string,
|
|
13
|
+
location: LatLng;
|
|
14
|
+
viewport: Record<string, LatLng>;
|
|
19
15
|
}
|
|
20
16
|
export interface GooglePlace {
|
|
21
17
|
address_components: Array<GooglePlaceAddressComponent>;
|
|
@@ -48,16 +44,16 @@ export declare const makeAddress: (place: GooglePlace) => {
|
|
|
48
44
|
lng: number | null;
|
|
49
45
|
formatted_address: string;
|
|
50
46
|
};
|
|
51
|
-
export declare const getDistance: (pointA:
|
|
52
|
-
export declare const inZone: (
|
|
53
|
-
export declare const addDistance: (revenueCenters: RevenueCenters,
|
|
47
|
+
export declare const getDistance: (pointA: LatLng, pointB: LatLng, inMiles?: boolean) => number;
|
|
48
|
+
export declare const inZone: (latLng: LatLng, polygon: number[][]) => boolean;
|
|
49
|
+
export declare const addDistance: (revenueCenters: RevenueCenters, latLng: LatLng) => RevenueCenters;
|
|
54
50
|
export declare const sortRevenueCenters: (revenueCenters: RevenueCenters, isDelivery?: boolean) => RevenueCenter[];
|
|
55
51
|
export declare const calcMinDistance: (revenueCenters: RevenueCenters, maxDistance?: number) => number;
|
|
56
52
|
export declare const checkServiceType: (revenueCenter: RevenueCenter, serviceType: ServiceType) => boolean;
|
|
57
53
|
export declare const makePickupRevenueCenters: (revenueCenters: Array<RevenueCenter>, maxDistance?: number) => RevenueCenter[];
|
|
58
54
|
export declare const makeWalkinRevenueCenters: (revenueCenters: Array<RevenueCenter>, maxDistance?: number) => RevenueCenter[];
|
|
59
55
|
export declare const makeDeliveryRevenueCenters: (revenueCenters: Array<RevenueCenter>) => RevenueCenter[];
|
|
60
|
-
export declare const makePickupMesssaging: (address: Address,
|
|
56
|
+
export declare const makePickupMesssaging: (address: Address | null, latLng: LatLng | null, count: number, minDistance: number, maxDistance?: number, messages?: {
|
|
61
57
|
PICKUP: {
|
|
62
58
|
default: {
|
|
63
59
|
title: string;
|
|
@@ -106,7 +102,7 @@ export declare const makePickupMesssaging: (address: Address, geoLatLng: any, co
|
|
|
106
102
|
title: string;
|
|
107
103
|
msg: string;
|
|
108
104
|
};
|
|
109
|
-
export declare const makeWalkinMessaging: (address: Address,
|
|
105
|
+
export declare const makeWalkinMessaging: (address: Address | null, latLng: LatLng | null, count: number, minDistance: number, maxDistance?: number, messages?: {
|
|
110
106
|
PICKUP: {
|
|
111
107
|
default: {
|
|
112
108
|
title: string;
|
|
@@ -155,7 +151,7 @@ export declare const makeWalkinMessaging: (address: Address, geoLatLng: any, cou
|
|
|
155
151
|
title: string;
|
|
156
152
|
msg: string;
|
|
157
153
|
};
|
|
158
|
-
export declare const makeDeliveryMesssaging: (address: Address, count: number, messages?: {
|
|
154
|
+
export declare const makeDeliveryMesssaging: (address: Address | null, count: number, messages?: {
|
|
159
155
|
PICKUP: {
|
|
160
156
|
default: {
|
|
161
157
|
title: string;
|
|
@@ -209,7 +205,7 @@ export declare const makeDeliveryMesssaging: (address: Address, count: number, m
|
|
|
209
205
|
msg: string;
|
|
210
206
|
error: string;
|
|
211
207
|
};
|
|
212
|
-
export declare const makeDisplayedRevenueCenters: (revenueCenters:
|
|
208
|
+
export declare const makeDisplayedRevenueCenters: (revenueCenters: RevenueCenter[], serviceType: ServiceType | null, address: Address | null, latLng: LatLng | null, maxDistance: number, isGroupOrder: boolean) => {
|
|
213
209
|
title: string;
|
|
214
210
|
msg: string;
|
|
215
211
|
error: string | null;
|
package/dist/esm/utils/maps.js
CHANGED
|
@@ -64,20 +64,20 @@ const pointInPolygon = (point, vs) => {
|
|
|
64
64
|
}
|
|
65
65
|
return inside;
|
|
66
66
|
};
|
|
67
|
-
export const inZone = (
|
|
68
|
-
const point = [
|
|
67
|
+
export const inZone = (latLng, polygon) => {
|
|
68
|
+
const point = [latLng.lat, latLng.lng];
|
|
69
69
|
return pointInPolygon(point, polygon);
|
|
70
70
|
};
|
|
71
|
-
export const addDistance = (revenueCenters,
|
|
72
|
-
if (!
|
|
71
|
+
export const addDistance = (revenueCenters, latLng) => {
|
|
72
|
+
if (!latLng)
|
|
73
73
|
return revenueCenters;
|
|
74
74
|
const withDistance = revenueCenters.map(i => {
|
|
75
|
-
const
|
|
75
|
+
const iLatLng = i.address.lat
|
|
76
76
|
? { lat: i.address.lat, lng: i.address.lng }
|
|
77
77
|
: null;
|
|
78
|
-
i.distance =
|
|
78
|
+
i.distance = iLatLng ? getDistance(latLng, iLatLng) : 1000;
|
|
79
79
|
const { coordinates, priority } = i.delivery_zone;
|
|
80
|
-
i.inZone = coordinates ? inZone(
|
|
80
|
+
i.inZone = coordinates ? inZone(latLng, coordinates) : false;
|
|
81
81
|
i.priority = priority !== null && priority !== void 0 ? priority : 0;
|
|
82
82
|
return i;
|
|
83
83
|
});
|
|
@@ -127,7 +127,7 @@ export const makeDeliveryRevenueCenters = (revenueCenters) => {
|
|
|
127
127
|
const sorted = sortRevenueCenters(hasDelivery, true);
|
|
128
128
|
return sorted.filter(i => i.inZone);
|
|
129
129
|
};
|
|
130
|
-
export const makePickupMesssaging = (address,
|
|
130
|
+
export const makePickupMesssaging = (address, latLng, count, minDistance, maxDistance = MAX_DISTANCE, messages = LOCATIONS_MESSAGES) => {
|
|
131
131
|
if (address) {
|
|
132
132
|
if (minDistance >= maxDistance) {
|
|
133
133
|
return messages.PICKUP.addressFar;
|
|
@@ -139,7 +139,7 @@ export const makePickupMesssaging = (address, geoLatLng, count, minDistance, max
|
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
else if (
|
|
142
|
+
else if (latLng) {
|
|
143
143
|
if (minDistance >= maxDistance) {
|
|
144
144
|
return messages.PICKUP.geoFar;
|
|
145
145
|
}
|
|
@@ -154,8 +154,8 @@ export const makePickupMesssaging = (address, geoLatLng, count, minDistance, max
|
|
|
154
154
|
return messages.PICKUP.default;
|
|
155
155
|
}
|
|
156
156
|
};
|
|
157
|
-
export const makeWalkinMessaging = (address,
|
|
158
|
-
const { title, msg } = makePickupMesssaging(address,
|
|
157
|
+
export const makeWalkinMessaging = (address, latLng, count, minDistance, maxDistance = MAX_DISTANCE, messages = LOCATIONS_MESSAGES) => {
|
|
158
|
+
const { title, msg } = makePickupMesssaging(address, latLng, count, minDistance, maxDistance, messages);
|
|
159
159
|
return {
|
|
160
160
|
title: title.replace('pickup', 'dine-in'),
|
|
161
161
|
msg: msg.replace('pickup', 'dine-in')
|
|
@@ -182,30 +182,30 @@ export const makeDeliveryMesssaging = (address, count, messages = LOCATIONS_MESS
|
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
};
|
|
185
|
-
export const makeDisplayedRevenueCenters = (revenueCenters, serviceType, address,
|
|
185
|
+
export const makeDisplayedRevenueCenters = (revenueCenters, serviceType, address, latLng, maxDistance, isGroupOrder) => {
|
|
186
186
|
const filtered = isGroupOrder
|
|
187
187
|
? revenueCenters.filter(i => i.group_ordering)
|
|
188
188
|
: revenueCenters;
|
|
189
|
-
if (serviceType === '
|
|
190
|
-
const displayed =
|
|
191
|
-
const minDistance = calcMinDistance(displayed);
|
|
189
|
+
if (serviceType === 'DELIVERY') {
|
|
190
|
+
const displayed = makeDeliveryRevenueCenters(filtered);
|
|
192
191
|
const count = displayed.length;
|
|
193
|
-
const { title, msg } =
|
|
194
|
-
const error = null;
|
|
192
|
+
const { title, msg, error } = makeDeliveryMesssaging(address, count);
|
|
195
193
|
return { title, msg, error, displayed };
|
|
196
194
|
}
|
|
197
|
-
else if (serviceType === '
|
|
198
|
-
const displayed =
|
|
195
|
+
else if (serviceType === 'WALKIN') {
|
|
196
|
+
const displayed = makeWalkinRevenueCenters(filtered, maxDistance);
|
|
199
197
|
const minDistance = calcMinDistance(displayed);
|
|
200
198
|
const count = displayed.length;
|
|
201
|
-
const { title, msg } =
|
|
199
|
+
const { title, msg } = makeWalkinMessaging(address, latLng, count, minDistance, maxDistance);
|
|
202
200
|
const error = null;
|
|
203
201
|
return { title, msg, error, displayed };
|
|
204
202
|
}
|
|
205
203
|
else {
|
|
206
|
-
const displayed =
|
|
204
|
+
const displayed = makePickupRevenueCenters(filtered, maxDistance);
|
|
205
|
+
const minDistance = calcMinDistance(displayed);
|
|
207
206
|
const count = displayed.length;
|
|
208
|
-
const { title, msg
|
|
207
|
+
const { title, msg } = makePickupMesssaging(address, latLng, count, minDistance, maxDistance);
|
|
208
|
+
const error = null;
|
|
209
209
|
return { title, msg, error, displayed };
|
|
210
210
|
}
|
|
211
211
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.97",
|
|
4
4
|
"description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"typescript": "^4.8.2"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@open-tender/types": "^0.
|
|
56
|
+
"@open-tender/types": "^0.2.43",
|
|
57
57
|
"@reduxjs/toolkit": "^1.8.5",
|
|
58
58
|
"react": "^18.2.0"
|
|
59
59
|
},
|