ordering-ui-react-native 0.24.10 → 0.24.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.24.10",
3
+ "version": "0.24.12",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -72,18 +72,20 @@ export const ProductItemAccordion = (props: ProductItemAccordionParams) => {
72
72
  const parseOptions = typeof productInfo().options === 'string' ? JSON.parse(productInfo().options) : productInfo().options
73
73
 
74
74
  const getProductPrice = (product: any) => {
75
- let subOptionPrice = 0;
76
- if (product?.options?.length > 0 && product?.options[0]?.suboptions?.length > 0) {
77
- for (const option of product?.options) {
78
- for (const suboption of option?.suboptions) {
79
- subOptionPrice += suboption.quantity * suboption.price;
75
+ let subOptionPrice = 0
76
+ if (Array.isArray(product?.options)) {
77
+ if (product.options?.length > 0) {
78
+ for (const option of product.options) {
79
+ for (const suboption of option.suboptions) {
80
+ subOptionPrice += suboption.quantity * ((['left', 'right'].includes(suboption.position)) ? (suboption.half_price ?? suboption.price) : suboption.price)
81
+ }
80
82
  }
81
83
  }
82
84
  }
83
85
 
84
- const price = product.quantity * (product.price + subOptionPrice);
85
- return parseFloat(price.toFixed(2));
86
- };
86
+ const price = product.quantity * (product.price + subOptionPrice)
87
+ return parseFloat(price.toFixed(2))
88
+ }
87
89
 
88
90
  const getFormattedSubOptionName = ({ quantity, name, position, price }: any) => {
89
91
  if (name !== 'No') {
@@ -255,7 +255,7 @@ const CheckoutUI = (props: any) => {
255
255
 
256
256
  const handleMomentClick = () => {
257
257
  if (isPreOrder) {
258
- navigation.navigate('MomentOption')
258
+ navigation.navigate('MomentOption', { business: businessDetails?.business })
259
259
  }
260
260
  }
261
261
 
@@ -163,6 +163,7 @@ const MomentOptionUI = (props: MomentOptionParams) => {
163
163
  const [selectDate, setSelectedDate] = useState<any>(dateSelected)
164
164
  const [timeList, setTimeList] = useState<any>(hoursList)
165
165
  const [nextTime, setNextTime] = useState(null)
166
+ const [isEnabled, setIsEnabled] = useState(false)
166
167
 
167
168
  const goToBack = () => navigation?.canGoBack() && navigation.goBack();
168
169
 
@@ -180,6 +181,60 @@ const MomentOptionUI = (props: MomentOptionParams) => {
180
181
  handleChangeTime(time ?? selectedTime);
181
182
  };
182
183
 
184
+ const validateSelectedDate = (curdate: any, menu: any) => {
185
+ const day = moment(curdate).format('d')
186
+ setIsEnabled(menu?.schedule?.[day]?.enabled || false)
187
+ }
188
+
189
+ const getTimes = (curdate: any, menu: any) => {
190
+ validateSelectedDate(curdate, menu)
191
+ const date = new Date()
192
+ var dateSeleted = new Date(curdate)
193
+ var times = []
194
+ for (var k = 0; k < menu.schedule[dateSeleted.getDay()].lapses.length; k++) {
195
+ var open = {
196
+ hour: menu.schedule[dateSeleted.getDay()].lapses[k].open.hour,
197
+ minute: menu.schedule[dateSeleted.getDay()].lapses[k].open.minute
198
+ }
199
+ var close = {
200
+ hour: menu.schedule[dateSeleted.getDay()].lapses[k].close.hour,
201
+ minute: menu.schedule[dateSeleted.getDay()].lapses[k].close.minute
202
+ }
203
+ for (var i = open.hour; i <= close.hour; i++) {
204
+ if (date.getDate() !== dateSeleted.getDate() || i >= date.getHours()) {
205
+ let hour = ''
206
+ let meridian = ''
207
+ if (is12hours) {
208
+ if (i === 0) {
209
+ hour = '12'
210
+ meridian = ' ' + t('AM', 'AM')
211
+ } else if (i > 0 && i < 12) {
212
+ hour = (i < 10 ? '0' + i : i)
213
+ meridian = ' ' + t('AM', 'AM')
214
+ } else if (i === 12) {
215
+ hour = '12'
216
+ meridian = ' ' + t('PM', 'PM')
217
+ } else {
218
+ hour = ((i - 12 < 10) ? '0' + (i - 12) : `${(i - 12)}`)
219
+ meridian = ' ' + t('PM', 'PM')
220
+ }
221
+ } else {
222
+ hour = i < 10 ? '0' + i : i
223
+ }
224
+ for (let j = (i === open.hour ? open.minute : 0); j <= (i === close.hour ? close.minute : 59); j += 15) {
225
+ if (i !== date.getHours() || j >= date.getMinutes() || date.getDate() !== dateSeleted.getDate()) {
226
+ times.push({
227
+ text: hour + ':' + (j < 10 ? '0' + j : j) + meridian,
228
+ value: (i < 10 ? '0' + i : i) + ':' + (j < 10 ? '0' + j : j)
229
+ })
230
+ }
231
+ }
232
+ }
233
+ }
234
+ }
235
+ return times
236
+ }
237
+
183
238
  const momento = moment(
184
239
  `${dateSelected} ${timeSelected}`,
185
240
  'YYYY-MM-DD HH:mm',
@@ -319,18 +374,8 @@ const MomentOptionUI = (props: MomentOptionParams) => {
319
374
  setTimeList(_timeLists)
320
375
  }
321
376
  } else {
322
- setTimeList(hoursList.map(hour => {
323
- return {
324
- value: hour.startTime,
325
- text: is12hours ? (
326
- hour.startTime.includes('12')
327
- ? `${hour.startTime}PM`
328
- : parseTime(moment(hour.startTime, 'HH:mm'), { outputFormat: 'hh:mma' })
329
- ) : (
330
- parseTime(moment(hour.startTime, 'HH:mm'), { outputFormat: 'HH:mm' })
331
- )
332
- }
333
- }))
377
+ const _times = getTimes(selectDate, business)
378
+ setTimeList(_times)
334
379
  }
335
380
  }, [dateSelected, hoursList?.length, JSON.stringify(datesWhitelist), JSON.stringify(business)])
336
381
 
@@ -454,7 +499,7 @@ const MomentOptionUI = (props: MomentOptionParams) => {
454
499
  </View>
455
500
  )}
456
501
  <TimeListWrapper nestedScrollEnabled={true} cateringPreorder={cateringPreorder}>
457
- {timeList?.length > 0 ? (
502
+ {isEnabled && timeList?.length > 0 ? (
458
503
  <TimeContentWrapper>
459
504
  {timeList.map((time: any, i: number) => (
460
505
  <TimeListItem
@@ -40,7 +40,7 @@ export const TimeItem = styled.View`
40
40
  border-radius: 7.6px;
41
41
  justify-content: center;
42
42
  align-items: center;
43
- margin: 10px 0px;
43
+ margin: 10px 5px;
44
44
  ${({ cateringPreorder }: any) => cateringPreorder && css`
45
45
  background: #fff;
46
46
  width: 100%;
@@ -114,7 +114,7 @@ const OrderProgressUI = (props: any) => {
114
114
  setInitialLoaded(true)
115
115
  }, [orderList.loading, initialLoaded])
116
116
 
117
- const progressBarObjt = (s: any) => lastOrder?.delivery_type && lastOrder?.delivery_type === 2 ? getOrderStatuPickUp(s) : getOrderStatus(s, t)
117
+ const progressBarObjt = (s: any) => lastOrder?.delivery_type && lastOrder?.delivery_type === 2 ? getOrderStatuPickUp(s, t) : getOrderStatus(s, t)
118
118
 
119
119
  return (
120
120
  <>