ordering-ui-external 13.0.4 → 13.0.5

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.
@@ -55,6 +55,8 @@ var MomentControlUI = function MomentControlUI(props) {
55
55
  getActualSchedule = props.getActualSchedule,
56
56
  preorderMaximumDays = props.preorderMaximumDays,
57
57
  preorderMinimumDays = props.preorderMinimumDays;
58
+ var scheduleItemRef = (0, _react.useRef)();
59
+ var timeListRef = (0, _react.useRef)();
58
60
  var _useConfig = (0, _orderingComponentsExternal.useConfig)(),
59
61
  _useConfig2 = _slicedToArray(_useConfig, 1),
60
62
  configs = _useConfig2[0].configs;
@@ -86,6 +88,10 @@ var MomentControlUI = function MomentControlUI(props) {
86
88
  _useState8 = _slicedToArray(_useState7, 2),
87
89
  isEnabled = _useState8[0],
88
90
  setIsEnabled = _useState8[1];
91
+ var _useState9 = (0, _react.useState)(null),
92
+ _useState10 = _slicedToArray(_useState9, 2),
93
+ nextTime = _useState10[0],
94
+ setNextTime = _useState10[1];
89
95
  var handleCheckBoxChange = function handleCheckBoxChange(index) {
90
96
  if (index) {
91
97
  !orderState.loading && handleAsap();
@@ -165,6 +171,36 @@ var MomentControlUI = function MomentControlUI(props) {
165
171
  (0, _react.useEffect)(function () {
166
172
  setLocalMoment();
167
173
  }, []);
174
+ (0, _react.useEffect)(function () {
175
+ if (timeListRef !== null && timeListRef !== void 0 && timeListRef.current && !orderState.loading && timeSelected) {
176
+ var _scheduleItemRef$curr;
177
+ timeListRef.current.scroll({
178
+ left: 0,
179
+ top: (scheduleItemRef === null || scheduleItemRef === void 0 || (_scheduleItemRef$curr = scheduleItemRef.current) === null || _scheduleItemRef$curr === void 0 ? void 0 : _scheduleItemRef$curr.offsetTop) - 300
180
+ });
181
+ }
182
+ }, [timeListRef === null || timeListRef === void 0 ? void 0 : timeListRef.current, timeSelected, orderState.loading, timeList === null || timeList === void 0 ? void 0 : timeList.length]);
183
+ (0, _react.useEffect)(function () {
184
+ if (preorderMinimumDays === 0 && preorderLeadTime === 0) return;
185
+ var isToday = dateSelected === (0, _moment.default)().format('YYYY-MM-DD');
186
+ if (isCart && isToday && !(orderState !== null && orderState !== void 0 && orderState.loading) && (timeList === null || timeList === void 0 ? void 0 : timeList.length) > 0) {
187
+ var _timeList$;
188
+ setNextTime((_timeList$ = timeList === null || timeList === void 0 ? void 0 : timeList[0]) !== null && _timeList$ !== void 0 ? _timeList$ : null);
189
+ }
190
+ }, [timeList === null || timeList === void 0 ? void 0 : timeList.length]);
191
+ (0, _react.useEffect)(function () {
192
+ if (nextTime !== null && nextTime !== void 0 && nextTime.value && (timeList === null || timeList === void 0 ? void 0 : timeList.length) > 0 && isCart && !(orderState !== null && orderState !== void 0 && orderState.loading) && !(preorderMinimumDays === 0 && preorderLeadTime === 0)) {
193
+ var _timeList$filter, _timeList$filter$find;
194
+ var notime = timeList === null || timeList === void 0 || (_timeList$filter = timeList.filter(function (_, i) {
195
+ return i !== 0;
196
+ })) === null || _timeList$filter === void 0 || (_timeList$filter$find = _timeList$filter.find) === null || _timeList$filter$find === void 0 ? void 0 : _timeList$filter$find.call(_timeList$filter, function (time) {
197
+ return (time === null || time === void 0 ? void 0 : time.value) === timeSelected;
198
+ });
199
+ if (!notime) {
200
+ handleChangeTime(nextTime === null || nextTime === void 0 ? void 0 : nextTime.value);
201
+ }
202
+ }
203
+ }, [nextTime === null || nextTime === void 0 ? void 0 : nextTime.value]);
168
204
  return /*#__PURE__*/_react.default.createElement("div", {
169
205
  id: "moment_control"
170
206
  }, !isAppoint && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, !isCart && /*#__PURE__*/_react.default.createElement(_styles.Title, null, t('WHEN_DO_WE_DELIVERY', 'When do we delivery?')), (preorderMinimumDays === 0 && preorderLeadTime === 0 || !cateringPreorder) && /*#__PURE__*/_react.default.createElement(_styles.CheckBoxWrapper, {
@@ -173,7 +209,7 @@ var MomentControlUI = function MomentControlUI(props) {
173
209
  return handleCheckBoxChange(true);
174
210
  },
175
211
  isLoading: orderState === null || orderState === void 0 ? void 0 : orderState.loading
176
- }, isASP ? /*#__PURE__*/_react.default.createElement(_styles.CheckedIcon, null) : /*#__PURE__*/_react.default.createElement(_CgRadioCheck.default, null), /*#__PURE__*/_react.default.createElement("span", null, t('CHECKOUT_ASAP', 'ASAP'), " (", (0, _moment.default)(new Date()).format('LLLL'), " - ", t('DELIVERY_TIME', 'delivery time'), ")")), /*#__PURE__*/_react.default.createElement(_styles.CheckBoxWrapper, {
212
+ }, isASP ? /*#__PURE__*/_react.default.createElement(_styles.CheckedIcon, null) : /*#__PURE__*/_react.default.createElement(_CgRadioCheck.default, null), /*#__PURE__*/_react.default.createElement("span", null, t('CHECKOUT_ASAP', 'ASAP'), " (", (0, _moment.default)(new Date()).format('LLLL'), " + ", t('DELIVERY_TIME', 'delivery time'), ")")), /*#__PURE__*/_react.default.createElement(_styles.CheckBoxWrapper, {
177
213
  highlight: !isASP,
178
214
  onClick: function onClick() {
179
215
  return handleCheckBoxChange(null);
@@ -222,7 +258,9 @@ var MomentControlUI = function MomentControlUI(props) {
222
258
  }, dayName), /*#__PURE__*/_react.default.createElement(_styles.DayNumber, {
223
259
  isAppoint: isAppoint
224
260
  }, dayNumber)));
225
- })))), /*#__PURE__*/_react.default.createElement(_styles.TimeListWrapper, null, isEnabled && (timeList === null || timeList === void 0 ? void 0 : timeList.length) > 0 ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, timeList.map(function (time, i) {
261
+ })))), /*#__PURE__*/_react.default.createElement(_styles.TimeListWrapper, {
262
+ ref: timeListRef
263
+ }, isEnabled && (timeList === null || timeList === void 0 ? void 0 : timeList.length) > 0 ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, timeList.map(function (time, i) {
226
264
  return /*#__PURE__*/_react.default.createElement(_styles.TimeItem, {
227
265
  key: i,
228
266
  active: timeSelected === time.value,
@@ -232,6 +270,7 @@ var MomentControlUI = function MomentControlUI(props) {
232
270
  isAppoint: isAppoint,
233
271
  cateringPreorder: cateringPreorder
234
272
  }, /*#__PURE__*/_react.default.createElement("span", null, cateringPreorder && /*#__PURE__*/_react.default.createElement(_styles.CheckIcon, null, timeSelected === time.value ? /*#__PURE__*/_react.default.createElement(_styles.CheckedIcon, {
273
+ ref: scheduleItemRef,
235
274
  cateringPreorder: cateringPreorder
236
275
  }) : /*#__PURE__*/_react.default.createElement(_CgRadioCheck.default, null)), /*#__PURE__*/_react.default.createElement("p", null, time.text, " ", cateringPreorder && "- ".concat(time.endText))));
237
276
  })) : /*#__PURE__*/_react.default.createElement(_styles.ClosedBusinessMsg, null, !business ? t('ERROR_SHEDULE_UNAVAILABLE', 'There are no schedules for this date') : t('ERROR_ADD_PRODUCT_BUSINESS_CLOSED', 'The business is closed at the moment')))) : /*#__PURE__*/_react.default.createElement(_CustomLayout.CustomLayout, {
@@ -40,7 +40,7 @@ var ActionsBlock = exports.ActionsBlock = _styledComponents.default.div(_templat
40
40
  var _props$theme;
41
41
  return ((_props$theme = props.theme) === null || _props$theme === void 0 ? void 0 : _props$theme.rtl) && (0, _styledComponents.css)(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["\n margin-left: 5px;\n margin-right: 0px;\n "])));
42
42
  });
