-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Create SaaStr Demo flow #24535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create SaaStr Demo flow #24535
Changes from all commits
70b6f38
69da9ad
e805fdc
49fb4c1
0507a0f
766f5eb
a3f7564
24843e6
247a58a
cdb31cb
0b32e91
24f4e36
2556d2f
e812d10
2d3d3a3
4cf5705
9be4aee
d6f0c1c
5451be6
ea4c983
1b56731
5a8c607
453ff52
1f97101
db90ed0
75651e3
bc97f1a
f4d1ff4
a2bda8c
511f438
3eb1707
e8f719c
ac14e22
7a71444
a32515a
a694759
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean to check if the key starts with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're receiving an onyx update here which has the |
||
| if (!reportUpdate) { | ||
| return; | ||
| } | ||
|
Comment on lines
+31
to
+33
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we call goBack here? Otherwise we may get stuck at the loader indicator
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The thing is that most of the Saastr attendees will land on this page after signup, so I'm not sure goBack would help. But we have a follow-up issue to add proper error handling with a new page related to Saastr. |
||
|
|
||
| // Get the policy expense chat update | ||
| const policyExpenseChatReport = _.find(reportUpdate.value, ({chatType}) => chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a report we only have one object in If that's the case we can merge this with the above _.find(response.onyxData, ({key, value}) => key.startsWith(ONYXKEYS.COLLECTION.REPORT) && value?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT);
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, here we are handling an onyx update of method |
||
| 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}; | ||
|
cristipaval marked this conversation as resolved.
|
| 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB. This belongs to SCREENS.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, I think we could do a follow-up to clean this up. But let's keep moving for now.