@open-tender/utils 0.4.64 → 0.4.65
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/cjs/hooks/useAccordion.js +2 -2
- package/dist/cjs/hooks/useCreditCard.js +6 -6
- package/dist/cjs/utils/revenueCenters.d.ts +1 -2
- package/dist/cjs/utils/revenueCenters.js +24 -27
- package/dist/esm/hooks/useAccordion.js +2 -2
- package/dist/esm/hooks/useCreditCard.js +1 -1
- package/dist/esm/utils/revenueCenters.d.ts +1 -2
- package/dist/esm/utils/revenueCenters.js +25 -27
- package/package.json +4 -3
|
@@ -5,7 +5,7 @@ const react_1 = require("react");
|
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const useAccordion = (builtItem, toggleOption, cartId, config) => {
|
|
7
7
|
var _a;
|
|
8
|
-
const { hasCals: showCals = false, hasCustomize = false, hasMadeFor: showMadeFor = true, hasNotes: showNotes = true
|
|
8
|
+
const { hasCals: showCals = false, hasCustomize = false, hasMadeFor: showMadeFor = true, hasNotes: showNotes = true } = config || {};
|
|
9
9
|
const [open, setOpen] = (0, react_1.useState)(null);
|
|
10
10
|
const { groups, ingredients, totalCals, madeFor, notes } = builtItem;
|
|
11
11
|
const hasMadeFor = showMadeFor && !cartId ? true : false;
|
|
@@ -13,7 +13,7 @@ const useAccordion = (builtItem, toggleOption, cartId, config) => {
|
|
|
13
13
|
const hasInstructions = hasMadeFor || hasNotes;
|
|
14
14
|
const hasCals = showCals && totalCals ? true : false;
|
|
15
15
|
const nutritionalInfo = hasCals ? (0, utils_1.calcNutritionalInfo)(builtItem) : null;
|
|
16
|
-
const hasIngredients =
|
|
16
|
+
const hasIngredients = ingredients && ingredients.length > 0 ? true : false;
|
|
17
17
|
const instructionsTitle = hasMadeFor && hasNotes
|
|
18
18
|
? 'Name / Special Instructions'
|
|
19
19
|
: hasMadeFor
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useCreditCard = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
const
|
|
5
|
+
const index_1 = require("../index");
|
|
6
6
|
const defaultState = {
|
|
7
7
|
acct: '',
|
|
8
8
|
exp: '',
|
|
@@ -19,7 +19,7 @@ const defaulStateAddress = {
|
|
|
19
19
|
is_default: false
|
|
20
20
|
};
|
|
21
21
|
const useCreditCard = (initState, cardErrors = {}, disabled = false, includeAddress = false) => {
|
|
22
|
-
const [initCard, initCardType] = (0,
|
|
22
|
+
const [initCard, initCardType] = (0, index_1.formatCard)(initState);
|
|
23
23
|
const submitRef = (0, react_1.useRef)(null);
|
|
24
24
|
const defaultCard = includeAddress ? defaulStateAddress : defaultState;
|
|
25
25
|
const [data, setData] = (0, react_1.useState)(initCard || defaultCard);
|
|
@@ -27,19 +27,19 @@ const useCreditCard = (initState, cardErrors = {}, disabled = false, includeAddr
|
|
|
27
27
|
const [errors, setErrors] = (0, react_1.useState)(cardErrors);
|
|
28
28
|
const { acct, addr, exp, cvv, zip } = data;
|
|
29
29
|
const addrComplete = includeAddress ? addr : true;
|
|
30
|
-
const isComplete = acct && exp && cvv && zip && addrComplete && (0,
|
|
30
|
+
const isComplete = acct && exp && cvv && zip && addrComplete && (0, index_1.isEmpty)(errors) ? true : false;
|
|
31
31
|
const handleChange = (name, value) => {
|
|
32
32
|
if (name === 'acct') {
|
|
33
|
-
const currentType = (0,
|
|
33
|
+
const currentType = (0, index_1.getCardType)(value.replace(/\s/g, ''));
|
|
34
34
|
setCardType(currentType);
|
|
35
35
|
}
|
|
36
36
|
if (name !== 'is_default') {
|
|
37
|
-
value = (0,
|
|
37
|
+
value = (0, index_1.formatCardField)(name, value);
|
|
38
38
|
}
|
|
39
39
|
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
40
40
|
};
|
|
41
41
|
const handleBlur = (name) => {
|
|
42
|
-
const { errors: validationErrors } = (0,
|
|
42
|
+
const { errors: validationErrors } = (0, index_1.validateCreditCard)(data, cardType);
|
|
43
43
|
if (validationErrors) {
|
|
44
44
|
const error = validationErrors[name];
|
|
45
45
|
setErrors(Object.assign(Object.assign({}, errors), { [name]: error }));
|
|
@@ -9,5 +9,4 @@ export declare const makeRevenueCenterMsg: (revenueCenter: RevenueCenter, servic
|
|
|
9
9
|
message: any;
|
|
10
10
|
color: string;
|
|
11
11
|
};
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const getRevenueCenterStatus: (revenueCenter: RevenueCenter, serviceType: ServiceType) => string;
|
|
12
|
+
export declare const getRevenueCenterStatus: (revenueCenter: RevenueCenter, serviceType: ServiceType) => string | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRevenueCenterStatus = exports.
|
|
3
|
+
exports.getRevenueCenterStatus = exports.makeRevenueCenterMsg = exports.makeNotAcceptingOrdersMsg = exports.makeOrderTypeName = exports.makeServiceTypeName = exports.makeOrderTypeFromParam = exports.makeFullAddress = exports.makeOrderAddress = void 0;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
5
|
const datetimes_1 = require("./datetimes");
|
|
6
6
|
const helpers_1 = require("./helpers");
|
|
@@ -125,35 +125,32 @@ const makeRevenueCenterMsg = (revenueCenter, serviceType, requestedAt, statusMes
|
|
|
125
125
|
return { message, color };
|
|
126
126
|
};
|
|
127
127
|
exports.makeRevenueCenterMsg = makeRevenueCenterMsg;
|
|
128
|
-
const isRevenueCenterOpen = (revenueCenter, serviceType) => {
|
|
129
|
-
const { status, first_times, order_times } = revenueCenter;
|
|
130
|
-
if (status !== 'OPEN')
|
|
131
|
-
return false;
|
|
132
|
-
const serviceOrderTimes = order_times ? order_times[serviceType] : null;
|
|
133
|
-
const serviceFirstTimes = first_times ? first_times[serviceType] : null;
|
|
134
|
-
const isHasFirstTimes = !!serviceFirstTimes;
|
|
135
|
-
const isHasOrderTime = !!serviceOrderTimes && serviceOrderTimes.length > 0;
|
|
136
|
-
return !isHasFirstTimes && !isHasOrderTime;
|
|
137
|
-
};
|
|
138
|
-
exports.isRevenueCenterOpen = isRevenueCenterOpen;
|
|
139
128
|
const getRevenueCenterStatus = (revenueCenter, serviceType) => {
|
|
140
|
-
const { first_times, status, timezone } = revenueCenter;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (isOpen)
|
|
144
|
-
return 'Open Now';
|
|
129
|
+
const { first_times, status, timezone, revenue_center_type, is_outpost } = revenueCenter;
|
|
130
|
+
if (revenue_center_type !== 'OLO' || is_outpost)
|
|
131
|
+
return null;
|
|
145
132
|
if (status !== 'OPEN')
|
|
146
133
|
return 'Closed';
|
|
147
|
-
const
|
|
148
|
-
|
|
134
|
+
const tz = datetimes_1.timezoneMap[timezone];
|
|
135
|
+
const firstTimes = first_times ? first_times[serviceType] : null;
|
|
136
|
+
if (!firstTimes)
|
|
149
137
|
return 'Closed';
|
|
150
|
-
const
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
138
|
+
const { date, has_asap, utc } = firstTimes;
|
|
139
|
+
const firstDt = (0, date_fns_tz_1.utcToZonedTime)(utc, tz);
|
|
140
|
+
const now = new Date();
|
|
141
|
+
const today = (0, datetimes_1.dateToZonedDateStr)(now, tz, 'yyyy-MM-dd');
|
|
142
|
+
const tomorrow = (0, datetimes_1.dateToZonedDateStr)(now, tz, 'yyyy-MM-dd', 1);
|
|
143
|
+
const isToday = date === today;
|
|
144
|
+
const isTomorrow = date === tomorrow;
|
|
145
|
+
if (isToday) {
|
|
146
|
+
if (has_asap) {
|
|
147
|
+
return 'Open Now';
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
return 'Currently closed, order for later today';
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const nextDay = isTomorrow ? 'tomorrow' : (0, date_fns_1.format)(firstDt, 'EEEE');
|
|
154
|
+
return `Closed for today, order for ${nextDay}`;
|
|
158
155
|
};
|
|
159
156
|
exports.getRevenueCenterStatus = getRevenueCenterStatus;
|
|
@@ -2,7 +2,7 @@ import { useState } from 'react';
|
|
|
2
2
|
import { calcNutritionalInfo } from '../utils';
|
|
3
3
|
export const useAccordion = (builtItem, toggleOption, cartId, config) => {
|
|
4
4
|
var _a;
|
|
5
|
-
const { hasCals: showCals = false, hasCustomize = false, hasMadeFor: showMadeFor = true, hasNotes: showNotes = true
|
|
5
|
+
const { hasCals: showCals = false, hasCustomize = false, hasMadeFor: showMadeFor = true, hasNotes: showNotes = true } = config || {};
|
|
6
6
|
const [open, setOpen] = useState(null);
|
|
7
7
|
const { groups, ingredients, totalCals, madeFor, notes } = builtItem;
|
|
8
8
|
const hasMadeFor = showMadeFor && !cartId ? true : false;
|
|
@@ -10,7 +10,7 @@ export const useAccordion = (builtItem, toggleOption, cartId, config) => {
|
|
|
10
10
|
const hasInstructions = hasMadeFor || hasNotes;
|
|
11
11
|
const hasCals = showCals && totalCals ? true : false;
|
|
12
12
|
const nutritionalInfo = hasCals ? calcNutritionalInfo(builtItem) : null;
|
|
13
|
-
const hasIngredients =
|
|
13
|
+
const hasIngredients = ingredients && ingredients.length > 0 ? true : false;
|
|
14
14
|
const instructionsTitle = hasMadeFor && hasNotes
|
|
15
15
|
? 'Name / Special Instructions'
|
|
16
16
|
: hasMadeFor
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useRef, useState } from 'react';
|
|
2
|
-
import { formatCardField, formatCard, getCardType, isEmpty, validateCreditCard } from '
|
|
2
|
+
import { formatCardField, formatCard, getCardType, isEmpty, validateCreditCard } from '../index';
|
|
3
3
|
const defaultState = {
|
|
4
4
|
acct: '',
|
|
5
5
|
exp: '',
|
|
@@ -9,5 +9,4 @@ export declare const makeRevenueCenterMsg: (revenueCenter: RevenueCenter, servic
|
|
|
9
9
|
message: any;
|
|
10
10
|
color: string;
|
|
11
11
|
};
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const getRevenueCenterStatus: (revenueCenter: RevenueCenter, serviceType: ServiceType) => string;
|
|
12
|
+
export declare const getRevenueCenterStatus: (revenueCenter: RevenueCenter, serviceType: ServiceType) => string | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { serviceTypeNamesMap } from './constants';
|
|
2
|
-
import { fmtDate, formatDateStr, isoToDate, makeOrderTimes, makeReadableDateStrFromIso, makeWeekday, time24ToDate, timezoneMap } from './datetimes';
|
|
2
|
+
import { dateToZonedDateStr, fmtDate, formatDateStr, isoToDate, makeOrderTimes, makeReadableDateStrFromIso, makeWeekday, time24ToDate, timezoneMap } from './datetimes';
|
|
3
3
|
import { capitalize } from './helpers';
|
|
4
|
-
import { format
|
|
4
|
+
import { format } from 'date-fns';
|
|
5
5
|
import { utcToZonedTime } from 'date-fns-tz';
|
|
6
6
|
export const makeOrderAddress = (address) => {
|
|
7
7
|
const { street, unit, city, state, postal_code } = address || {};
|
|
@@ -115,33 +115,31 @@ export const makeRevenueCenterMsg = (revenueCenter, serviceType, requestedAt, st
|
|
|
115
115
|
}
|
|
116
116
|
return { message, color };
|
|
117
117
|
};
|
|
118
|
-
export const isRevenueCenterOpen = (revenueCenter, serviceType) => {
|
|
119
|
-
const { status, first_times, order_times } = revenueCenter;
|
|
120
|
-
if (status !== 'OPEN')
|
|
121
|
-
return false;
|
|
122
|
-
const serviceOrderTimes = order_times ? order_times[serviceType] : null;
|
|
123
|
-
const serviceFirstTimes = first_times ? first_times[serviceType] : null;
|
|
124
|
-
const isHasFirstTimes = !!serviceFirstTimes;
|
|
125
|
-
const isHasOrderTime = !!serviceOrderTimes && serviceOrderTimes.length > 0;
|
|
126
|
-
return !isHasFirstTimes && !isHasOrderTime;
|
|
127
|
-
};
|
|
128
118
|
export const getRevenueCenterStatus = (revenueCenter, serviceType) => {
|
|
129
|
-
const { first_times, status, timezone } = revenueCenter;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (isOpen)
|
|
133
|
-
return 'Open Now';
|
|
119
|
+
const { first_times, status, timezone, revenue_center_type, is_outpost } = revenueCenter;
|
|
120
|
+
if (revenue_center_type !== 'OLO' || is_outpost)
|
|
121
|
+
return null;
|
|
134
122
|
if (status !== 'OPEN')
|
|
135
123
|
return 'Closed';
|
|
136
|
-
const
|
|
137
|
-
|
|
124
|
+
const tz = timezoneMap[timezone];
|
|
125
|
+
const firstTimes = first_times ? first_times[serviceType] : null;
|
|
126
|
+
if (!firstTimes)
|
|
138
127
|
return 'Closed';
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
128
|
+
const { date, has_asap, utc } = firstTimes;
|
|
129
|
+
const firstDt = utcToZonedTime(utc, tz);
|
|
130
|
+
const now = new Date();
|
|
131
|
+
const today = dateToZonedDateStr(now, tz, 'yyyy-MM-dd');
|
|
132
|
+
const tomorrow = dateToZonedDateStr(now, tz, 'yyyy-MM-dd', 1);
|
|
133
|
+
const isToday = date === today;
|
|
134
|
+
const isTomorrow = date === tomorrow;
|
|
135
|
+
if (isToday) {
|
|
136
|
+
if (has_asap) {
|
|
137
|
+
return 'Open Now';
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
return 'Currently closed, order for later today';
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const nextDay = isTomorrow ? 'tomorrow' : format(firstDt, 'EEEE');
|
|
144
|
+
return `Closed for today, order for ${nextDay}`;
|
|
147
145
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.65",
|
|
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",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"private": false,
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@emotion/react": "^11.10.4",
|
|
39
|
-
"@open-tender/types": "^0.4.
|
|
39
|
+
"@open-tender/types": "^0.4.77",
|
|
40
40
|
"@reduxjs/toolkit": "^1.8.5",
|
|
41
41
|
"@types/google.maps": "^3.53.5",
|
|
42
42
|
"@types/jest": "^29.5.11",
|
|
@@ -65,5 +65,6 @@
|
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"date-fns": "^2.29.3",
|
|
67
67
|
"date-fns-tz": "^1.3.7"
|
|
68
|
-
}
|
|
68
|
+
},
|
|
69
|
+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
69
70
|
}
|