ordering-ui-react-native 0.15.54 → 0.15.57

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 (29) hide show
  1. package/package.json +1 -1
  2. package/src/components/OrderDetails/index.tsx +2 -2
  3. package/themes/business/src/components/Home/index.tsx +128 -55
  4. package/themes/business/src/components/Home/styles.tsx +8 -1
  5. package/themes/business/src/components/NewOrderNotification/index.tsx +59 -98
  6. package/themes/business/src/components/OrderDetails/OrderContentComponent.tsx +125 -91
  7. package/themes/business/src/components/OrderDetails/styles.tsx +7 -0
  8. package/themes/kiosk/src/components/Cart/index.tsx +99 -25
  9. package/themes/kiosk/src/components/Cart/styles.tsx +6 -0
  10. package/themes/kiosk/src/components/OrderDetails/index.tsx +134 -39
  11. package/themes/kiosk/src/components/OrderDetails/styles.tsx +5 -0
  12. package/themes/kiosk/src/types/index.d.ts +2 -0
  13. package/themes/original/index.tsx +151 -0
  14. package/themes/original/src/components/AddressList/index.tsx +1 -1
  15. package/themes/original/src/components/AppleLogin/index.tsx +58 -21
  16. package/themes/original/src/components/BusinessProductsList/index.tsx +104 -18
  17. package/themes/original/src/components/BusinessProductsList/styles.tsx +12 -1
  18. package/themes/original/src/components/BusinessProductsListing/index.tsx +5 -0
  19. package/themes/original/src/components/BusinessReviews/index.tsx +4 -25
  20. package/themes/original/src/components/BusinessesListing/index.tsx +1 -1
  21. package/themes/original/src/components/Home/index.tsx +1 -1
  22. package/themes/original/src/components/PhoneInputNumber/index.tsx +10 -4
  23. package/themes/original/src/components/SignupForm/index.tsx +41 -13
  24. package/themes/original/src/components/UserFormDetails/index.tsx +13 -2
  25. package/themes/original/src/components/UserProfile/index.tsx +1 -1
  26. package/themes/original/src/config/constants.tsx +6 -6
  27. package/themes/original/src/types/index.tsx +6 -1
  28. package/themes/single-business/src/components/AddressList/index.tsx +1 -1
  29. package/themes/single-business/src/components/UserProfile/index.tsx +1 -1
@@ -23,6 +23,7 @@ import {
23
23
  Table,
24
24
  OrderBill,
25
25
  Total,
26
+ OSRow,
26
27
  } from './styles'
27
28
  import { OrderDetailsParams, Product } from '../../types'
28
29
  import { Container } from '../../layouts/Container';
@@ -178,6 +179,20 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
178
179
  setIsLoading(false)
179
180
  }
180
181
 
