From a691d7eb3b7f121964201387bccce67f3ce594d4 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Thu, 28 Sep 2023 11:51:21 +0200 Subject: [PATCH 1/9] Migrated Welcome.js to TypeScript. Signed-off-by: Kacper Falat --- src/libs/ReportUtils.js | 2 +- src/libs/actions/Policy.js | 2 +- src/libs/actions/{Welcome.js => Welcome.ts} | 64 ++++++++++++--------- 3 files changed, 39 insertions(+), 29 deletions(-) rename src/libs/actions/{Welcome.js => Welcome.ts} (73%) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index eb512b7927a9..b279c8cfc6f7 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -363,7 +363,7 @@ function isUserCreatedPolicyRoom(report) { /** * Whether the provided report is a Policy Expense chat. * @param {Object} report - * @param {String} report.chatType + * @param {String} [report.chatType] * @returns {Boolean} */ function isPolicyExpenseChat(report) { diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 89324dd35485..4696ab2f0649 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -162,7 +162,7 @@ function deleteWorkspace(policyID, reports, policyName) { /** * Is the user an admin of a free policy (aka workspace)? * - * @param {Array} policies + * @param {Record} policies * @returns {Boolean} */ function isAdminOfFreePolicy(policies) { diff --git a/src/libs/actions/Welcome.js b/src/libs/actions/Welcome.ts similarity index 73% rename from src/libs/actions/Welcome.js rename to src/libs/actions/Welcome.ts index 8e1832edb9a7..0c6f69451d1e 100644 --- a/src/libs/actions/Welcome.js +++ b/src/libs/actions/Welcome.ts @@ -1,6 +1,4 @@ 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'; @@ -8,15 +6,28 @@ import * as Policy from './Policy'; import ONYXKEYS from '../../ONYXKEYS'; import SCREENS from '../../SCREENS'; import CONST from '../../CONST'; +import Report from '../../types/onyx/Report'; +import OnyxPolicy from "../../types/onyx/Policy"; -let resolveIsReadyPromise; +let resolveIsReadyPromise: (value?: (PromiseLike)) => void; let isReadyPromise = new Promise((resolve) => { resolveIsReadyPromise = resolve; }); -let isFirstTimeNewExpensifyUser; +let isFirstTimeNewExpensifyUser: boolean | undefined; let isLoadingReportData = true; -let currentUserAccountID; +let currentUserAccountID: number | undefined; + +type Route = { + name: string; + params?: {path: string, exitTo?: string, openOnAdminRoom?: boolean}; +}; + +type ShowParams = { + routes: Route[]; + showCreateMenu?: () => void; + showPopoverMenu?: () => boolean; +}; /** * Check that a few requests have completed so that the welcome action can proceed: @@ -26,11 +37,13 @@ let currentUserAccountID; * - Whether we have loaded all reports the server knows about */ function checkOnReady() { - if (!_.isBoolean(isFirstTimeNewExpensifyUser) || isLoadingReportData) { + if (typeof isFirstTimeNewExpensifyUser !== "boolean" || isLoadingReportData) { return; } - resolveIsReadyPromise(); + if(resolveIsReadyPromise) { + resolveIsReadyPromise(); + } } Onyx.connect({ @@ -39,7 +52,7 @@ Onyx.connect({ callback: (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) { + if (val !== null) { isFirstTimeNewExpensifyUser = val; } checkOnReady(); @@ -50,12 +63,15 @@ Onyx.connect({ key: ONYXKEYS.IS_LOADING_REPORT_DATA, initWithStoredValues: false, callback: (val) => { - isLoadingReportData = val; + if(val) + { + isLoadingReportData = val; + } checkOnReady(); }, }); -const allReports = {}; +const allReports: Record = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, initWithStoredValues: false, @@ -68,7 +84,7 @@ Onyx.connect({ }, }); -const allPolicies = {}; +const allPolicies: Record = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.POLICY, callback: (val, key) => { @@ -98,13 +114,8 @@ Onyx.connect({ /** * Shows a welcome action on first login - * - * @param {Object} params - * @param {Object} params.routes - * @param {Function} [params.showCreateMenu] - * @param {Function} [params.showPopoverMenu] */ -function show({routes, showCreateMenu = () => {}, showPopoverMenu = () => {}}) { +function show({routes, showCreateMenu = () => {}, showPopoverMenu = () => false}: ShowParams) { isReadyPromise.then(() => { if (!isFirstTimeNewExpensifyUser) { return; @@ -112,20 +123,19 @@ function show({routes, showCreateMenu = () => {}, showPopoverMenu = () => {}}) { // 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. We should also stay on the workspace page if that is our destination. - const topRoute = _.last(routes); - const isWorkspaceRoute = topRoute.name === 'Settings' && topRoute.params.path.includes('workspace'); - const transitionRoute = _.find(routes, (route) => route.name === SCREENS.TRANSITION_BETWEEN_APPS); - const exitingToWorkspaceRoute = lodashGet(transitionRoute, 'params.exitTo', '') === 'workspace/new'; - const openOnAdminRoom = lodashGet(topRoute, 'params.openOnAdminRoom', false); - const isDisplayingWorkspaceRoute = isWorkspaceRoute || exitingToWorkspaceRoute; + const topRoute = routes[routes.length - 1] + const isWorkspaceRoute = topRoute.name === 'Settings' && topRoute.params?.path.includes('workspace'); + const transitionRoute = routes.find((route) => route.name === SCREENS.TRANSITION_BETWEEN_APPS); + const exitingToWorkspaceRoute = transitionRoute?.params?.exitTo === 'workspace/new'; + const openOnAdminRoom = topRoute.params?.openOnAdminRoom ?? false; + const isDisplayingWorkspaceRoute = isWorkspaceRoute ?? exitingToWorkspaceRoute; // If we already opened the workspace settings or want the admin room to stay open, do not // navigate away to the workspace chat report const shouldNavigateToWorkspaceChat = !isDisplayingWorkspaceRoute && !openOnAdminRoom; - const workspaceChatReport = _.find( - allReports, - (report) => ReportUtils.isPolicyExpenseChat(report) && report.ownerAccountID === currentUserAccountID && report.statusNum !== CONST.REPORT.STATUS.CLOSED, + const workspaceChatReport = Object(allReports).values().find((report: Report) => + ReportUtils.isPolicyExpenseChat(report) && report.ownerAccountID === currentUserAccountID && report.statusNum !== CONST.REPORT.STATUS.CLOSED ); if (workspaceChatReport || openOnAdminRoom) { @@ -138,7 +148,7 @@ function show({routes, showCreateMenu = () => {}, showPopoverMenu = () => {}}) { // 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()) { + if (showPopoverMenu && showPopoverMenu()) { isFirstTimeNewExpensifyUser = false; } From 51272573c6b7619615dc61b6d0598e2d4c4fdf5d Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Fri, 29 Sep 2023 09:27:02 +0200 Subject: [PATCH 2/9] Requested changes implemented. Signed-off-by: Kacper Falat --- src/libs/actions/Welcome.ts | 39 ++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/libs/actions/Welcome.ts b/src/libs/actions/Welcome.ts index 0c6f69451d1e..7a8d64b0e37e 100644 --- a/src/libs/actions/Welcome.ts +++ b/src/libs/actions/Welcome.ts @@ -1,4 +1,4 @@ -import Onyx from 'react-native-onyx'; +import Onyx, {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import Navigation from '../Navigation/Navigation'; import * as ReportUtils from '../ReportUtils'; import ROUTES from '../../ROUTES'; @@ -9,7 +9,7 @@ import CONST from '../../CONST'; import Report from '../../types/onyx/Report'; import OnyxPolicy from "../../types/onyx/Policy"; -let resolveIsReadyPromise: (value?: (PromiseLike)) => void; +let resolveIsReadyPromise: (value?: (PromiseLike)) => void | undefined; let isReadyPromise = new Promise((resolve) => { resolveIsReadyPromise = resolve; }); @@ -37,23 +37,21 @@ type ShowParams = { * - Whether we have loaded all reports the server knows about */ function checkOnReady() { - if (typeof isFirstTimeNewExpensifyUser !== "boolean" || isLoadingReportData) { + if (isFirstTimeNewExpensifyUser === undefined || isLoadingReportData) { return; } - if(resolveIsReadyPromise) { - resolveIsReadyPromise(); - } + resolveIsReadyPromise?.(); } Onyx.connect({ key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, initWithStoredValues: false, - callback: (val) => { + callback: (val: OnyxEntry) => { // 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 (val !== null) { - isFirstTimeNewExpensifyUser = val; + if (!isFirstTimeNewExpensifyUser) { + isFirstTimeNewExpensifyUser = val ?? undefined; } checkOnReady(); }, @@ -71,7 +69,7 @@ Onyx.connect({ }, }); -const allReports: Record = {}; +const allReports: OnyxCollection = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, initWithStoredValues: false, @@ -84,7 +82,7 @@ Onyx.connect({ }, }); -const allPolicies: Record = {}; +const allPolicies: OnyxCollection = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.POLICY, callback: (val, key) => { @@ -134,21 +132,26 @@ function show({routes, showCreateMenu = () => {}, showPopoverMenu = () => false} // navigate away to the workspace chat report const shouldNavigateToWorkspaceChat = !isDisplayingWorkspaceRoute && !openOnAdminRoom; - const workspaceChatReport = Object(allReports).values().find((report: Report) => - ReportUtils.isPolicyExpenseChat(report) && report.ownerAccountID === currentUserAccountID && report.statusNum !== CONST.REPORT.STATUS.CLOSED - ); + const workspaceChatReport = Object.values(allReports ?? {}).find((report) => { + if (report) { + return ReportUtils.isPolicyExpenseChat(report) && report.ownerAccountID === currentUserAccountID && report.statusNum !== CONST.REPORT.STATUS.CLOSED + } + return false; + }); - if (workspaceChatReport || openOnAdminRoom) { + if (workspaceChatReport ?? openOnAdminRoom) { // 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); } if (shouldNavigateToWorkspaceChat && workspaceChatReport) { - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(workspaceChatReport.reportID)); + if (workspaceChatReport.reportID != null) { + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(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 && showPopoverMenu()) { + if (showPopoverMenu?.()) { isFirstTimeNewExpensifyUser = false; } @@ -157,7 +160,7 @@ function show({routes, showCreateMenu = () => {}, showPopoverMenu = () => false} // If user is not already an admin of a free policy and we are not navigating them to their workspace or creating a new workspace via workspace/new then // we will show the create menu. - if (!Policy.isAdminOfFreePolicy(allPolicies) && !isDisplayingWorkspaceRoute) { + if (allPolicies && !Policy.isAdminOfFreePolicy(allPolicies) && !isDisplayingWorkspaceRoute) { showCreateMenu(); } From 220991b5d2f67cb96dcc96cff435b0cbe35a065a Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Fri, 29 Sep 2023 09:27:53 +0200 Subject: [PATCH 3/9] Requested changes implemented + prettier. Signed-off-by: Kacper Falat --- src/libs/actions/Welcome.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/Welcome.ts b/src/libs/actions/Welcome.ts index 7a8d64b0e37e..2c211ef6c117 100644 --- a/src/libs/actions/Welcome.ts +++ b/src/libs/actions/Welcome.ts @@ -7,9 +7,9 @@ import ONYXKEYS from '../../ONYXKEYS'; import SCREENS from '../../SCREENS'; import CONST from '../../CONST'; import Report from '../../types/onyx/Report'; -import OnyxPolicy from "../../types/onyx/Policy"; +import OnyxPolicy from '../../types/onyx/Policy'; -let resolveIsReadyPromise: (value?: (PromiseLike)) => void | undefined; +let resolveIsReadyPromise: (value?: PromiseLike) => void | undefined; let isReadyPromise = new Promise((resolve) => { resolveIsReadyPromise = resolve; }); @@ -20,7 +20,7 @@ let currentUserAccountID: number | undefined; type Route = { name: string; - params?: {path: string, exitTo?: string, openOnAdminRoom?: boolean}; + params?: {path: string; exitTo?: string; openOnAdminRoom?: boolean}; }; type ShowParams = { @@ -61,8 +61,7 @@ Onyx.connect({ key: ONYXKEYS.IS_LOADING_REPORT_DATA, initWithStoredValues: false, callback: (val) => { - if(val) - { + if (val) { isLoadingReportData = val; } checkOnReady(); @@ -121,7 +120,7 @@ function show({routes, showCreateMenu = () => {}, showPopoverMenu = () => false} // 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. We should also stay on the workspace page if that is our destination. - const topRoute = routes[routes.length - 1] + const topRoute = routes[routes.length - 1]; const isWorkspaceRoute = topRoute.name === 'Settings' && topRoute.params?.path.includes('workspace'); const transitionRoute = routes.find((route) => route.name === SCREENS.TRANSITION_BETWEEN_APPS); const exitingToWorkspaceRoute = transitionRoute?.params?.exitTo === 'workspace/new'; @@ -134,7 +133,7 @@ function show({routes, showCreateMenu = () => {}, showPopoverMenu = () => false} const workspaceChatReport = Object.values(allReports ?? {}).find((report) => { if (report) { - return ReportUtils.isPolicyExpenseChat(report) && report.ownerAccountID === currentUserAccountID && report.statusNum !== CONST.REPORT.STATUS.CLOSED + return ReportUtils.isPolicyExpenseChat(report) && report.ownerAccountID === currentUserAccountID && report.statusNum !== CONST.REPORT.STATUS.CLOSED; } return false; }); From c5a2f2b6e56e8c8a89e4874e1b67b480135f7483 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Fri, 29 Sep 2023 10:50:20 +0200 Subject: [PATCH 4/9] Solved comments. Signed-off-by: Kacper Falat --- src/libs/actions/Welcome.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Welcome.ts b/src/libs/actions/Welcome.ts index 2c211ef6c117..2fc5a0553c5e 100644 --- a/src/libs/actions/Welcome.ts +++ b/src/libs/actions/Welcome.ts @@ -1,4 +1,4 @@ -import Onyx, {OnyxCollection, OnyxEntry} from 'react-native-onyx'; +import Onyx, {OnyxCollection} from 'react-native-onyx'; import Navigation from '../Navigation/Navigation'; import * as ReportUtils from '../ReportUtils'; import ROUTES from '../../ROUTES'; @@ -9,8 +9,8 @@ import CONST from '../../CONST'; import Report from '../../types/onyx/Report'; import OnyxPolicy from '../../types/onyx/Policy'; -let resolveIsReadyPromise: (value?: PromiseLike) => void | undefined; -let isReadyPromise = new Promise((resolve) => { +let resolveIsReadyPromise: (value?: Promise) => void | undefined; +let isReadyPromise = new Promise((resolve) => { resolveIsReadyPromise = resolve; }); @@ -47,7 +47,7 @@ function checkOnReady() { Onyx.connect({ key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, initWithStoredValues: false, - callback: (val: OnyxEntry) => { + callback: (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) { @@ -176,7 +176,7 @@ function resetReadyCheck() { isLoadingReportData = true; } -function serverDataIsReadyPromise() { +function serverDataIsReadyPromise(): Promise { return isReadyPromise; } From 2258f1f5af167705841070e72b11401ebf3ff2bf Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Fri, 29 Sep 2023 11:40:13 +0200 Subject: [PATCH 5/9] Renamed val -> value. Signed-off-by: Kacper Falat --- src/libs/actions/Welcome.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Welcome.ts b/src/libs/actions/Welcome.ts index 2fc5a0553c5e..e4ab9caa39bc 100644 --- a/src/libs/actions/Welcome.ts +++ b/src/libs/actions/Welcome.ts @@ -47,11 +47,11 @@ function checkOnReady() { Onyx.connect({ key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, initWithStoredValues: false, - callback: (val) => { + callback: (value) => { // 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) { - isFirstTimeNewExpensifyUser = val ?? undefined; + isFirstTimeNewExpensifyUser = value ?? undefined; } checkOnReady(); }, @@ -60,9 +60,9 @@ Onyx.connect({ Onyx.connect({ key: ONYXKEYS.IS_LOADING_REPORT_DATA, initWithStoredValues: false, - callback: (val) => { - if (val) { - isLoadingReportData = val; + callback: (value) => { + if (value) { + isLoadingReportData = value; } checkOnReady(); }, From bdd184110b6ae91f1937c8e24c7d8111f56d8d40 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Tue, 3 Oct 2023 09:56:34 +0200 Subject: [PATCH 6/9] Resolved comment. Signed-off-by: Kacper Falat --- src/libs/actions/Welcome.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Welcome.ts b/src/libs/actions/Welcome.ts index e4ab9caa39bc..b0dc1738c193 100644 --- a/src/libs/actions/Welcome.ts +++ b/src/libs/actions/Welcome.ts @@ -144,7 +144,7 @@ function show({routes, showCreateMenu = () => {}, showPopoverMenu = () => false} } if (shouldNavigateToWorkspaceChat && workspaceChatReport) { - if (workspaceChatReport.reportID != null) { + if (workspaceChatReport.reportID !== null) { Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(workspaceChatReport.reportID)); } From f97333182f7c011d21ef7044ad1aa8d81c173e1a Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Thu, 5 Oct 2023 10:05:11 +0200 Subject: [PATCH 7/9] Graceful handling of last array element. Signed-off-by: Kacper Falat --- src/libs/actions/Welcome.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Welcome.ts b/src/libs/actions/Welcome.ts index b0dc1738c193..cbfac7c917da 100644 --- a/src/libs/actions/Welcome.ts +++ b/src/libs/actions/Welcome.ts @@ -120,11 +120,11 @@ function show({routes, showCreateMenu = () => {}, showPopoverMenu = () => false} // 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. We should also stay on the workspace page if that is our destination. - const topRoute = routes[routes.length - 1]; - const isWorkspaceRoute = topRoute.name === 'Settings' && topRoute.params?.path.includes('workspace'); + const topRoute = routes.length > 0 ? routes[routes.length - 1] : undefined; + const isWorkspaceRoute = topRoute !== undefined && topRoute.name === 'Settings' && topRoute.params?.path.includes('workspace'); const transitionRoute = routes.find((route) => route.name === SCREENS.TRANSITION_BETWEEN_APPS); const exitingToWorkspaceRoute = transitionRoute?.params?.exitTo === 'workspace/new'; - const openOnAdminRoom = topRoute.params?.openOnAdminRoom ?? false; + const openOnAdminRoom = topRoute === undefined ? undefined : topRoute.params?.openOnAdminRoom ?? false; const isDisplayingWorkspaceRoute = isWorkspaceRoute ?? exitingToWorkspaceRoute; // If we already opened the workspace settings or want the admin room to stay open, do not From 69b495a9daf2f3bcc4aba586de2c96db1f6954ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Fa=C5=82at?= Date: Mon, 9 Oct 2023 09:11:37 +0200 Subject: [PATCH 8/9] Requested change on Welcome.ts Co-authored-by: Hayata Suenaga Signed-off-by: Kacper Falat --- src/libs/actions/Welcome.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Welcome.ts b/src/libs/actions/Welcome.ts index cbfac7c917da..5494f5437a76 100644 --- a/src/libs/actions/Welcome.ts +++ b/src/libs/actions/Welcome.ts @@ -124,7 +124,7 @@ function show({routes, showCreateMenu = () => {}, showPopoverMenu = () => false} const isWorkspaceRoute = topRoute !== undefined && topRoute.name === 'Settings' && topRoute.params?.path.includes('workspace'); const transitionRoute = routes.find((route) => route.name === SCREENS.TRANSITION_BETWEEN_APPS); const exitingToWorkspaceRoute = transitionRoute?.params?.exitTo === 'workspace/new'; - const openOnAdminRoom = topRoute === undefined ? undefined : topRoute.params?.openOnAdminRoom ?? false; + const openOnAdminRoom = topRoute?.params?.openOnAdminRoom ?? false; const isDisplayingWorkspaceRoute = isWorkspaceRoute ?? exitingToWorkspaceRoute; // If we already opened the workspace settings or want the admin room to stay open, do not From e651ba360ce9c32793cbf11bb83a6276aad08abf Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Thu, 19 Oct 2023 10:47:38 +0200 Subject: [PATCH 9/9] Rebased and resigned old commit tree. --- src/libs/actions/Policy.js | 2 +- src/libs/actions/Welcome.ts | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 4696ab2f0649..02dd45ce7969 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -162,7 +162,7 @@ function deleteWorkspace(policyID, reports, policyName) { /** * Is the user an admin of a free policy (aka workspace)? * - * @param {Record} policies + * @param {Record} [policies] * @returns {Boolean} */ function isAdminOfFreePolicy(policies) { diff --git a/src/libs/actions/Welcome.ts b/src/libs/actions/Welcome.ts index 5494f5437a76..29e0088ed689 100644 --- a/src/libs/actions/Welcome.ts +++ b/src/libs/actions/Welcome.ts @@ -50,9 +50,9 @@ Onyx.connect({ callback: (value) => { // 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) { - isFirstTimeNewExpensifyUser = value ?? undefined; - } + + isFirstTimeNewExpensifyUser = value ?? undefined; + checkOnReady(); }, }); @@ -61,9 +61,7 @@ Onyx.connect({ key: ONYXKEYS.IS_LOADING_REPORT_DATA, initWithStoredValues: false, callback: (value) => { - if (value) { - isLoadingReportData = value; - } + isLoadingReportData = value ?? false; checkOnReady(); }, }); @@ -159,7 +157,7 @@ function show({routes, showCreateMenu = () => {}, showPopoverMenu = () => false} // If user is not already an admin of a free policy and we are not navigating them to their workspace or creating a new workspace via workspace/new then // we will show the create menu. - if (allPolicies && !Policy.isAdminOfFreePolicy(allPolicies) && !isDisplayingWorkspaceRoute) { + if (!Policy.isAdminOfFreePolicy(allPolicies ?? undefined) && !isDisplayingWorkspaceRoute) { showCreateMenu(); }