@open-tender/utils 0.4.31 → 0.4.33
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/LICENSE.md +21 -21
- package/README.md +2 -2
- package/dist/cjs/__tests__/utils/helpers.test.d.ts +1 -1
- package/dist/cjs/__tests__/utils/helpers.test.js +96 -96
- package/dist/cjs/__tests__/utils/theme.test.d.ts +1 -1
- package/dist/cjs/__tests__/utils/theme.test.js +37 -37
- package/dist/cjs/hooks/index.d.ts +35 -35
- package/dist/cjs/hooks/index.js +38 -38
- package/dist/cjs/hooks/types.d.ts +4 -4
- package/dist/cjs/hooks/types.js +2 -2
- package/dist/cjs/hooks/useAccordion.d.ts +22 -22
- package/dist/cjs/hooks/useAccordion.js +56 -56
- package/dist/cjs/hooks/useAddressForm.d.ts +12 -12
- package/dist/cjs/hooks/useAddressForm.js +83 -83
- package/dist/cjs/hooks/useAllergenForm.d.ts +10 -10
- package/dist/cjs/hooks/useAllergenForm.js +58 -58
- package/dist/cjs/hooks/useBuilder.d.ts +14 -14
- package/dist/cjs/hooks/useBuilder.js +144 -144
- package/dist/cjs/hooks/useCartGuestForm.d.ts +12 -12
- package/dist/cjs/hooks/useCartGuestForm.js +58 -58
- package/dist/cjs/hooks/useCartPoints.d.ts +13 -13
- package/dist/cjs/hooks/useCartPoints.js +74 -74
- package/dist/cjs/hooks/useCommunicationPreferences.js +1 -1
- package/dist/cjs/hooks/useCreditCard.d.ts +13 -13
- package/dist/cjs/hooks/useCreditCard.js +63 -63
- package/dist/cjs/hooks/useCreditCardForm.d.ts +10 -10
- package/dist/cjs/hooks/useCreditCardForm.js +71 -71
- package/dist/cjs/hooks/useCurbside.d.ts +9 -9
- package/dist/cjs/hooks/useCurbside.js +39 -39
- package/dist/cjs/hooks/useDineInForm.d.ts +11 -11
- package/dist/cjs/hooks/useDineInForm.js +56 -56
- package/dist/cjs/hooks/useDonationForm.d.ts +28 -28
- package/dist/cjs/hooks/useDonationForm.js +172 -172
- package/dist/cjs/hooks/useFirstTimes.d.ts +18 -18
- package/dist/cjs/hooks/useFirstTimes.js +81 -81
- package/dist/cjs/hooks/useGiftCardAssignForm.d.ts +14 -14
- package/dist/cjs/hooks/useGiftCardAssignForm.js +57 -57
- package/dist/cjs/hooks/useGiftCardAssignOtherForm.d.ts +14 -14
- package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +50 -50
- package/dist/cjs/hooks/useGiftCardForm.d.ts +12 -12
- package/dist/cjs/hooks/useGiftCardForm.js +74 -74
- package/dist/cjs/hooks/useGiftCardsForm.d.ts +31 -31
- package/dist/cjs/hooks/useGiftCardsForm.js +195 -195
- package/dist/cjs/hooks/useGuestCheckoutForm.d.ts +21 -21
- package/dist/cjs/hooks/useGuestCheckoutForm.js +89 -89
- package/dist/cjs/hooks/useGuestForm.d.ts +12 -12
- package/dist/cjs/hooks/useGuestForm.js +60 -60
- package/dist/cjs/hooks/useImage.d.ts +5 -5
- package/dist/cjs/hooks/useImage.js +33 -33
- package/dist/cjs/hooks/useLoginForm.d.ts +12 -12
- package/dist/cjs/hooks/useLoginForm.js +67 -67
- package/dist/cjs/hooks/useMenuItem.d.ts +57 -57
- package/dist/cjs/hooks/useMenuItem.js +67 -67
- package/dist/cjs/hooks/useModifier.d.ts +53 -53
- package/dist/cjs/hooks/useModifier.js +72 -72
- package/dist/cjs/hooks/useModifierGroup.d.ts +15 -15
- package/dist/cjs/hooks/useModifierGroup.js +17 -17
- package/dist/cjs/hooks/useOneTimePasscodeForm.d.ts +16 -16
- package/dist/cjs/hooks/useOneTimePasscodeForm.js +87 -87
- package/dist/cjs/hooks/useOrderFulfillmentForm.d.ts +11 -11
- package/dist/cjs/hooks/useOrderFulfillmentForm.js +65 -65
- package/dist/cjs/hooks/useOrderItem.d.ts +48 -48
- package/dist/cjs/hooks/useOrderItem.js +54 -54
- package/dist/cjs/hooks/useOrderRating.d.ts +10 -10
- package/dist/cjs/hooks/useOrderRating.js +34 -34
- package/dist/cjs/hooks/useOrderRatingForm.d.ts +11 -11
- package/dist/cjs/hooks/useOrderRatingForm.js +35 -35
- package/dist/cjs/hooks/useProfileForm.d.ts +15 -15
- package/dist/cjs/hooks/useProfileForm.js +116 -116
- package/dist/cjs/hooks/useResetPasswordForm.d.ts +12 -12
- package/dist/cjs/hooks/useResetPasswordForm.js +77 -77
- package/dist/cjs/hooks/useSendResetForm.d.ts +14 -14
- package/dist/cjs/hooks/useSendResetForm.js +57 -57
- package/dist/cjs/hooks/useSignUpForm.d.ts +20 -20
- package/dist/cjs/hooks/useSignUpForm.js +160 -151
- package/dist/cjs/hooks/useSignUpGuestForm.d.ts +23 -23
- package/dist/cjs/hooks/useSignUpGuestForm.js +124 -113
- package/dist/cjs/hooks/useSigninForm.d.ts +12 -12
- package/dist/cjs/hooks/useSigninForm.js +66 -66
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +5 -5
- package/dist/cjs/utils/cards.d.ts +20 -20
- package/dist/cjs/utils/cards.js +155 -155
- package/dist/cjs/utils/cart.d.ts +202 -202
- package/dist/cjs/utils/cart.js +909 -909
- package/dist/cjs/utils/checkout.d.ts +55 -55
- package/dist/cjs/utils/checkout.js +125 -125
- package/dist/cjs/utils/constants.d.ts +43 -43
- package/dist/cjs/utils/constants.js +58 -58
- package/dist/cjs/utils/customer.d.ts +4 -4
- package/dist/cjs/utils/customer.js +34 -34
- package/dist/cjs/utils/datetimes.d.ts +99 -99
- package/dist/cjs/utils/datetimes.js +601 -601
- package/dist/cjs/utils/errors.d.ts +51 -51
- package/dist/cjs/utils/errors.js +191 -191
- package/dist/cjs/utils/favorites.d.ts +10 -10
- package/dist/cjs/utils/favorites.js +119 -119
- package/dist/cjs/utils/googleMaps.d.ts +14 -14
- package/dist/cjs/utils/googleMaps.js +30 -30
- package/dist/cjs/utils/helpers.d.ts +63 -63
- package/dist/cjs/utils/helpers.js +244 -244
- package/dist/cjs/utils/index.d.ts +19 -19
- package/dist/cjs/utils/index.js +23 -23
- package/dist/cjs/utils/keypad.d.ts +9 -9
- package/dist/cjs/utils/keypad.js +105 -105
- package/dist/cjs/utils/maps.d.ts +226 -226
- package/dist/cjs/utils/maps.js +334 -334
- package/dist/cjs/utils/menu.d.ts +117 -117
- package/dist/cjs/utils/menu.js +82 -82
- package/dist/cjs/utils/orders.d.ts +21 -21
- package/dist/cjs/utils/orders.js +202 -202
- package/dist/cjs/utils/pizzaBuilder.d.ts +10 -10
- package/dist/cjs/utils/pizzaBuilder.js +43 -43
- package/dist/cjs/utils/refunds.d.ts +35 -35
- package/dist/cjs/utils/refunds.js +98 -98
- package/dist/cjs/utils/revenueCenters.d.ts +11 -11
- package/dist/cjs/utils/revenueCenters.js +125 -125
- package/dist/cjs/utils/rewards.d.ts +4 -4
- package/dist/cjs/utils/rewards.js +106 -106
- package/dist/cjs/utils/theme.d.ts +27 -27
- package/dist/cjs/utils/theme.js +266 -266
- package/dist/cjs/utils/version.d.ts +4 -4
- package/dist/cjs/utils/version.js +38 -38
- package/dist/esm/__tests__/utils/helpers.test.d.ts +1 -1
- package/dist/esm/__tests__/utils/helpers.test.js +94 -94
- package/dist/esm/__tests__/utils/theme.test.d.ts +1 -1
- package/dist/esm/__tests__/utils/theme.test.js +35 -35
- package/dist/esm/hooks/index.d.ts +35 -35
- package/dist/esm/hooks/index.js +35 -35
- package/dist/esm/hooks/types.d.ts +4 -4
- package/dist/esm/hooks/types.js +1 -1
- package/dist/esm/hooks/useAccordion.d.ts +22 -22
- package/dist/esm/hooks/useAccordion.js +52 -52
- package/dist/esm/hooks/useAddressForm.d.ts +12 -12
- package/dist/esm/hooks/useAddressForm.js +79 -79
- package/dist/esm/hooks/useAllergenForm.d.ts +10 -10
- package/dist/esm/hooks/useAllergenForm.js +54 -54
- package/dist/esm/hooks/useBuilder.d.ts +14 -14
- package/dist/esm/hooks/useBuilder.js +140 -140
- package/dist/esm/hooks/useCartGuestForm.d.ts +12 -12
- package/dist/esm/hooks/useCartGuestForm.js +54 -54
- package/dist/esm/hooks/useCartPoints.d.ts +13 -13
- package/dist/esm/hooks/useCartPoints.js +70 -70
- package/dist/esm/hooks/useCommunicationPreferences.js +1 -1
- package/dist/esm/hooks/useCreditCard.d.ts +13 -13
- package/dist/esm/hooks/useCreditCard.js +59 -59
- package/dist/esm/hooks/useCreditCardForm.d.ts +10 -10
- package/dist/esm/hooks/useCreditCardForm.js +67 -67
- package/dist/esm/hooks/useCurbside.d.ts +9 -9
- package/dist/esm/hooks/useCurbside.js +35 -35
- package/dist/esm/hooks/useDineInForm.d.ts +11 -11
- package/dist/esm/hooks/useDineInForm.js +52 -52
- package/dist/esm/hooks/useDonationForm.d.ts +28 -28
- package/dist/esm/hooks/useDonationForm.js +168 -168
- package/dist/esm/hooks/useFirstTimes.d.ts +18 -18
- package/dist/esm/hooks/useFirstTimes.js +77 -77
- package/dist/esm/hooks/useGiftCardAssignForm.d.ts +14 -14
- package/dist/esm/hooks/useGiftCardAssignForm.js +53 -53
- package/dist/esm/hooks/useGiftCardAssignOtherForm.d.ts +14 -14
- package/dist/esm/hooks/useGiftCardAssignOtherForm.js +46 -46
- package/dist/esm/hooks/useGiftCardForm.d.ts +12 -12
- package/dist/esm/hooks/useGiftCardForm.js +70 -70
- package/dist/esm/hooks/useGiftCardsForm.d.ts +31 -31
- package/dist/esm/hooks/useGiftCardsForm.js +191 -191
- package/dist/esm/hooks/useGuestCheckoutForm.d.ts +21 -21
- package/dist/esm/hooks/useGuestCheckoutForm.js +85 -85
- package/dist/esm/hooks/useGuestForm.d.ts +12 -12
- package/dist/esm/hooks/useGuestForm.js +56 -56
- package/dist/esm/hooks/useImage.d.ts +5 -5
- package/dist/esm/hooks/useImage.js +29 -29
- package/dist/esm/hooks/useLoginForm.d.ts +12 -12
- package/dist/esm/hooks/useLoginForm.js +63 -63
- package/dist/esm/hooks/useMenuItem.d.ts +57 -57
- package/dist/esm/hooks/useMenuItem.js +63 -63
- package/dist/esm/hooks/useModifier.d.ts +53 -53
- package/dist/esm/hooks/useModifier.js +68 -68
- package/dist/esm/hooks/useModifierGroup.d.ts +15 -15
- package/dist/esm/hooks/useModifierGroup.js +13 -13
- package/dist/esm/hooks/useOneTimePasscodeForm.d.ts +16 -16
- package/dist/esm/hooks/useOneTimePasscodeForm.js +83 -83
- package/dist/esm/hooks/useOrderFulfillmentForm.d.ts +11 -11
- package/dist/esm/hooks/useOrderFulfillmentForm.js +61 -61
- package/dist/esm/hooks/useOrderItem.d.ts +48 -48
- package/dist/esm/hooks/useOrderItem.js +50 -50
- package/dist/esm/hooks/useOrderRating.d.ts +10 -10
- package/dist/esm/hooks/useOrderRating.js +30 -30
- package/dist/esm/hooks/useOrderRatingForm.d.ts +11 -11
- package/dist/esm/hooks/useOrderRatingForm.js +31 -31
- package/dist/esm/hooks/useProfileForm.d.ts +15 -15
- package/dist/esm/hooks/useProfileForm.js +112 -112
- package/dist/esm/hooks/useResetPasswordForm.d.ts +12 -12
- package/dist/esm/hooks/useResetPasswordForm.js +73 -73
- package/dist/esm/hooks/useSendResetForm.d.ts +14 -14
- package/dist/esm/hooks/useSendResetForm.js +53 -53
- package/dist/esm/hooks/useSignUpForm.d.ts +20 -20
- package/dist/esm/hooks/useSignUpForm.js +156 -147
- package/dist/esm/hooks/useSignUpGuestForm.d.ts +23 -23
- package/dist/esm/hooks/useSignUpGuestForm.js +120 -109
- package/dist/esm/hooks/useSigninForm.d.ts +12 -12
- package/dist/esm/hooks/useSigninForm.js +62 -62
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/utils/cards.d.ts +20 -20
- package/dist/esm/utils/cards.js +146 -146
- package/dist/esm/utils/cart.d.ts +202 -202
- package/dist/esm/utils/cart.js +868 -868
- package/dist/esm/utils/checkout.d.ts +55 -55
- package/dist/esm/utils/checkout.js +117 -117
- package/dist/esm/utils/constants.d.ts +43 -43
- package/dist/esm/utils/constants.js +55 -55
- package/dist/esm/utils/customer.d.ts +4 -4
- package/dist/esm/utils/customer.js +29 -29
- package/dist/esm/utils/datetimes.d.ts +99 -99
- package/dist/esm/utils/datetimes.js +531 -531
- package/dist/esm/utils/errors.d.ts +51 -51
- package/dist/esm/utils/errors.js +180 -180
- package/dist/esm/utils/favorites.d.ts +10 -10
- package/dist/esm/utils/favorites.js +109 -109
- package/dist/esm/utils/googleMaps.d.ts +14 -14
- package/dist/esm/utils/googleMaps.js +26 -26
- package/dist/esm/utils/helpers.d.ts +63 -63
- package/dist/esm/utils/helpers.js +205 -205
- package/dist/esm/utils/index.d.ts +19 -19
- package/dist/esm/utils/index.js +20 -20
- package/dist/esm/utils/keypad.d.ts +9 -9
- package/dist/esm/utils/keypad.js +97 -97
- package/dist/esm/utils/maps.d.ts +226 -226
- package/dist/esm/utils/maps.js +316 -316
- package/dist/esm/utils/menu.d.ts +117 -117
- package/dist/esm/utils/menu.js +74 -74
- package/dist/esm/utils/orders.d.ts +21 -21
- package/dist/esm/utils/orders.js +185 -185
- package/dist/esm/utils/pizzaBuilder.d.ts +10 -10
- package/dist/esm/utils/pizzaBuilder.js +38 -38
- package/dist/esm/utils/refunds.d.ts +35 -35
- package/dist/esm/utils/refunds.js +90 -90
- package/dist/esm/utils/revenueCenters.d.ts +11 -11
- package/dist/esm/utils/revenueCenters.js +115 -115
- package/dist/esm/utils/rewards.d.ts +4 -4
- package/dist/esm/utils/rewards.js +100 -100
- package/dist/esm/utils/theme.d.ts +27 -27
- package/dist/esm/utils/theme.js +254 -254
- package/dist/esm/utils/version.d.ts +4 -4
- package/dist/esm/utils/version.js +34 -34
- package/package.json +69 -68
package/dist/esm/utils/maps.js
CHANGED
|
@@ -1,316 +1,316 @@
|
|
|
1
|
-
import { MAX_DISTANCE } from './constants';
|
|
2
|
-
const RADIUS_MILES = 3959; // radius of the earth in miles
|
|
3
|
-
const RADIUS_KM = 6371; // radius of the earth in kilometers
|
|
4
|
-
// https://stackoverflow.com/questions/18883601/function-to-calculate-distance-between-two-coordinates
|
|
5
|
-
export const getDistance = (pointA, pointB, inMiles = true) => {
|
|
6
|
-
const { lat: lat1, lng: lng1 } = pointA;
|
|
7
|
-
const { lat: lat2, lng: lng2 } = pointB;
|
|
8
|
-
const R = inMiles ? RADIUS_MILES : RADIUS_KM;
|
|
9
|
-
const dLat = deg2rad(lat2 - lat1); // see deg2rad below
|
|
10
|
-
const dLng = deg2rad(lng2 - lng1);
|
|
11
|
-
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
|
12
|
-
Math.cos(deg2rad(lat1)) *
|
|
13
|
-
Math.cos(deg2rad(lat2)) *
|
|
14
|
-
Math.sin(dLng / 2) *
|
|
15
|
-
Math.sin(dLng / 2);
|
|
16
|
-
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
17
|
-
const d = R * c;
|
|
18
|
-
return d;
|
|
19
|
-
};
|
|
20
|
-
const deg2rad = (deg) => {
|
|
21
|
-
return deg * (Math.PI / 180);
|
|
22
|
-
};
|
|
23
|
-
// ray-casting algorithm based on
|
|
24
|
-
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
|
25
|
-
const pointInPolygon = (point, vs) => {
|
|
26
|
-
const x = point[0], y = point[1];
|
|
27
|
-
let inside = false;
|
|
28
|
-
for (let i = 0, j = vs.length - 1; i < vs.length; j = i++) {
|
|
29
|
-
const xi = vs[i][0], yi = vs[i][1];
|
|
30
|
-
const xj = vs[j][0], yj = vs[j][1];
|
|
31
|
-
const intersect = yi > y != yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
|
|
32
|
-
if (intersect)
|
|
33
|
-
inside = !inside;
|
|
34
|
-
}
|
|
35
|
-
return inside;
|
|
36
|
-
};
|
|
37
|
-
export const inZone = (latLng, polygon) => {
|
|
38
|
-
const point = [latLng.lat, latLng.lng];
|
|
39
|
-
return pointInPolygon(point, polygon);
|
|
40
|
-
};
|
|
41
|
-
export const addDistance = (revenueCenters, latLng) => {
|
|
42
|
-
if (!latLng)
|
|
43
|
-
return revenueCenters;
|
|
44
|
-
const withDistance = revenueCenters.map(i => {
|
|
45
|
-
const iLatLng = i.address.lat
|
|
46
|
-
? { lat: i.address.lat, lng: i.address.lng }
|
|
47
|
-
: null;
|
|
48
|
-
i.distance = iLatLng ? getDistance(latLng, iLatLng) : 1000;
|
|
49
|
-
const { coordinates, priority } = i.delivery_zone;
|
|
50
|
-
i.inZone = coordinates ? inZone(latLng, coordinates) : false;
|
|
51
|
-
i.priority = priority !== null && priority !== void 0 ? priority : 0;
|
|
52
|
-
return i;
|
|
53
|
-
});
|
|
54
|
-
return withDistance;
|
|
55
|
-
};
|
|
56
|
-
export const sortRevenueCenters = (revenueCenters, isDelivery = false) => {
|
|
57
|
-
if (!isDelivery) {
|
|
58
|
-
return [...revenueCenters].sort((a, b) => { var _a, _b; return ((_a = a.distance) !== null && _a !== void 0 ? _a : 0) - ((_b = b.distance) !== null && _b !== void 0 ? _b : 0); });
|
|
59
|
-
}
|
|
60
|
-
const inZoneWithPriority = revenueCenters
|
|
61
|
-
.filter(i => i.inZone && i.priority)
|
|
62
|
-
.sort((a, b) => { var _a, _b; return ((_a = a.priority) !== null && _a !== void 0 ? _a : 0) - ((_b = b.priority) !== null && _b !== void 0 ? _b : 0); });
|
|
63
|
-
const inZoneWithoutPriority = revenueCenters
|
|
64
|
-
.filter(i => i.inZone && !i.priority)
|
|
65
|
-
.sort((a, b) => { var _a, _b; return ((_a = a.distance) !== null && _a !== void 0 ? _a : 0) - ((_b = b.distance) !== null && _b !== void 0 ? _b : 0); });
|
|
66
|
-
const outOfZone = revenueCenters
|
|
67
|
-
.filter(i => !i.inZone)
|
|
68
|
-
.sort((a, b) => { var _a, _b; return ((_a = a.distance) !== null && _a !== void 0 ? _a : 0) - ((_b = b.distance) !== null && _b !== void 0 ? _b : 0); });
|
|
69
|
-
return [...inZoneWithPriority, ...inZoneWithoutPriority, ...outOfZone];
|
|
70
|
-
};
|
|
71
|
-
export const calcMinDistance = (revenueCenters, maxDistance = MAX_DISTANCE) => {
|
|
72
|
-
const withDistance = revenueCenters
|
|
73
|
-
.filter(i => i.distance !== null && i.distance !== undefined)
|
|
74
|
-
.map(i => { var _a; return (_a = i.distance) !== null && _a !== void 0 ? _a : 0; });
|
|
75
|
-
return withDistance ? Math.min(...withDistance) : maxDistance;
|
|
76
|
-
};
|
|
77
|
-
export const checkServiceType = (revenueCenter, serviceType) => {
|
|
78
|
-
const { service_types } = revenueCenter;
|
|
79
|
-
if (!service_types)
|
|
80
|
-
return false;
|
|
81
|
-
return service_types.includes(serviceType);
|
|
82
|
-
};
|
|
83
|
-
export const makePickupRevenueCenters = (revenueCenters, maxDistance = MAX_DISTANCE) => {
|
|
84
|
-
const hasPickup = revenueCenters
|
|
85
|
-
.filter(i => checkServiceType(i, 'PICKUP'))
|
|
86
|
-
.filter(i => !i.distance || i.distance < maxDistance);
|
|
87
|
-
return sortRevenueCenters(hasPickup);
|
|
88
|
-
};
|
|
89
|
-
export const makeWalkinRevenueCenters = (revenueCenters, maxDistance = MAX_DISTANCE) => {
|
|
90
|
-
const hasWalkin = revenueCenters
|
|
91
|
-
.filter(i => checkServiceType(i, 'WALKIN'))
|
|
92
|
-
.filter(i => !i.distance || i.distance < maxDistance);
|
|
93
|
-
return sortRevenueCenters(hasWalkin);
|
|
94
|
-
};
|
|
95
|
-
export const makeDeliveryRevenueCenters = (revenueCenters) => {
|
|
96
|
-
const hasDelivery = revenueCenters.filter(i => checkServiceType(i, 'DELIVERY'));
|
|
97
|
-
const sorted = sortRevenueCenters(hasDelivery, true);
|
|
98
|
-
return sorted.filter(i => i.inZone);
|
|
99
|
-
};
|
|
100
|
-
export const makePickupMesssaging = (address, latLng, count, minDistance, maxDistance = MAX_DISTANCE, messages = LOCATIONS_MESSAGES) => {
|
|
101
|
-
if (address) {
|
|
102
|
-
if (minDistance >= maxDistance) {
|
|
103
|
-
return messages.PICKUP.addressFar;
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
return {
|
|
107
|
-
title: `${count} ${messages.PICKUP.address.title}`,
|
|
108
|
-
msg: messages.PICKUP.address.msg
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
else if (latLng) {
|
|
113
|
-
if (minDistance >= maxDistance) {
|
|
114
|
-
return messages.PICKUP.geoFar;
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
return {
|
|
118
|
-
title: `${count} ${messages.PICKUP.geo.title}`,
|
|
119
|
-
msg: messages.PICKUP.geo.msg
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
return messages.PICKUP.default;
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
export const makeWalkinMessaging = (address, latLng, count, minDistance, maxDistance = MAX_DISTANCE, messages = LOCATIONS_MESSAGES) => {
|
|
128
|
-
const { title, msg } = makePickupMesssaging(address, latLng, count, minDistance, maxDistance, messages);
|
|
129
|
-
return {
|
|
130
|
-
title: title.replace('pickup', 'dine-in'),
|
|
131
|
-
msg: msg.replace('pickup', 'dine-in')
|
|
132
|
-
};
|
|
133
|
-
};
|
|
134
|
-
export const makeDeliveryMesssaging = (address, count, messages = LOCATIONS_MESSAGES) => {
|
|
135
|
-
if (!address) {
|
|
136
|
-
return messages.DELIVERY.default;
|
|
137
|
-
}
|
|
138
|
-
else if (!address.street) {
|
|
139
|
-
return messages.DELIVERY.noStreet;
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
if (count) {
|
|
143
|
-
const locationMsg = count > 1 ? 'locations deliver' : 'location delivers';
|
|
144
|
-
return {
|
|
145
|
-
title: messages.DELIVERY.hasDelivery.title,
|
|
146
|
-
msg: `${count} ${locationMsg} to your address.`,
|
|
147
|
-
error: null
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
return messages.DELIVERY.noDelivery;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
export const makeDisplayedRevenueCenters = (revenueCenters, serviceType, address, latLng, maxDistance, isGroupOrder) => {
|
|
156
|
-
const filtered = isGroupOrder
|
|
157
|
-
? revenueCenters.filter(i => i.group_ordering)
|
|
158
|
-
: revenueCenters;
|
|
159
|
-
if (serviceType === 'DELIVERY') {
|
|
160
|
-
const displayed = makeDeliveryRevenueCenters(filtered);
|
|
161
|
-
const count = displayed.length;
|
|
162
|
-
const { title, msg, error } = makeDeliveryMesssaging(address, count);
|
|
163
|
-
return { title, msg, error, displayed };
|
|
164
|
-
}
|
|
165
|
-
else if (serviceType === 'WALKIN') {
|
|
166
|
-
const displayed = makeWalkinRevenueCenters(filtered, maxDistance);
|
|
167
|
-
const minDistance = calcMinDistance(displayed);
|
|
168
|
-
const count = displayed.length;
|
|
169
|
-
const { title, msg } = makeWalkinMessaging(address, latLng, count, minDistance, maxDistance);
|
|
170
|
-
const error = null;
|
|
171
|
-
return { title, msg, error, displayed };
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
const displayed = makePickupRevenueCenters(filtered, maxDistance);
|
|
175
|
-
const minDistance = calcMinDistance(displayed);
|
|
176
|
-
const count = displayed.length;
|
|
177
|
-
const { title, msg } = makePickupMesssaging(address, latLng, count, minDistance, maxDistance);
|
|
178
|
-
const error = null;
|
|
179
|
-
return { title, msg, error, displayed };
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
export const LOCATIONS_MESSAGES = {
|
|
183
|
-
PICKUP: {
|
|
184
|
-
default: {
|
|
185
|
-
title: 'Please choose a location',
|
|
186
|
-
msg: 'Or enter a zip code to find the location nearest you.'
|
|
187
|
-
},
|
|
188
|
-
address: {
|
|
189
|
-
title: 'locations near you',
|
|
190
|
-
msg: 'Please choose a location below.'
|
|
191
|
-
},
|
|
192
|
-
addressFar: {
|
|
193
|
-
title: "Looks like we don't have any locations that offer pickup in your area",
|
|
194
|
-
msg: 'Sorry about that. Please enter a different address or head back and choose a different order type.'
|
|
195
|
-
},
|
|
196
|
-
geo: {
|
|
197
|
-
title: 'locations in your area',
|
|
198
|
-
msg: 'Please enter an address or zip code for a more accurate result.'
|
|
199
|
-
},
|
|
200
|
-
geoFar: {
|
|
201
|
-
title: "Looks like we don't have any locations that offer pickup in your area",
|
|
202
|
-
msg: 'Please enter an address or zip code if you live in a different area.'
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
DELIVERY: {
|
|
206
|
-
default: {
|
|
207
|
-
title: "Let's find the nearest location",
|
|
208
|
-
msg: 'Please enter your address.',
|
|
209
|
-
error: null
|
|
210
|
-
},
|
|
211
|
-
noStreet: {
|
|
212
|
-
title: 'Please enter a street address',
|
|
213
|
-
msg: '',
|
|
214
|
-
error: 'A full address with street number is required for delivery orders.'
|
|
215
|
-
},
|
|
216
|
-
hasDelivery: {
|
|
217
|
-
title: 'Delivery is available!',
|
|
218
|
-
msg: 'Please choose a location below.',
|
|
219
|
-
error: null
|
|
220
|
-
},
|
|
221
|
-
noDelivery: {
|
|
222
|
-
title: "Delivery isn't available in your area at this time",
|
|
223
|
-
msg: "We're really sorry about that. Please enter a different address or head back and start a pickup order.",
|
|
224
|
-
error: null
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
export const renameLocation = (str, names) => {
|
|
229
|
-
const [singular, plural] = names;
|
|
230
|
-
return str
|
|
231
|
-
.replace('1 locations', '1 location')
|
|
232
|
-
.replace('locations', plural)
|
|
233
|
-
.replace('location', singular)
|
|
234
|
-
.replace(' a a', ' an a')
|
|
235
|
-
.replace(' a e', ' an e')
|
|
236
|
-
.replace(' a i', ' an i')
|
|
237
|
-
.replace(' a o', ' an o')
|
|
238
|
-
.replace(' a u', ' an u');
|
|
239
|
-
};
|
|
240
|
-
export const makeMapStyles = ({ labelColor, roadColor, featureColor, waterColor, backgroundColor }) => [
|
|
241
|
-
{
|
|
242
|
-
featureType: 'transit',
|
|
243
|
-
elementType: 'all',
|
|
244
|
-
stylers: [{ visibility: 'off' }]
|
|
245
|
-
},
|
|
246
|
-
{
|
|
247
|
-
featureType: 'administrative',
|
|
248
|
-
elementType: 'labels.text.fill',
|
|
249
|
-
stylers: [{ visibility: 'off' }]
|
|
250
|
-
},
|
|
251
|
-
{
|
|
252
|
-
featureType: 'administrative',
|
|
253
|
-
elementType: 'labels.text.stroke',
|
|
254
|
-
stylers: [{ visibility: 'off' }]
|
|
255
|
-
},
|
|
256
|
-
{
|
|
257
|
-
featureType: 'road',
|
|
258
|
-
elementType: 'labels.icon',
|
|
259
|
-
stylers: [{ visibility: 'off' }]
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
featureType: 'road',
|
|
263
|
-
elementType: 'geometry',
|
|
264
|
-
stylers: [{ visibility: 'simplified' }, { color: roadColor }]
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
featureType: 'road',
|
|
268
|
-
elementType: 'labels.text.fill',
|
|
269
|
-
stylers: [{ color: labelColor }]
|
|
270
|
-
},
|
|
271
|
-
{
|
|
272
|
-
featureType: 'road',
|
|
273
|
-
elementType: 'labels.text.stroke',
|
|
274
|
-
stylers: [{ visibility: 'off' }]
|
|
275
|
-
},
|
|
276
|
-
{
|
|
277
|
-
featureType: 'road.highway',
|
|
278
|
-
elementType: 'geometry',
|
|
279
|
-
stylers: [{ color: featureColor }]
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
featureType: 'road.highway',
|
|
283
|
-
elementType: 'labels',
|
|
284
|
-
stylers: [{ visibility: 'off' }]
|
|
285
|
-
},
|
|
286
|
-
{
|
|
287
|
-
featureType: 'water',
|
|
288
|
-
elementType: 'geometry',
|
|
289
|
-
stylers: [{ color: waterColor }]
|
|
290
|
-
},
|
|
291
|
-
{
|
|
292
|
-
featureType: 'water',
|
|
293
|
-
elementType: 'labels',
|
|
294
|
-
stylers: [{ visibility: 'off' }]
|
|
295
|
-
},
|
|
296
|
-
{
|
|
297
|
-
featureType: 'poi',
|
|
298
|
-
elementType: 'geometry',
|
|
299
|
-
stylers: [{ color: backgroundColor }]
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
featureType: 'poi',
|
|
303
|
-
elementType: 'labels',
|
|
304
|
-
stylers: [{ visibility: 'off' }]
|
|
305
|
-
},
|
|
306
|
-
{
|
|
307
|
-
featureType: 'landscape',
|
|
308
|
-
elementType: 'geometry',
|
|
309
|
-
stylers: [{ color: backgroundColor }]
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
featureType: 'landscape',
|
|
313
|
-
elementType: 'labels',
|
|
314
|
-
stylers: [{ visibility: 'off' }]
|
|
315
|
-
}
|
|
316
|
-
];
|
|
1
|
+
import { MAX_DISTANCE } from './constants';
|
|
2
|
+
const RADIUS_MILES = 3959; // radius of the earth in miles
|
|
3
|
+
const RADIUS_KM = 6371; // radius of the earth in kilometers
|
|
4
|
+
// https://stackoverflow.com/questions/18883601/function-to-calculate-distance-between-two-coordinates
|
|
5
|
+
export const getDistance = (pointA, pointB, inMiles = true) => {
|
|
6
|
+
const { lat: lat1, lng: lng1 } = pointA;
|
|
7
|
+
const { lat: lat2, lng: lng2 } = pointB;
|
|
8
|
+
const R = inMiles ? RADIUS_MILES : RADIUS_KM;
|
|
9
|
+
const dLat = deg2rad(lat2 - lat1); // see deg2rad below
|
|
10
|
+
const dLng = deg2rad(lng2 - lng1);
|
|
11
|
+
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
|
12
|
+
Math.cos(deg2rad(lat1)) *
|
|
13
|
+
Math.cos(deg2rad(lat2)) *
|
|
14
|
+
Math.sin(dLng / 2) *
|
|
15
|
+
Math.sin(dLng / 2);
|
|
16
|
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
17
|
+
const d = R * c;
|
|
18
|
+
return d;
|
|
19
|
+
};
|
|
20
|
+
const deg2rad = (deg) => {
|
|
21
|
+
return deg * (Math.PI / 180);
|
|
22
|
+
};
|
|
23
|
+
// ray-casting algorithm based on
|
|
24
|
+
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
|
25
|
+
const pointInPolygon = (point, vs) => {
|
|
26
|
+
const x = point[0], y = point[1];
|
|
27
|
+
let inside = false;
|
|
28
|
+
for (let i = 0, j = vs.length - 1; i < vs.length; j = i++) {
|
|
29
|
+
const xi = vs[i][0], yi = vs[i][1];
|
|
30
|
+
const xj = vs[j][0], yj = vs[j][1];
|
|
31
|
+
const intersect = yi > y != yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
|
|
32
|
+
if (intersect)
|
|
33
|
+
inside = !inside;
|
|
34
|
+
}
|
|
35
|
+
return inside;
|
|
36
|
+
};
|
|
37
|
+
export const inZone = (latLng, polygon) => {
|
|
38
|
+
const point = [latLng.lat, latLng.lng];
|
|
39
|
+
return pointInPolygon(point, polygon);
|
|
40
|
+
};
|
|
41
|
+
export const addDistance = (revenueCenters, latLng) => {
|
|
42
|
+
if (!latLng)
|
|
43
|
+
return revenueCenters;
|
|
44
|
+
const withDistance = revenueCenters.map(i => {
|
|
45
|
+
const iLatLng = i.address.lat
|
|
46
|
+
? { lat: i.address.lat, lng: i.address.lng }
|
|
47
|
+
: null;
|
|
48
|
+
i.distance = iLatLng ? getDistance(latLng, iLatLng) : 1000;
|
|
49
|
+
const { coordinates, priority } = i.delivery_zone;
|
|
50
|
+
i.inZone = coordinates ? inZone(latLng, coordinates) : false;
|
|
51
|
+
i.priority = priority !== null && priority !== void 0 ? priority : 0;
|
|
52
|
+
return i;
|
|
53
|
+
});
|
|
54
|
+
return withDistance;
|
|
55
|
+
};
|
|
56
|
+
export const sortRevenueCenters = (revenueCenters, isDelivery = false) => {
|
|
57
|
+
if (!isDelivery) {
|
|
58
|
+
return [...revenueCenters].sort((a, b) => { var _a, _b; return ((_a = a.distance) !== null && _a !== void 0 ? _a : 0) - ((_b = b.distance) !== null && _b !== void 0 ? _b : 0); });
|
|
59
|
+
}
|
|
60
|
+
const inZoneWithPriority = revenueCenters
|
|
61
|
+
.filter(i => i.inZone && i.priority)
|
|
62
|
+
.sort((a, b) => { var _a, _b; return ((_a = a.priority) !== null && _a !== void 0 ? _a : 0) - ((_b = b.priority) !== null && _b !== void 0 ? _b : 0); });
|
|
63
|
+
const inZoneWithoutPriority = revenueCenters
|
|
64
|
+
.filter(i => i.inZone && !i.priority)
|
|
65
|
+
.sort((a, b) => { var _a, _b; return ((_a = a.distance) !== null && _a !== void 0 ? _a : 0) - ((_b = b.distance) !== null && _b !== void 0 ? _b : 0); });
|
|
66
|
+
const outOfZone = revenueCenters
|
|
67
|
+
.filter(i => !i.inZone)
|
|
68
|
+
.sort((a, b) => { var _a, _b; return ((_a = a.distance) !== null && _a !== void 0 ? _a : 0) - ((_b = b.distance) !== null && _b !== void 0 ? _b : 0); });
|
|
69
|
+
return [...inZoneWithPriority, ...inZoneWithoutPriority, ...outOfZone];
|
|
70
|
+
};
|
|
71
|
+
export const calcMinDistance = (revenueCenters, maxDistance = MAX_DISTANCE) => {
|
|
72
|
+
const withDistance = revenueCenters
|
|
73
|
+
.filter(i => i.distance !== null && i.distance !== undefined)
|
|
74
|
+
.map(i => { var _a; return (_a = i.distance) !== null && _a !== void 0 ? _a : 0; });
|
|
75
|
+
return withDistance ? Math.min(...withDistance) : maxDistance;
|
|
76
|
+
};
|
|
77
|
+
export const checkServiceType = (revenueCenter, serviceType) => {
|
|
78
|
+
const { service_types } = revenueCenter;
|
|
79
|
+
if (!service_types)
|
|
80
|
+
return false;
|
|
81
|
+
return service_types.includes(serviceType);
|
|
82
|
+
};
|
|
83
|
+
export const makePickupRevenueCenters = (revenueCenters, maxDistance = MAX_DISTANCE) => {
|
|
84
|
+
const hasPickup = revenueCenters
|
|
85
|
+
.filter(i => checkServiceType(i, 'PICKUP'))
|
|
86
|
+
.filter(i => !i.distance || i.distance < maxDistance);
|
|
87
|
+
return sortRevenueCenters(hasPickup);
|
|
88
|
+
};
|
|
89
|
+
export const makeWalkinRevenueCenters = (revenueCenters, maxDistance = MAX_DISTANCE) => {
|
|
90
|
+
const hasWalkin = revenueCenters
|
|
91
|
+
.filter(i => checkServiceType(i, 'WALKIN'))
|
|
92
|
+
.filter(i => !i.distance || i.distance < maxDistance);
|
|
93
|
+
return sortRevenueCenters(hasWalkin);
|
|
94
|
+
};
|
|
95
|
+
export const makeDeliveryRevenueCenters = (revenueCenters) => {
|
|
96
|
+
const hasDelivery = revenueCenters.filter(i => checkServiceType(i, 'DELIVERY'));
|
|
97
|
+
const sorted = sortRevenueCenters(hasDelivery, true);
|
|
98
|
+
return sorted.filter(i => i.inZone);
|
|
99
|
+
};
|
|
100
|
+
export const makePickupMesssaging = (address, latLng, count, minDistance, maxDistance = MAX_DISTANCE, messages = LOCATIONS_MESSAGES) => {
|
|
101
|
+
if (address) {
|
|
102
|
+
if (minDistance >= maxDistance) {
|
|
103
|
+
return messages.PICKUP.addressFar;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return {
|
|
107
|
+
title: `${count} ${messages.PICKUP.address.title}`,
|
|
108
|
+
msg: messages.PICKUP.address.msg
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (latLng) {
|
|
113
|
+
if (minDistance >= maxDistance) {
|
|
114
|
+
return messages.PICKUP.geoFar;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
return {
|
|
118
|
+
title: `${count} ${messages.PICKUP.geo.title}`,
|
|
119
|
+
msg: messages.PICKUP.geo.msg
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
return messages.PICKUP.default;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
export const makeWalkinMessaging = (address, latLng, count, minDistance, maxDistance = MAX_DISTANCE, messages = LOCATIONS_MESSAGES) => {
|
|
128
|
+
const { title, msg } = makePickupMesssaging(address, latLng, count, minDistance, maxDistance, messages);
|
|
129
|
+
return {
|
|
130
|
+
title: title.replace('pickup', 'dine-in'),
|
|
131
|
+
msg: msg.replace('pickup', 'dine-in')
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
export const makeDeliveryMesssaging = (address, count, messages = LOCATIONS_MESSAGES) => {
|
|
135
|
+
if (!address) {
|
|
136
|
+
return messages.DELIVERY.default;
|
|
137
|
+
}
|
|
138
|
+
else if (!address.street) {
|
|
139
|
+
return messages.DELIVERY.noStreet;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
if (count) {
|
|
143
|
+
const locationMsg = count > 1 ? 'locations deliver' : 'location delivers';
|
|
144
|
+
return {
|
|
145
|
+
title: messages.DELIVERY.hasDelivery.title,
|
|
146
|
+
msg: `${count} ${locationMsg} to your address.`,
|
|
147
|
+
error: null
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
return messages.DELIVERY.noDelivery;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
export const makeDisplayedRevenueCenters = (revenueCenters, serviceType, address, latLng, maxDistance, isGroupOrder) => {
|
|
156
|
+
const filtered = isGroupOrder
|
|
157
|
+
? revenueCenters.filter(i => i.group_ordering)
|
|
158
|
+
: revenueCenters;
|
|
159
|
+
if (serviceType === 'DELIVERY') {
|
|
160
|
+
const displayed = makeDeliveryRevenueCenters(filtered);
|
|
161
|
+
const count = displayed.length;
|
|
162
|
+
const { title, msg, error } = makeDeliveryMesssaging(address, count);
|
|
163
|
+
return { title, msg, error, displayed };
|
|
164
|
+
}
|
|
165
|
+
else if (serviceType === 'WALKIN') {
|
|
166
|
+
const displayed = makeWalkinRevenueCenters(filtered, maxDistance);
|
|
167
|
+
const minDistance = calcMinDistance(displayed);
|
|
168
|
+
const count = displayed.length;
|
|
169
|
+
const { title, msg } = makeWalkinMessaging(address, latLng, count, minDistance, maxDistance);
|
|
170
|
+
const error = null;
|
|
171
|
+
return { title, msg, error, displayed };
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
const displayed = makePickupRevenueCenters(filtered, maxDistance);
|
|
175
|
+
const minDistance = calcMinDistance(displayed);
|
|
176
|
+
const count = displayed.length;
|
|
177
|
+
const { title, msg } = makePickupMesssaging(address, latLng, count, minDistance, maxDistance);
|
|
178
|
+
const error = null;
|
|
179
|
+
return { title, msg, error, displayed };
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
export const LOCATIONS_MESSAGES = {
|
|
183
|
+
PICKUP: {
|
|
184
|
+
default: {
|
|
185
|
+
title: 'Please choose a location',
|
|
186
|
+
msg: 'Or enter a zip code to find the location nearest you.'
|
|
187
|
+
},
|
|
188
|
+
address: {
|
|
189
|
+
title: 'locations near you',
|
|
190
|
+
msg: 'Please choose a location below.'
|
|
191
|
+
},
|
|
192
|
+
addressFar: {
|
|
193
|
+
title: "Looks like we don't have any locations that offer pickup in your area",
|
|
194
|
+
msg: 'Sorry about that. Please enter a different address or head back and choose a different order type.'
|
|
195
|
+
},
|
|
196
|
+
geo: {
|
|
197
|
+
title: 'locations in your area',
|
|
198
|
+
msg: 'Please enter an address or zip code for a more accurate result.'
|
|
199
|
+
},
|
|
200
|
+
geoFar: {
|
|
201
|
+
title: "Looks like we don't have any locations that offer pickup in your area",
|
|
202
|
+
msg: 'Please enter an address or zip code if you live in a different area.'
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
DELIVERY: {
|
|
206
|
+
default: {
|
|
207
|
+
title: "Let's find the nearest location",
|
|
208
|
+
msg: 'Please enter your address.',
|
|
209
|
+
error: null
|
|
210
|
+
},
|
|
211
|
+
noStreet: {
|
|
212
|
+
title: 'Please enter a street address',
|
|
213
|
+
msg: '',
|
|
214
|
+
error: 'A full address with street number is required for delivery orders.'
|
|
215
|
+
},
|
|
216
|
+
hasDelivery: {
|
|
217
|
+
title: 'Delivery is available!',
|
|
218
|
+
msg: 'Please choose a location below.',
|
|
219
|
+
error: null
|
|
220
|
+
},
|
|
221
|
+
noDelivery: {
|
|
222
|
+
title: "Delivery isn't available in your area at this time",
|
|
223
|
+
msg: "We're really sorry about that. Please enter a different address or head back and start a pickup order.",
|
|
224
|
+
error: null
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
export const renameLocation = (str, names) => {
|
|
229
|
+
const [singular, plural] = names;
|
|
230
|
+
return str
|
|
231
|
+
.replace('1 locations', '1 location')
|
|
232
|
+
.replace('locations', plural)
|
|
233
|
+
.replace('location', singular)
|
|
234
|
+
.replace(' a a', ' an a')
|
|
235
|
+
.replace(' a e', ' an e')
|
|
236
|
+
.replace(' a i', ' an i')
|
|
237
|
+
.replace(' a o', ' an o')
|
|
238
|
+
.replace(' a u', ' an u');
|
|
239
|
+
};
|
|
240
|
+
export const makeMapStyles = ({ labelColor, roadColor, featureColor, waterColor, backgroundColor }) => [
|
|
241
|
+
{
|
|
242
|
+
featureType: 'transit',
|
|
243
|
+
elementType: 'all',
|
|
244
|
+
stylers: [{ visibility: 'off' }]
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
featureType: 'administrative',
|
|
248
|
+
elementType: 'labels.text.fill',
|
|
249
|
+
stylers: [{ visibility: 'off' }]
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
featureType: 'administrative',
|
|
253
|
+
elementType: 'labels.text.stroke',
|
|
254
|
+
stylers: [{ visibility: 'off' }]
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
featureType: 'road',
|
|
258
|
+
elementType: 'labels.icon',
|
|
259
|
+
stylers: [{ visibility: 'off' }]
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
featureType: 'road',
|
|
263
|
+
elementType: 'geometry',
|
|
264
|
+
stylers: [{ visibility: 'simplified' }, { color: roadColor }]
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
featureType: 'road',
|
|
268
|
+
elementType: 'labels.text.fill',
|
|
269
|
+
stylers: [{ color: labelColor }]
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
featureType: 'road',
|
|
273
|
+
elementType: 'labels.text.stroke',
|
|
274
|
+
stylers: [{ visibility: 'off' }]
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
featureType: 'road.highway',
|
|
278
|
+
elementType: 'geometry',
|
|
279
|
+
stylers: [{ color: featureColor }]
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
featureType: 'road.highway',
|
|
283
|
+
elementType: 'labels',
|
|
284
|
+
stylers: [{ visibility: 'off' }]
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
featureType: 'water',
|
|
288
|
+
elementType: 'geometry',
|
|
289
|
+
stylers: [{ color: waterColor }]
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
featureType: 'water',
|
|
293
|
+
elementType: 'labels',
|
|
294
|
+
stylers: [{ visibility: 'off' }]
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
featureType: 'poi',
|
|
298
|
+
elementType: 'geometry',
|
|
299
|
+
stylers: [{ color: backgroundColor }]
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
featureType: 'poi',
|
|
303
|
+
elementType: 'labels',
|
|
304
|
+
stylers: [{ visibility: 'off' }]
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
featureType: 'landscape',
|
|
308
|
+
elementType: 'geometry',
|
|
309
|
+
stylers: [{ color: backgroundColor }]
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
featureType: 'landscape',
|
|
313
|
+
elementType: 'labels',
|
|
314
|
+
stylers: [{ visibility: 'off' }]
|
|
315
|
+
}
|
|
316
|
+
];
|