Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c8951b4
Add optional parameter showPopoverMenu to Welcome.show
Apr 5, 2023
612317f
Call welcome show method to check for welcome popover when opening re…
Apr 5, 2023
78d1062
Bind showPopoverMenu to this so it updates the correct state
Apr 5, 2023
910cf23
Not take closed/archived workspace chats in consideration for new users
Apr 5, 2023
904cdbe
Linting Welcome
Apr 5, 2023
a3896c5
Merge branch 'main' of github.com:Expensify/App into paulogasparsv-wo…
Apr 6, 2023
304abe3
Add missing trailing comma to ReportActionCompose
Apr 6, 2023
20bc260
Merge branch 'main' of github.com:Expensify/App into paulogasparsv-wo…
Apr 12, 2023
29f9ad7
Add missing reference to CONST
Apr 12, 2023
ae34acf
Remove extra CONST import
Apr 12, 2023
576b196
Remove remaining reference to withwithNavigation
Apr 12, 2023
5d70fed
Add imports to Welcome and withNavigation removed during merge with main
Apr 12, 2023
b4bcbf0
Clear NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER after opening Popover menu…
Apr 12, 2023
7065e94
Update showPopoverMenu comments
Apr 12, 2023
9a1379c
Merge branch 'main' of github.com:Expensify/App into paulogasparsv-wo…
Apr 13, 2023
b39d606
Merge branch 'main' of github.com:Expensify/App into paulogasparsv-wo…
Apr 13, 2023
d21d32a
Refactor Welcome logic to control the state of isFirstTimeNewExpensif…
Apr 13, 2023
70db7a6
Only call Welcome.show at first-sign in from the correct enabled comp…
Apr 13, 2023
8f85ae5
Merge branch 'main' of github.com:Expensify/App into paulogasparsv-wo…
Apr 14, 2023
4251d01
Merge branch 'main' of github.com:Expensify/App into paulogasparsv-wo…
Apr 17, 2023
32f0299
Remove unecessary showPopoverMenu check
Apr 17, 2023
5974435
Merge branch 'main' of github.com:Expensify/App into paulogasparsv-wo…
Apr 17, 2023
820fbaf
Add missing imports removed in last merge with main
Apr 17, 2023
ffb37e2
Merge branch 'main' of github.com:Expensify/App into paulogasparsv-wo…
Apr 19, 2023
2bc4c59
Remove mentions of state from stateless Welcome.js component comments
Apr 19, 2023
af0539e
Rephrase NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER callback logic comment
Apr 19, 2023
64c4b7c
Remove last mention of state from Welcome.js comments
Apr 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/libs/actions/Welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ROUTES from '../../ROUTES';
import * as Policy from './Policy';
import ONYXKEYS from '../../ONYXKEYS';
import SCREENS from '../../SCREENS';
import CONST from '../../CONST';

