ordering-ui-react-native 0.18.80 → 0.18.81

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.18.80",
3
+ "version": "0.18.81",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -3,6 +3,8 @@ import {
3
3
  useLanguage,
4
4
  useConfig,
5
5
  useUtils,
6
+ useToast,
7
+ ToastType,
6
8
  MultiCartsPaymethodsAndWallets as MultiCartsPaymethodsAndWalletsController
7
9
  } from 'ordering-components/native'
8
10
  import { useTheme } from 'styled-components/native'
@@ -45,7 +47,8 @@ const MultiCartsPaymethodsAndWalletsUI = (props: any) => {
45
47
  const [, t] = useLanguage()
46
48
  const [{ configs }] = useConfig()
47
49
  const [{ parsePrice }] = useUtils()
48
- const { confirmApplePayPayment } = useApplePay()
50
+ const [, { showToast }] = useToast();
51
+ const { confirmApplePayPayment } = useApplePay()
49
52
 
50
53
  const [addCardOpen, setAddCardOpen] = useState({ stripe: false, stripeConnect: false });
51
54
 
@@ -91,20 +94,38 @@ const MultiCartsPaymethodsAndWalletsUI = (props: any) => {
91
94
  }
92
95
 
93
96
  useEffect(() => {
94
- if (methodsPay.includes(paymethodSelected?.gateway)) {
95
- if (typeof paymethodSelected?.paymethod_data === 'string'){
96
- const sourceId = JSON.parse(paymethodSelected?.paymethod_data)?.source_id
97
+ if (methodsPay.includes(paymethodSelected?.gateway)) {
98
+ if (typeof paymethodSelected?.paymethod_data === 'string') {
99
+ const sourceId = JSON.parse(paymethodSelected?.paymethod_data)?.source_id
97
100
  sourceId && handlePlaceOrder(confirmApplePayPayment)
98
101
  }
99
- }
100
- }, [JSON.stringify(paymethodSelected)])
102
+ }
103
+ }, [JSON.stringify(paymethodSelected)])
104
+
105
+ useEffect(() => {
106
+ if (cartTotal === 0) {
107
+ handlePaymethodDataChange(null)
108
+ handleSelectPaymethod(null)
109
+ }
110
+ }, [cartTotal])
111
+
112
+ const handleChangePaymethod = (paymethod: any) => {
113
+ if (cartTotal > 0) {
114
+ handleSelectPaymethod(paymethod)
115
+ return
116
+ }
117
+ showToast(
118
+ ToastType.Error,
119
+ t('CART_BALANCE_ZERO', 'Sorry, the amount to pay is equal to zero and it is not necessary to select a payment method'))
120
+ ;
121
+ }
101
122
 
102
123
  const renderPaymethods = ({ item }: any) => {
103
124
  return (
104
125
  <>
105
126
  {item?.gateway === 'global_apple_pay' ? (
106
127
  <TouchableOpacity
107
- onPress={() => handleSelectPaymethod({ ...item, paymethod: { gateway: item.gateway }, paymethod_id: item?.id })}
128
+ onPress={() => handleChangePaymethod({ ...item, paymethod: { gateway: item.gateway }, paymethod_id: item?.id })}
108
129
  >
109
130
  <OIcon
110
131
  src={getPayIcon(item.gateway)}
@@ -115,7 +136,7 @@ const MultiCartsPaymethodsAndWalletsUI = (props: any) => {
115
136
  </TouchableOpacity>
116
137
  ) : (
117
138
  <TouchableOpacity
118
- onPress={() => handleSelectPaymethod({ ...item, paymethod: { gateway: item.gateway }, paymethod_id: item?.id })}
139
+ onPress={() => handleChangePaymethod({ ...item, paymethod: { gateway: item.gateway }, paymethod_id: item?.id })}
119
140
  >
120
141
  <PMItem
121
142
  key={item.id}
@@ -208,9 +229,9 @@ const MultiCartsPaymethodsAndWalletsUI = (props: any) => {
208
229
  handleSource={handlePaymethodDataChange}
209
230
  onCancel={() => setAddCardOpen({ ...addCardOpen, stripe: false })}
210
231
  setMethodPaySupported={setMethodPaySupported}
211
- methodPaySupported={methodPaySupported}
212
- placeByMethodPay={placeByMethodPay}
213
- setPlaceByMethodPay={setPlaceByMethodPay}
232
+ methodPaySupported={methodPaySupported}
233
+ placeByMethodPay={placeByMethodPay}
234
+ setPlaceByMethodPay={setPlaceByMethodPay}
214
235
  methodsPay={methodsPay}
215
236
  paymethod={paymethodSelected?.paymethod?.gateway}
216
237
  cartTotal={cartTotal}
@@ -1018,7 +1018,9 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
1018
1018
  )} */}
1019
1019
  </View>
1020
1020
  <OText>
1021
- -{parsePrice(event.amount, { isTruncable: true })}
1021
+ {configs.currency_position?.value === 'left'
1022
+ ? `${configs.format_number_currency?.value} -${parseNumber(event.amount, { isTruncable: true })}`
1023
+ : `-${parsePrice(event.amount, { isTruncable: true })}`}
1022
1024
  </OText>
1023
1025
  </View>
1024
1026
  ))}
@@ -126,6 +126,12 @@ const PaymentOptionsUI = (props: any) => {
126
126
  ;
127
127
  }
128
128
 
129
+ useEffect(() => {
130
+ if (cart?.balance === 0) {
131
+ handlePaymethodClick(null)
132
+ }
133
+ }, [cart?.balance])
134
+
129
135
  useEffect(() => {
130
136
  if (paymethodsList.paymethods.length === 1) {
131
137
  handlePaymethodClick && handlePaymethodClick(paymethodsList.paymethods[0])
@@ -339,7 +345,7 @@ const PaymentOptionsUI = (props: any) => {
339
345
  onPaymentChange={onPaymentChange}
340
346
  payType={isOpenMethod?.paymethod?.name}
341
347
  onSelectCard={handlePaymethodDataChange}
342
- addCardOpen={addCardOpen}
348
+ addCardOpen={addCardOpen}
343
349
  setAddCardOpen={setAddCardOpen}
344
350
  onCancel={() => handlePaymethodClick(null)}
345
351
  paymethodSelected={paymethodSelected?.data?.id}