43
- var OrderInfo = exports.OrderInfo = _styledComponents.default.div(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n width: 100%;\n margin: 0px 0px 35px;\n position: relative;\n h1, p {\n margin: 0px;\n color: ", ";\n }\n h1 {\n margin-bottom: 5px;\n font-weight: 600;\n font-size: 32px;\n }\n p {\n font-size: 14px;\n text-overflow: ellipsis;\n overflow: hidden;\n white-space: nowrap;\n }\n .date {\n margin-bottom: 6px;\n text-transform: uppercase;\n }\n .types {\n margin-bottom: 6px;\n font-size: 16px;\n }\n .order-status {\n font-weight: 600;\n font-size: 16px;\n }\n\n #error-subs {\n margin: 20px 0 0;\n width: 100%;\n box-sizing: border-box;\n text-align: center;\n }\n\n @media (min-width: 768px) {\n #error-subs {\n margin: 20px 0;\n }\n }\n"])), function (props) {
43
+ var OrderInfo = exports.OrderInfo = _styledComponents.default.div(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n width: 100%;\n margin: 0px 0px 35px;\n position: relative;\n h1, p {\n margin: 0px;\n color: ", ";\n }\n h1 {\n margin-bottom: 5px;\n font-weight: 600;\n font-size: 32px;\n }\n p {\n font-size: 14px;\n text-overflow: ellipsis;\n overflow: hidden;\n white-space: nowrap;\n }\n .date {\n margin-bottom: 6px;\n }\n .types {\n margin-bottom: 6px;\n font-size: 16px;\n }\n .order-status {\n font-weight: 600;\n font-size: 16px;\n }\n\n #error-subs {\n margin: 20px 0 0;\n width: 100%;\n box-sizing: border-box;\n text-align: center;\n }\n\n @media (min-width: 768px) {\n #error-subs {\n margin: 20px 0;\n }\n }\n"])), function (props) {
44
44
  return props.theme.colors.darkTextColor;
45
45
  });
