Skip to content

Commit

Permalink
fix: give button features authenticated link support (#2458)
Browse files Browse the repository at this point in the history
* fix: give button features authenticated link support

* list all actions

* import
  • Loading branch information
redreceipt committed Apr 11, 2022
1 parent fde31fc commit 1e9025c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
36 changes: 26 additions & 10 deletions packages/apollos-ui-connected/src/features/ButtonFeature.js
@@ -1,9 +1,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Linking } from 'react-native';
import { useMutation, useQuery, gql } from '@apollo/client';
import { withTrackOnPress } from '@apollosproject/ui-analytics';
import { Button, PaddedView, styled } from '@apollosproject/ui-kit';
import RockAuthedWebBrowser from '../RockAuthedWebBrowser';

const ButtonFeature = ({ action }) => {
const ButtonWithAnalytics = styled(
Expand Down Expand Up @@ -41,23 +41,39 @@ const ButtonFeature = ({ action }) => {
}
);

const handlePress = () => {
const handlePress = (openUrl) => {
const externalActions = [
'OPEN_URL_EXTERNALLY',
'OPEN_AUTHENTICATED_URL_EXTERNALLY',
];
const rockAuthenticatedActions = [
'OPEN_AUTHENTICATED_URL',
'OPEN_AUTHENTICATED_URL_EXTERNALLY',
];
if (action.action === 'COMPLETE_NODE') {
complete();
} else {
Linking.openURL(action.relatedNode?.url);
openUrl(
action.relatedNode?.url,
{ externalBrowser: externalActions.includes(action.action) },
{ useRockToken: rockAuthenticatedActions.includes(action.action) }
);
}
};

return (
<PaddedView>
<ButtonWithAnalytics
title={action?.title || 'Go!'}
onPress={handlePress}
disabled={isDisabled}
trackEventName={action?.title || 'Button Clicked'}
trackProperties={{ itemId: action?.relatedNode?.id }}
/>
<RockAuthedWebBrowser>
{(openUrl) => (
<ButtonWithAnalytics
title={action?.title || 'Go!'}
onPress={() => handlePress(openUrl)}
disabled={isDisabled}
trackEventName={action?.title || 'Button Clicked'}
trackProperties={{ itemId: action?.relatedNode?.id }}
/>
)}
</RockAuthedWebBrowser>
</PaddedView>
);
};
Expand Down
4 changes: 2 additions & 2 deletions templates/mobile/ios/Podfile.lock
Expand Up @@ -297,7 +297,7 @@ PODS:
- React-jsinspector (0.67.2)
- React-logger (0.67.2):
- glog
- react-native-apollos-player (3.0.2):
- react-native-apollos-player (3.1.2):
- React
- react-native-config (0.11.7):
- React
Expand Down Expand Up @@ -721,7 +721,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: 52beb652bbc61201bd70cbe4f0b8edb607e8da4f
React-jsinspector: 595f76eba2176ebd8817a1fffd47b84fbdab9383
React-logger: 23de8ea0f44fa00ee77e96060273225607fd4d78
react-native-apollos-player: 5d82ad77249183f024b93147792521a8809c2de1
react-native-apollos-player: fe92d51c7795019e9c2df7b9e16a3966ce49bcf5
react-native-config: 55548054279d92e0e4566ea15a8b9b81028ec342
react-native-geolocation: c956aeb136625c23e0dce0467664af2c437888c9
react-native-geolocation-service: c0efb872258ed9240f1003a70fca9e9757e5c785
Expand Down

0 comments on commit 1e9025c

Please sign in to comment.