ordering-ui-external 11.0.11 → 12.0.0
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/_bundles/{0.ordering-ui.f6ab4fd53f85792a6e5f.js → 0.ordering-ui.6487547c80bb5fd2fdee.js} +1 -1
- package/_bundles/{7.ordering-ui.f6ab4fd53f85792a6e5f.js → 7.ordering-ui.6487547c80bb5fd2fdee.js} +1 -1
- package/_bundles/{ordering-ui.f6ab4fd53f85792a6e5f.js → ordering-ui.6487547c80bb5fd2fdee.js} +2 -2
- package/_modules/themes/callcenterOriginal/src/components/Orders/OrdersTable/styles.js +1 -1
- package/_modules/themes/five/src/components/BusinessController/styles.js +2 -2
- package/_modules/themes/five/src/components/Cart/index.js +7 -7
- package/_modules/themes/five/src/components/Checkout/index.js +108 -87
- package/_modules/themes/five/src/components/MultiCheckout/index.js +65 -20
- package/_modules/themes/five/src/components/UserDetails/index.js +2 -2
- package/_modules/themes/five/src/components/UserFormDetails/index.js +59 -49
- package/_modules/utils/index.js +4 -3
- package/package.json +2 -2
- package/src/themes/callcenterOriginal/src/components/Orders/OrdersTable/styles.js +1 -1
- package/src/themes/five/src/components/BusinessController/styles.js +4 -4
- package/src/themes/five/src/components/Cart/index.js +6 -6
- package/src/themes/five/src/components/Checkout/index.js +75 -66
- package/src/themes/five/src/components/MultiCheckout/index.js +53 -21
- package/src/themes/five/src/components/UserDetails/index.js +2 -2
- package/src/themes/five/src/components/UserFormDetails/index.js +75 -66
- package/src/utils/index.js +3 -3
- /package/_bundles/{1.ordering-ui.f6ab4fd53f85792a6e5f.js → 1.ordering-ui.6487547c80bb5fd2fdee.js} +0 -0
- /package/_bundles/{2.ordering-ui.f6ab4fd53f85792a6e5f.js → 2.ordering-ui.6487547c80bb5fd2fdee.js} +0 -0
- /package/_bundles/{4.ordering-ui.f6ab4fd53f85792a6e5f.js → 4.ordering-ui.6487547c80bb5fd2fdee.js} +0 -0
- /package/_bundles/{5.ordering-ui.f6ab4fd53f85792a6e5f.js → 5.ordering-ui.6487547c80bb5fd2fdee.js} +0 -0
- /package/_bundles/{6.ordering-ui.f6ab4fd53f85792a6e5f.js → 6.ordering-ui.6487547c80bb5fd2fdee.js} +0 -0
- /package/_bundles/{7.ordering-ui.f6ab4fd53f85792a6e5f.js.LICENSE.txt → 7.ordering-ui.6487547c80bb5fd2fdee.js.LICENSE.txt} +0 -0
- /package/_bundles/{8.ordering-ui.f6ab4fd53f85792a6e5f.js → 8.ordering-ui.6487547c80bb5fd2fdee.js} +0 -0
- /package/_bundles/{9.ordering-ui.f6ab4fd53f85792a6e5f.js → 9.ordering-ui.6487547c80bb5fd2fdee.js} +0 -0
- /package/_bundles/{ordering-ui.f6ab4fd53f85792a6e5f.js.LICENSE.txt → ordering-ui.6487547c80bb5fd2fdee.js.LICENSE.txt} +0 -0
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
useApi,
|
|
11
11
|
useLanguage,
|
|
12
12
|
useUtils,
|
|
13
|
-
useValidationFields,
|
|
14
13
|
useConfig,
|
|
15
14
|
useCustomer,
|
|
16
15
|
useEvent
|
|
@@ -104,7 +103,6 @@ const CheckoutUI = (props) => {
|
|
|
104
103
|
} = props
|
|
105
104
|
|
|
106
105
|
const theme = useTheme()
|
|
107
|
-
const [validationFields] = useValidationFields()
|
|
108
106
|
const [{ options, loading }] = useOrder()
|
|
109
107
|
const [, t] = useLanguage()
|
|
110
108
|
const [{ parsePrice }] = useUtils()
|
|
@@ -128,7 +126,6 @@ const CheckoutUI = (props) => {
|
|
|
128
126
|
const [allowedGuest, setAllowedGuest] = useState(false)
|
|
129
127
|
const [cardList, setCardList] = useState([])
|
|
130
128
|
const [paymethodClicked, setPaymethodClicked] = useState(null)
|
|
131
|
-
const [orderTypeValidationFields, setOrderTypeValidationFields] = useState([])
|
|
132
129
|
const [productLoading, setProductLoading] = useState(false)
|
|
133
130
|
|
|
134
131
|
const cardsMethods = ['stripe', 'credomatic']
|
|
@@ -141,20 +138,22 @@ const CheckoutUI = (props) => {
|
|
|
141
138
|
(isWalletCashEnabled || isWalletCreditPointsEnabled) && !useKioskApp && !isCustomerMode
|
|
142
139
|
const isMultiDriverTips = theme?.header?.components?.layout?.type?.toLowerCase() === 'chew'
|
|
143
140
|
const notFields = ['coupon', 'driver_tip', 'mobile_phone', 'address', 'zipcode', 'address_notes', 'comments']
|
|
144
|
-
|
|
141
|
+
const hexTest = /[0-9A-Fa-f]{6}/g;
|
|
142
|
+
const primaryColor = theme?.colors?.primary?.split?.('#')?.[1]
|
|
145
143
|
const placeSpotTypes = [3, 4, 5]
|
|
146
144
|
const placeSpotsEnabled = placeSpotTypes.includes(options?.type) && !useKioskApp
|
|
147
145
|
const isGiftCardCart = !cart?.business_id
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const validateCommentsCartField = (!user?.guest_id ? (validationFields?.fields?.checkout?.comments?.enabled && validationFields?.fields?.checkout?.comments?.required) : (guestCheckoutComment?.enabled && guestCheckoutComment?.required)) && (cart?.comment === null || cart?.comment?.trim().length === 0)
|
|
154
|
-
const validateDriverTipField = options.type === 1 && (!user?.guest_id ? (validationFields?.fields?.checkout?.driver_tip?.enabled && validationFields?.fields?.checkout?.driver_tip?.required) : (guestCheckoutDriveTip?.enabled && guestCheckoutDriveTip?.required)) && (Number(cart?.driver_tip) <= 0)
|
|
146
|
+
const checkoutFields = useMemo(() => checkoutFieldsState?.fields?.filter(field => field.order_type_id === options?.type), [checkoutFieldsState, options])
|
|
147
|
+
const guestCheckoutDriveTip = useMemo(() => checkoutFields?.find(field => field.order_type_id === 1 && field?.validation_field?.code === 'driver_tip'), [JSON.stringify(checkoutFields), options])
|
|
148
|
+
const guestCheckoutComment = useMemo(() => checkoutFields?.find(field => field.order_type_id === options?.type && field?.validation_field?.code === 'comments'), [JSON.stringify(checkoutFields), options])
|
|
149
|
+
const guestCheckoutCoupon = useMemo(() => checkoutFields?.find(field => field.order_type_id === options?.type && field?.validation_field?.code === 'coupon'), [JSON.stringify(checkoutFields), options])
|
|
150
|
+
const guestCheckoutZipcode = useMemo(() => checkoutFields?.find(field => field.order_type_id === options?.type && field?.validation_field?.code === 'zipcode'), [JSON.stringify(checkoutFields), options])
|
|
155
151
|
|
|
156
|
-
const
|
|
157
|
-
|
|
152
|
+
// const [hasBusinessPlaces, setHasBusinessPlaces] = useState(null)
|
|
153
|
+
const validateCommentsCartField = (guestCheckoutComment?.enabled && (user?.guest_id ? guestCheckoutComment?.required_with_guest : guestCheckoutComment?.required)) && (cart?.comment === null || cart?.comment?.trim().length === 0)
|
|
154
|
+
const validateDriverTipField = options.type === 1 && (guestCheckoutDriveTip?.enabled && (user?.guest_id ? guestCheckoutDriveTip?.required_with_guest : guestCheckoutDriveTip?.required)) && (Number(cart?.driver_tip) <= 0)
|
|
155
|
+
const validateCouponField = (guestCheckoutCoupon?.enabled && (user?.guest_id ? guestCheckoutCoupon?.required_with_guest : guestCheckoutCoupon?.required)) && !cart?.offers?.some(offer => offer?.type === 2)
|
|
156
|
+
const validateZipcodeCard = (guestCheckoutZipcode?.enabled && (user?.guest_id ? guestCheckoutZipcode?.required_with_guest : guestCheckoutZipcode?.required)) && paymethodSelected?.gateway === 'stripe' && paymethodSelected?.data?.card && !paymethodSelected?.data?.card?.zipcode
|
|
158
157
|
|
|
159
158
|
const isDisablePlaceOrderButton = !cart?.valid ||
|
|
160
159
|
(!paymethodSelected && cart?.balance > 0) ||
|
|
@@ -166,8 +165,9 @@ const CheckoutUI = (props) => {
|
|
|
166
165
|
!cart?.valid_maximum ||
|
|
167
166
|
(!cart?.valid_minimum && !(cart?.discount_type === 1 && cart?.discount_rate === 100)) ||
|
|
168
167
|
// (((placeSpotTypes.includes(options?.type) && !cart?.place) && hasBusinessPlaces)) ||
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
validateCommentsCartField ||
|
|
169
|
+
validateDriverTipField ||
|
|
170
|
+
validateCouponField ||
|
|
171
171
|
validateZipcodeCard
|
|
172
172
|
|
|
173
173
|
const driverTipsOptions = typeof configs?.driver_tip_options?.value === 'string'
|
|
@@ -184,7 +184,7 @@ const CheckoutUI = (props) => {
|
|
|
184
184
|
const hideBusinessDetails = theme?.checkout?.components?.business?.hidden
|
|
185
185
|
const hideBusinessMap = theme?.checkout?.components?.map?.hidden
|
|
186
186
|
const hideCustomerDetails = theme?.checkout?.components?.customer?.hidden
|
|
187
|
-
const driverTipsField = !cartState.loading && cart && cart?.business_id && options.type === 1 && cart?.status !== 2 && (
|
|
187
|
+
const driverTipsField = !cartState.loading && cart && cart?.business_id && options.type === 1 && cart?.status !== 2 && (guestCheckoutDriveTip?.enabled) && driverTipsOptions.length > 0 && !useKioskApp
|
|
188
188
|
|
|
189
189
|
const creditPointPlan = loyaltyPlansState?.result?.find(loyal => loyal.type === 'credit_point')
|
|
190
190
|
const creditPointPlanOnBusiness = creditPointPlan?.businesses?.find(b => b.business_id === cart?.business_id && b.accumulates)
|
|
@@ -235,22 +235,21 @@ const CheckoutUI = (props) => {
|
|
|
235
235
|
const checkGuestValidationFields = () => {
|
|
236
236
|
const userSelected = isCustomerMode ? customerState.user : user
|
|
237
237
|
const _requiredFields = checkoutFieldsState?.fields
|
|
238
|
-
.filter(field => (field?.order_type_id === options?.type) && field?.enabled && field?.
|
|
238
|
+
.filter((field) => (field?.order_type_id === options?.type) && field?.enabled && field?.required_with_guest &&
|
|
239
239
|
!notFields.includes(field?.validation_field?.code) &&
|
|
240
240
|
userSelected && !userSelected[field?.validation_field?.code])
|
|
241
|
-
|
|
242
|
-
const guestCheckoutCellPhone = checkoutFieldsState?.fields?.find(field => field.order_type_id === options?.type && field?.validation_field?.code === 'mobile_phone')
|
|
243
|
-
|
|
241
|
+
const requiredFieldsCode = _requiredFields.map((item) => item?.validation_field?.code)
|
|
242
|
+
const guestCheckoutCellPhone = checkoutFieldsState?.fields?.find((field) => field.order_type_id === options?.type && field?.validation_field?.code === 'mobile_phone')
|
|
244
243
|
if (
|
|
245
244
|
userSelected &&
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
245
|
+
!userSelected?.cellphone &&
|
|
246
|
+
((guestCheckoutCellPhone?.enabled &&
|
|
247
|
+
guestCheckoutCellPhone?.required_with_guest) ||
|
|
248
|
+
configs?.verification_phone_required?.value === '1')
|
|
250
249
|
) {
|
|
251
|
-
|
|
250
|
+
requiredFieldsCode.push('cellphone')
|
|
252
251
|
}
|
|
253
|
-
setRequiredFields(
|
|
252
|
+
setRequiredFields(requiredFieldsCode)
|
|
254
253
|
}
|
|
255
254
|
|
|
256
255
|
const checkValidationFields = () => {
|
|
@@ -258,26 +257,28 @@ const CheckoutUI = (props) => {
|
|
|
258
257
|
const errors = []
|
|
259
258
|
const userSelected = isCustomerMode ? customerState.user : user
|
|
260
259
|
const _requiredFields = []
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
260
|
+
Object.values(checkoutFieldsState?.fields).map(field => {
|
|
261
|
+
if (options?.type === field?.order_type_id &&
|
|
262
|
+
field?.enabled &&
|
|
263
|
+
field?.required &&
|
|
264
|
+
!notFields.includes(field?.validation_field?.code)
|
|
265
|
+
) {
|
|
266
|
+
if (userSelected && !userSelected[field?.validation_field?.code]) {
|
|
267
|
+
_requiredFields.push(field?.validation_field?.code)
|
|
266
268
|
}
|
|
267
269
|
}
|
|
268
270
|
})
|
|
269
|
-
|
|
271
|
+
const mobilePhoneField = Object.values(checkoutFieldsState?.fields)?.find(field => field?.order_type_id === options?.type && field?.validation_field?.code === 'mobile_phone')
|
|
270
272
|
if (
|
|
271
273
|
userSelected &&
|
|
272
274
|
!userSelected?.cellphone &&
|
|
273
|
-
((
|
|
274
|
-
|
|
275
|
+
((mobilePhoneField?.enabled &&
|
|
276
|
+
mobilePhoneField?.required) ||
|
|
275
277
|
configs?.verification_phone_required?.value === '1')
|
|
276
278
|
) {
|
|
277
279
|
_requiredFields.push('cellphone')
|
|
278
280
|
}
|
|
279
281
|
setRequiredFields(_requiredFields)
|
|
280
|
-
|
|
281
282
|
if (userSelected && userSelected?.cellphone) {
|
|
282
283
|
if (userSelected?.country_phone_code) {
|
|
283
284
|
let phone = null
|
|
@@ -314,15 +315,13 @@ const CheckoutUI = (props) => {
|
|
|
314
315
|
}
|
|
315
316
|
|
|
316
317
|
useEffect(() => {
|
|
317
|
-
if (
|
|
318
|
+
if (checkoutFieldsState?.loading || customerState.loading || userLoading) return
|
|
319
|
+
if (user?.guest_id) {
|
|
320
|
+
checkGuestValidationFields()
|
|
321
|
+
} else {
|
|
318
322
|
checkValidationFields()
|
|
319
323
|
}
|
|
320
|
-
}, [
|
|
321
|
-
|
|
322
|
-
useEffect(() => {
|
|
323
|
-
if (checkoutFieldsState?.loading || !user?.guest_id || customerState.loading || userLoading) return
|
|
324
|
-
checkGuestValidationFields()
|
|
325
|
-
}, [user, checkoutFieldsState, customerState])
|
|
324
|
+
}, [checkoutFieldsState, user, customerState, options?.type])
|
|
326
325
|
|
|
327
326
|
useEffect(() => {
|
|
328
327
|
if (errors) {
|
|
@@ -387,13 +386,15 @@ const CheckoutUI = (props) => {
|
|
|
387
386
|
</div>
|
|
388
387
|
) : (
|
|
389
388
|
<AddressDetails
|
|
390
|
-
location={
|
|
389
|
+
location={cart?.business?.location}
|
|
391
390
|
businessLogo={businessDetails?.business?.logo || theme.images?.dummies?.businessLogo}
|
|
392
391
|
isCartPending={cart?.status === 2}
|
|
393
392
|
businessId={cart?.business_id}
|
|
394
393
|
apiKey={configs?.google_maps_api_key?.value}
|
|
395
394
|
mapConfigs={mapConfigs}
|
|
396
395
|
isCustomerMode={isCustomerMode}
|
|
396
|
+
cart={cart}
|
|
397
|
+
primaryColor={hexTest.test(primaryColor || '') ? `0x${primaryColor}` : 'red'}
|
|
397
398
|
/>
|
|
398
399
|
)}
|
|
399
400
|
</>
|
|
@@ -428,12 +429,14 @@ const CheckoutUI = (props) => {
|
|
|
428
429
|
isUserDetailsEdit={isUserDetailsEdit}
|
|
429
430
|
cartStatus={cart?.status}
|
|
430
431
|
businessId={cart?.business_id}
|
|
431
|
-
useValidationFields
|
|
432
432
|
useDefualtSessionManager
|
|
433
433
|
useSessionUser={!isCustomerMode}
|
|
434
434
|
isCustomerMode={isCustomerMode}
|
|
435
435
|
userData={isCustomerMode && customerState.user}
|
|
436
436
|
userId={isCustomerMode && customerState?.user?.id}
|
|
437
|
+
isOrderTypeValidationField
|
|
438
|
+
requiredFields={requiredFields}
|
|
439
|
+
checkoutFields={checkoutFields}
|
|
437
440
|
isSuccess={isSuccess}
|
|
438
441
|
isCheckout
|
|
439
442
|
/>
|
|
@@ -572,24 +575,24 @@ const CheckoutUI = (props) => {
|
|
|
572
575
|
|
|
573
576
|
{
|
|
574
577
|
!!(!isMultiDriverTips && driverTipsField) &&
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
578
|
+
<>
|
|
579
|
+
<DriverTipContainer>
|
|
580
|
+
<h1>{t('DRIVER_TIPS', 'Driver Tips')}</h1>
|
|
581
|
+
<p>{t('100%_OF_THE_TIP_YOUR_DRIVER', '100% of the tip goes to your driver')}</p>
|
|
582
|
+
<DriverTips
|
|
583
|
+
businessId={cart?.business_id}
|
|
584
|
+
driverTipsOptions={driverTipsOptions}
|
|
585
|
+
isFixedPrice={parseInt(configs?.driver_tip_type?.value, 10) === 1}
|
|
586
|
+
isDriverTipUseCustom={!!parseInt(configs?.driver_tip_use_custom?.value, 10)}
|
|
587
|
+
driverTip={parseInt(configs?.driver_tip_type?.value, 10) === 1
|
|
588
|
+
? cart?.driver_tip
|
|
589
|
+
: cart?.driver_tip_rate}
|
|
590
|
+
cart={cart}
|
|
591
|
+
useOrderContext
|
|
592
|
+
/>
|
|
593
|
+
</DriverTipContainer>
|
|
594
|
+
<DriverTipDivider />
|
|
595
|
+
</>
|
|
593
596
|
}
|
|
594
597
|
{!cartState.loading && placeSpotsEnabled && cart?.business_id && (
|
|
595
598
|
<SelectSpotContainer>
|
|
@@ -624,8 +627,8 @@ const CheckoutUI = (props) => {
|
|
|
624
627
|
creditPointPlanOnBusiness?.accumulation_rate ??
|
|
625
628
|
(!!creditPointPlanOnBusiness && creditPointPlan?.accumulation_rate) ?? 0
|
|
626
629
|
}
|
|
627
|
-
|
|
628
|
-
|
|
630
|
+
hideCommentsByValidationCheckout={!guestCheckoutComment?.enabled}
|
|
631
|
+
hideCouponByValidationCheckout={!guestCheckoutCoupon?.enabled}
|
|
629
632
|
productLoading={productLoading}
|
|
630
633
|
setProductLoading={setProductLoading}
|
|
631
634
|
/>
|
|
@@ -698,7 +701,12 @@ const CheckoutUI = (props) => {
|
|
|
698
701
|
{t('WARNING_INVALID_DRIVER_TIP', 'Driver Tip is required.')}
|
|
699
702
|
</WarningText>
|
|
700
703
|
)}
|
|
701
|
-
|
|
704
|
+
{validateCouponField &&
|
|
705
|
+
(
|
|
706
|
+
<WarningText>
|
|
707
|
+
{t('WARNING_INVALID_COUPON_FIELD', 'Coupon is required.')}
|
|
708
|
+
</WarningText>
|
|
709
|
+
)}
|
|
702
710
|
{validateCommentsCartField && (
|
|
703
711
|
<WarningText>
|
|
704
712
|
{t('WARNING_INVALID_CART_COMMENTS', 'Cart comments is required.')}
|
|
@@ -751,7 +759,6 @@ const CheckoutUI = (props) => {
|
|
|
751
759
|
isUserDetailsEdit={isUserDetailsEdit}
|
|
752
760
|
cartStatus={cart?.status}
|
|
753
761
|
businessId={cart?.business_id}
|
|
754
|
-
useValidationFields
|
|
755
762
|
useDefualtSessionManager
|
|
756
763
|
useSessionUser={!isCustomerMode}
|
|
757
764
|
isCustomerMode={isCustomerMode}
|
|
@@ -764,6 +771,8 @@ const CheckoutUI = (props) => {
|
|
|
764
771
|
isEdit
|
|
765
772
|
isModal
|
|
766
773
|
handlePlaceOrderAsGuest={handlePlaceOrderAsGuest}
|
|
774
|
+
isOrderTypeValidationField
|
|
775
|
+
checkoutFields={checkoutFields}
|
|
767
776
|
isAllowGuest={paymethodSelected?.gateway === 'cash' || paymethodSelected?.gateway === 'card_delivery'}
|
|
768
777
|
onClose={() => {
|
|
769
778
|
setIsOpen(false)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useEffect } from 'react'
|
|
1
|
+
import React, { useState, useEffect, useMemo } from 'react'
|
|
2
2
|
import { useHistory } from 'react-router-dom'
|
|
3
3
|
import {
|
|
4
4
|
MultiCheckout as MultiCheckoutController,
|
|
@@ -71,7 +71,8 @@ const MultiCheckoutUI = (props) => {
|
|
|
71
71
|
cartUuid,
|
|
72
72
|
totalCartsFee,
|
|
73
73
|
walletState,
|
|
74
|
-
handleSearchRedirect
|
|
74
|
+
handleSearchRedirect,
|
|
75
|
+
checkoutFieldsState
|
|
75
76
|
} = props
|
|
76
77
|
|
|
77
78
|
const [, t] = useLanguage()
|
|
@@ -79,7 +80,7 @@ const MultiCheckoutUI = (props) => {
|
|
|
79
80
|
const [{ parsePrice }] = useUtils()
|
|
80
81
|
const [customerState] = useCustomer()
|
|
81
82
|
const [validationFields] = useValidationFields()
|
|
82
|
-
const [{ user }, { login }] = useSession()
|
|
83
|
+
const [{ user, loading: userLoading }, { login }] = useSession()
|
|
83
84
|
const [orderState] = useOrder()
|
|
84
85
|
const history = useHistory()
|
|
85
86
|
const [, { showToast }] = useToast()
|
|
@@ -102,6 +103,7 @@ const MultiCheckoutUI = (props) => {
|
|
|
102
103
|
(paymethodSelected?.gateway === 'stripe' && cardList?.cards?.length === 0) ||
|
|
103
104
|
walletCarts.length > 0
|
|
104
105
|
|
|
106
|
+
const notFields = ['coupon', 'driver_tip', 'mobile_phone', 'address', 'zipcode', 'address_notes', 'comments']
|
|
105
107
|
const isMultiDriverTips = configs?.checkout_multi_business_enabled?.value === '1'
|
|
106
108
|
const driverTipsOptions = typeof configs?.driver_tip_options?.value === 'string'
|
|
107
109
|
? JSON.parse(configs?.driver_tip_options?.value) || []
|
|
@@ -121,8 +123,11 @@ const MultiCheckoutUI = (props) => {
|
|
|
121
123
|
const loyalBusinessAvailable = creditPointGeneralPlan?.businesses?.filter((b) => b.accumulates) ?? []
|
|
122
124
|
const isWalletEnabled = (configs?.cash_wallet?.value && configs?.wallet_enabled?.value === '1' &&
|
|
123
125
|
(configs?.wallet_cash_enabled?.value === '1' ||
|
|
124
|
-
|
|
126
|
+
configs?.wallet_credit_point_enabled?.value === '1'))
|
|
127
|
+
const checkoutFields = useMemo(() => checkoutFieldsState?.fields?.filter(field => field.order_type_id === orderState?.options?.type), [checkoutFieldsState, orderState?.options])
|
|
125
128
|
|
|
129
|
+
const hexTest = /[0-9A-Fa-f]{6}/g
|
|
130
|
+
const primaryColor = theme?.colors?.primary?.split?.('#')?.[1]
|
|
126
131
|
const accumulationRateBusiness = (businessId) => {
|
|
127
132
|
const value = loyalBusinessAvailable?.find((loyal) => loyal.business_id === businessId)?.accumulation_rate ?? 0
|
|
128
133
|
return value || (creditPointGeneralPlan?.accumulation_rate ?? 0)
|
|
@@ -147,8 +152,7 @@ const MultiCheckoutUI = (props) => {
|
|
|
147
152
|
return
|
|
148
153
|
}
|
|
149
154
|
|
|
150
|
-
if (!userErrors.length &&
|
|
151
|
-
(allowedGuest && (paymethodSelected?.gateway === 'cash' || paymethodSelected?.gateway === 'card_delivery')))) {
|
|
155
|
+
if (!userErrors.length && !requiredFields?.length) {
|
|
152
156
|
handleGroupPlaceOrder && handleGroupPlaceOrder()
|
|
153
157
|
return
|
|
154
158
|
}
|
|
@@ -176,36 +180,57 @@ const MultiCheckoutUI = (props) => {
|
|
|
176
180
|
setIsUserDetailsEdit(false)
|
|
177
181
|
}
|
|
178
182
|
|
|
183
|
+
const checkGuestValidationFields = () => {
|
|
184
|
+
const userSelected = isCustomerMode ? customerState.user : user
|
|
185
|
+
const _requiredFields = checkoutFieldsState?.fields
|
|
186
|
+
.filter((field) => (field?.order_type_id === orderState?.options?.type) && field?.enabled && field?.required_with_guest &&
|
|
187
|
+
!notFields.includes(field?.validation_field?.code) &&
|
|
188
|
+
userSelected && !userSelected[field?.validation_field?.code])
|
|
189
|
+
const requiredFieldsCode = _requiredFields.map((item) => item?.validation_field?.code)
|
|
190
|
+
const guestCheckoutCellPhone = checkoutFieldsState?.fields?.find((field) => field.order_type_id === orderState?.options?.type && field?.validation_field?.code === 'mobile_phone')
|
|
191
|
+
if (
|
|
192
|
+
userSelected &&
|
|
193
|
+
!userSelected?.cellphone &&
|
|
194
|
+
((guestCheckoutCellPhone?.enabled &&
|
|
195
|
+
guestCheckoutCellPhone?.required_with_guest) ||
|
|
196
|
+
configs?.verification_phone_required?.value === '1')
|
|
197
|
+
) {
|
|
198
|
+
requiredFieldsCode.push('cellphone')
|
|
199
|
+
}
|
|
200
|
+
setRequiredFields(requiredFieldsCode)
|
|
201
|
+
}
|
|
202
|
+
|
|
179
203
|
const checkValidationFields = () => {
|
|
180
204
|
setUserErrors([])
|
|
181
205
|
const errors = []
|
|
182
|
-
const notFields = ['coupon', 'driver_tip', 'mobile_phone', 'address', 'zipcode', 'address_notes']
|
|
183
206
|
const userSelected = isCustomerMode ? customerState.user : user
|
|
184
207
|
const _requiredFields = []
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
208
|
+
Object.values(checkoutFieldsState?.fields).map(field => {
|
|
209
|
+
if (orderState.options?.type === field?.order_type_id &&
|
|
210
|
+
field?.enabled &&
|
|
211
|
+
field?.required &&
|
|
212
|
+
!notFields.includes(field?.validation_field?.code)
|
|
213
|
+
) {
|
|
214
|
+
if (userSelected && !userSelected[field?.validation_field?.code]) {
|
|
215
|
+
_requiredFields.push(field?.validation_field?.code)
|
|
190
216
|
}
|
|
191
217
|
}
|
|
192
218
|
})
|
|
193
|
-
|
|
219
|
+
const mobilePhoneField = Object.values(checkoutFieldsState?.fields)?.find(field => field?.order_type_id === orderState?.options?.type && field?.validation_field?.code === 'mobile_phone')
|
|
194
220
|
if (
|
|
195
221
|
userSelected &&
|
|
196
222
|
!userSelected?.cellphone &&
|
|
197
|
-
((
|
|
198
|
-
|
|
223
|
+
((mobilePhoneField?.enabled &&
|
|
224
|
+
mobilePhoneField?.required) ||
|
|
199
225
|
configs?.verification_phone_required?.value === '1')
|
|
200
226
|
) {
|
|
201
227
|
_requiredFields.push('cellphone')
|
|
202
228
|
}
|
|
203
229
|
setRequiredFields(_requiredFields)
|
|
204
|
-
|
|
205
230
|
if (userSelected && userSelected?.cellphone) {
|
|
206
231
|
if (userSelected?.country_phone_code) {
|
|
207
232
|
let phone = null
|
|
208
|
-
phone = `+${userSelected?.country_phone_code}${userSelected?.cellphone}`
|
|
233
|
+
phone = `+${userSelected?.country_phone_code}${userSelected?.cellphone.replace(`+${userSelected?.country_phone_code}`, '')}`
|
|
209
234
|
const phoneNumber = parsePhoneNumber(phone)
|
|
210
235
|
if (!phoneNumber?.isValid()) {
|
|
211
236
|
errors.push(t('VALIDATION_ERROR_MOBILE_PHONE_INVALID', 'The field Phone number is invalid.'))
|
|
@@ -232,10 +257,13 @@ const MultiCheckoutUI = (props) => {
|
|
|
232
257
|
}
|
|
233
258
|
|
|
234
259
|
useEffect(() => {
|
|
235
|
-
if (
|
|
260
|
+
if (checkoutFieldsState?.loading || customerState.loading || userLoading) return
|
|
261
|
+
if (user?.guest_id) {
|
|
262
|
+
checkGuestValidationFields()
|
|
263
|
+
} else {
|
|
236
264
|
checkValidationFields()
|
|
237
265
|
}
|
|
238
|
-
}, [
|
|
266
|
+
}, [checkoutFieldsState, user, customerState, orderState?.options?.type])
|
|
239
267
|
|
|
240
268
|
useEffect(() => {
|
|
241
269
|
if (openCarts.length || cartGroup.loading) {
|
|
@@ -308,7 +336,6 @@ const MultiCheckoutUI = (props) => {
|
|
|
308
336
|
) : (
|
|
309
337
|
<UserDetails
|
|
310
338
|
isUserDetailsEdit={isUserDetailsEdit}
|
|
311
|
-
useValidationFields
|
|
312
339
|
useDefualtSessionManager
|
|
313
340
|
useSessionUser={!isCustomerMode}
|
|
314
341
|
isCustomerMode={isCustomerMode}
|
|
@@ -316,6 +343,9 @@ const MultiCheckoutUI = (props) => {
|
|
|
316
343
|
userId={isCustomerMode && customerState?.user?.id}
|
|
317
344
|
isCheckout
|
|
318
345
|
isSuccess={isSuccess}
|
|
346
|
+
isOrderTypeValidationField
|
|
347
|
+
requiredFields={requiredFields}
|
|
348
|
+
checkoutFields={checkoutFields}
|
|
319
349
|
/>
|
|
320
350
|
)}
|
|
321
351
|
</WrapperUserDetails>
|
|
@@ -474,13 +504,15 @@ const MultiCheckoutUI = (props) => {
|
|
|
474
504
|
>
|
|
475
505
|
<UserDetails
|
|
476
506
|
isUserDetailsEdit={isUserDetailsEdit}
|
|
477
|
-
useValidationFields
|
|
478
507
|
useDefualtSessionManager
|
|
479
508
|
useSessionUser={!isCustomerMode}
|
|
480
509
|
isCustomerMode={isCustomerMode}
|
|
481
510
|
userData={isCustomerMode && customerState.user}
|
|
482
511
|
userId={isCustomerMode && customerState?.user?.id}
|
|
483
512
|
requiredFields={requiredFields}
|
|
513
|
+
isOrderTypeValidationField
|
|
514
|
+
checkoutFields={checkoutFields}
|
|
515
|
+
isCheckoutPlace
|
|
484
516
|
setIsSuccess={setIsSuccess}
|
|
485
517
|
isCheckout
|
|
486
518
|
isEdit
|
|
@@ -153,7 +153,7 @@ const UserDetailsUI = (props) => {
|
|
|
153
153
|
<Container>
|
|
154
154
|
{isModal && (
|
|
155
155
|
<TitleContainer isAddressFormOpen={isAddressFormOpen && !isEdit}>
|
|
156
|
-
{!
|
|
156
|
+
{!isCheckoutPlace && (
|
|
157
157
|
<ModalIcon>
|
|
158
158
|
<MdClose onClick={() => onClose()} />
|
|
159
159
|
</ModalIcon>
|
|
@@ -161,7 +161,7 @@ const UserDetailsUI = (props) => {
|
|
|
161
161
|
<h1>{t('CUSTOMER_DETAILS', 'Customer Details')}</h1>
|
|
162
162
|
</TitleContainer>
|
|
163
163
|
)}
|
|
164
|
-
{!
|
|
164
|
+
{!isCheckoutPlace && (
|
|
165
165
|
<Header className='user-form'>
|
|
166
166
|
{!isModal && (
|
|
167
167
|
<h1>{t('CUSTOMER_DETAILS', 'Customer Details')}</h1>
|