ordering-components-external 13.2.14 → 13.2.16
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/{7.ordering-component.71fcc1b93f7c954870c3.js → 7.ordering-component.6b92f3ab4699d251734f.js} +1 -1
- package/_bundles/ordering-component.6b92f3ab4699d251734f.js +2 -0
- package/_modules/components/Checkout/index.js +19 -1
- package/_modules/components/OrderListGroups/index.js +60 -54
- package/_modules/components/PaymentOptionStripeLink/index.js +154 -0
- package/_modules/components/PaymentOptions/index.js +16 -16
- package/_modules/index.js +7 -0
- package/package.json +1 -1
- package/src/components/Checkout/index.js +17 -1
- package/src/components/OrderListGroups/index.js +63 -52
- package/src/components/PaymentOptionStripeLink/index.js +91 -0
- package/src/components/PaymentOptions/index.js +7 -6
- package/src/index.js +2 -0
- package/_bundles/ordering-component.71fcc1b93f7c954870c3.js +0 -2
- /package/_bundles/{0.ordering-component.71fcc1b93f7c954870c3.js → 0.ordering-component.6b92f3ab4699d251734f.js} +0 -0
- /package/_bundles/{1.ordering-component.71fcc1b93f7c954870c3.js → 1.ordering-component.6b92f3ab4699d251734f.js} +0 -0
- /package/_bundles/{2.ordering-component.71fcc1b93f7c954870c3.js → 2.ordering-component.6b92f3ab4699d251734f.js} +0 -0
- /package/_bundles/{4.ordering-component.71fcc1b93f7c954870c3.js → 4.ordering-component.6b92f3ab4699d251734f.js} +0 -0
- /package/_bundles/{5.ordering-component.71fcc1b93f7c954870c3.js → 5.ordering-component.6b92f3ab4699d251734f.js} +0 -0
- /package/_bundles/{6.ordering-component.71fcc1b93f7c954870c3.js → 6.ordering-component.6b92f3ab4699d251734f.js} +0 -0
- /package/_bundles/{7.ordering-component.71fcc1b93f7c954870c3.js.LICENSE.txt → 7.ordering-component.6b92f3ab4699d251734f.js.LICENSE.txt} +0 -0
- /package/_bundles/{8.ordering-component.71fcc1b93f7c954870c3.js → 8.ordering-component.6b92f3ab4699d251734f.js} +0 -0
- /package/_bundles/{ordering-component.71fcc1b93f7c954870c3.js.LICENSE.txt → ordering-component.6b92f3ab4699d251734f.js.LICENSE.txt} +0 -0
|
@@ -12,7 +12,6 @@ export const OrderListGroups = (props) => {
|
|
|
12
12
|
UIComponent,
|
|
13
13
|
orderBy,
|
|
14
14
|
isIos,
|
|
15
|
-
useDefualtSessionManager,
|
|
16
15
|
paginationSettings,
|
|
17
16
|
asDashboard,
|
|
18
17
|
orderGroupStatusCustom,
|
|
@@ -102,6 +101,7 @@ export const OrderListGroups = (props) => {
|
|
|
102
101
|
const [orderLogisticAdded, setOrderLogisticAdded] = useState(null)
|
|
103
102
|
const [orderLogisticUpdated, setOrderLogisticUpdated] = useState(null)
|
|
104
103
|
const [recentlyReceivedMessage, setRecentlyReceivedMessage] = useState(null)
|
|
104
|
+
|
|
105
105
|
const [ordersFiltered, setOrdersFiltered] = useState({
|
|
106
106
|
orders: [],
|
|
107
107
|
loading: false,
|
|
@@ -115,9 +115,27 @@ export const OrderListGroups = (props) => {
|
|
|
115
115
|
}
|
|
116
116
|
})
|
|
117
117
|
|
|
118
|
-
const accessToken = useDefualtSessionManager ? session.token : props.accessToken
|
|
119
118
|
const requestsState = {}
|
|
120
119
|
|
|
120
|
+
const handleSelectCurrentTab = (value) => {
|
|
121
|
+
if (!isDriverApp) {
|
|
122
|
+
setOrdersGroup({
|
|
123
|
+
...ordersGroup,
|
|
124
|
+
[value]: {
|
|
125
|
+
...ordersGroup[value],
|
|
126
|
+
loading: true
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
if (value === 'logisticOrders') {
|
|
131
|
+
setlogisticOrders({
|
|
132
|
+
...logisticOrders,
|
|
133
|
+
loading: true
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
setCurrentTabSelected(value)
|
|
137
|
+
}
|
|
138
|
+
|
|
121
139
|
const getOrders = async ({
|
|
122
140
|
page,
|
|
123
141
|
pageSize = paginationSettings.pageSize,
|
|
@@ -285,8 +303,8 @@ export const OrderListGroups = (props) => {
|
|
|
285
303
|
options.cancelToken = source
|
|
286
304
|
|
|
287
305
|
const functionFetch = asDashboard
|
|
288
|
-
? ordering.setAccessToken(
|
|
289
|
-
: ordering.setAccessToken(
|
|
306
|
+
? ordering.setAccessToken(session.token).orders().asDashboard()
|
|
307
|
+
: ordering.setAccessToken(session.token).orders()
|
|
290
308
|
return await functionFetch.get(options)
|
|
291
309
|
}
|
|
292
310
|
|
|
@@ -294,7 +312,7 @@ export const OrderListGroups = (props) => {
|
|
|
294
312
|
try {
|
|
295
313
|
setControlsState({ ...controlsState, loading: true })
|
|
296
314
|
const { content: { error, result } } = await ordering
|
|
297
|
-
.setAccessToken(
|
|
315
|
+
.setAccessToken(session.token)
|
|
298
316
|
.controls()
|
|
299
317
|
.get()
|
|
300
318
|
const obj = {
|
|
@@ -527,7 +545,7 @@ export const OrderListGroups = (props) => {
|
|
|
527
545
|
method: 'GET',
|
|
528
546
|
headers: {
|
|
529
547
|
'Content-Type': 'application/json',
|
|
530
|
-
Authorization: `Bearer ${
|
|
548
|
+
Authorization: `Bearer ${session.token}`,
|
|
531
549
|
'X-App-X': ordering.appId,
|
|
532
550
|
'X-Socket-Id-X': socket?.getId()
|
|
533
551
|
}
|
|
@@ -557,11 +575,11 @@ export const OrderListGroups = (props) => {
|
|
|
557
575
|
const errorState = []
|
|
558
576
|
|
|
559
577
|
if (orderIds.length === 1) {
|
|
560
|
-
const { content: { error } } = await ordering.setAccessToken(
|
|
578
|
+
const { content: { error } } = await ordering.setAccessToken(session.token).orders(orderIds[0]).delete()
|
|
561
579
|
errorState.push({ error, id: orderIds[0] })
|
|
562
580
|
} else if (orderIds.length > 1) {
|
|
563
581
|
for (const id of orderIds) {
|
|
564
|
-
const { content: { error: multiError } } = await ordering.setAccessToken(
|
|
582
|
+
const { content: { error: multiError } } = await ordering.setAccessToken(session.token).orders(id).delete()
|
|
565
583
|
errorState.push({ error: multiError, id })
|
|
566
584
|
}
|
|
567
585
|
}
|
|
@@ -602,7 +620,7 @@ export const OrderListGroups = (props) => {
|
|
|
602
620
|
method: 'GET',
|
|
603
621
|
headers: {
|
|
604
622
|
'Content-Type': 'application/json',
|
|
605
|
-
Authorization: `Bearer ${
|
|
623
|
+
Authorization: `Bearer ${session.token}`,
|
|
606
624
|
'X-App-X': ordering.appId,
|
|
607
625
|
'X-Socket-Id-X': socket?.getId()
|
|
608
626
|
}
|
|
@@ -699,38 +717,38 @@ export const OrderListGroups = (props) => {
|
|
|
699
717
|
}
|
|
700
718
|
|
|
701
719
|
const actionOrderToTab = (orderAux, status, type) => {
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
...orderAux,
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
:
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
if (type !== 'update') {
|
|
719
|
-
_pagination = {
|
|
720
|
-
...ordersGroup[status].pagination,
|
|
721
|
-
total: ordersGroup[status].pagination.total + (type === 'add' ? 1 : -1)
|
|
720
|
+
setOrdersGroup(prevState => {
|
|
721
|
+
if (!prevState[status]?.orders) return
|
|
722
|
+
const orderList = prevState[status]?.orders
|
|
723
|
+
const order = { ...orderAux, showNotification: false }
|
|
724
|
+
let updatedOrders
|
|
725
|
+
|
|
726
|
+
switch (type) {
|
|
727
|
+
case 'update':
|
|
728
|
+
updatedOrders = orderList.map(o => o.id === order.id ? { ...order, action: `${type}${order?.status}` } : o)
|
|
729
|
+
break
|
|
730
|
+
case 'add':
|
|
731
|
+
updatedOrders = [{ ...order, action: `${type}${order?.status}` }, ...orderList]
|
|
732
|
+
break
|
|
733
|
+
case 'remove':
|
|
734
|
+
updatedOrders = orderList.filter(o => o.id !== order.id)
|
|
735
|
+
break
|
|
722
736
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
737
|
+
|
|
738
|
+
const updatedPagination = {
|
|
739
|
+
...prevState[status].pagination,
|
|
740
|
+
total: prevState[status].pagination.total + (type === 'add' ? 1 : type === 'remove' ? -1 : 0)
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
return {
|
|
744
|
+
...prevState,
|
|
745
|
+
[status]: {
|
|
746
|
+
...prevState[status],
|
|
747
|
+
orders: filterByIdUnique(sortOrders(updatedOrders), status),
|
|
748
|
+
pagination: updatedPagination
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
})
|
|
734
752
|
}
|
|
735
753
|
|
|
736
754
|
const handleClickOrder = (orderAux) => {
|
|
@@ -773,7 +791,7 @@ export const OrderListGroups = (props) => {
|
|
|
773
791
|
try {
|
|
774
792
|
const response = await fetch(`${ordering.root}/drivers/${session.user?.id}/assign_requests/${orderId}`, {
|
|
775
793
|
method: 'PUT',
|
|
776
|
-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${
|
|
794
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${session.token}` },
|
|
777
795
|
body: JSON.stringify({
|
|
778
796
|
status,
|
|
779
797
|
user_id: session.user?.id
|
|
@@ -1127,16 +1145,9 @@ export const OrderListGroups = (props) => {
|
|
|
1127
1145
|
const userId = session.user.id
|
|
1128
1146
|
const userLevel = session.user.level
|
|
1129
1147
|
|
|
1130
|
-
const ordersRoom =
|
|
1131
|
-
?
|
|
1132
|
-
|
|
1133
|
-
room: 'orders',
|
|
1134
|
-
user_id: userId,
|
|
1135
|
-
role: 'manager'
|
|
1136
|
-
}
|
|
1137
|
-
: userLevel === 0
|
|
1138
|
-
? 'orders'
|
|
1139
|
-
: `orders_${userId}`
|
|
1148
|
+
const ordersRoom = userLevel === 0
|
|
1149
|
+
? 'orders'
|
|
1150
|
+
: `orders_${userId}`
|
|
1140
1151
|
|
|
1141
1152
|
const requestsRoom = `requests_${userId}`
|
|
1142
1153
|
const groupsRoom = `ordergroups_${userId}`
|
|
@@ -1204,7 +1215,7 @@ export const OrderListGroups = (props) => {
|
|
|
1204
1215
|
currentFilters={currentFilters}
|
|
1205
1216
|
setCurrentFilters={setCurrentFilters}
|
|
1206
1217
|
currentTabSelected={currentTabSelected}
|
|
1207
|
-
setCurrentTabSelected={
|
|
1218
|
+
setCurrentTabSelected={handleSelectCurrentTab}
|
|
1208
1219
|
ordersGroup={ordersGroup}
|
|
1209
1220
|
setOrdersGroup={setOrdersGroup}
|
|
1210
1221
|
logisticOrders={logisticOrders}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import { useLanguage } from '../../contexts/LanguageContext'
|
|
4
|
+
import { useApi } from '../../contexts/ApiContext'
|
|
5
|
+
import { useToast, ToastType } from '../../contexts/ToastContext'
|
|
6
|
+
import { useSession } from '../../contexts/SessionContext'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Component to manage payment option stripe link behavior UI component
|
|
10
|
+
*/
|
|
11
|
+
export const PaymentOptionStripeLink = (props) => {
|
|
12
|
+
const {
|
|
13
|
+
UIComponent,
|
|
14
|
+
paymentURL
|
|
15
|
+
} = props
|
|
16
|
+
|
|
17
|
+
const [ordering] = useApi()
|
|
18
|
+
const [{ token }] = useSession()
|
|
19
|
+
const [, t] = useLanguage()
|
|
20
|
+
const [, { showToast }] = useToast()
|
|
21
|
+
|
|
22
|
+
const [stripeLinkState, setStripeLinkState] = useState({ loading: true, error: null, paymentURL: null })
|
|
23
|
+
const [userInfo, setUserInfo] = useState({})
|
|
24
|
+
|
|
25
|
+
const handleChangeUserInfo = (changes) => {
|
|
26
|
+
setUserInfo({ ...userInfo, ...changes })
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const handleSendStripeLink = async (type, callback) => {
|
|
30
|
+
try {
|
|
31
|
+
setStripeLinkState({ ...stripeLinkState, loading: true })
|
|
32
|
+
const data = {
|
|
33
|
+
type,
|
|
34
|
+
provider: ordering?.project === 'pizzahutmexico' ? 'custom' : 'twilio',
|
|
35
|
+
country_phone_code: userInfo.country_phone_code,
|
|
36
|
+
cellphone: userInfo.cellphone,
|
|
37
|
+
message: t('LINK_TO_PAY_MESSAGE',
|
|
38
|
+
'Hello there _name_ _lastname_, click on the following link to complete the payment: _link_')
|
|
39
|
+
.replace('_name_', userInfo?.name)
|
|
40
|
+
.replace('_lastname_', userInfo?.lastname)
|
|
41
|
+
.replace('_link_', paymentURL)
|
|
42
|
+
}
|
|
43
|
+
const response = await fetch(`${ordering.root}/text_messages/send`, {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers: {
|
|
46
|
+
'Content-Type': 'application/json',
|
|
47
|
+
Authorization: `Bearer ${token}`,
|
|
48
|
+
'X-App-X': ordering.appId
|
|
49
|
+
},
|
|
50
|
+
body: JSON.stringify(data)
|
|
51
|
+
})
|
|
52
|
+
const { result, error } = await response.json()
|
|
53
|
+
if (error) {
|
|
54
|
+
setStripeLinkState({ ...stripeLinkState, loading: false, error: result })
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
setStripeLinkState({ ...stripeLinkState, loading: false })
|
|
58
|
+
callback && callback()
|
|
59
|
+
showToast(ToastType.Success, t('MESSAGE_SENT_SUCCESSFULLY', 'The link has been sent'))
|
|
60
|
+
} catch (error) {
|
|
61
|
+
setStripeLinkState({ ...stripeLinkState, loading: false, error: [error.message] })
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!paymentURL) return
|
|
67
|
+
setStripeLinkState({ ...stripeLinkState, loading: false, paymentURL })
|
|
68
|
+
}, [paymentURL])
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<>
|
|
72
|
+
{UIComponent && (
|
|
73
|
+
<UIComponent
|
|
74
|
+
{...props}
|
|
75
|
+
userInfo={userInfo}
|
|
76
|
+
stripeLinkState={stripeLinkState}
|
|
77
|
+
setStripeLinkState={setStripeLinkState}
|
|
78
|
+
handleSendStripeLink={handleSendStripeLink}
|
|
79
|
+
handleChangeUserInfo={handleChangeUserInfo}
|
|
80
|
+
/>
|
|
81
|
+
)}
|
|
82
|
+
</>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
PaymentOptionStripeLink.propTypes = {
|
|
87
|
+
/**
|
|
88
|
+
* UI Component, this must be containt all graphic elements and use parent props
|
|
89
|
+
*/
|
|
90
|
+
UIComponent: PropTypes.elementType
|
|
91
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
import React, { useEffect, useState } from 'react'
|
|
2
3
|
import PropTypes from 'prop-types'
|
|
3
4
|
import { useOrder } from '../../contexts/OrderContext'
|
|
@@ -5,9 +6,10 @@ import { useApi } from '../../contexts/ApiContext'
|
|
|
5
6
|
import { useEvent } from '../../contexts/EventContext'
|
|
6
7
|
import { useSession } from '../../contexts/SessionContext'
|
|
7
8
|
|
|
9
|
+
const stripeLink = 'stripe_link'
|
|
8
10
|
const paymethodsExisting = ['stripe', 'stripe_direct', 'stripe_connect', 'paypal', 'square']
|
|
9
11
|
const paymethodsNotAllowed = ['paypal_express', 'authorize']
|
|
10
|
-
const paymethodsCallcenterMode = ['cash', 'card_delivery', 'ivrpay', '100_coupon']
|
|
12
|
+
const paymethodsCallcenterMode = ['cash', 'card_delivery', 'ivrpay', '100_coupon', stripeLink]
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Component to manage payment options behavior without UI component
|
|
@@ -28,7 +30,7 @@ export const PaymentOptions = (props) => {
|
|
|
28
30
|
const [events] = useEvent()
|
|
29
31
|
const [ordering] = useApi()
|
|
30
32
|
const [orderState, { changePaymethod }] = useOrder()
|
|
31
|
-
const [
|
|
33
|
+
const [{ device_code }] = useSession()
|
|
32
34
|
const orderTotal = orderState.carts?.[`businessId:${businessId}`]?.total || 0
|
|
33
35
|
|
|
34
36
|
const [paymethodsList, setPaymethodsList] = useState({ paymethods: [], loading: true, error: null })
|
|
@@ -42,7 +44,7 @@ export const PaymentOptions = (props) => {
|
|
|
42
44
|
.filter(credentials => isCustomerMode
|
|
43
45
|
? !paymethodsNotAllowed.includes(credentials?.paymethod?.gateway) &&
|
|
44
46
|
(isAlsea || paymethodsCallcenterMode.includes(credentials?.paymethod?.gateway))
|
|
45
|
-
: !paymethodsNotAllowed.includes(credentials?.paymethod?.gateway))
|
|
47
|
+
: ![...paymethodsNotAllowed, stripeLink].includes(credentials?.paymethod?.gateway))
|
|
46
48
|
.map(credentials => {
|
|
47
49
|
return {
|
|
48
50
|
...credentials?.paymethod,
|
|
@@ -58,14 +60,13 @@ export const PaymentOptions = (props) => {
|
|
|
58
60
|
*/
|
|
59
61
|
const getPaymentOptions = async () => {
|
|
60
62
|
setPaymethodsList({ ...paymethodsList, loading: true })
|
|
61
|
-
const deviceCode = sessionState?.device_code
|
|
62
63
|
|
|
63
64
|
const headers = {
|
|
64
|
-
'X-Physical-Device-Code-X': `${
|
|
65
|
+
'X-Physical-Device-Code-X': `${device_code}`
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
try {
|
|
68
|
-
const { content: { error, result } } = await ordering.businesses(businessId).get(
|
|
69
|
+
const { content: { error, result } } = await ordering.businesses(businessId).get(device_code ? { headers } : {})
|
|
69
70
|
if (!error) {
|
|
70
71
|
paymethodsList.paymethods = parsePaymethods(result.paymethods)
|
|
71
72
|
}
|
package/src/index.js
CHANGED
|
@@ -115,6 +115,7 @@ import { PaymentOptionCash } from './components/PaymentOptionCash'
|
|
|
115
115
|
import { PaymentOptionPaypal } from './components/PaymentOptionPaypal'
|
|
116
116
|
import { PaymentOptionStripe } from './components/PaymentOptionStripe'
|
|
117
117
|
import { PaymentOptionStripeDirect } from './components/PaymentOptionStripeDirect'
|
|
118
|
+
import { PaymentOptionStripeLink } from './components/PaymentOptionStripeLink'
|
|
118
119
|
import { PaymentOptionStripeRedirect } from './components/PaymentOptionStripeRedirect'
|
|
119
120
|
import { PaymentOptionSquare } from './components/PaymentOptionSquare'
|
|
120
121
|
import { StripeElementsForm } from './components/StripeElementsForm'
|
|
@@ -265,6 +266,7 @@ export {
|
|
|
265
266
|
PaymentOptionPaypal,
|
|
266
267
|
PaymentOptionStripe,
|
|
267
268
|
PaymentOptionStripeDirect,
|
|
269
|
+
PaymentOptionStripeLink,
|
|
268
270
|
PaymentOptionStripeRedirect,
|
|
269
271
|
PaymentOptionSquare,
|
|
270
272
|
PhoneAutocomplete,
|