ordering-ui-react-native 0.15.35 → 0.15.38-test

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 (79) hide show
  1. package/package.json +3 -2
  2. package/src/components/BusinessTypeFilter/index.tsx +4 -1
  3. package/src/components/LanguageSelector/index.tsx +1 -0
  4. package/src/components/OrderDetails/index.tsx +2 -2
  5. package/src/components/PaymentOptions/index.tsx +2 -2
  6. package/src/components/StripeMethodForm/index.tsx +22 -21
  7. package/src/pages/BusinessProductsList.tsx +1 -0
  8. package/src/pages/BusinessesListing.tsx +1 -1
  9. package/themes/business/src/components/Home/index.tsx +128 -55
  10. package/themes/business/src/components/Home/styles.tsx +8 -1
  11. package/themes/business/src/components/NewOrderNotification/index.tsx +59 -98
  12. package/themes/business/src/components/OrderDetails/Delivery.tsx +9 -9
  13. package/themes/business/src/components/OrderDetails/OrderContentComponent.tsx +152 -91
  14. package/themes/business/src/components/OrderDetails/styles.tsx +7 -0
  15. package/themes/business/src/components/OrdersListManager/index.tsx +51 -48
  16. package/themes/business/src/components/OrdersOption/index.tsx +52 -48
  17. package/themes/business/src/components/PreviousOrders/index.tsx +50 -14
  18. package/themes/kiosk/src/components/Cart/index.tsx +99 -25
  19. package/themes/kiosk/src/components/Cart/styles.tsx +6 -0
  20. package/themes/kiosk/src/components/OrderDetails/index.tsx +134 -39
  21. package/themes/kiosk/src/components/OrderDetails/styles.tsx +5 -0
  22. package/themes/kiosk/src/components/ProductForm/index.tsx +2 -2
  23. package/themes/kiosk/src/types/index.d.ts +2 -0
  24. package/themes/original/index.tsx +176 -1
  25. package/themes/original/src/components/AddressForm/index.tsx +15 -10
  26. package/themes/original/src/components/AddressList/index.tsx +28 -2
  27. package/themes/original/src/components/AppleLogin/index.tsx +118 -77
  28. package/themes/original/src/components/BusinessBasicInformation/index.tsx +96 -45
  29. package/themes/original/src/components/BusinessBasicInformation/styles.tsx +28 -1
  30. package/themes/original/src/components/BusinessController/index.tsx +28 -6
  31. package/themes/original/src/components/BusinessController/styles.tsx +22 -0
  32. package/themes/original/src/components/BusinessFeaturedController/index.tsx +20 -1
  33. package/themes/original/src/components/BusinessFeaturedController/styles.tsx +23 -0
  34. package/themes/original/src/components/BusinessListingSearch/index.tsx +4 -0
  35. package/themes/original/src/components/BusinessMenuList/index.tsx +11 -4
  36. package/themes/original/src/components/BusinessPreorder/index.tsx +141 -121
  37. package/themes/original/src/components/BusinessProductsCategories/index.tsx +7 -5
  38. package/themes/original/src/components/BusinessProductsList/index.tsx +126 -21
  39. package/themes/original/src/components/BusinessProductsList/styles.tsx +32 -2
  40. package/themes/original/src/components/BusinessProductsListing/index.tsx +27 -6
  41. package/themes/original/src/components/BusinessReviews/index.tsx +4 -25
  42. package/themes/original/src/components/BusinessesListing/index.tsx +23 -22
  43. package/themes/original/src/components/Cart/index.tsx +1 -3
  44. package/themes/original/src/components/CartContent/index.tsx +2 -2
  45. package/themes/original/src/components/Checkout/index.tsx +2 -1
  46. package/themes/original/src/components/Home/index.tsx +1 -1
  47. package/themes/original/src/components/LoginForm/index.tsx +73 -2
  48. package/themes/original/src/components/LoginForm/styles.tsx +6 -1
  49. package/themes/original/src/components/LogoutButton/index.tsx +7 -1
  50. package/themes/original/src/components/Messages/index.tsx +5 -0
  51. package/themes/original/src/components/Messages/styles.tsx +1 -3
  52. package/themes/original/src/components/MomentOption/index.tsx +10 -1
  53. package/themes/original/src/components/MomentOption/styles.tsx +1 -1
  54. package/themes/original/src/components/OrderDetails/index.tsx +11 -5
  55. package/themes/original/src/components/OrderProgress/index.tsx +3 -3
  56. package/themes/original/src/components/OrderProgress/styles.tsx +1 -0
  57. package/themes/original/src/components/OrderSummary/index.tsx +2 -2
  58. package/themes/original/src/components/PaymentOptionWallet/index.tsx +6 -2
  59. package/themes/original/src/components/PaymentOptions/index.tsx +3 -1
  60. package/themes/original/src/components/PhoneInputNumber/index.tsx +10 -4
  61. package/themes/original/src/components/PreviousOrders/index.tsx +14 -12
  62. package/themes/original/src/components/ProductForm/index.tsx +20 -13
  63. package/themes/original/src/components/Promotions/index.tsx +232 -0
  64. package/themes/original/src/components/Promotions/styles.tsx +80 -0
  65. package/themes/original/src/components/SignupForm/index.tsx +109 -13
  66. package/themes/original/src/components/SingleProductCard/index.tsx +39 -18
  67. package/themes/original/src/components/SingleProductCard/styles.tsx +28 -1
  68. package/themes/original/src/components/TaxInformation/index.tsx +10 -4
  69. package/themes/original/src/components/UserFormDetails/index.tsx +13 -2
  70. package/themes/original/src/components/UserProfile/index.tsx +53 -8
  71. package/themes/original/src/components/Wallets/index.tsx +57 -3
  72. package/themes/original/src/components/Wallets/styles.tsx +21 -0
  73. package/themes/original/src/components/shared/HeaderTitle.tsx +21 -0
  74. package/themes/original/src/components/shared/index.tsx +2 -0
  75. package/themes/original/src/config/constants.tsx +6 -6
  76. package/themes/original/src/types/index.tsx +21 -1
  77. package/themes/original/src/utils/index.tsx +9 -0
  78. package/themes/single-business/src/components/AddressList/index.tsx +1 -1
  79. package/themes/single-business/src/components/UserProfile/index.tsx +1 -1
