ordering-ui-external 2.5.0 → 2.5.1

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.
Files changed (30) hide show
  1. package/_bundles/{0.ordering-ui.5657c6a53b3791887fd7.js → 0.ordering-ui.5488030edb520175432d.js} +1 -1
  2. package/_bundles/{1.ordering-ui.5657c6a53b3791887fd7.js → 1.ordering-ui.5488030edb520175432d.js} +1 -1
  3. package/_bundles/{2.ordering-ui.5657c6a53b3791887fd7.js → 2.ordering-ui.5488030edb520175432d.js} +1 -1
  4. package/_bundles/{4.ordering-ui.5657c6a53b3791887fd7.js → 4.ordering-ui.5488030edb520175432d.js} +1 -1
  5. package/_bundles/{5.ordering-ui.5657c6a53b3791887fd7.js → 5.ordering-ui.5488030edb520175432d.js} +1 -1
  6. package/_bundles/{6.ordering-ui.5657c6a53b3791887fd7.js → 6.ordering-ui.5488030edb520175432d.js} +1 -1
  7. package/_bundles/{7.ordering-ui.5657c6a53b3791887fd7.js → 7.ordering-ui.5488030edb520175432d.js} +2 -2
  8. package/_bundles/{8.ordering-ui.5657c6a53b3791887fd7.js → 8.ordering-ui.5488030edb520175432d.js} +1 -1
  9. package/_bundles/{9.ordering-ui.5657c6a53b3791887fd7.js → 9.ordering-ui.5488030edb520175432d.js} +1 -1
  10. package/_bundles/ordering-ui.5488030edb520175432d.js +2 -0
  11. package/_modules/components/StripeMethodForm/index.js +26 -11
  12. package/_modules/themes/five/src/components/CitiesControl/index.js +1 -1
  13. package/_modules/themes/five/src/components/HomeHero/layouts/OriginalHomeHero/index.js +1 -1
  14. package/_modules/themes/five/src/components/MultiCartsPaymethodsAndWallets/index.js +36 -5
  15. package/_modules/themes/five/src/components/MultiCheckout/index.js +30 -3
  16. package/_modules/themes/five/src/components/OrderDetails/OrderEta.js +2 -4
  17. package/_modules/themes/five/src/components/PaymentOptions/index.js +8 -5
  18. package/_modules/themes/five/src/components/StripeElementsForm/index.js +3 -1
  19. package/package.json +1 -1
  20. package/src/components/StripeMethodForm/index.js +22 -10
  21. package/src/themes/five/src/components/CitiesControl/index.js +1 -1
  22. package/src/themes/five/src/components/HomeHero/layouts/OriginalHomeHero/index.js +1 -1
  23. package/src/themes/five/src/components/MultiCartsPaymethodsAndWallets/index.js +83 -51
  24. package/src/themes/five/src/components/MultiCheckout/index.js +16 -0
  25. package/src/themes/five/src/components/OrderDetails/OrderEta.js +4 -2
  26. package/src/themes/five/src/components/PaymentOptions/index.js +7 -4
  27. package/src/themes/five/src/components/StripeElementsForm/index.js +3 -1
  28. package/_bundles/ordering-ui.5657c6a53b3791887fd7.js +0 -2
  29. /package/_bundles/{7.ordering-ui.5657c6a53b3791887fd7.js.LICENSE.txt → 7.ordering-ui.5488030edb520175432d.js.LICENSE.txt} +0 -0
  30. /package/_bundles/{ordering-ui.5657c6a53b3791887fd7.js.LICENSE.txt → ordering-ui.5488030edb520175432d.js.LICENSE.txt} +0 -0
