-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24535 from Expensify/beaman-createSaastrDemoFeatures
Create SaaStr Demo flow
- Loading branch information
Showing
15 changed files
with
228 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
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'; | ||
import * as Localize from '../Localize'; | ||
|
||
/** | ||
* @param {String} workspaceOwnerEmail email of the workspace owner | ||
* @param {String} apiCommand | ||
*/ | ||
function createDemoWorkspaceAndNavigate(workspaceOwnerEmail, apiCommand) { | ||
// Try to navigate to existing demo workspace expense chat if it exists in Onyx | ||
const demoWorkspaceChatReportID = ReportUtils.getPolicyExpenseChatReportIDByOwner(workspaceOwnerEmail); | ||
if (demoWorkspaceChatReportID) { | ||
// We must call goBack() to remove the demo route from nav history | ||
Navigation.goBack(); | ||
Navigation.navigate(ROUTES.getReportRoute(demoWorkspaceChatReportID)); | ||
return; | ||
} | ||
|
||
// We use makeRequestWithSideEffects here because we need to get the workspace chat report ID to navigate to it after it's created | ||
// eslint-disable-next-line rulesdir/no-api-side-effects-method | ||
API.makeRequestWithSideEffects(apiCommand).then((response) => { | ||
// Get report updates from Onyx response data | ||
const reportUpdate = _.find(response.onyxData, ({key}) => key === ONYXKEYS.COLLECTION.REPORT); | ||
if (!reportUpdate) { | ||
return; | ||
} | ||
|
||
// Get the policy expense chat update | ||
const policyExpenseChatReport = _.find(reportUpdate.value, ({chatType}) => chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); | ||
if (!policyExpenseChatReport) { | ||
return; | ||
} | ||
|
||
// Navigate to the new policy expense chat report | ||
// Note: We must call goBack() to remove the demo route from history | ||
Navigation.goBack(); | ||
Navigation.navigate(ROUTES.getReportRoute(policyExpenseChatReport.reportID)); | ||
}); | ||
} | ||
|
||
function runSbeDemo() { | ||
createDemoWorkspaceAndNavigate(CONST.EMAIL.SBE, 'CreateSbeDemoWorkspace'); | ||
} | ||
|
||
function runSaastrDemo() { | ||
createDemoWorkspaceAndNavigate(CONST.EMAIL.SAASTR, 'CreateSaastrDemoWorkspace'); | ||
} | ||
|
||
/** | ||
* Runs code for specific demos, based on the provided URL | ||
* | ||
* @param {String} url - URL user is navigating to via deep link (or regular link in web) | ||
*/ | ||
function runDemoByURL(url = '') { | ||
const cleanUrl = (url || '').toLowerCase(); | ||
|
||
if (cleanUrl.endsWith(ROUTES.SAASTR)) { | ||
Onyx.set(ONYXKEYS.DEMO_INFO, { | ||
saastr: { | ||
isBeginningDemo: true, | ||
}, | ||
}); | ||
} else if (cleanUrl.endsWith(ROUTES.SBE)) { | ||
Onyx.set(ONYXKEYS.DEMO_INFO, { | ||
sbe: { | ||
isBeginningDemo: true, | ||
}, | ||
}); | ||
} else { | ||
// No demo is being run, so clear out demo info | ||
Onyx.set(ONYXKEYS.DEMO_INFO, null); | ||
} | ||
} | ||
|
||
function getHeadlineKeyByDemoInfo(demoInfo = {}) { | ||
if (lodashGet(demoInfo, 'saastr.isBeginningDemo')) { | ||
return Localize.translateLocal('demos.saastr.signInWelcome'); | ||
} | ||
if (lodashGet(demoInfo, 'sbe.isBeginningDemo')) { | ||
return Localize.translateLocal('demos.sbe.signInWelcome'); | ||
} | ||
return ''; | ||
} | ||
|
||
export {runSaastrDemo, runSbeDemo, runDemoByURL, getHeadlineKeyByDemoInfo}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {useFocusEffect} from '@react-navigation/native'; | ||
import FullScreenLoadingIndicator from '../components/FullscreenLoadingIndicator'; | ||
import CONST from '../CONST'; | ||
import * as DemoActions from '../libs/actions/DemoActions'; | ||
import Navigation from '../libs/Navigation/Navigation'; | ||
|
||
const propTypes = { | ||
/** Navigation route context info provided by react navigation */ | ||
route: PropTypes.shape({ | ||
/** The exact route name used to get to this screen */ | ||
name: PropTypes.string.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
/* | ||
* This is a "utility page", that does this: | ||
* - Looks at the current route | ||
* - Determines if there's a demo command we need to call | ||
* - If not, routes back to home | ||
*/ | ||
function DemoSetupPage(props) { | ||
useFocusEffect(() => { | ||
// Depending on the route that the user hit to get here, run a specific demo flow | ||
if (props.route.name === CONST.DEMO_PAGES.SAASTR) { | ||
DemoActions.runSaastrDemo(); | ||
} else if (props.route.name === CONST.DEMO_PAGES.SBE) { | ||
DemoActions.runSbeDemo(); | ||
} else { | ||
Navigation.goBack(); | ||
} | ||
}); | ||
|
||
return <FullScreenLoadingIndicator />; | ||
} | ||
|
||
DemoSetupPage.propTypes = propTypes; | ||
DemoSetupPage.displayName = 'DemoSetupPage'; | ||
|
||
export default DemoSetupPage; |
Oops, something went wrong.