-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[No QA] Show Workspace Chat first instead of opening Global Create #7865
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e3b4839
change welcome logic in SidebarScreen
luacmartins 6e98933
update comments
luacmartins 7836583
fix styles
luacmartins 8450995
create WelcomeActions
luacmartins 1bb84f8
create WelcomeActions
luacmartins 2349e83
add docs
luacmartins 62ed85c
remove console log
luacmartins 68ff8d0
move function inside timeout
luacmartins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import _ from 'underscore'; | ||
import lodashGet from 'lodash/get'; | ||
import Navigation from '../Navigation/Navigation'; | ||
import * as ReportUtils from '../reportUtils'; | ||
import ROUTES from '../../ROUTES'; | ||
import * as Policy from './Policy'; | ||
import ONYXKEYS from '../../ONYXKEYS'; | ||
import NameValuePair from './NameValuePair'; | ||
import CONST from '../../CONST'; | ||
|
||
/* Flag for new users used to show welcome actions on first load */ | ||
let isFirstTimeNewExpensifyUser = false; | ||
Onyx.connect({ | ||
key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, | ||
callback: val => isFirstTimeNewExpensifyUser = val, | ||
}); | ||
|
||
const allReports = {}; | ||
Onyx.connect({ | ||
key: ONYXKEYS.COLLECTION.REPORT, | ||
callback: (val, key) => { | ||
if (!val || !key) { | ||
return; | ||
} | ||
|
||
allReports[key] = {...allReports[key], ...val}; | ||
}, | ||
}); | ||
|
||
const allPolicies = {}; | ||
Onyx.connect({ | ||
key: ONYXKEYS.COLLECTION.REPORT, | ||
callback: (val, key) => { | ||
if (!val || !key) { | ||
return; | ||
} | ||
|
||
allPolicies[key] = {...allPolicies[key], ...val}; | ||
}, | ||
}); | ||
|
||
/** | ||
* Shows a welcome action on first login | ||
* | ||
* @param {Object} params | ||
* @param {Object} params.routes | ||
* @param {Function} params.toggleCreateMenu | ||
*/ | ||
function show({routes, toggleCreateMenu}) { | ||
// NOTE: This setTimeout is required due to a bug in react-navigation where modals do not display properly in a drawerContent | ||
// This is a short-term workaround, see this issue for updates on a long-term solution: https://github.com/Expensify/App/issues/5296 | ||
setTimeout(() => { | ||
if (!isFirstTimeNewExpensifyUser) { | ||
return; | ||
} | ||
|
||
// Set the NVP back to false so we don't automatically run welcome actions again | ||
NameValuePair.set(CONST.NVP.IS_FIRST_TIME_NEW_EXPENSIFY_USER, false, ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER); | ||
|
||
// We want to display the Workspace chat first since that means a user is already in a Workspace and doesn't need to create another one | ||
const workspaceChatReport = _.find(allReports, report => ReportUtils.isPolicyExpenseChat(report)); | ||
if (workspaceChatReport) { | ||
Navigation.navigate(ROUTES.getReportRoute(workspaceChatReport.reportID)); | ||
return; | ||
} | ||
|
||
// If we are rendering the SidebarScreen at the same time as a workspace route that means we've already created a workspace via workspace/new and should not open the global | ||
// create menu right now. | ||
const topRouteName = lodashGet(_.last(routes), 'name', ''); | ||
const isDisplayingWorkspaceRoute = topRouteName.toLowerCase().includes('workspace'); | ||
|
||
// It's also possible that we already have a workspace policy. In either case we will not toggle the menu but do still want to set the NVP in this case | ||
// since the user does not need to create a workspace. | ||
if (!Policy.isAdminOfFreePolicy(allPolicies) && !isDisplayingWorkspaceRoute) { | ||
toggleCreateMenu(); | ||
} | ||
}, 1500); | ||
} | ||
|
||
export { | ||
// eslint-disable-next-line import/prefer-default-export | ||
show, | ||
}; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I added this to fix a RN error that I was seeing where text is a child of View
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.
I haven't seen it done like this, good thinking.