@@ -7,11 +7,15 @@ import { SignupForm } from './src/components/SignupForm';
7
7
  import { ActiveOrders } from './src/components/ActiveOrders';
8
8
  import { AddressList } from './src/components/AddressList';
9
9
  import { AppleLogin } from './src/components/AppleLogin';
10
+ import { BusinessBasicInformation } from './src/components/BusinessBasicInformation';
11
+ import { BusinessProductsCategories } from './src/components/BusinessProductsCategories';
12
+ import { BusinessProductsList } from './src/components/BusinessProductsList';
10
13
  import { BusinessesListing } from './src/components/BusinessesListing';
11
14
  import { BusinessProductsListing } from './src/components/BusinessProductsListing';
12
15
  import { CartContent } from './src/components/CartContent';
13
16
  import { BusinessCart } from './src/components/BusinessCart';
14
17
  import { Checkout } from './src/components/Checkout';
18
+ import { FloatingButton } from './src/components/FloatingButton';
15
19
  import { ForgotPasswordForm } from './src/components/ForgotPasswordForm';
16
20
  import { MomentOption } from './src/components/MomentOption';
17
21
  import { OrdersOption } from './src/components/OrdersOption';
@@ -33,12 +37,87 @@ import { HelpOrder } from './src/components/HelpOrder';
33
37
  import { NetworkError } from './src/components/NetworkError';
34
38
  import { NotFoundSource } from './src/components/NotFoundSource';
35
39
  import { OrderTypeSelector } from './src/components/OrderTypeSelector';
40
+ import { SearchBar } from './src/components/SearchBar';
36
41
  import { Wallets } from './src/components/Wallets';
37
42
  import { PaymentOptionWallet } from './src/components/PaymentOptionWallet';