46
46
  var ValidationText = exports.ValidationText = _styledComponents.default.div(_templateObject15 || (_templateObject15 = _taggedTemplateLiteral(["\n color: ", ";\n ", "\n"])), function (props) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-external",
3
- "version": "13.0.4",
3
+ "version": "13.0.5",
4
4
  "description": "Ordering UI Components",
5
5
  "main": "./_modules/index.js",
6
6
  "exports": {
@@ -1,4 +1,4 @@
1
- import React, { useState, useEffect } from 'react'
1
+ import React, { useState, useEffect, useRef } from 'react'
2
2
  import moment from 'moment'
3
3
  import { useLocation } from 'react-router-dom'
4
4
  import {
@@ -62,6 +62,8 @@ const MomentControlUI = (props) => {
62
62
  preorderMinimumDays
63
63
  } = props
64
64
 
65
+ const scheduleItemRef = useRef()
66
+ const timeListRef = useRef()
65
67
  const [{ configs }] = useConfig()
66
68
  const is12hours = configs?.general_hour_format?.value?.includes('hh:mm')
67
69
  const [{ parseTime }] = useUtils()
@@ -72,6 +74,7 @@ const MomentControlUI = (props) => {
72
74
  const [timeList, setTimeList] = useState([])
73
75
  const [scheduleList, setScheduleList] = useState(null)
74
76
  const [isEnabled, setIsEnabled] = useState(true)
77
+ const [nextTime, setNextTime] = useState(null)
75
78
 
76
79
  const handleCheckBoxChange = (index) => {
77
80
  if (index) {
@@ -167,8 +170,8 @@ const MomentControlUI = (props) => {
167
170
  _timeLists = hoursList
168
171
  .filter(hour => (Object.keys(business || {})?.length === 0 || schedule?.lapses?.some(lapse =>
169
172
  moment(dateSelected + ` ${hour.startTime}`) >= moment(dateSelected + ` ${lapse.open.hour}:${lapse.open.minute}`).add(preorderLeadTime, 'minutes') && moment(dateSelected + ` ${hour.endTime}`) <= moment(dateSelected + ` ${lapse.close.hour}:${lapse.close.minute}`))) &&
170
- moment(dateSelected + ` ${hour.startTime}`) < moment(dateSelected + ` ${hour.endTime}`) &&
171
- (moment().add(preorderLeadTime, 'minutes') < moment(dateSelected + ` ${hour.startTime}`) || !cateringPreorder))
173
+ moment(dateSelected + ` ${hour.startTime}`) < moment(dateSelected + ` ${hour.endTime}`) &&
174
+ (moment().add(preorderLeadTime, 'minutes') < moment(dateSelected + ` ${hour.startTime}`) || !cateringPreorder))
172
175
  .map(hour => {
173
176
  return {
174
177
  value: hour.startTime,
@@ -213,6 +216,32 @@ const MomentControlUI = (props) => {
213
216
  setLocalMoment()
214
217
  }, [])
215
218
 
219
+ useEffect(() => {
220
+ if (timeListRef?.current && !orderState.loading && timeSelected) {
221
+ timeListRef.current.scroll({
222
+ left: 0,
223
+ top: scheduleItemRef?.current?.offsetTop - 300
224
+ })
225
+ }
226
+ }, [timeListRef?.current, timeSelected, orderState.loading, timeList?.length])
227
+
228
+ useEffect(() => {
229
+ if (preorderMinimumDays === 0 && preorderLeadTime === 0) return
230
+ const isToday = dateSelected === moment().format('YYYY-MM-DD')
231
+ if (isCart && isToday && !orderState?.loading && timeList?.length > 0) {
232
+ setNextTime(timeList?.[0] ?? null)
233
+ }
234
+ }, [timeList?.length])
235
+
236
+ useEffect(() => {
237
+ if (nextTime?.value && timeList?.length > 0 && isCart && !orderState?.loading && !(preorderMinimumDays === 0 && preorderLeadTime === 0)) {
238
+ const notime = timeList?.filter((_, i) => i !== 0)?.find?.(time => time?.value === timeSelected)
239
+ if (!notime) {
240
+ handleChangeTime(nextTime?.value)
241
+ }
242
+ }
243
+ }, [nextTime?.value])
244
+
216
245
  return (
217
246
  <div id='moment_control'>
218
247
  {!isAppoint && (
@@ -227,7 +256,7 @@ const MomentControlUI = (props) => {
227
256
  isLoading={orderState?.loading}
228
257
  >
229
258
  {isASP ? <CheckedIcon /> : <CgRadioCheck />}
230
- <span>{t('CHECKOUT_ASAP', 'ASAP')} ({moment(new Date()).format('LLLL')} - {t('DELIVERY_TIME', 'delivery time')})</span>
259
+ <span>{t('CHECKOUT_ASAP', 'ASAP')} ({moment(new Date()).format('LLLL')} + {t('DELIVERY_TIME', 'delivery time')})</span>
231
260
  </CheckBoxWrapper>
232
261
  )}
233
262
  <CheckBoxWrapper
@@ -300,7 +329,7 @@ const MomentControlUI = (props) => {
300
329
  </Swiper>
301
330
  </DaysSwiper>
302
331
  </DateWrapper>
303
- <TimeListWrapper>
332
+ <TimeListWrapper ref={timeListRef}>
304
333
  {(isEnabled && timeList?.length > 0) ? (
305
334
  <>
306
335
  {timeList.map((time, i) => (
@@ -314,7 +343,7 @@ const MomentControlUI = (props) => {
314
343
  <span>
315
344
  {cateringPreorder && (
316
345
  <CheckIcon>
317
- {timeSelected === time.value ? <CheckedIcon cateringPreorder={cateringPreorder} /> : <CgRadioCheck />}
346
+ {timeSelected === time.value ? <CheckedIcon ref={scheduleItemRef} cateringPreorder={cateringPreorder} /> : <CgRadioCheck />}
318
347
  </CheckIcon>
319
348
  )}
320
349
  <p>
@@ -183,7 +183,6 @@ export const OrderInfo = styled.div`
183
183
  }
184
184
  .date {
185
185
  margin-bottom: 6px;
186
- text-transform: uppercase;
187
186
  }
188
187
  .types {
189
188
  margin-bottom: 6px;