@bigbinary/neeto-commons-rn 1.4.7 → 1.4.9
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.usePushNotification=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=require("react");var _reactNative=require("react-native");var _dayjs=_interopRequireDefault(require("dayjs"));var _reactNativeNotifications=require("react-native-notifications");var _reactNativePermissions=require("react-native-permissions");var _reactNativePushNotification=_interopRequireDefault(require("react-native-push-notification"));var _bugsnag=require("../../config/bugsnag");var _constants=require("../../constants");var _asyncStore=require("../asyncStore");var _useNotification2=require("../../hooks/query/useNotification");var _useAppState=require("../../hooks/useAppState");var _store=require("../../store");var usePushNotification=exports.usePushNotification=function usePushNotification(isLoggedIn){var _ref=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{handleClick:function handleClick(){}},handleClick=_ref.handleClick;var appState=(0,_useAppState.useAppState)();var _useState=(0,_react.useState)(false),_useState2=(0,_slicedToArray2.default)(_useState,2),notificationPermission=_useState2[0],setNotificationPermission=_useState2[1];var _useNotification=(0,_useNotification2.useNotification)(),useRegisterTokenMutation=_useNotification.useRegisterTokenMutation,useMarkReadUnreadNotification=_useNotification.useMarkReadUnreadNotification;var _useRegisterTokenMuta=useRegisterTokenMutation(),registerToken=_useRegisterTokenMuta.mutate;var _useMarkReadUnreadNot=useMarkReadUnreadNotification(),markReadUnreadNotification=_useMarkReadUnreadNot.mutate;(0,_react.useEffect)(function(){var checkPermission=function(){var _ref2=(0,_asyncToGenerator2.default)(function*(){try{if(_reactNative.Platform.OS==="android"&&_reactNative.Platform.Version<33){setNotificationPermission(true);return;}var _yield$checkNotificat=yield(0,_reactNativePermissions.checkNotifications)(),status=_yield$checkNotificat.status;setNotificationPermission(status===_reactNativePermissions.RESULTS.GRANTED);}catch(error){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(error),"notification");}});return function checkPermission(){return _ref2.apply(this,arguments);};}();if(appState==="active"){checkPermission();}},[appState]);var registerNotificationEvents=(0,_react.useCallback)(function(){var foregroundEvent=_reactNativeNotifications.Notifications.events().registerNotificationReceivedForeground(function(notification,completion){if(_reactNative.Platform.OS==="android"){var _notification$payload,_notification$payload2,_notification$payload3,_notification$payload4,_notification$payload5;var notificationTitle=(notification==null?void 0:(_notification$payload=notification.payload)==null?void 0:_notification$payload["gcm.notification.title"])||(notification==null?void 0:(_notification$payload2=notification.payload)==null?void 0:_notification$payload2.title)||"New Notification";var notificationBody=(notification==null?void 0:(_notification$payload3=notification.payload)==null?void 0:_notification$payload3["gcm.notification.body"])||(notification==null?void 0:(_notification$payload4=notification.payload)==null?void 0:_notification$payload4.message)||"You have a new message";_reactNativeNotifications.Notifications.postLocalNotification({body:notificationBody,title:notificationTitle,url:notification==null?void 0:(_notification$payload5=notification.payload)==null?void 0:_notification$payload5.url,channelId:_reactNative.Platform.OS==="android"?"default":undefined,android_channel_id:"default"});}completion({alert:true,sound:true,badge:false});});var backgroundEvent=_reactNativeNotifications.Notifications.events().registerNotificationReceivedBackground(function(notification,completion){var _notification$payload6,_notification$payload7,_notification$payload8,_notification$payload9,_notification$payload0;var notificationTitle=(notification==null?void 0:(_notification$payload6=notification.payload)==null?void 0:_notification$payload6["gcm.notification.title"])||(notification==null?void 0:(_notification$payload7=notification.payload)==null?void 0:_notification$payload7.title)||"New Notification";var notificationBody=(notification==null?void 0:(_notification$payload8=notification.payload)==null?void 0:_notification$payload8["gcm.notification.body"])||(notification==null?void 0:(_notification$payload9=notification.payload)==null?void 0:_notification$payload9.message)||"You have a new message";_reactNativeNotifications.Notifications.postLocalNotification({body:notificationBody,title:notificationTitle,url:notification==null?void 0:(_notification$payload0=notification.payload)==null?void 0:_notification$payload0.url,channelId:_reactNative.Platform.OS==="android"?"default":undefined,android_channel_id:"default"});completion({alert:true,sound:true,badge:false});});var openedEvent=_reactNativeNotifications.Notifications.events().registerNotificationOpened(function(notification,completion){markNotificationsAsRead(notification);completion();});if(_reactNative.Platform.OS==="android"){var defaultNotificationChannel={channelId:"default",name:"Default Channel",importance:5,sound:"default",enableVibration:true,enableLights:true,showBadge:true};var channel01NotificationChannel={channelId:"channel_01",name:"Channel 01",importance:5,enableLights:true,enableVibration:true,showBadge:true};_reactNativeNotifications.Notifications.setNotificationChannel(defaultNotificationChannel);_reactNativeNotifications.Notifications.setNotificationChannel(channel01NotificationChannel);}return[foregroundEvent,backgroundEvent,openedEvent];},[]);(0,_react.useEffect)(function(){var events=registerNotificationEvents();return function(){events.forEach(function(event){return event.remove();});};},[registerNotificationEvents]);(0,_react.useEffect)(function(){if(isLoggedIn&&appState==="active"&¬ificationPermission){initializePN();}},[initializePN,isLoggedIn,appState,notificationPermission]);var registerForRemoteNotifications=(0,_react.useCallback)(function(){_reactNativeNotifications.Notifications.registerRemoteNotifications();var registerDeviceOnce=function(){var isRegistered=false;return function(){var _ref3=(0,_asyncToGenerator2.default)(function*(event){var _Store$getState,_Store$getState$auth;if(isRegistered)return;var isLoggedIn=((_Store$getState=_store.Store.getState())==null?void 0:(_Store$getState$auth=_Store$getState.auth)==null?void 0:_Store$getState$auth.isLoggedIn)||false;if(isLoggedIn&&event.deviceToken){isRegistered=true;var payload={device:{device_token:event.deviceToken,platform:_reactNative.Platform.OS}};var notificationDeviceId=yield(0,_asyncStore.getItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN);if(typeof notificationDeviceId!=="string"){registerToken(payload,{onSuccess:function(){var _onSuccess=(0,_asyncToGenerator2.default)(function*(){yield(0,_asyncStore.setItem)(_constants.STORAGE_KEYS.DEVICE_REGISTERED,true);});function onSuccess(){return _onSuccess.apply(this,arguments);}return onSuccess;}(),onError:function onError(){isRegistered=false;}});}}});return function(_x){return _ref3.apply(this,arguments);};}();}();_reactNativeNotifications.Notifications.events().registerRemoteNotificationsRegistered(function(event){registerDeviceOnce(event);});_reactNativeNotifications.Notifications.events().registerRemoteNotificationsRegistrationFailed(function(event){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(event),"notification");});},[registerToken]);var initializePN=(0,_react.useCallback)((0,_asyncToGenerator2.default)(function*(){try{var isRegisteredAlready=yield _reactNativeNotifications.Notifications.isRegisteredForRemoteNotifications();var storedDeviceToken=yield(0,_asyncStore.getItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN);var deviceRegistered=yield(0,_asyncStore.getItem)(_constants.STORAGE_KEYS.DEVICE_REGISTERED);if(isRegisteredAlready&&storedDeviceToken&&deviceRegistered)return;registerForRemoteNotifications();}catch(error){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(error),"notification");}}),[registerForRemoteNotifications]);var markNotificationsAsRead=function markNotificationsAsRead(notification){var _notification$payload1,_notification$payload10,_notification$payload11,_notification$payload12;var notificationId=(notification==null?void 0:(_notification$payload1=notification.payload)==null?void 0:_notification$payload1.notification_id)||(notification==null?void 0:(_notification$payload10=notification.payload)==null?void 0:(_notification$payload11=_notification$payload10.aps)==null?void 0:(_notification$payload12=_notification$payload11.alert)==null?void 0:_notification$payload12.notification_id);handleClick(notification);if(notificationId){markReadUnreadNotification({readAt:(0,_dayjs.default)().toISOString(),notificationId:notificationId});}};_reactNativePushNotification.default.configure({onNotification:function onNotification(notification){return handleClick(notification);}});return[];};
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.usePushNotification=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=require("react");var _reactNative=require("react-native");var _dayjs=_interopRequireDefault(require("dayjs"));var _reactNativeNotifications=require("react-native-notifications");var _reactNativePermissions=require("react-native-permissions");var _reactNativePushNotification=_interopRequireDefault(require("react-native-push-notification"));var _bugsnag=require("../../config/bugsnag");var _constants=require("../../constants");var _asyncStore=require("../asyncStore");var _useNotification2=require("../../hooks/query/useNotification");var _useAppState=require("../../hooks/useAppState");var _store=require("../../store");var usePushNotification=exports.usePushNotification=function usePushNotification(isLoggedIn){var _ref=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{handleClick:function handleClick(){}},handleClick=_ref.handleClick;var appState=(0,_useAppState.useAppState)();var _useState=(0,_react.useState)(false),_useState2=(0,_slicedToArray2.default)(_useState,2),notificationPermission=_useState2[0],setNotificationPermission=_useState2[1];var _useNotification=(0,_useNotification2.useNotification)(),useRegisterTokenMutation=_useNotification.useRegisterTokenMutation,useMarkReadUnreadNotification=_useNotification.useMarkReadUnreadNotification;var _useRegisterTokenMuta=useRegisterTokenMutation(),registerToken=_useRegisterTokenMuta.mutate;var _useMarkReadUnreadNot=useMarkReadUnreadNotification(),markReadUnreadNotification=_useMarkReadUnreadNot.mutate;(0,_react.useEffect)(function(){var checkPermission=function(){var _ref2=(0,_asyncToGenerator2.default)(function*(){try{if(_reactNative.Platform.OS==="android"&&_reactNative.Platform.Version<33){setNotificationPermission(true);return;}var _yield$checkNotificat=yield(0,_reactNativePermissions.checkNotifications)(),status=_yield$checkNotificat.status;setNotificationPermission(status===_reactNativePermissions.RESULTS.GRANTED);}catch(error){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(error),"notification");}});return function checkPermission(){return _ref2.apply(this,arguments);};}();if(appState==="active"){checkPermission();}},[appState]);var registerNotificationEvents=(0,_react.useCallback)(function(){var foregroundEvent=_reactNativeNotifications.Notifications.events().registerNotificationReceivedForeground(function(notification,completion){if(_reactNative.Platform.OS==="android"){var _notification$payload,_notification$payload2,_notification$payload3,_notification$payload4,_notification$payload5;var notificationTitle=(notification==null?void 0:(_notification$payload=notification.payload)==null?void 0:_notification$payload["gcm.notification.title"])||(notification==null?void 0:(_notification$payload2=notification.payload)==null?void 0:_notification$payload2.title)||"New Notification";var notificationBody=(notification==null?void 0:(_notification$payload3=notification.payload)==null?void 0:_notification$payload3["gcm.notification.body"])||(notification==null?void 0:(_notification$payload4=notification.payload)==null?void 0:_notification$payload4.message)||"You have a new message";_reactNativeNotifications.Notifications.postLocalNotification({body:notificationBody,title:notificationTitle,url:notification==null?void 0:(_notification$payload5=notification.payload)==null?void 0:_notification$payload5.url,channelId:_reactNative.Platform.OS==="android"?"default":undefined,android_channel_id:"default"});}completion({alert:true,sound:true,badge:false});});var backgroundEvent=_reactNativeNotifications.Notifications.events().registerNotificationReceivedBackground(function(notification,completion){if(_reactNative.Platform.OS==="android"){var _notification$payload6,_notification$payload7,_notification$payload8,_notification$payload9,_notification$payload0;var notificationTitle=(notification==null?void 0:(_notification$payload6=notification.payload)==null?void 0:_notification$payload6["gcm.notification.title"])||(notification==null?void 0:(_notification$payload7=notification.payload)==null?void 0:_notification$payload7.title)||"New Notification";var notificationBody=(notification==null?void 0:(_notification$payload8=notification.payload)==null?void 0:_notification$payload8["gcm.notification.body"])||(notification==null?void 0:(_notification$payload9=notification.payload)==null?void 0:_notification$payload9.message)||"You have a new message";_reactNativeNotifications.Notifications.postLocalNotification({body:notificationBody,title:notificationTitle,url:notification==null?void 0:(_notification$payload0=notification.payload)==null?void 0:_notification$payload0.url,channelId:_reactNative.Platform.OS==="android"?"default":undefined,android_channel_id:"default"});}completion({alert:true,sound:true,badge:false});});var openedEvent=_reactNativeNotifications.Notifications.events().registerNotificationOpened(function(notification,completion){markNotificationsAsRead(notification);completion();});if(_reactNative.Platform.OS==="android"){var defaultNotificationChannel={channelId:"default",name:"Default Channel",importance:5,sound:"default",enableVibration:true,enableLights:true,showBadge:true};var channel01NotificationChannel={channelId:"channel_01",name:"Channel 01",importance:5,enableLights:true,enableVibration:true,showBadge:true};_reactNativeNotifications.Notifications.setNotificationChannel(defaultNotificationChannel);_reactNativeNotifications.Notifications.setNotificationChannel(channel01NotificationChannel);}return[foregroundEvent,backgroundEvent,openedEvent];},[]);(0,_react.useEffect)(function(){var events=registerNotificationEvents();return function(){events.forEach(function(event){return event.remove();});};},[registerNotificationEvents]);(0,_react.useEffect)(function(){if(isLoggedIn&&appState==="active"&¬ificationPermission){initializePN();}},[initializePN,isLoggedIn,appState,notificationPermission]);var registerForRemoteNotifications=(0,_react.useCallback)(function(){_reactNativeNotifications.Notifications.registerRemoteNotifications();var registerDeviceOnce=function(){var isRegistered=false;return function(){var _ref3=(0,_asyncToGenerator2.default)(function*(event){var _Store$getState,_Store$getState$auth;if(isRegistered)return;var isLoggedIn=((_Store$getState=_store.Store.getState())==null?void 0:(_Store$getState$auth=_Store$getState.auth)==null?void 0:_Store$getState$auth.isLoggedIn)||false;if(isLoggedIn&&event.deviceToken){isRegistered=true;var payload={device:{device_token:event.deviceToken,platform:_reactNative.Platform.OS}};var notificationDeviceId=yield(0,_asyncStore.getItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN);if(typeof notificationDeviceId!=="string"){registerToken(payload,{onSuccess:function(){var _onSuccess=(0,_asyncToGenerator2.default)(function*(){yield(0,_asyncStore.setItem)(_constants.STORAGE_KEYS.DEVICE_REGISTERED,true);});function onSuccess(){return _onSuccess.apply(this,arguments);}return onSuccess;}(),onError:function onError(){isRegistered=false;}});}}});return function(_x){return _ref3.apply(this,arguments);};}();}();_reactNativeNotifications.Notifications.events().registerRemoteNotificationsRegistered(function(event){registerDeviceOnce(event);});_reactNativeNotifications.Notifications.events().registerRemoteNotificationsRegistrationFailed(function(event){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(event),"notification");});},[registerToken]);var initializePN=(0,_react.useCallback)((0,_asyncToGenerator2.default)(function*(){try{var isRegisteredAlready=yield _reactNativeNotifications.Notifications.isRegisteredForRemoteNotifications();var storedDeviceToken=yield(0,_asyncStore.getItem)(_constants.STORAGE_KEYS.DEVICE_TOKEN);var deviceRegistered=yield(0,_asyncStore.getItem)(_constants.STORAGE_KEYS.DEVICE_REGISTERED);if(isRegisteredAlready&&storedDeviceToken&&deviceRegistered)return;registerForRemoteNotifications();}catch(error){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(error),"notification");}}),[registerForRemoteNotifications]);var markNotificationsAsRead=function markNotificationsAsRead(notification){var _notification$payload1,_notification$payload10,_notification$payload11,_notification$payload12;var notificationId=(notification==null?void 0:(_notification$payload1=notification.payload)==null?void 0:_notification$payload1.notification_id)||(notification==null?void 0:(_notification$payload10=notification.payload)==null?void 0:(_notification$payload11=_notification$payload10.aps)==null?void 0:(_notification$payload12=_notification$payload11.alert)==null?void 0:_notification$payload12.notification_id);handleClick(notification);if(notificationId){markReadUnreadNotification({readAt:(0,_dayjs.default)().toISOString(),notificationId:notificationId});}};_reactNativePushNotification.default.configure({onNotification:function onNotification(notification){return handleClick(notification);}});return[];};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.AuthOptions=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _react=_interopRequireDefault(require("react"));var _reactNative=require("react-native");var _neetouiRn=require("@bigbinary/neetoui-rn");var _reactNativeAppleAuthentication=_interopRequireDefault(require("@invertase/react-native-apple-authentication"));var _googleSignin=require("@react-native-google-signin/google-signin");var _propTypes=_interopRequireDefault(require("prop-types"));var _ramda=require("ramda");var _bugsnag=require("../../config/bugsnag");var _localization=require("../../contexts/localization");var _keychain=require("../../helpers/keychain");var _useAuth2=require("../../hooks/query/useAuth");var _constants=require("./constants");var _jsxRuntime=require("react/jsx-runtime");var _this=this,_jsxFileName="/home/runner/work/neeto-commons-rn/neeto-commons-rn/src/screens/authentication/AuthOptions.jsx";var AuthOptions=exports.AuthOptions=function AuthOptions(_ref){var handleSubmit=_ref.handleSubmit,_ref$buttonLoading=_ref.buttonLoading,buttonLoading=_ref$buttonLoading===void 0?false:_ref$buttonLoading;var _useLocalization=(0,_localization.useLocalization)(),strings=_useLocalization.strings;var _useAuth=(0,_useAuth2.useAuth)(),useLoginViaGoogleMutation=_useAuth.useLoginViaGoogleMutation,useLoginViaAppleMutation=_useAuth.useLoginViaAppleMutation;var _useLoginViaGoogleMut=useLoginViaGoogleMutation(),loginViaGoogle=_useLoginViaGoogleMut.mutate,isLoginViaGoogleLoading=_useLoginViaGoogleMut.isLoading;var _useLoginViaAppleMuta=useLoginViaAppleMutation(),loginViaApple=_useLoginViaAppleMuta.mutate,isLoginViaAppleLoading=_useLoginViaAppleMuta.isLoading;var _onGoogleButtonPress=function(){var _ref2=(0,_asyncToGenerator2.default)(function*(){var retryCount=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;try{var signedInUsingGoogle=_googleSignin.GoogleSignin.hasPreviousSignIn();if(signedInUsingGoogle){yield _googleSignin.GoogleSignin.signOut();}yield _googleSignin.GoogleSignin.hasPlayServices();var authResponse=yield _googleSignin.GoogleSignin.signIn();if((0,_googleSignin.isSuccessResponse)(authResponse)){var serverAuthCode=authResponse.data.serverAuthCode;if((0,_ramda.isEmpty)(serverAuthCode)){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(authResponse),"Empty serverAuthCode in GoogleLogin");}else{loginViaGoogle({serverAuthCode:serverAuthCode});}}}catch(error){if((0,_googleSignin.isErrorWithCode)(error)){if(_constants.RETRYABLE_ERROR_CODES.includes(error.code)&&retryCount<_constants.MAX_RETRY_ATTEMPTS){_neetouiRn.Alert.show({title:strings.commons.errors.googleSignIn.retryTitle,description:strings.commons.errors.googleSignIn.retryableError,buttons:[{label:strings.commons.buttons.retry,onPress:function onPress(){return _onGoogleButtonPress(retryCount+1);}},{label:strings.commons.buttons.cancel,onPress:function onPress(){}}]});}else if(retryCount>=_constants.MAX_RETRY_ATTEMPTS){_neetouiRn.Alert.show({title:strings.commons.errors.googleSignIn.failureTitle,description:strings.commons.errors.googleSignIn.maxRetries});}else{var errorMessage=strings.commons.errors.googleSignIn.default;switch(error.code){case _constants.GOOGLE_LOGIN_ERRORS.SIGN_IN_CANCELLED:return;case _constants.GOOGLE_LOGIN_ERRORS.PLAY_SERVICES_NOT_AVAILABLE:errorMessage=strings.commons.errors.googleSignIn.playServicesNotAvailable;break;case _constants.GOOGLE_LOGIN_ERRORS.SIGN_IN_REQUIRED:errorMessage=strings.commons.errors.googleSignIn.signInRequired;break;case _constants.GOOGLE_LOGIN_ERRORS.INVALID_ACCOUNT:errorMessage=strings.commons.errors.googleSignIn.invalidAccount;break;case _constants.GOOGLE_LOGIN_ERRORS.RESOLUTION_REQUIRED:errorMessage=strings.commons.errors.googleSignIn.resolutionRequired;break;case _constants.GOOGLE_LOGIN_ERRORS.API_NOT_CONNECTED:errorMessage=strings.commons.errors.googleSignIn.apiNotConnected;break;case _constants.GOOGLE_LOGIN_ERRORS.DEVELOPER_ERROR:errorMessage=strings.commons.errors.googleSignIn.developerError;break;}_neetouiRn.Alert.show({title:strings.commons.errors.googleSignIn.failureTitle,description:errorMessage});(0,_bugsnag.bugsnagErrorHandler)(error,"Google Sign-in API Error in GoogleLogin");}}else{(0,_bugsnag.bugsnagErrorHandler)(error,"Error in GoogleLogin");}}});return function onGoogleButtonPress(){return _ref2.apply(this,arguments);};}();var onAppleButtonPress=function(){var _ref3=(0,_asyncToGenerator2.default)(function*(){try{var _yield$appleAuth$perf=yield _reactNativeAppleAuthentication.default.performRequest({requestedOperation:_reactNativeAppleAuthentication.default.Operation.LOGIN,requestedScopes:[_reactNativeAppleAuthentication.default.Scope.EMAIL,_reactNativeAppleAuthentication.default.Scope.FULL_NAME]}),identityToken=_yield$appleAuth$perf.identityToken,authorizationCode=_yield$appleAuth$perf.authorizationCode;loginViaApple({identityToken:identityToken,authorizationCode:authorizationCode});}catch(error){if(!["1000","1001"].includes(error.code)){(0,_bugsnag.bugsnagErrorHandler)(error,"AppleLogin");yield(0,_keychain.removeSecureValue)("userAuth");}}});return function onAppleButtonPress(){return _ref3.apply(this,arguments);};}();var handleOnLogin=function(){var _ref4=(0,_asyncToGenerator2.default)(function*(type){yield(0,_keychain.removeSecureValue)("userAuth");switch(type){case"email":handleSubmit();break;case"google":_onGoogleButtonPress();break;case"apple":onAppleButtonPress();break;}});return function handleOnLogin(_x){return _ref4.apply(this,arguments);};}();return(0,_jsxRuntime.jsxs)(_neetouiRn.Container,{children:[(0,_jsxRuntime.jsx)(_neetouiRn.Button,{isLoading:buttonLoading,label:strings.commons.buttons.continue,onPress:function onPress(){return handleOnLogin("email");}}),(0,_jsxRuntime.jsxs)(_neetouiRn.Container,{alignItems:"center",flexDirection:"row",justifyContent:"space-between",my:32,children:[(0,_jsxRuntime.jsx)(_neetouiRn.Divider,{bg:"background.grey400",flex:1,orientation:"horizontal",thickness:1}),(0,_jsxRuntime.jsx)(_neetouiRn.Typography,{fontFamily:"sf400",mx:2,textStyle:"subtext",children:strings.commons.conditionals.OR}),(0,_jsxRuntime.jsx)(_neetouiRn.Divider,{bg:"background.grey400",flex:1,orientation:"horizontal",thickness:1})]}),(0,_jsxRuntime.jsx)(_neetouiRn.SocialButton,{isLoading:isLoginViaGoogleLoading,variant:"google",onPress:function onPress(){return handleOnLogin("google");}}),_reactNative.Platform.OS==="ios"&&_reactNativeAppleAuthentication.default.isSupported&&(0,_jsxRuntime.jsx)(_neetouiRn.SocialButton,{isLoading:isLoginViaAppleLoading,mt:24,variant:"apple",onPress:function onPress(){return handleOnLogin("apple");}})]});};AuthOptions.propTypes={handleSubmit:_propTypes.default.func.isRequired,buttonLoading:_propTypes.default.bool};
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.AuthOptions=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _react=_interopRequireDefault(require("react"));var _reactNative=require("react-native");var _neetouiRn=require("@bigbinary/neetoui-rn");var _reactNativeAppleAuthentication=_interopRequireDefault(require("@invertase/react-native-apple-authentication"));var _googleSignin=require("@react-native-google-signin/google-signin");var _propTypes=_interopRequireDefault(require("prop-types"));var _ramda=require("ramda");var _bugsnag=require("../../config/bugsnag");var _localization=require("../../contexts/localization");var _keychain=require("../../helpers/keychain");var _useAuth2=require("../../hooks/query/useAuth");var _constants=require("./constants");var _jsxRuntime=require("react/jsx-runtime");var _this=this,_jsxFileName="/home/runner/work/neeto-commons-rn/neeto-commons-rn/src/screens/authentication/AuthOptions.jsx";var AuthOptions=exports.AuthOptions=function AuthOptions(_ref){var handleSubmit=_ref.handleSubmit,_ref$buttonLoading=_ref.buttonLoading,buttonLoading=_ref$buttonLoading===void 0?false:_ref$buttonLoading;var _useLocalization=(0,_localization.useLocalization)(),strings=_useLocalization.strings;var _useAuth=(0,_useAuth2.useAuth)(),useLoginViaGoogleMutation=_useAuth.useLoginViaGoogleMutation,useLoginViaAppleMutation=_useAuth.useLoginViaAppleMutation;var _useLoginViaGoogleMut=useLoginViaGoogleMutation(),loginViaGoogle=_useLoginViaGoogleMut.mutate,isLoginViaGoogleLoading=_useLoginViaGoogleMut.isLoading;var _useLoginViaAppleMuta=useLoginViaAppleMutation(),loginViaApple=_useLoginViaAppleMuta.mutate,isLoginViaAppleLoading=_useLoginViaAppleMuta.isLoading;var _onGoogleButtonPress=function(){var _ref2=(0,_asyncToGenerator2.default)(function*(){var retryCount=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;try{var signedInUsingGoogle=_googleSignin.GoogleSignin.hasPreviousSignIn();if(signedInUsingGoogle){yield _googleSignin.GoogleSignin.signOut();}yield _googleSignin.GoogleSignin.hasPlayServices({showPlayServicesUpdateDialog:true});var authResponse=yield _googleSignin.GoogleSignin.signIn();if((0,_googleSignin.isSuccessResponse)(authResponse)){var serverAuthCode=authResponse.data.serverAuthCode;if((0,_ramda.isEmpty)(serverAuthCode)){(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify(authResponse),"Empty serverAuthCode in GoogleLogin");}else{loginViaGoogle({serverAuthCode:serverAuthCode});}}}catch(error){if((0,_googleSignin.isErrorWithCode)(error)){if(_constants.RETRYABLE_ERROR_CODES.includes(error.code)&&retryCount<_constants.MAX_RETRY_ATTEMPTS){_neetouiRn.Alert.show({title:strings.commons.errors.googleSignIn.retryTitle,description:strings.commons.errors.googleSignIn.retryableError,buttons:[{label:strings.commons.buttons.retry,onPress:function onPress(){return _onGoogleButtonPress(retryCount+1);}},{label:strings.commons.buttons.cancel,onPress:function onPress(){}}]});}else if(retryCount>=_constants.MAX_RETRY_ATTEMPTS){_neetouiRn.Alert.show({title:strings.commons.errors.googleSignIn.failureTitle,description:strings.commons.errors.googleSignIn.maxRetries});}else{var errorMessage=strings.commons.errors.googleSignIn.default;switch(error.code){case _constants.GOOGLE_LOGIN_ERRORS.SIGN_IN_CANCELLED:return;case _constants.GOOGLE_LOGIN_ERRORS.PLAY_SERVICES_NOT_AVAILABLE:errorMessage=strings.commons.errors.googleSignIn.playServicesNotAvailable;break;case _constants.GOOGLE_LOGIN_ERRORS.SIGN_IN_REQUIRED:errorMessage=strings.commons.errors.googleSignIn.signInRequired;break;case _constants.GOOGLE_LOGIN_ERRORS.INVALID_ACCOUNT:errorMessage=strings.commons.errors.googleSignIn.invalidAccount;break;case _constants.GOOGLE_LOGIN_ERRORS.RESOLUTION_REQUIRED:errorMessage=strings.commons.errors.googleSignIn.resolutionRequired;break;case _constants.GOOGLE_LOGIN_ERRORS.API_NOT_CONNECTED:errorMessage=strings.commons.errors.googleSignIn.apiNotConnected;break;case _constants.GOOGLE_LOGIN_ERRORS.DEVELOPER_ERROR:errorMessage=strings.commons.errors.googleSignIn.developerError;break;}_neetouiRn.Alert.show({title:strings.commons.errors.googleSignIn.failureTitle,description:errorMessage});(0,_bugsnag.bugsnagErrorHandler)(JSON.stringify({code:error.code,message:error.message}),"Google Sign-in API Error in GoogleLogin");}}else{(0,_bugsnag.bugsnagErrorHandler)(error,"Error in GoogleLogin");}}});return function onGoogleButtonPress(){return _ref2.apply(this,arguments);};}();var onAppleButtonPress=function(){var _ref3=(0,_asyncToGenerator2.default)(function*(){try{var _yield$appleAuth$perf=yield _reactNativeAppleAuthentication.default.performRequest({requestedOperation:_reactNativeAppleAuthentication.default.Operation.LOGIN,requestedScopes:[_reactNativeAppleAuthentication.default.Scope.EMAIL,_reactNativeAppleAuthentication.default.Scope.FULL_NAME]}),identityToken=_yield$appleAuth$perf.identityToken,authorizationCode=_yield$appleAuth$perf.authorizationCode;loginViaApple({identityToken:identityToken,authorizationCode:authorizationCode});}catch(error){if(!["1000","1001"].includes(error.code)){(0,_bugsnag.bugsnagErrorHandler)(error,"AppleLogin");yield(0,_keychain.removeSecureValue)("userAuth");}}});return function onAppleButtonPress(){return _ref3.apply(this,arguments);};}();var handleOnLogin=function(){var _ref4=(0,_asyncToGenerator2.default)(function*(type){yield(0,_keychain.removeSecureValue)("userAuth");switch(type){case"email":handleSubmit();break;case"google":_onGoogleButtonPress();break;case"apple":onAppleButtonPress();break;}});return function handleOnLogin(_x){return _ref4.apply(this,arguments);};}();return(0,_jsxRuntime.jsxs)(_neetouiRn.Container,{children:[(0,_jsxRuntime.jsx)(_neetouiRn.Button,{isLoading:buttonLoading,label:strings.commons.buttons.continue,onPress:function onPress(){return handleOnLogin("email");}}),(0,_jsxRuntime.jsxs)(_neetouiRn.Container,{alignItems:"center",flexDirection:"row",justifyContent:"space-between",my:32,children:[(0,_jsxRuntime.jsx)(_neetouiRn.Divider,{bg:"background.grey400",flex:1,orientation:"horizontal",thickness:1}),(0,_jsxRuntime.jsx)(_neetouiRn.Typography,{fontFamily:"sf400",mx:2,textStyle:"subtext",children:strings.commons.conditionals.OR}),(0,_jsxRuntime.jsx)(_neetouiRn.Divider,{bg:"background.grey400",flex:1,orientation:"horizontal",thickness:1})]}),(0,_jsxRuntime.jsx)(_neetouiRn.SocialButton,{isLoading:isLoginViaGoogleLoading,variant:"google",onPress:function onPress(){return handleOnLogin("google");}}),_reactNative.Platform.OS==="ios"&&_reactNativeAppleAuthentication.default.isSupported&&(0,_jsxRuntime.jsx)(_neetouiRn.SocialButton,{isLoading:isLoginViaAppleLoading,mt:24,variant:"apple",onPress:function onPress(){return handleOnLogin("apple");}})]});};AuthOptions.propTypes={handleSubmit:_propTypes.default.func.isRequired,buttonLoading:_propTypes.default.bool};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.Organization=void 0;var _react=_interopRequireWildcard(require("react"));var _neetouiRn=require("@bigbinary/neetoui-rn");var _propTypes=_interopRequireDefault(require("prop-types"));var _reactNativeRemixIcon=_interopRequireDefault(require("react-native-remix-icon"));var _reactNativeSizeMatters=require("react-native-size-matters");var _native=require("styled-components/native");var _jsxRuntime=require("react/jsx-runtime");var _this=this,_jsxFileName="/home/runner/work/neeto-commons-rn/neeto-commons-rn/src/screens/authentication/Organization.jsx";function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap(),n=new WeakMap();return(_interopRequireWildcard=function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var o,i,f={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return f;if(o=t?n:r){if(o.has(e))return o.get(e);o.set(e,f);}for(var _t in e)"default"!==_t&&{}.hasOwnProperty.call(e,_t)&&((i=(o=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,_t))&&(i.get||i.set)?o(f,_t,i):f[_t]=e[_t]);return f;})(e,t);}var Organization=exports.Organization=function Organization(_ref){var organization=_ref.organization,onOrganizationSelect=_ref.onOrganizationSelect,_ref$isSidePane=_ref.isSidePane,isSidePane=_ref$isSidePane===void 0?false:_ref$isSidePane;var organization_name=organization.organization_name,subdomain=organization.subdomain;var theme=(0,_react.useContext)(_native.ThemeContext);var showOrganizationDetails=function showOrganizationDetails(){return(0,_jsxRuntime.jsxs)(_neetouiRn.Container,{justifyContent:"center",children:[(0,_jsxRuntime.jsx)(_neetouiRn.Typography,{color:"font.primary",fontFamily:"sf400",fontSize:"xl",children:organization_name}),(0,_jsxRuntime.jsx)(_neetouiRn.Typography,{color:"font.grey600",fontFamily:"sf400",fontSize:"xs",children:subdomain})]});};return(0,_jsxRuntime.jsxs)(_neetouiRn.Touchable,{alignItems:"center",border:1,borderColor:"border.primary",borderRadius:8,flexDirection:"row",justifyContent:"space-between",mb:18,px:12,py:10,onPress:function onPress(){return onOrganizationSelect({organization:organization});},children:[isSidePane?(0,_jsxRuntime.jsxs)(_neetouiRn.Container,{alignItems:"center",flexDirection:"row",justifyContent:"space-between",children:[(0,_jsxRuntime.jsx)(_neetouiRn.Container,{mr:(0,_reactNativeSizeMatters.moderateScale)(4),children:(0,_jsxRuntime.jsx)(_neetouiRn.Avatar,{imageUrl:"",name:organization_name?organization_name.charAt(0):"",variant:"small"})}),showOrganizationDetails]}):showOrganizationDetails,(0,_jsxRuntime.jsx)(_reactNativeRemixIcon.default,{color:theme.colors.font.base,name:"arrow-right-s-line",size:25})]});};Organization.propTypes={organization:_propTypes.default.object,onOrganizationSelect:_propTypes.default.func};
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.Organization=void 0;var _react=_interopRequireWildcard(require("react"));var _neetouiRn=require("@bigbinary/neetoui-rn");var _propTypes=_interopRequireDefault(require("prop-types"));var _reactNativeRemixIcon=_interopRequireDefault(require("react-native-remix-icon"));var _reactNativeSizeMatters=require("react-native-size-matters");var _native=require("styled-components/native");var _jsxRuntime=require("react/jsx-runtime");var _this=this,_jsxFileName="/home/runner/work/neeto-commons-rn/neeto-commons-rn/src/screens/authentication/Organization.jsx";function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap(),n=new WeakMap();return(_interopRequireWildcard=function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var o,i,f={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return f;if(o=t?n:r){if(o.has(e))return o.get(e);o.set(e,f);}for(var _t in e)"default"!==_t&&{}.hasOwnProperty.call(e,_t)&&((i=(o=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,_t))&&(i.get||i.set)?o(f,_t,i):f[_t]=e[_t]);return f;})(e,t);}var Organization=exports.Organization=function Organization(_ref){var organization=_ref.organization,onOrganizationSelect=_ref.onOrganizationSelect,_ref$isSidePane=_ref.isSidePane,isSidePane=_ref$isSidePane===void 0?false:_ref$isSidePane;var organization_name=organization.organization_name,subdomain=organization.subdomain;var theme=(0,_react.useContext)(_native.ThemeContext);var showOrganizationDetails=function showOrganizationDetails(){return(0,_jsxRuntime.jsxs)(_neetouiRn.Container,{justifyContent:"center",children:[(0,_jsxRuntime.jsx)(_neetouiRn.Typography,{color:"font.primary",fontFamily:"sf400",fontSize:"xl",children:organization_name}),(0,_jsxRuntime.jsx)(_neetouiRn.Typography,{color:"font.grey600",fontFamily:"sf400",fontSize:"xs",children:subdomain})]});};return(0,_jsxRuntime.jsxs)(_neetouiRn.Touchable,{alignItems:"center",border:1,borderColor:"border.primary",borderRadius:8,flexDirection:"row",justifyContent:"space-between",mb:18,px:12,py:10,onPress:function onPress(){return onOrganizationSelect({organization:organization});},children:[isSidePane?(0,_jsxRuntime.jsxs)(_neetouiRn.Container,{alignItems:"center",flexDirection:"row",justifyContent:"space-between",children:[(0,_jsxRuntime.jsx)(_neetouiRn.Container,{mr:(0,_reactNativeSizeMatters.moderateScale)(4),children:(0,_jsxRuntime.jsx)(_neetouiRn.Avatar,{imageUrl:"",name:organization_name?organization_name.charAt(0):"",variant:"small"})}),showOrganizationDetails()]}):showOrganizationDetails(),(0,_jsxRuntime.jsx)(_reactNativeRemixIcon.default,{color:theme.colors.font.base,name:"arrow-right-s-line",size:25})]});};Organization.propTypes={organization:_propTypes.default.object,onOrganizationSelect:_propTypes.default.func};
|