38
43
  import { ProductForm } from './src/components/ProductForm';
39
44
  import { UpsellingProducts } from './src/components/UpsellingProducts';
40
45
  import { UserVerification } from './src/components/UserVerification';
41
46
  import { BusinessListingSearch } from './src/components/BusinessListingSearch';
47
+ import { LastOrders } from './src/components/LastOrders';
48
+ import NavBar from './src/components/NavBar';
49
+ import { BusinessTypeFilter } from './src/components/BusinessTypeFilter';
50
+ import { BusinessController } from './src/components/BusinessController';
51
+ import { BusinessFeaturedController } from './src/components/BusinessFeaturedController';
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';
42
121
 
43
122
  import { Toast } from './src/components/shared/OToast';
44
123
  import {
@@ -55,10 +134,13 @@ import {
55
134
  OAlert,
56
135
  OModal,
57
136
  OBottomPopup,
137
+ HeaderTitle
58
138
  } from './src/components/shared';
59
139
 
60
140
  import { Container } from './src/layouts/Container';
61
141
  import { SafeAreaContainer } from './src/layouts/SafeAreaContainer';
142
+ import { FloatingBottomContainer } from './src/layouts/FloatingBottomContainer';
143
+
62
144
  import {
63
145
  _retrieveStoreData,
64
146
  _setStoreData,
@@ -94,7 +176,7 @@ export {
94
176
  BusinessMenuList,
95
177
  UserProfile,
96
178
  MessageListing,
97
- Messages,
179
+ Messages,
98
180
  Help,
99
181
  HelpAccountAndPayment,
100
182
  HelpGuide,
@@ -108,6 +190,96 @@ export {
108
190
  UpsellingProducts,
109
191
  UserVerification,
110
192
  BusinessListingSearch,
193
+ BusinessBasicInformation,
194
+ BusinessProductsCategories,
195
+ BusinessProductsList,
196
+ FloatingButton,
197
+ SearchBar,
198
+ LastOrders,
199
+ BusinessTypeFilter,
200
+ BusinessController,
201
+ BusinessFeaturedController,
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,
111
283
 
112
284
  // OComponents
113
285
  Toast,
@@ -124,10 +296,13 @@ export {
124
296
  OAlert,
125
297
  OModal,
126
298
  OBottomPopup,
299
+ HeaderTitle,
127
300
 
128
301
  // layout
129
302
  Container,
130
303
  SafeAreaContainer,
304
+ FloatingBottomContainer,
305
+ NavBar,
131
306
 
132
307
  // utils
133
308
  _retrieveStoreData,
@@ -108,6 +108,9 @@ const AddressFormUI = (props: AddressFormParams) => {
108
108
  top: 12,
109
109
  zIndex: 1002,
110
110
  },
111
+ wrapperNavbar: Platform.OS === 'ios'
112
+ ? { paddingVertical: 0, paddingHorizontal: 40 }
113
+ : { paddingVertical: 20, paddingHorizontal: 40 }
111
114
  });
112
115
 
113
116
  const [, t] = useLanguage();
@@ -500,16 +503,18 @@ const AddressFormUI = (props: AddressFormParams) => {
500
503
  keyboardShouldPersistTaps='always'
501
504
  listViewDisplayed={false}
502
505
  >
503
- <NavBar
504
- title={t('WHERE_DO_WE_DELIVERY', 'Where do we delivery?')}
505
- titleAlign={'center'}
506
- onActionLeft={goToBack}
507
- showCall={false}
508
- paddingTop={20}
509
- btnStyle={{ paddingLeft: 40 }}
510
- titleStyle={{ fontSize: 14 }}
511
- titleWrapStyle={{ paddingHorizontal: 0 }}
512
- />
506
+ <View style={styles.wrapperNavbar}>
507
+ <NavBar
508
+ title={t('WHERE_DO_WE_DELIVERY', 'Where do we delivery?')}
509
+ titleAlign={'center'}
510
+ onActionLeft={goToBack}
511
+ showCall={false}
512
+ btnStyle={{ paddingLeft: 0 }}
513
+ style={{ flexDirection: 'column', alignItems: 'flex-start' }}
514
+ titleWrapStyle={{ paddingHorizontal: 0 }}
515
+ titleStyle={{ marginRight: 0, marginLeft: 0 }}
516
+ />
517
+ </View>
513
518
  <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
514
519
  <AddressFormContainer style={{ height: 600, overflow: 'scroll' }}>
515
520
  <View>
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect } from 'react'
2
2
  import { AddressList as AddressListController, useLanguage, useOrder, useSession } from 'ordering-components/native'
3
3
  import { AddressListContainer, AddressItem } from './styles'
4
- import { StyleSheet, View } from 'react-native'
4
+ import { Platform, StyleSheet, View } from 'react-native'
5
5
  import { OButton, OText, OAlert, OModal, OIcon } from '../shared'
6
6
  import { Container } from '../../layouts/Container'
7
7
  import { AddressListParams } from '../../types'
@@ -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}
@@ -261,6 +261,32 @@ const AddressListUI = (props: AddressListParams) => {
261
261
  )}
262
262
  {!addressList.loading && !addressList.error && (
263
263
  <>
264
+ {addressList?.addresses?.length === 0 && (
265
+ <View
266
+ style={{
267
+ flexDirection: 'column',
268
+ paddingHorizontal: 10,
269
+ paddingTop: 20
270
+ }}
271
+ >
272
+ <OText
273
+ size={24}
274
+ lineHeight={36}
275
+ weight={Platform.OS === 'ios' ? '600' : 'bold'}
276
+ style={{
277
+ textAlign: 'center',
278
+ marginRight: 40,
279
+ color: theme.colors.textNormal,
280
+ paddingHorizontal: 0,
281
+ width: '100%',
282
+ marginLeft: 0
283
+ }}
284
+ >
285
+ {t('ADDRESS_LIST', 'Address List')}
286
+ </OText>
287
+ </View>
288
+ )}
289
+
264
290
  <OButton
265
291
  text={t('ADD_NEW_ADDRESS', 'Add new Address')}
266
292
  imgRightSrc=''
@@ -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 } 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';
@@ -16,12 +16,17 @@ export const AppleLogin = (props: any) => {
16
16
  } = props
17
17
 
18
18
  const [ordering] = useApi();
19
- const [{ auth }] = useSession();
20
- const [, t] = useLanguage();
19
+ const [{ auth }] = useSession();
20
+ const [, t] = useLanguage();
21
+ const [{ configs }] = useConfig();
22
+ const [, {showToast}] = useToast()
23
+ const [credentialStateForUser, updateCredentialStateForUser] = useState<any>(-1);
21
24
 
22
- const buttonText = auth
23
- ? t('CONTINUE_WITH_APPLE', 'Logout with Apple')
24
- : t('CONTINUE_WITH_FACEBOOK', 'Continue with Apple');
25
+ let user : any= null
26
+
27
+ const buttonText = auth
28
+ ? t('CONTINUE_WITH_APPLE', 'Logout with Apple')
29
+ : t('CONTINUE_WITH_FACEBOOK', 'Continue with Apple');
25
30
 
26
31
  const performAppleLogin = async (code: string) => {
27
32
  try {
@@ -29,17 +34,19 @@ export const AppleLogin = (props: any) => {
29
34
  method: 'POST',
30
35
  headers: { 'Content-Type': 'application/json' },
31
36
  body: JSON.stringify({
32
- code: code
37
+ code: code,
38
+ platform: Platform.OS === 'ios' ? 'ios' : 'other'
33
39
  })
34
40
  })
35
- if (!response.content.error) {
41
+ const { result, error } = await response.json()
42
+ if (!error) {
36
43
  if (handleSuccessAppleLogin) {
37
- handleSuccessAppleLogin(response.content.result)
44
+ handleSuccessAppleLogin(result)
38
45
  handleLoading && handleLoading(false)
39
46
  }
40
47
  } else {
48
+ handleErrors && handleErrors(result)
41
49
  handleLoading && handleLoading(false)
42
- logoutFromApple()
43
50
  }
44
51
  } catch (err: any) {
45
52
  handleLoading && handleLoading(false)
@@ -47,66 +54,99 @@ export const AppleLogin = (props: any) => {
47
54
  }
48
55
  }
49
56
 
50
- const logoutFromApple = () => {
51
-
57
+ const fetchAndUpdateCredentialState = async (updateCredentialStateForUser : any) => {
58
+ if (user === null) {
59
+ updateCredentialStateForUser('N/A');
60
+ } else {
61
+ const credentialState = await appleAuth.getCredentialStateForUser(user);
62
+ if (credentialState === appleAuth.State.AUTHORIZED) {
63
+ updateCredentialStateForUser('AUTHORIZED');
64
+ } else {
65
+ updateCredentialStateForUser(credentialState);
66
+ }
67
+ }
52
68
  }
53
69
 
54
- const onIOSButtonPress = async () => {
55
-
56
- const appleAuthRequestResponse = await appleAuth.performRequest({
57
- requestedOperation: appleAuth.Operation.LOGIN,
58
- requestedScopes: [appleAuth.Scope.EMAIL, appleAuth.Scope.FULL_NAME],
59
- });
60
-
61
- // get current authentication state for user
62
- // /!\ This method must be tested on a real device. On the iOS simulator it always throws an error.
63
- const credentialState = await appleAuth.getCredentialStateForUser(appleAuthRequestResponse.user);
70
+ const onIOSButtonPress = async (updateCredentialStateForUser : any) => {
71
+ try {
72
+ const appleAuthRequestResponse = await appleAuth.performRequest({
73
+ requestedOperation: appleAuth.Operation.LOGIN,
74
+ requestedScopes: [appleAuth.Scope.EMAIL, appleAuth.Scope.FULL_NAME],
75
+ });
76
+
77
+ const {
78
+ user: newUser,
79
+ email,
80
+ identityToken,
81
+ authorizationCode
82
+ } = appleAuthRequestResponse;
64
83
 
65
- // use credentialState response to ensure the user is authenticated
66
- if (credentialState === appleAuth.State.AUTHORIZED) {
67
- // user is authenticated
68
- if (appleAuthRequestResponse.authorizationCode) {
69
- performAppleLogin(appleAuthRequestResponse.authorizationCode)
84
+ user = newUser;
85
+
86
+ fetchAndUpdateCredentialState(updateCredentialStateForUser).catch(error =>
87
+ updateCredentialStateForUser(`Error: ${error.code}`),
88
+ );
89
+
90
+ if (identityToken && authorizationCode) {
91
+ showToast(ToastType.Success, `Apple Authentication Completed, ${email}`)
92
+ performAppleLogin(authorizationCode)
93
+ } else {
94
+ handleErrors && handleErrors('UNABLE_LOGIN_TOKEN', 'Unable to login, no token found')
70
95
  }
71
- }
72
96
 
97
+ } catch (err: any) {
98
+ handleLoading && handleLoading(false)
99
+ handleErrors && handleErrors(err.message)
100
+ }
73
101
  }
74
102
 
75
103
  const onAndroidButtonPress = async () => {
76
- // Generate secure, random values for state and nonce
77
- const rawNonce: any = uuid.v4();
78
- const state: any = uuid.v4();
79
-
80
- // Configure the request
81
- appleAuthAndroid.configure({
82
- clientId: 'com.example.client-android',
83
- // Return URL added to your Apple dev console. We intercept this redirect, but it must still match
84
- // the URL you provided to Apple. It can be an empty route on your backend as it's never called.
85
- redirectUri: 'https://example.com/auth/callback',
86
- responseType: appleAuthAndroid.ResponseType.ALL,
87
- scope: appleAuthAndroid.Scope.ALL,
88
- // Random nonce value that will be SHA256 hashed before sending to Apple.
89
- nonce: rawNonce,
90
- state,
91
- });
92
-
93
- // Open the browser window for user sign in
94
- const response = await appleAuthAndroid.signIn();
95
-
96
104
  try {
105
+ // Generate secure, random values for state and nonce
106
+ const rawNonce: any = uuid.v4();
107
+ const state: any = uuid.v4();
108
+
109
+ // Configure the request
110
+ appleAuthAndroid.configure({
111
+ // The Service ID you registered with Apple
112
+ clientId: configs?.apple_login_client_id?.value,
113
+ // Return URL added to your Apple dev console. We intercept this redirect, but it must still match
114
+ // the URL you provided to Apple. It can be an empty route on your backend as it's never called.
115
+ redirectUri: 'https://example.com/auth/callback',
116
+ responseType: appleAuthAndroid.ResponseType.ALL,
117
+ scope: appleAuthAndroid.Scope.ALL,
118
+ // Random nonce value that will be SHA256 hashed before sending to Apple.
119
+ nonce: rawNonce,
120
+ state,
121
+ });
122
+
123
+ // Open the browser window for user sign in
124
+ const response = await appleAuthAndroid.signIn();
97
125
  if (response.code) {
98
126
  performAppleLogin(response.code)
99
127
  }
100
128
  } catch (err: any) {
101
-
129
+ handleLoading && handleLoading(false)
130
+ handleErrors && handleErrors(err.message)
102
131
  }
132
+
103
133
  }
104
134
 
105
135
  useEffect(() => {
106
- if (Platform.OS == 'android') return;
107
- // onCredentialRevoked returns a function that will remove the event listener. useEffect will call this function when the component unmounts
136
+ if (!appleAuth.isSupported || Platform.OS === 'android') return;
137
+
138
+ fetchAndUpdateCredentialState(updateCredentialStateForUser).catch(error =>
139
+ updateCredentialStateForUser(`Error: ${error.code}`),
140
+ );
141
+ }, []);
142
+
143
+ useEffect(() => {
144
+ if (!appleAuth.isSupported || Platform.OS === 'android') return;
145
+
108
146
  return appleAuth.onCredentialRevoked(async () => {
109
- console.warn('If this function executes, User Credentials have been Revoked');
147
+ fetchAndUpdateCredentialState(updateCredentialStateForUser).catch(error =>
148
+ updateCredentialStateForUser(`Error: ${error.code}`),
149
+ );
110
150
  });
111
151
  }, []);
112
152
 
@@ -115,35 +155,36 @@ export const AppleLogin = (props: any) => {
115
155
  if (Platform.OS === 'android') return appleAuthAndroid.isSupported;
116
156
  return false;
117
157
  }
158
+
118
159
  return (
119
160
  <Container>
120
- {canShowButton() &&
121
- <AppleButton
122
- onPress={() => Platform.OS == 'android' ? onAndroidButtonPress() : onIOSButtonPress()}
123
- >
124
- <Icon
125
- name="apple"
126
- size={20}
127
- color={'black'}
128
- style={style.fbBtn}
129
- />
130
- <Text style={style.textBtn}>
131
- {buttonText}
132
- </Text>
133
- </AppleButton>
161
+ {canShowButton() &&
162
+ <AppleButton
163
+ onPress={() => Platform.OS == 'android' ? onAndroidButtonPress() : onIOSButtonPress(updateCredentialStateForUser)}
164
+ >
165
+ <Icon
166
+ name="apple"
167
+ size={20}
168
+ color={'black'}
169
+ style={style.fbBtn}
170
+ />
171
+ <Text style={style.textBtn}>
172
+ {buttonText}
173
+ </Text>
174
+ </AppleButton>
134
175
  }
135
176
  </Container>
136
177
  );
137
178
  }
138
179
 
139
180
  const style = StyleSheet.create({
140
- fbBtn: {
141
- position: 'absolute',
142
- left: 0,
143
- marginHorizontal: 16
144
- },
145
- textBtn: {
146
- fontSize: 14,
147
- color: '#000000'
148
- }
149
- })
181
+ fbBtn: {
182
+ position: 'absolute',
183
+ left: 0,
184
+ marginHorizontal: 16
185
+ },
186
+ textBtn: {
187
+ fontSize: 14,
188
+ color: '#000000'
189
+ }
190
+ })