let resolveIsReadyPromise;
let isReadyPromise = new Promise((resolve) => {
Expand Down Expand Up @@ -36,7 +37,11 @@ Onyx.connect({
key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER,
initWithStoredValues: false,
callback: (val) => {
isFirstTimeNewExpensifyUser = val;
// If isFirstTimeNewExpensifyUser was true do not update it to false. We update it to false inside the Welcome.show logic
// More context here https://github.com/Expensify/App/pull/16962#discussion_r1167351359
if (!isFirstTimeNewExpensifyUser) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused, you mention in the comment above this block updates isFirstTimeNewExpensifyUser from true to false.

But for a new user, isFirstTimeNewExpensifyUser is first null from the top and then when backend returns true for ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER won't this be set from null to true?

Additionally from logic here if isFirstTimeNewExpensifyUser is true it will never set it to false. The condition here will give true only for !false so you can only change isFirstTimeNewExpensifyUser from false or null to true/false here.

So maybe your comment needs to be rephrased. Let me know if I'm mistaken.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my comment is very poorly written @chiragsalian so I'll explain each question and rework the comment too.

But for a new user, isFirstTimeNewExpensifyUser is first null from the top and then when backend returns true for ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER won't this be set from null to true?

Yes, the first time this logic is reached is when we first set isFirstTimeNewExpensifyUser to true.

Additionally from logic here if isFirstTimeNewExpensifyUser is true it will never set it to false. The condition here will give true only for !false so you can only change isFirstTimeNewExpensifyUser from false or null to true/false here.

Yes! It only updates the value of isFirstTimeNewExpensifyUser if it already was falsy.
Since we never update isFirstTimeNewExpensifyUser to true, we only set isFirstTimeNewExpensifyUser when it first loads through Onyx.

isFirstTimeNewExpensifyUser = val;
}
checkOnReady();
},
});
Expand Down Expand Up @@ -96,9 +101,10 @@ Onyx.connect({
*
* @param {Object} params
* @param {Object} params.routes
* @param {Function} params.showCreateMenu
* @param {Function} [params.showCreateMenu]
* @param {Function} [params.showPopoverMenu]
*/
function show({routes, showCreateMenu}) {
function show({routes, showCreateMenu = () => {}, showPopoverMenu = () => {}}) {
isReadyPromise.then(() => {
if (!isFirstTimeNewExpensifyUser) {
return;
Expand All @@ -113,9 +119,21 @@ function show({routes, showCreateMenu}) {
const isDisplayingWorkspaceRoute = isWorkspaceRoute || exitingToWorkspaceRoute;

// 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) && report.ownerEmail === email);
const workspaceChatReport = _.find(
allReports,
report => ReportUtils.isPolicyExpenseChat(report) && report.ownerEmail === email && report.statusNum !== CONST.REPORT.STATUS.CLOSED,
Comment thread
luacmartins marked this conversation as resolved.
);
if (workspaceChatReport && !isDisplayingWorkspaceRoute) {
// This key is only updated when we call ReconnectApp, setting it to false now allows the user to navigate normally instead of always redirecting to the workspace chat
Onyx.set(ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, false);
Navigation.navigate(ROUTES.getReportRoute(workspaceChatReport.reportID));

// If showPopoverMenu exists and returns true then it opened the Popover Menu successfully, and we can update isFirstTimeNewExpensifyUser
// so the Welcome logic doesn't run again
if (showPopoverMenu()) {
isFirstTimeNewExpensifyUser = false;
Comment thread
luacmartins marked this conversation as resolved.
}

return;
}

Expand All @@ -124,6 +142,9 @@ function show({routes, showCreateMenu}) {
if (!Policy.isAdminOfFreePolicy(allPolicies) && !isDisplayingWorkspaceRoute) {
showCreateMenu();
}

// Update isFirstTimeNewExpensifyUser so the Welcome logic doesn't run again
isFirstTimeNewExpensifyUser = false;
Comment thread
luacmartins marked this conversation as resolved.
});
}

Expand Down
21 changes: 21 additions & 0 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import toggleReportActionComposeView from '../../../libs/toggleReportActionCompo
import OfflineIndicator from '../../../components/OfflineIndicator';
import ExceededCommentLength from '../../../components/ExceededCommentLength';
import withNavigationFocus from '../../../components/withNavigationFocus';
import withNavigation from '../../../components/withNavigation';
import * as EmojiUtils from '../../../libs/EmojiUtils';
import ReportDropUI from './ReportDropUI';
import DragAndDrop from '../../../components/DragAndDrop';
Expand All @@ -52,6 +53,7 @@ import withKeyboardState, {keyboardStatePropTypes} from '../../../components/wit
import ArrowKeyFocusManager from '../../../components/ArrowKeyFocusManager';
import OfflineWithFeedback from '../../../components/OfflineWithFeedback';
import KeyboardShortcut from '../../../libs/KeyboardShortcut';
import * as Welcome from '../../../libs/actions/Welcome';
import Permissions from '../../../libs/Permissions';

const propTypes = {
Expand Down Expand Up @@ -179,6 +181,7 @@ class ReportActionCompose extends React.Component {
this.insertSelectedEmoji = this.insertSelectedEmoji.bind(this);
this.setExceededMaxCommentLength = this.setExceededMaxCommentLength.bind(this);
this.updateNumberOfLines = this.updateNumberOfLines.bind(this);
this.showPopoverMenu = this.showPopoverMenu.bind(this);
this.comment = props.comment;

// React Native will retain focus on an input for native devices but web/mWeb behave differently so we have some focus management
Expand Down Expand Up @@ -233,6 +236,14 @@ class ReportActionCompose extends React.Component {

this.setMaxLines();
this.updateComment(this.comment);

// Shows Popover Menu on Workspace Chat at first sign-in
if (!this.props.disabled) {
Welcome.show({
routes: lodashGet(this.props.navigation.getState(), 'routes', []),
showPopoverMenu: this.showPopoverMenu,
});
}
}

componentDidUpdate(prevProps) {
Expand Down Expand Up @@ -711,6 +722,15 @@ class ReportActionCompose extends React.Component {
this.props.onSubmit(comment);
}

/**
* Used to show Popover menu on Workspace chat at first sign-in
* @returns {Boolean}
*/
showPopoverMenu() {
this.setMenuVisibility(true);
return true;
}

render() {
const reportParticipants = _.without(lodashGet(this.props.report, 'participants', []), this.props.currentUserPersonalDetails.login);
const participantsWithoutExpensifyEmails = _.difference(reportParticipants, CONST.EXPENSIFY_EMAILS);
Expand Down Expand Up @@ -979,6 +999,7 @@ ReportActionCompose.defaultProps = defaultProps;
export default compose(
withWindowDimensions,
withDrawerState,
withNavigation,
withNavigationFocus,
withLocalize,
withNetwork(),
Expand Down