@@ -1,4 +1,4 @@
1
- import React from 'react'
1
+ import React, { useState } from 'react'
2
2
  import {
3
3
  useLanguage,
4
4
  useConfig,
@@ -28,6 +28,8 @@ import {
28
28
  SectionLeft,
29
29
  SectionLeftText
30
30
  } from './styles'
31
+ import { StripeElementsForm } from '../StripeElementsForm'
32
+ import Modal from '../Modal'
31
33
 
32
34
  const stripeOptions = ['stripe_direct', 'stripe', 'stripe_connect']
33
35
 
@@ -72,17 +74,21 @@ const MultiCartsPaymethodsAndWalletsUI = (props) => {
72
74
  handlePaymethodDataChange,
73
75
  setCardList,
74
76
  walletsPaymethod,
75
- isCustomerMode
77
+ isCustomerMode,
78
+ handlePlaceOrder,
79
+ cartGroup
76
80
  } = props
77
81
 
78
82
  const theme = useTheme()
79
83
  const [, t] = useLanguage()
80
84
  const [{ configs }] = useConfig()
81
85
  const [{ parsePrice }] = useUtils()
86
+ const [openPaymethod, setOpenPaymethod] = useState(null)
82
87
 
83
88
  const isWalletCashEnabled = configs?.wallet_cash_enabled?.value === '1'
84
89
  const isWalletPointsEnabled = configs?.wallet_credit_point_enabled?.value === '1'
85
-
90
+ const methodsPay = ['global_google_pay', 'global_apple_pay']
91
+ const stripeDirectMethods = ['stripe_direct', ...methodsPay]
86
92
  const walletName = {
87
93
  cash: {
88
94
  name: t('PAY_WITH_CASH_WALLET', 'Pay with Cash Wallet'),
@@ -109,7 +115,10 @@ const MultiCartsPaymethodsAndWalletsUI = (props) => {
109
115
  {(!isCustomerMode || (isCustomerMode && (paymethod.gateway === 'card_delivery' || paymethod.gateway === 'cash'))) && (
110
116
  <PayCard
111
117
  isActive={paymethodSelected?.id === paymethod.id}
112
- onClick={() => handleSelectPaymethod({ ...paymethod, paymethod: { gateway: paymethod.gateway }, paymethod_id: paymethod?.id })}
118
+ onClick={() => {
119
+ handleSelectPaymethod({ ...paymethod, paymethod: { gateway: paymethod.gateway }, paymethod_id: paymethod?.id })
120
+ setOpenPaymethod(paymethod)
121
+ }}
113
122
  >
114
123
  <div>{getPayIcon(paymethod.id)}</div>
115
124
  <p>{t(paymethod?.gateway.toUpperCase(), paymethod?.name)}</p>
@@ -161,57 +170,80 @@ const MultiCartsPaymethodsAndWalletsUI = (props) => {
161
170
  {walletsState?.result?.filter(wallet =>
162
171
  paymethodsAndWallets.wallets.find(item => item.type === wallet.type))
163
172
  .map((wallet, idx) => walletName[wallet.type]?.isActive &&
164
- (
165
- <WalletOptionContainer
166
- key={wallet.type}
167
- isBottomBorder={idx === paymethodsAndWallets.wallets?.length - 1}
168
- >
169
- <SectionLeft>
170
- <Checkbox
171
- name={`payment_option_${wallet.type}`}
172
- id={`custom-checkbox-${idx}`}
173
- disabled={
174
- (balance === 0 && !walletsPaymethod?.find(walletPay => walletPay.wallet_id === wallet.id)?.id) ||
175
- wallet.balance === 0
176
- }
177
- value={`payment_option_${wallet.type}`}
178
- checked={!!walletsPaymethod?.find(walletPay => walletPay.wallet_id === wallet.id)?.id}
179
- onChange={() => handleSelectWallet(
180
- !walletsPaymethod?.find(walletPay => walletPay.wallet_id === wallet.id)?.id,
181
- wallet
182
- )}
183
- />
184
- <SectionLeftText>
185
- <label
186
- style={{
187
- color: (balance === 0 && !walletsPaymethod?.find(walletPay => walletPay.wallet_id === wallet.id)?.id) ||
188
- wallet.balance === 0 ? theme.colors.darkGray : 'black'
189
- }}
190
- htmlFor={`custom-checkbox-${idx}`}
191
- >
192
- {walletName[wallet.type]?.name}
193
- </label>
194
- </SectionLeftText>
195
- </SectionLeft>
196
- <div>
197
- {wallet.type === 'cash' && (
198
- <span>{parsePrice(wallet?.balance, { isTruncable: true })}</span>
199
- )}
200
- {wallet.type === 'credit_point' && (
201
- <span>
202
- <span style={{ color: theme.colors.primary }}>
203
- {`${wallet?.balance} ${t('POINTS', 'Points')}`}
204
- </span> {wallet?.balance > 0 && `= ${parsePrice(wallet?.balance / wallet?.redemption_rate, { isTruncable: true })}`}
205
- </span>
206
- )}
207
- </div>
208
- </WalletOptionContainer>
209
- ))}
173
+ (
174
+ <WalletOptionContainer
175
+ key={wallet.type}
176
+ isBottomBorder={idx === paymethodsAndWallets.wallets?.length - 1}
177
+ >
178
+ <SectionLeft>
179
+ <Checkbox
180
+ name={`payment_option_${wallet.type}`}
181
+ id={`custom-checkbox-${idx}`}
182
+ disabled={
183
+ (balance === 0 && !walletsPaymethod?.find(walletPay => walletPay.wallet_id === wallet.id)?.id) ||
184
+ wallet.balance === 0
185
+ }
186
+ value={`payment_option_${wallet.type}`}
187
+ checked={!!walletsPaymethod?.find(walletPay => walletPay.wallet_id === wallet.id)?.id}
188
+ onChange={() => handleSelectWallet(
189
+ !walletsPaymethod?.find(walletPay => walletPay.wallet_id === wallet.id)?.id,
190
+ wallet
191
+ )}
192
+ />
193
+ <SectionLeftText>
194
+ <label
195
+ style={{
196
+ color: (balance === 0 && !walletsPaymethod?.find(walletPay => walletPay.wallet_id === wallet.id)?.id) ||
197
+ wallet.balance === 0 ? theme.colors.darkGray : 'black'
198
+ }}
199
+ htmlFor={`custom-checkbox-${idx}`}
200
+ >
201
+ {walletName[wallet.type]?.name}
202
+ </label>
203
+ </SectionLeftText>
204
+ </SectionLeft>
205
+ <div>
206
+ {wallet.type === 'cash' && (
207
+ <span>{parsePrice(wallet?.balance, { isTruncable: true })}</span>
208
+ )}
209
+ {wallet.type === 'credit_point' && (
210
+ <span>
211
+ <span style={{ color: theme.colors.primary }}>
212
+ {`${wallet?.balance} ${t('POINTS', 'Points')}`}
213
+ </span> {wallet?.balance > 0 && `= ${parsePrice(wallet?.balance / wallet?.redemption_rate, { isTruncable: true })}`}
214
+ </span>
215
+ )}
216
+ </div>
217
+ </WalletOptionContainer>
218
+ ))}
210
219
  </>
211
220
  )}
212
221
  </WalletPaymentOptionContainer>
213
222
  )}
214
-
223
+ {/* Stripe direct, Google pay, Apple pay */}
224
+ <Modal
225
+ title={t('ADD_CARD', 'Add card')}
226
+ open={stripeDirectMethods?.includes(openPaymethod?.gateway) && !paymethodSelected?.paymethod_data?.id}
227
+ className='modal-info'
228
+ onClose={() => setOpenPaymethod(null)}
229
+ >
230
+ {!paymethodSelected?.data?.publishable &&
231
+ <Container>
232
+ <p>{t('ADD_PUBLISHABLE_KEY', 'Please add a publishable key')}</p>
233
+ </Container>}
234
+ {paymethodSelected?.data?.publishable && stripeDirectMethods?.includes(paymethodSelected?.paymethod?.gateway) && (
235
+ <StripeElementsForm
236
+ methodsPay={methodsPay}
237
+ paymethod={paymethodSelected?.paymethod?.gateway}
238
+ businessId={props.businessId}
239
+ cartGroup={cartGroup?.result}
240
+ publicKey={paymethodSelected?.data?.publishable || paymethodSelected?.data?.publishable_key}
241
+ handleSource={handlePaymethodDataChange}
242
+ onCancel={() => setOpenPaymethod(null)}
243
+ handlePlaceOrder={handlePlaceOrder}
244
+ />
245
+ )}
246
+ </Modal>
215
247
  </Container>
216
248
  )
