@open-tender/utils 0.4.62 → 0.4.64

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.
@@ -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 } = config || {};
8
+ const { hasCals: showCals = false, hasCustomize = false, hasMadeFor: showMadeFor = true, hasNotes: showNotes = true, hasIngredients: showIngredients = 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 = ingredients && ingredients.length > 0 ? true : false;
16
+ const hasIngredients = showIngredients && ingredients && ingredients.length > 0 ? true : false;
17
17
  const instructionsTitle = hasMadeFor && hasNotes
18
18
  ? 'Name / Special Instructions'
19
19
  : hasMadeFor
@@ -9,4 +9,5 @@ export declare const makeRevenueCenterMsg: (revenueCenter: RevenueCenter, servic
9
9
  message: any;
10
10
  color: string;
11
11
  };
12
- export declare const getRevenueCenterStatus: (revenueCenter: RevenueCenter, serviceType: ServiceType) => string | null;
12
+ export declare const isRevenueCenterOpen: (revenueCenter: RevenueCenter, serviceType: ServiceType) => boolean;
13
+ export declare const getRevenueCenterStatus: (revenueCenter: RevenueCenter, serviceType: ServiceType) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRevenueCenterStatus = exports.makeRevenueCenterMsg = exports.makeNotAcceptingOrdersMsg = exports.makeOrderTypeName = exports.makeServiceTypeName = exports.makeOrderTypeFromParam = exports.makeFullAddress = exports.makeOrderAddress = void 0;
3
+ exports.getRevenueCenterStatus = exports.isRevenueCenterOpen = 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,32 +125,35 @@ 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;
128
139
  const getRevenueCenterStatus = (revenueCenter, serviceType) => {
129
- const { first_times, status, timezone, revenue_center_type, is_outpost } = revenueCenter;
130
- if (revenue_center_type !== 'OLO' || is_outpost)
131
- return null;
140
+ const { first_times, status, timezone } = revenueCenter;
141
+ const tz = datetimes_1.timezoneMap[timezone];
142
+ const isOpen = (0, exports.isRevenueCenterOpen)(revenueCenter, serviceType);
143
+ if (isOpen)
144
+ return 'Open Now';
132
145
  if (status !== 'OPEN')
133
146
  return 'Closed';
134
- const tz = datetimes_1.timezoneMap[timezone];
135
- const firstTimes = first_times ? first_times[serviceType] : null;
136
- if (!firstTimes)
147
+ const serviceFirstTimes = first_times ? first_times[serviceType] : null;
148
+ if (!serviceFirstTimes)
137
149
  return 'Closed';
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}`;
150
+ const firstTimeDate = (0, date_fns_tz_1.utcToZonedTime)(serviceFirstTimes.utc, tz);
151
+ const canOrderToday = (0, date_fns_1.isToday)(firstTimeDate);
152
+ if (canOrderToday)
153
+ return 'Currently closed, order for later today';
154
+ const nextAvailableDate = (0, date_fns_1.isTomorrow)(firstTimeDate)
155
+ ? 'tomorrow'
156
+ : (0, date_fns_1.format)(firstTimeDate, 'EEEE');
157
+ return `Closed for today, order for ${nextAvailableDate}`;
155
158
  };
156
159
  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 } = config || {};
5
+ const { hasCals: showCals = false, hasCustomize = false, hasMadeFor: showMadeFor = true, hasNotes: showNotes = true, hasIngredients: showIngredients = 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 = ingredients && ingredients.length > 0 ? true : false;
13
+ const hasIngredients = showIngredients && ingredients && ingredients.length > 0 ? true : false;
14
14
  const instructionsTitle = hasMadeFor && hasNotes
15
15
  ? 'Name / Special Instructions'
16
16
  : hasMadeFor
@@ -9,4 +9,5 @@ export declare const makeRevenueCenterMsg: (revenueCenter: RevenueCenter, servic
9
9
  message: any;
10
10
  color: string;
11
11
  };
12
- export declare const getRevenueCenterStatus: (revenueCenter: RevenueCenter, serviceType: ServiceType) => string | null;
12
+ export declare const isRevenueCenterOpen: (revenueCenter: RevenueCenter, serviceType: ServiceType) => boolean;
13
+ export declare const getRevenueCenterStatus: (revenueCenter: RevenueCenter, serviceType: ServiceType) => string;
@@ -1,7 +1,7 @@
1
1
  import { serviceTypeNamesMap } from './constants';
2
- import { dateToZonedDateStr, fmtDate, formatDateStr, isoToDate, makeOrderTimes, makeReadableDateStrFromIso, makeWeekday, time24ToDate, timezoneMap } from './datetimes';
2
+ import { fmtDate, formatDateStr, isoToDate, makeOrderTimes, makeReadableDateStrFromIso, makeWeekday, time24ToDate, timezoneMap } from './datetimes';
3
3
  import { capitalize } from './helpers';
4
- import { format } from 'date-fns';
4
+ import { format, isToday, isTomorrow } 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,31 +115,33 @@ 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
+ };
118
128
  export const getRevenueCenterStatus = (revenueCenter, serviceType) => {
119
- const { first_times, status, timezone, revenue_center_type, is_outpost } = revenueCenter;
120
- if (revenue_center_type !== 'OLO' || is_outpost)
121
- return null;
129
+ const { first_times, status, timezone } = revenueCenter;
130
+ const tz = timezoneMap[timezone];
131
+ const isOpen = isRevenueCenterOpen(revenueCenter, serviceType);
132
+ if (isOpen)
133
+ return 'Open Now';
122
134
  if (status !== 'OPEN')
123
135
  return 'Closed';
124
- const tz = timezoneMap[timezone];
125
- const firstTimes = first_times ? first_times[serviceType] : null;
126
- if (!firstTimes)
136
+ const serviceFirstTimes = first_times ? first_times[serviceType] : null;
137
+ if (!serviceFirstTimes)
127
138
  return 'Closed';
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}`;
139
+ const firstTimeDate = utcToZonedTime(serviceFirstTimes.utc, tz);
140
+ const canOrderToday = isToday(firstTimeDate);
141
+ if (canOrderToday)
142
+ return 'Currently closed, order for later today';
143
+ const nextAvailableDate = isTomorrow(firstTimeDate)
144
+ ? 'tomorrow'
145
+ : format(firstTimeDate, 'EEEE');
146
+ return `Closed for today, order for ${nextAvailableDate}`;
145
147
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.4.62",
3
+ "version": "0.4.64",
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.77",
39
+ "@open-tender/types": "^0.4.85",
40
40
  "@reduxjs/toolkit": "^1.8.5",
41
41
  "@types/google.maps": "^3.53.5",
42
42
  "@types/jest": "^29.5.11",