From 833cc72ba5eba533c8fafd3c11e35c81caa9ad9c Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Tue, 10 Oct 2023 17:07:56 +0300 Subject: [PATCH 01/10] Adding in activation flow for money2020 --- src/CONST.ts | 1 + src/Expensify.js | 3 ++ src/ROUTES.ts | 3 +- .../Navigation/AppNavigator/AuthScreens.js | 20 +++++++++++ src/libs/Navigation/linkingConfig.js | 3 ++ src/libs/actions/DemoActions.js | 36 +++++++++++++++++++ src/pages/DemoSetupPage.js | 8 +++-- .../FloatingActionButtonAndPopover.js | 17 +++++++++ 8 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 src/libs/actions/DemoActions.js diff --git a/src/CONST.ts b/src/CONST.ts index 23957827d140..bf034783b321 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2704,6 +2704,7 @@ const CONST = { DEMO_PAGES: { SAASTR: 'SaaStrDemoSetup', SBE: 'SbeDemoSetup', + MONEY2020: 'Money2020DemoSetup', }, MAPBOX: { diff --git a/src/Expensify.js b/src/Expensify.js index 9e6ae1ff27b4..e5582f5cd903 100644 --- a/src/Expensify.js +++ b/src/Expensify.js @@ -30,6 +30,7 @@ import KeyboardShortcutsModal from './components/KeyboardShortcutsModal'; import AppleAuthWrapper from './components/SignInButtons/AppleAuthWrapper'; import EmojiPicker from './components/EmojiPicker/EmojiPicker'; import * as EmojiPickerAction from './libs/actions/EmojiPickerAction'; +import * as DemoActions from './libs/actions/DemoActions'; import DeeplinkWrapper from './components/DeeplinkWrapper'; // This lib needs to be imported, but it has nothing to export since all it contains is an Onyx connection @@ -168,11 +169,13 @@ function Expensify(props) { // If the app is opened from a deep link, get the reportID (if exists) from the deep link and navigate to the chat report Linking.getInitialURL().then((url) => { + DemoActions.runDemoByURL(url); Report.openReportFromDeepLink(url, isAuthenticated); }); // Open chat report from a deep link (only mobile native) Linking.addEventListener('url', (state) => { + DemoActions.runDemoByURL(state.url); Report.openReportFromDeepLink(state.url, isAuthenticated); }); diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 21aaa55f099b..ef1a04dd191f 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -319,9 +319,10 @@ export default { getRoute: (policyID: string) => `workspace/${policyID}/members`, }, - // These are some on-off routes that will be removed once they're no longer needed (see GH issues for details) + // These are some one-off routes that will be removed once they're no longer needed (see GH issues for details) SAASTR: 'saastr', SBE: 'sbe', + MONEY2020: 'money2020', // Iframe screens from olddot HOME_OLDDOT: 'home', diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 428550a43aa8..8a0fecd98fda 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -117,6 +117,13 @@ const propTypes = { /** The last Onyx update ID was applied to the client */ lastUpdateIDAppliedToClient: PropTypes.number, + /** Information about any currently running demos */ + demoInfo: PropTypes.shape({ + money2020: PropTypes.shape({ + isBeginningDemo: PropTypes.bool, + }), + }), + ...windowDimensionsPropTypes, }; @@ -127,6 +134,7 @@ const defaultProps = { }, lastOpenedPublicRoomID: null, lastUpdateIDAppliedToClient: null, + demoInfo: {}, }; class AuthScreens extends React.Component { @@ -169,6 +177,10 @@ class AuthScreens extends React.Component { App.setUpPoliciesAndNavigate(this.props.session, !this.props.isSmallScreenWidth); App.redirectThirdPartyDesktopSignIn(); + // Check if we should be running any demos immediately after signing in. + if (lodashGet(this.props.demoInfo, 'money2020.isBeginningDemo', false)) { + Navigation.navigate(ROUTES.MONEY2020, CONST.NAVIGATION.TYPE.FORCED_UP); + } if (this.props.lastOpenedPublicRoomID) { // Re-open the last opened public room if the user logged in from a public room link Report.openLastOpenedPublicRoom(this.props.lastOpenedPublicRoomID); @@ -293,6 +305,11 @@ class AuthScreens extends React.Component { options={defaultScreenOptions} component={DemoSetupPage} /> + { Navigation.isNavigationReady().then(() => { - Navigation.goBack(ROUTES.HOME); + if (props.route.name === CONST.DEMO_PAGES.MONEY2020) { + DemoActions.runMoney2020Demo(); + } else { + Navigation.goBack(ROUTES.HOME); + } }); }); diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js index e9ede2c9a89a..0892302e17a5 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js @@ -62,6 +62,13 @@ const propTypes = { /** Forwarded ref to FloatingActionButtonAndPopover */ innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), + + /** Information about any currently running demos */ + demoInfo: PropTypes.shape({ + money2020: PropTypes.shape({ + isBeginningDemo: PropTypes.bool, + }), + }), }; const defaultProps = { onHideCreateMenu: () => {}, @@ -70,6 +77,7 @@ const defaultProps = { betas: [], isLoading: false, innerRef: null, + demoInfo: {}, }; /** @@ -152,6 +160,12 @@ function FloatingActionButtonAndPopover(props) { if (currentRoute && ![NAVIGATORS.CENTRAL_PANE_NAVIGATOR, SCREENS.HOME].includes(currentRoute.name)) { return; } + if (lodashGet(props.demoInfo, 'saastr.isBeginningDemo', false) || lodashGet(props.demoInfo, 'sbe.isBeginningDemo', false)) { + return; + } + if (lodashGet(props.demoInfo, 'money2020.isBeginningDemo', false)) { + return; + } Welcome.show({routes, showCreateMenu}); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); @@ -261,6 +275,9 @@ export default compose( isLoading: { key: ONYXKEYS.IS_LOADING_REPORT_DATA, }, + demoInfo: { + key: ONYXKEYS.DEMO_INFO, + }, }), )( forwardRef((props, ref) => ( From 4d7e665b75ead30475578abc3785903967fb237e Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Wed, 11 Oct 2023 17:13:35 +0300 Subject: [PATCH 02/10] Add in needed imports --- src/pages/DemoSetupPage.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/DemoSetupPage.js b/src/pages/DemoSetupPage.js index 10ea4b7afad3..75309cc9a999 100644 --- a/src/pages/DemoSetupPage.js +++ b/src/pages/DemoSetupPage.js @@ -4,6 +4,8 @@ import {useFocusEffect} from '@react-navigation/native'; import FullScreenLoadingIndicator from '../components/FullscreenLoadingIndicator'; import Navigation from '../libs/Navigation/Navigation'; import ROUTES from '../ROUTES'; +import CONST from '../CONST'; +import * as DemoActions from '../libs/actions/DemoActions'; const propTypes = { /** Navigation route context info provided by react navigation */ From 18418968787edba18e87f14ad842433c189a5e2d Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Wed, 11 Oct 2023 17:13:45 +0300 Subject: [PATCH 03/10] Fix up demo action --- src/libs/actions/DemoActions.js | 40 +++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/DemoActions.js b/src/libs/actions/DemoActions.js index 7e225ef0f290..bde3b7f58846 100644 --- a/src/libs/actions/DemoActions.js +++ b/src/libs/actions/DemoActions.js @@ -1,15 +1,51 @@ +import Config from 'react-native-config'; import Onyx from 'react-native-onyx'; import _ from 'underscore'; import lodashGet from 'lodash/get'; -import CONST from '../../CONST'; import * as API from '../API'; import * as ReportUtils from '../ReportUtils'; import Navigation from '../Navigation/Navigation'; import ROUTES from '../../ROUTES'; import ONYXKEYS from '../../ONYXKEYS'; +let currentUserAccountID; +let currentUserEmail; +Onyx.connect({ + key: ONYXKEYS.SESSION, + callback: (val) => { + currentUserAccountID = lodashGet(val, 'accountID', 0); + currentUserEmail = lodashGet(val, 'email', ''); + }, +}); + function runMoney2020Demo() { - // createDemoWorkspaceAndNavigate(CONST.EMAIL.MONEY2020, 'CreateChatReport'); + // Try to navigate to existing demo chat if it exists in Onyx + const money2020AccountID = Number(Config?.EXPENSIFY_ACCOUNT_ID_MONEY2020 ?? 15864555); + const chatReportID = ReportUtils.getChatByParticipants([money2020AccountID]); + if (chatReportID) { + // We must call goBack() to remove the demo route from nav history + Navigation.goBack(); + Navigation.navigate(ROUTES.getReportRoute(chatReportID)); + return; + } + + API.makeRequestWithSideEffects('CreateChatReport', { + emailList: `${currentUserEmail},money2020@expensify.com`, + activationConference: 'money2020', + }).then((response) => { + // If there's no response or no reportID in the response, navigate the user home so user doesn't get stuck. + if (!response || !response.reportID) { + Navigation.goBack(); + Navigation.navigate(ROUTES.HOME); + return; + } + + // Get reportID & navigate to it + // Note: We must call goBack() to remove the demo route from history + const chatReportID = response.reportID; + Navigation.goBack(); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(chatReportID)); + }); } /** From d96a8073a781728c341f348ff90d13a92b575d3a Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Wed, 11 Oct 2023 17:34:05 +0300 Subject: [PATCH 04/10] Fix existing report route logic --- src/libs/actions/DemoActions.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/DemoActions.js b/src/libs/actions/DemoActions.js index bde3b7f58846..8ef4c96f9594 100644 --- a/src/libs/actions/DemoActions.js +++ b/src/libs/actions/DemoActions.js @@ -21,11 +21,11 @@ Onyx.connect({ function runMoney2020Demo() { // Try to navigate to existing demo chat if it exists in Onyx const money2020AccountID = Number(Config?.EXPENSIFY_ACCOUNT_ID_MONEY2020 ?? 15864555); - const chatReportID = ReportUtils.getChatByParticipants([money2020AccountID]); - if (chatReportID) { + const existingChatReport = ReportUtils.getChatByParticipants([money2020AccountID]); + if (existingChatReport) { // We must call goBack() to remove the demo route from nav history Navigation.goBack(); - Navigation.navigate(ROUTES.getReportRoute(chatReportID)); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(existingChatReport.reportID)); return; } From 55119bda4495138209520e43b66b0bff27a5f3d4 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Wed, 11 Oct 2023 17:34:20 +0300 Subject: [PATCH 05/10] Fix double-triggering demo flow --- src/pages/DemoSetupPage.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/DemoSetupPage.js b/src/pages/DemoSetupPage.js index 75309cc9a999..2fd1252a5ac5 100644 --- a/src/pages/DemoSetupPage.js +++ b/src/pages/DemoSetupPage.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, {useCallback} from 'react'; import PropTypes from 'prop-types'; import {useFocusEffect} from '@react-navigation/native'; import FullScreenLoadingIndicator from '../components/FullscreenLoadingIndicator'; @@ -21,15 +21,15 @@ const propTypes = { * don't show them a "Hmm... It's not here" message (which looks broken). */ function DemoSetupPage(props) { - useFocusEffect(() => { - Navigation.isNavigationReady().then(() => { + useFocusEffect( + useCallback(() => { if (props.route.name === CONST.DEMO_PAGES.MONEY2020) { DemoActions.runMoney2020Demo(); } else { Navigation.goBack(ROUTES.HOME); } - }); - }); + }, []), + ); return ; } From aaab62502d46346af3dfcb06a41a0ab78b20fd44 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Wed, 11 Oct 2023 17:43:14 +0300 Subject: [PATCH 06/10] Address lint issues --- src/libs/actions/DemoActions.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/DemoActions.js b/src/libs/actions/DemoActions.js index 8ef4c96f9594..cfe21eb422dc 100644 --- a/src/libs/actions/DemoActions.js +++ b/src/libs/actions/DemoActions.js @@ -1,6 +1,5 @@ import Config from 'react-native-config'; import Onyx from 'react-native-onyx'; -import _ from 'underscore'; import lodashGet from 'lodash/get'; import * as API from '../API'; import * as ReportUtils from '../ReportUtils'; @@ -8,19 +7,17 @@ import Navigation from '../Navigation/Navigation'; import ROUTES from '../../ROUTES'; import ONYXKEYS from '../../ONYXKEYS'; -let currentUserAccountID; let currentUserEmail; Onyx.connect({ key: ONYXKEYS.SESSION, callback: (val) => { - currentUserAccountID = lodashGet(val, 'accountID', 0); currentUserEmail = lodashGet(val, 'email', ''); }, }); function runMoney2020Demo() { // Try to navigate to existing demo chat if it exists in Onyx - const money2020AccountID = Number(Config?.EXPENSIFY_ACCOUNT_ID_MONEY2020 ?? 15864555); + const money2020AccountID = Number(Config ? Config.EXPENSIFY_ACCOUNT_ID_MONEY2020 : 15864555); const existingChatReport = ReportUtils.getChatByParticipants([money2020AccountID]); if (existingChatReport) { // We must call goBack() to remove the demo route from nav history @@ -29,6 +26,8 @@ function runMoney2020Demo() { return; } + // We use makeRequestWithSideEffects here because we need to get the chat report ID to navigate to it after it's created + // eslint-disable-next-line rulesdir/no-api-side-effects-method API.makeRequestWithSideEffects('CreateChatReport', { emailList: `${currentUserEmail},money2020@expensify.com`, activationConference: 'money2020', From c3436309eb0dc0bbbf287787750ff34dfb1c05e7 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Wed, 11 Oct 2023 17:49:32 +0300 Subject: [PATCH 07/10] I guess this belongs here --- src/pages/DemoSetupPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/DemoSetupPage.js b/src/pages/DemoSetupPage.js index 2fd1252a5ac5..5432bea0c806 100644 --- a/src/pages/DemoSetupPage.js +++ b/src/pages/DemoSetupPage.js @@ -28,7 +28,7 @@ function DemoSetupPage(props) { } else { Navigation.goBack(ROUTES.HOME); } - }, []), + }, [props.route.name]), ); return ; From bb922d8351ce414c682ef3db8f50d5ebbf281798 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Wed, 11 Oct 2023 17:56:56 +0300 Subject: [PATCH 08/10] prettier didn't like... something --- src/libs/actions/DemoActions.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/DemoActions.js b/src/libs/actions/DemoActions.js index cfe21eb422dc..29c983c35262 100644 --- a/src/libs/actions/DemoActions.js +++ b/src/libs/actions/DemoActions.js @@ -68,4 +68,3 @@ function runDemoByURL(url = '') { } export {runMoney2020Demo, runDemoByURL}; - From 1681974ae78e2642550a171e6369c4004b8887cd Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Fri, 13 Oct 2023 15:01:47 +0300 Subject: [PATCH 09/10] Add money2020 deep link --- .well-known/apple-app-site-association | 4 ++++ android/app/src/main/AndroidManifest.xml | 2 ++ 2 files changed, 6 insertions(+) diff --git a/.well-known/apple-app-site-association b/.well-known/apple-app-site-association index d6da0232f2fc..1e63fdcb2d52 100644 --- a/.well-known/apple-app-site-association +++ b/.well-known/apple-app-site-association @@ -79,6 +79,10 @@ { "/": "/search/*", "comment": "Search" + }, + { + "/": "/money2020/*", + "comment": "Money 2020" } ] } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index d823324f50bf..7419d5b1e1a7 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -70,6 +70,7 @@ + @@ -87,6 +88,7 @@ + From 70443816c2b5dbfefe512d0fe4b4a63cbc84df84 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Fri, 13 Oct 2023 18:35:19 +0300 Subject: [PATCH 10/10] Remove old code Co-authored-by: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> --- .../sidebar/SidebarScreen/FloatingActionButtonAndPopover.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js index 5db2e610192c..c87d4f06e1f4 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js @@ -160,9 +160,6 @@ function FloatingActionButtonAndPopover(props) { if (currentRoute && ![NAVIGATORS.CENTRAL_PANE_NAVIGATOR, SCREENS.HOME].includes(currentRoute.name)) { return; } - if (lodashGet(props.demoInfo, 'saastr.isBeginningDemo', false) || lodashGet(props.demoInfo, 'sbe.isBeginningDemo', false)) { - return; - } if (lodashGet(props.demoInfo, 'money2020.isBeginningDemo', false)) { return; }