217
249
  }
@@ -101,6 +101,11 @@ const MultiCheckoutUI = (props) => {
101
101
  ? JSON.parse(configs?.driver_tip_options?.value) || []
102
102
  : configs?.driver_tip_options?.value || []
103
103
 
104
+ const methodsPay = ['global_google_pay', 'global_apple_pay']
105
+ const creditPointPlan = loyaltyPlansState?.result?.find((loyal) => loyal.type === 'credit_point')
106
+ const businessIds = openCarts.map((cart) => cart.business_id)
107
+ const loyalBusinessIds = creditPointPlan?.businesses?.filter((b) => b.accumulates).map((item) => item.business_id) ?? []
108
+ const creditPointPlanOnBusiness = businessIds.every((bid) => loyalBusinessIds.includes(bid)) && creditPointPlan
104
109
  const creditPointGeneralPlan = loyaltyPlansState?.result?.find((loyal) => loyal.type === 'credit_point')
105
110
  const loyalBusinessAvailable = creditPointGeneralPlan?.businesses?.filter((b) => b.accumulates) ?? []
106
111
 
@@ -209,6 +214,15 @@ const MultiCheckoutUI = (props) => {
209
214
  }
210
215
  }, [walletState.error])
211
216
 
217
+ useEffect(() => {
218
+ if (methodsPay.includes(paymethodSelected?.paymethod?.gateway) && typeof paymethodSelected?.paymethod_data === 'string') {
219
+ const hasSource = JSON.parse(paymethodSelected?.paymethod_data)?.source_id
220
+ if (hasSource) {
221
+ handlePlaceOrder()
222
+ }
223
+ }
224
+ }, [paymethodSelected])
225
+
212
226
  return (
213
227
  <>
214
228
  {((!cartGroup?.loading && openCarts.length === 0) || !cartUuid) ? (
@@ -260,7 +274,9 @@ const MultiCheckoutUI = (props) => {
260
274
  handlePaymethodDataChange={handlePaymethodDataChange}
261
275
  cartUuid={cartUuid}
262
276
  isCustomerMode={isCustomerMode}
277
+ cartGroup={cartGroup}
263
278
  setCardList={setCardList}
279
+ handlePlaceOrder={handlePlaceOrder}
264
280
  />
265
281
  </PaymentMethodContainer>
266
282
 
@@ -38,9 +38,11 @@ export const OrderEta = (props) => {
38
38
  }
39
39
  _estimatedTime = moment.utc(_delivery).add(totalEta, 'minutes')
40
40
  } else {
41
- _estimatedTime = moment.utc(_delivery).add(order?.eta_time, 'minutes')
41
+ const _etaTime = order?.delivered_in
42
+ ? order?.delivered_in + order?.eta_time
43
+ : order?.eta_time
44
+ _estimatedTime = moment.utc(_delivery).add(_etaTime, 'minutes')
42
45
  }
43
- if (order?.delivered_in) { _estimatedTime = moment.utc(_delivery).add(order?.delivered_in, 'minutes')}
44
46
  _estimatedTime = outputFormat ? moment(_estimatedTime).local().format(outputFormat) : parseDate(_estimatedTime, { utc: false })
45
47
  setEstimatedDeliveryTime(_estimatedTime)
46
48
  }
@@ -112,10 +112,13 @@ const PaymentOptionsUI = (props) => {
112
112
 
113
113
  const includeKioskPaymethods = ['cash', 'card_delivery']
114
114
 
115
+ const multiCheckoutMethods = ['global_google_pay', 'global_apple_pay']
116
+
115
117
  const list = paymethodsList ? paymethodsList?.paymethods : paymethods?.map(pay => pay.paymethod)
116
118
 
117
119
  const popupMethods = ['stripe', 'stripe_direct', 'stripe_connect', 'stripe_redirect', 'paypal', 'square', 'google_pay', 'apple_pay']
118
- const supportedMethods = list?.filter(p => useKioskApp ? includeKioskPaymethods.includes(p.gateway) : p)
120
+
121
+ const supportedMethods = list?.filter(p => !multiCheckoutMethods.includes(p.gateway))?.filter(p => useKioskApp ? includeKioskPaymethods.includes(p.gateway) : p)
119
122
 
120
123
  const handlePaymentMethodClick = (paymethod) => {
121
124
  if (paymethod?.gateway === 'paypal' &&
@@ -176,7 +179,7 @@ const PaymentOptionsUI = (props) => {
176
179
  if (methodsPay.includes(paymethodSelected?.gateway) && paymethodData?.id && paymethodSelected?.data?.card) {
177
180
  handlePlaceOrder()
178
181
  }
179
- }, [paymethodData, paymethodSelected])
182
+ }, [JSON.stringify(paymethodData), paymethodSelected])
180
183
 
181
184
  return (
182
185
  <>
@@ -193,10 +196,10 @@ const PaymentOptionsUI = (props) => {
193
196
  supportedMethods.sort((a, b) => a.id - b.id).map(paymethod => (
194
197
  <React.Fragment key={paymethod.id}>
195
198
  {
196
- (!isCustomerMode || (isCustomerMode && (paymethod.gateway === 'card_delivery' || paymethod.gateway === 'cash'))) && (
199
+ ((!isCustomerMode && paymethod.gateway) || (isCustomerMode && (paymethod.gateway === 'card_delivery' || paymethod.gateway === 'cash'))) && (
197
200
  <PayCard
198
201
  isDisabled={isDisabled}
199
- className={`card ${(paymethodSelected?.id || isOpenMethod?.paymethod?.id) === paymethod.id ? 'active' : ''}`}
202
+ className={`${(paymethodSelected?.id || isOpenMethod?.paymethod?.id) === paymethod.id ? 'active' : ''}`}
200
203
  onClick={() => handlePaymentMethodClick(paymethod)}
201
204
  >
202
205
  <div>
@@ -22,7 +22,8 @@ const StripeElementsFormUI = (props) => {
22
22
  paymethod,
23
23
  cart,
24
24
  handlePlaceOrder,
25
- methodsPay
25
+ methodsPay,
26
+ cartGroup
26
27
  } = props
27
28
  const [, t] = useLanguage()
28
29
  return (
@@ -38,6 +39,7 @@ const StripeElementsFormUI = (props) => {
38
39
  {methodsPay?.includes(paymethod) ? (
39
40
  <StripeMethodForm
40
41
  cart={cart}
42
+ cartGroup={cartGroup}
41
43
  handleSource={handleSource}
42
44
  onNewCard={onNewCard}
43
45
  toSave={toSave}