182
+ const getIncludedTaxes = () => {
183
+ if (order?.taxes?.length === 0) {
184
+ return order.tax_type === 1 ? order?.summary?.tax ?? 0 : 0
185
+ } else {
186
+ return order?.taxes.reduce((taxIncluded: number, tax: any) => {
187
+ return taxIncluded + (tax.type === 1 ? tax.summary?.tax : 0)
188
+ }, 0)
189
+ }
190
+ }
191
+
192
+ const getIncludedTaxesDiscounts = () => {
193
+ return order?.taxes?.filter((tax: any) => tax?.type === 1)?.reduce((carry: number, tax: any) => carry + (tax?.summary?.tax_after_discount ?? tax?.summary?.tax), 0)
194
+ }
195
+
181
196
  useEffect(() => {
182
197
  const backAction = () => {
183
198
  Alert.alert(`${t('HOLD_ON', 'Hold on')}!`, `${t('ARE_YOU_SURE_YOU_WANT_TO_GO_BACK', 'Are you sure you want to go back')}?`, [
@@ -209,7 +224,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
209
224
  const getCustomerName = async () => {
210
225
  try {
211
226
  const { customerName: name } = await _retrieveStoreData('customer_name')
212
- setCustomerName(name)
227
+ setCustomerName(name)
213
228
  } catch (e) {
214
229
  if (e) {
215
230
  setCustomerName(null)
@@ -217,8 +232,8 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
217
232
  }
218
233
  }
219
234
  getCustomerName()
220
- const redirectHome = setTimeout(() =>{
221
- _setStoreData('customer_name', {customerName: ''});
235
+ const redirectHome = setTimeout(() => {
236
+ _setStoreData('customer_name', { customerName: '' });
222
237
  navigation.reset({
223
238
  routes: [{ name: 'Intro' }],
224
239
  });
@@ -345,7 +360,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
345
360
  <OButton
346
361
  text={`${t('YOU_ARE_DONE', 'You are done! Click to close')}!`}
347
362
  onClick={() => {
348
- _setStoreData('customer_name', {customerName: ''});
363
+ _setStoreData('customer_name', { customerName: '' });
349
364
  navigation.reset({
350
365
  routes: [{ name: 'Intro' }],
351
366
  });
@@ -419,46 +434,135 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
419
434
  <Table>
420
435
  <OText>{t('SUBTOTAL', 'Subtotal')}</OText>
421
436
  <OText>
422
- {parsePrice(isTaxIncluded
423
- ? (order?.summary?.subtotal + order?.summary?.tax) ?? 0
424
- : order?.summary?.subtotal ?? 0
425
- )}
437
+ {parsePrice(((order?.summary?.subtotal ?? order?.subtotal) + getIncludedTaxes()))}
426
438
  </OText>
427
439
  </Table>
428
- {order?.summary?.discount > 0 && (
440
+ {(order?.summary?.discount > 0 ?? order?.discount > 0) && order?.offers?.length === 0 && (
429
441
  <Table>
430
442
  {order?.offer_type === 1 ? (
431
443
  <OText>
432
444
  {t('DISCOUNT', 'Discount')}
433
- <OText>{`(${verifyDecimals(order?.offer_rate, parsePrice)}%)`}</OText>
445
+ <OText>{`(${verifyDecimals(
446
+ order?.offer_rate,
447
+ parsePrice,
448
+ )}%)`}</OText>
434
449
  </OText>
435
450
  ) : (
436
451
  <OText>{t('DISCOUNT', 'Discount')}</OText>
437
452
  )}
438
- <OText>- {parsePrice(order?.summary?.discount)}</OText>
453
+ <OText>
454
+ - {parsePrice(order?.summary?.discount || order?.discount)}
455
+ </OText>
439
456
  </Table>
440
457
  )}
458
+ {
459
+ order?.offers?.length > 0 && order?.offers?.filter((offer: any) => offer?.target === 1)?.map((offer: any) => (
460
+ <Table key={offer.id}>
461
+ <OSRow>
462
+ <OText>
463
+ {offer.name}
464
+ {offer.rate_type === 1 && (
465
+ <OText>{`(${verifyDecimals(offer?.rate, parsePrice)}%)`}</OText>
466
+ )}
467
+ </OText>
468
+ </OSRow>
469
+ <OText>- {parsePrice(offer?.summary?.discount)}</OText>
470
+ </Table>
471
+ ))
472
+ }
441
473
  {order?.summary?.subtotal_with_discount > 0 && order?.summary?.discount > 0 && order?.summary?.total >= 0 && (
442
474
  <Table>
443
475
  <OText>{t('SUBTOTAL_WITH_DISCOUNT', 'Subtotal with discount')}</OText>
444
- <OText>{parsePrice(order?.summary?.subtotal_with_discount ?? 0)}</OText>
445
- </Table>
446
- )}
447
- {order?.tax_type !== 1 && (
448
- <Table>
449
- <OText>
450
- {t('TAX', 'Tax')}
451
- {`(${verifyDecimals(order?.summary?.tax_rate, parseNumber)}%)`}
452
- </OText>
453
- <OText>{parsePrice(order?.summary?.tax)}</OText>
476
+ {order?.tax_type === 1 ? (
477
+ <OText>{parsePrice((order?.summary?.subtotal_with_discount + getIncludedTaxesDiscounts() ?? 0))}</OText>
478
+ ) : (
479
+ <OText>{parsePrice(order?.summary?.subtotal_with_discount ?? 0)}</OText>
480
+ )}
454
481
  </Table>
455
482
  )}
483
+ {
484
+ order?.taxes?.length === 0 && order?.tax_type === 2 && (
485
+ <Table>
486
+ <OText>
487
+ {t('TAX', 'Tax')} {`(${verifyDecimals(order?.tax, parseNumber)}%)`}
488
+ </OText>
489
+ <OText>{parsePrice(order?.summary?.tax || 0)}</OText>
490
+ </Table>
491
+ )
492
+ }
493
+ {
494
+ order?.fees?.length === 0 && (
495
+ <Table>
496
+ <OText>
497
+ {t('SERVICE_FEE', 'Service fee')}
498
+ {`(${verifyDecimals(order?.service_fee, parseNumber)}%)`}
499
+ </OText>
500
+ <OText>{parsePrice(order?.summary?.service_fee || 0)}</OText>
501
+ </Table>
502
+ )
503
+ }
504
+ {
505
+ order?.taxes?.length > 0 && order?.taxes?.filter((tax: any) => tax?.type === 2 && tax?.rate !== 0).map((tax: any) => (
506
+ <Table key={tax.id}>
507
+ <OSRow>
508
+ <OText>
509
+ {tax.name || t('INHERIT_FROM_BUSINESS', 'Inherit from business')}
510
+ {`(${verifyDecimals(tax?.rate, parseNumber)}%)`}{' '}
511
+ </OText>
512
+ </OSRow>
513
+ <OText>{parsePrice(tax?.summary?.tax_after_discount ?? tax?.summary?.tax ?? 0)}</OText>
514
+ </Table>
515
+ ))
516
+ }
517
+ {
518
+ order?.fees?.length > 0 && order?.fees?.filter((fee: any) => !(fee.fixed === 0 && fee.percentage === 0))?.map((fee: any) => (
519
+ <Table key={fee.id}>
520
+ <OSRow>
521
+ <OText>
522
+ {fee.name || t('INHERIT_FROM_BUSINESS', 'Inherit from business')}
523
+ ({fee?.fixed > 0 && `${parsePrice(fee?.fixed)} + `}{fee.percentage}%){' '}
524
+ </OText>
525
+ </OSRow>
526
+ <OText>{parsePrice(fee?.summary?.fixed + (fee?.summary?.percentage_after_discount ?? fee?.summary?.percentage) ?? 0)}</OText>
527
+ </Table>
528
+ ))
529
+ }
530
+ {
531
+ order?.offers?.length > 0 && order?.offers?.filter((offer: any) => offer?.target === 3)?.map((offer: any) => (
532
+ <Table key={offer.id}>
533
+ <OSRow>
534
+ <OText>
535
+ {offer.name}
536
+ {offer.rate_type === 1 && (
537
+ <OText>{`(${verifyDecimals(offer?.rate, parsePrice)}%)`}</OText>
538
+ )}
539
+ </OText>
540
+ </OSRow>
541
+ <OText>- {parsePrice(offer?.summary?.discount)}</OText>
542
+ </Table>
543
+ ))
544
+ }
456
545
  {order?.summary?.delivery_price > 0 && (
457
546
  <Table>
458
547
  <OText>{t('DELIVERY_FEE', 'Delivery Fee')}</OText>
459
548
  <OText>{parsePrice(order?.summary?.delivery_price)}</OText>
460
549
  </Table>
461
550
  )}
551
+ {
552
+ order?.offers?.length > 0 && order?.offers?.filter((offer: any) => offer?.target === 2)?.map((offer: any) => (
553
+ <Table key={offer.id}>
554
+ <OSRow>
555
+ <OText>
556
+ {offer.name}
557
+ {offer.rate_type === 1 && (
558
+ <OText>{`(${verifyDecimals(offer?.rate, parsePrice)}%)`}</OText>
559
+ )}
560
+ </OText>
561
+ </OSRow>
562
+ <OText>- {parsePrice(offer?.summary?.discount)}</OText>
563
+ </Table>
564
+ ))
565
+ }
462
566
  {order?.summary?.driver_tip > 0 && (
463
567
  <Table>
464
568
  <OText>
@@ -470,23 +574,14 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
470
574
  `(${verifyDecimals(order?.summary?.driver_tip, parseNumber)}%)`
471
575
  )}
472
576
  </OText>
473
- <OText>{parsePrice(order?.summary?.driver_tip ?? 0)}</OText>
474
- </Table>
475
- )}
476
- {order?.summary?.service_fee > 0 && (
477
- <Table>
478
- <OText>
479
- {t('SERVICE_FEE', 'Service Fee')}
480
- {`(${verifyDecimals(order?.summary?.service_fee, parseNumber)}%)`}
481
- </OText>
482
- <OText>{parsePrice(order?.summary?.service_fee)}</OText>
577
+ <OText>{parsePrice(order?.summary?.driver_tip ?? order?.totalDriverTip)}</OText>
483
578
  </Table>
484
579
  )}
485
580
  <Total>
486
581
  <Table>
487
582
  <OText style={styles.textBold}>{t('TOTAL', 'Total')}</OText>
488
583
  <OText style={styles.textBold} color={theme.colors.primary}>
489
- {parsePrice(order?.summary?.total ?? 0)}
584
+ {parsePrice(order?.summary?.total ?? order?.total)}
490
585
  </OText>
491
586
  </Table>
492
587
  </Total>
@@ -508,14 +603,14 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
508
603
  <OIconButton
509
604
  bgColor="transparent"
510
605
  borderColor="transparent"
511
- RenderIcon={() =>
512
- <EvilIcons
513
- name={'close'}
514
- size={40}
515
- color={theme.colors.primary}
516
- />
606
+ RenderIcon={() =>
607
+ <EvilIcons
608
+ name={'close'}
609
+ size={40}
610
+ color={theme.colors.primary}
611
+ />
517
612
  }
518
- style={{ flex:1, justifyContent: 'flex-end', left: 30 }}
613
+ style={{ flex: 1, justifyContent: 'flex-end', left: 30 }}
519
614
  onClick={() => {
520
615
  navigation.reset({
521
616
  routes: [{ name: 'Intro' }],
@@ -51,3 +51,8 @@ export const Total = styled.View`
51
51
  padding-vertical: 10px;
52
52
  `
53
53
 
54
+ export const OSRow = styled.View`
55
+ flex-direction: row;
56
+ overflow: hidden;
57
+ width: 80%;
58
+ `
@@ -472,6 +472,8 @@ export interface Cart {
472
472
  delivery_price_with_discount: number;
473
473
  total: number;
474
474
  clearInactivityTimeout: any;
475
+ taxes: Array<any>;
476
+ fees: Array<any>;
475
477
  }
476
478
 
477
479
  export interface NoNetworkParams {
@@ -50,6 +50,74 @@ import { BusinessTypeFilter } from './src/components/BusinessTypeFilter';
50
50
  import { BusinessController } from './src/components/BusinessController';
51
51
  import { BusinessFeaturedController } from './src/components/BusinessFeaturedController';
52
52
  import { HighestRatedBusinesses } from './src/components/HighestRatedBusinesses';
53
+ import { PaymentOptions } from './src/components/PaymentOptions';
54
+ import { DriverTips } from './src/components/DriverTips';
55
+ import { UserDetails } from './src/components/UserDetails';
56
+ import { OrderSummary } from './src/components/OrderSummary';
57
+ import { CartStoresListing } from './src/components/CartStoresListing';
58
+ import { PaymentOptionsWebView } from '../../src/components/PaymentOptionsWebView';
59
+ import { GoogleMap } from './src/components/GoogleMap';
60
+ import { SingleProductCard } from './src/components/SingleProductCard';
61
+ import { UpsellingRedirect } from './src/components/BusinessProductsListing/UpsellingRedirect';
62
+ import { ProductItemAccordion } from './src/components/ProductItemAccordion';
63
+ import { BusinessItemAccordion } from './src/components/BusinessItemAccordion';
64
+ import { CouponControl } from './src/components/CouponControl';
65
+ import { TaxInformation } from './src/components/TaxInformation';
66
+ import { PlaceSpot } from './src/components/PlaceSpot';
67
+ import { Cart } from './src/components/Cart';
68
+ import { LanguageSelector } from './src/components/LanguageSelector';
69
+ import { PhoneInputNumber } from './src/components/PhoneInputNumber'
70
+ import { FacebookLogin } from './src/components/FacebookLogin';
71
+ import { VerifyPhone } from './src/components/VerifyPhone';
72
+ import { GoogleLogin } from './src/components/GoogleLogin';
73
+ import { PreviousOrders } from './src/components/PreviousOrders';
74
+ import { PaymentOptionCash } from './src/components/PaymentOptionCash';
75
+ import { StripeElementsForm } from './src/components/StripeElementsForm';
76
+ import { StripeCardsList } from './src/components/StripeCardsList';
77
+ import { ProductIngredient } from './src/components/ProductIngredient';
78
+ import { ProductOption } from './src/components/ProductOption';
79
+ import { ProductOptionSubOption } from './src/components/ProductOptionSubOption';
80
+ import { SingleProductReview } from './src/components/SingleProductReview';
81
+ import { LogoutButton } from './src/components/LogoutButton';
82
+ import { UserFormDetailsUI } from './src/components/UserFormDetails';
83
+ import { WalletTransactionItem } from './src/components/WalletTransactionItem';
84
+
85
+ import { USER_TYPE, ORDER_TYPES } from './src/config/constants'
86
+
87
+ import { OSBill, OSTable, OSCoupon, OSTotal, OSRow } from './src/components/OrderSummary/styles';
88
+
89
+ import { FormInput, FormSide, ButtonsWrapper, LoginWith, OTab, OTabs } from './src/components/LoginForm/styles';
90
+ import { OSItem, OSItemContent, OSItemActions} from './src/components/PaymentOptionStripe/styles';
91
+
92
+ import Alert from './src/providers/AlertProvider'
93
+
94
+ import {
95
+ LoginParams,
96
+ ProfileParams,
97
+ AddressListParams,
98
+ AddressFormParams,
99
+ SignupParams,
100
+ PhoneInputParams,
101
+ LanguageSelectorParams,
102
+ BusinessesListingParams,
103
+ HighestRatedBusinessesParams,
104
+ BusinessTypeFilterParams,
105
+ BusinessControllerParams,
106
+ BusinessProductsListingParams,
107
+ BusinessBasicInformationParams,
108
+ BusinessProductsCategoriesParams,
109
+ BusinessProductsListParams,
110
+ SingleProductCardParams,
111
+ BusinessInformationParams,
112
+ BusinessReviewsParams,
113
+ SearchBarParams,
114
+ NotFoundSourceParams,
115
+ OrdersOptionParams,
116
+ ActiveOrdersParams,
117
+ PreviousOrdersParams,
118
+ OrderDetailsParams,
119
+ ReviewDriverParams
120
+ } from './src/types';
53
121
 
54
122
  import { Toast } from './src/components/shared/OToast';
55
123
  import {
@@ -71,6 +139,8 @@ import {
71
139
 
72
140
  import { Container } from './src/layouts/Container';
73
141
  import { SafeAreaContainer } from './src/layouts/SafeAreaContainer';
142
+ import { FloatingBottomContainer } from './src/layouts/FloatingBottomContainer';
143
+
74
144
  import {
75
145
  _retrieveStoreData,
76
146
  _setStoreData,
@@ -130,6 +200,86 @@ export {
130
200
  BusinessController,
131
201
  BusinessFeaturedController,
132
202
  HighestRatedBusinesses,
203
+ PaymentOptions,
204
+ DriverTips,
205
+ UserDetails,
206
+ OrderSummary,
207
+ CartStoresListing,
208
+ PaymentOptionsWebView,
209
+ GoogleMap,
210
+ SingleProductCard,
211
+ UpsellingRedirect,
212
+ ProductItemAccordion,
213
+ BusinessItemAccordion,
214
+ CouponControl,
215
+ TaxInformation,
216
+ PlaceSpot,
217
+ Cart,
218
+ LanguageSelector,
219
+ PhoneInputNumber,
220
+ FacebookLogin,
221
+ VerifyPhone,
222
+ GoogleLogin,
223
+ PreviousOrders,
224
+ PaymentOptionCash,
225
+ StripeElementsForm,
226
+ StripeCardsList,
227
+ ProductIngredient,
228
+ ProductOption,
229
+ ProductOptionSubOption,
230
+ SingleProductReview,
231
+ LogoutButton,
232
+ UserFormDetailsUI,
233
+ WalletTransactionItem,
234
+
235
+ ORDER_TYPES,
236
+ USER_TYPE,
237
+
238
+ OSBill,
239
+ OSTable,
240
+ OSCoupon,
241
+ OSTotal,
242
+ OSRow,
243
+
244
+ FormInput,
245
+ FormSide,
246
+ ButtonsWrapper,
247
+ LoginWith,
248
+ OTab,
249
+ OTabs,
250
+
251
+ OSItem,
252
+ OSItemContent,
253
+ OSItemActions,
254
+
255
+ Alert,
256
+
257
+ //Types
258
+ LoginParams,
259
+ ProfileParams,
260
+ AddressListParams,
261
+ AddressFormParams,
262
+ SignupParams,
263
+ PhoneInputParams,
264
+ LanguageSelectorParams,
265
+ BusinessesListingParams,
266
+ HighestRatedBusinessesParams,
267
+ BusinessTypeFilterParams,
268
+ BusinessControllerParams,
269
+ BusinessProductsListingParams,
270
+ BusinessBasicInformationParams,
271
+ BusinessProductsCategoriesParams,
272
+ BusinessProductsListParams,
273
+ SingleProductCardParams,
274
+ BusinessInformationParams,
275
+ BusinessReviewsParams,
276
+ SearchBarParams,
277
+ NotFoundSourceParams,
278
+ OrdersOptionParams,
279
+ ActiveOrdersParams,
280
+ PreviousOrdersParams,
281
+ OrderDetailsParams,
282
+ ReviewDriverParams,
133
283
 
134
284
  // OComponents
135
285
  Toast,
@@ -151,6 +301,7 @@ export {
151
301
  // layout
152
302
  Container,
153
303
  SafeAreaContainer,
304
+ FloatingBottomContainer,
154
305
  NavBar,
155
306
 
156
307
  // utils
@@ -140,7 +140,7 @@ const AddressListUI = (props: AddressListParams) => {
140
140
  <AddressListContainer>
141
141
  {isProfile && (
142
142
  <NavBar
143
- title={t('MY_SAVED_PLACES', 'My saved places')}
143
+ title={t('SAVED_PLACES', 'My saved places')}
144
144
  titleAlign={'center'}
145
145
  onActionLeft={() => goToBack()}
146
146
  showCall={false}
@@ -1,6 +1,6 @@
1
- import React, { useEffect } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import { Platform, Text, StyleSheet } from 'react-native';
3
- import { useApi, useSession, useLanguage, useConfig } from 'ordering-components/native';
3
+ import { useApi, useSession, useLanguage, useConfig, useToast, ToastType } from 'ordering-components/native';
4
4
  import { appleAuthAndroid, appleAuth } from '@invertase/react-native-apple-authentication';
5
5
  import uuid from 'react-native-uuid';
6
6
  import Icon from 'react-native-vector-icons/FontAwesome5';
@@ -18,7 +18,12 @@ export const AppleLogin = (props: any) => {
18
18
  const [ordering] = useApi();
19
19
  const [{ auth }] = useSession();
20
20
  const [, t] = useLanguage();
21
- const [{ configs }] = useConfig()
21
+ const [{ configs }] = useConfig();
22
+ const [, {showToast}] = useToast()
23
+ const [credentialStateForUser, updateCredentialStateForUser] = useState<any>(-1);
24
+
25
+ let user : any= null
26
+
22
27
  const buttonText = auth
23
28
  ? t('CONTINUE_WITH_APPLE', 'Logout with Apple')
24
29
  : t('CONTINUE_WITH_FACEBOOK', 'Continue with Apple');
@@ -39,8 +44,8 @@ export const AppleLogin = (props: any) => {
39
44
  handleLoading && handleLoading(false)
40
45
  }
41
46
  } else {
47
+ showToast(ToastType.Error, `Error login on apple from api Code: ${code}`, 10000)
42
48
  handleLoading && handleLoading(false)
43
- logoutFromApple()
44
49
  }
45
50
  } catch (err: any) {
46
51
  handleLoading && handleLoading(false)
@@ -48,33 +53,52 @@ export const AppleLogin = (props: any) => {
48
53
  }
49
54
  }
50
55
 
51
- const logoutFromApple = () => {
52
-
56
+ const fetchAndUpdateCredentialState = async (updateCredentialStateForUser : any) => {
57
+ if (user === null) {
58
+ updateCredentialStateForUser('N/A');
59
+ } else {
60
+ const credentialState = await appleAuth.getCredentialStateForUser(user);
61
+ if (credentialState === appleAuth.State.AUTHORIZED) {
62
+ updateCredentialStateForUser('AUTHORIZED');
63
+ } else {
64
+ updateCredentialStateForUser(credentialState);
65
+ }
66
+ }
53
67
  }
54
68
 
55
- const onIOSButtonPress = async () => {
69
+ const onIOSButtonPress = async (updateCredentialStateForUser : any) => {
56
70
  try {
57
71
  const appleAuthRequestResponse = await appleAuth.performRequest({
58
72
  requestedOperation: appleAuth.Operation.LOGIN,
59
73
  requestedScopes: [appleAuth.Scope.EMAIL, appleAuth.Scope.FULL_NAME],
60
74
  });
61
75
 
62
- // get current authentication state for user
63
- // /!\ This method must be tested on a real device. On the iOS simulator it always throws an error.
64
- const credentialState = await appleAuth.getCredentialStateForUser(appleAuthRequestResponse.user);
65
-
66
- // use credentialState response to ensure the user is authenticated
67
- if (credentialState === appleAuth.State.AUTHORIZED) {
68
- // user is authenticated
69
- if (appleAuthRequestResponse.authorizationCode) {
70
- performAppleLogin(appleAuthRequestResponse.authorizationCode)
71
- }
76
+ const {
77
+ user: newUser,
78
+ email,
79
+ identityToken,
80
+ authorizationCode
81
+ } = appleAuthRequestResponse;
82
+
83
+ user = newUser;
84
+
85
+ fetchAndUpdateCredentialState(updateCredentialStateForUser).catch(error =>
86
+ updateCredentialStateForUser(`Error: ${error.code}`),
87
+ );
88
+
89
+ if (identityToken && authorizationCode) {
90
+ showToast(ToastType.Success, `Apple Authentication Completed, ${email}`)
91
+ performAppleLogin(authorizationCode)
92
+ } else {
93
+ handleErrors && handleErrors('UNABLE_LOGIN_TOKEN', 'Unable to login, no token found')
72
94
  }
95
+
73
96
  } catch (err: any) {
74
97
  handleLoading && handleLoading(false)
75
98
  handleErrors && handleErrors(err.message)
76
99
  }
77
100
  }
101
+
78
102
  const onAndroidButtonPress = async () => {
79
103
  try {
80
104
  // Generate secure, random values for state and nonce
@@ -108,10 +132,20 @@ export const AppleLogin = (props: any) => {
108
132
  }
109
133
 
110
134
  useEffect(() => {
111
- if (Platform.OS == 'android') return;
112
- // onCredentialRevoked returns a function that will remove the event listener. useEffect will call this function when the component unmounts
135
+ if (!appleAuth.isSupported || Platform.OS === 'android') return;
136
+
137
+ fetchAndUpdateCredentialState(updateCredentialStateForUser).catch(error =>
138
+ updateCredentialStateForUser(`Error: ${error.code}`),
139
+ );
140
+ }, []);
141
+
142
+ useEffect(() => {
143
+ if (!appleAuth.isSupported || Platform.OS === 'android') return;
144
+
113
145
  return appleAuth.onCredentialRevoked(async () => {
114
- console.warn('If this function executes, User Credentials have been Revoked');
146
+ fetchAndUpdateCredentialState(updateCredentialStateForUser).catch(error =>
147
+ updateCredentialStateForUser(`Error: ${error.code}`),
148
+ );
115
149
  });
116
150
  }, []);
117
151
 
@@ -123,9 +157,12 @@ export const AppleLogin = (props: any) => {
123
157
 
124
158
  return (
125
159
  <Container>
160
+ {credentialStateForUser !== -1 && (
161
+ <Text>{credentialStateForUser}</Text>
162
+ )}
126
163
  {canShowButton() &&
127
164
  <AppleButton
128
- onPress={() => Platform.OS == 'android' ? onAndroidButtonPress() : onIOSButtonPress()}
165
+ onPress={() => Platform.OS == 'android' ? onAndroidButtonPress() : onIOSButtonPress(updateCredentialStateForUser)}
129
166
  >
130
167
  <Icon
131
168
  name="apple"