From aea2bcc2ed75d5f9028880769a80b80f4aa6ccb8 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 18 Dec 2024 10:52:22 +0700 Subject: [PATCH 1/4] fix: display invoices badge currency --- src/pages/workspace/WorkspaceInitialPage.tsx | 5 +---- .../workspace/invoices/WorkspaceInvoiceBalanceSection.tsx | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 95449e4c10ea..e95e46f29599 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -201,10 +201,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac icon: Expensicons.InvoiceGeneric, action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_INVOICES.getRoute(policyID)))), routeName: SCREENS.WORKSPACE.INVOICES, - badgeText: `${CurrencyUtils.getCurrencySymbol(currencyCode)}${CurrencyUtils.convertToFrontendAmountAsString( - policy?.invoice?.bankAccount?.stripeConnectAccountBalance ?? 0, - currencyCode, - )}`, + badgeText: CurrencyUtils.convertToDisplayString(policy?.invoice?.bankAccount?.stripeConnectAccountBalance ?? 0, currencyCode), }); } diff --git a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx index 1b71333c3087..fc4545baa030 100644 --- a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx +++ b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx @@ -28,7 +28,7 @@ function WorkspaceInvoiceBalanceSection({policyID}: WorkspaceInvoiceBalanceSecti > Date: Wed, 18 Dec 2024 15:18:57 +0700 Subject: [PATCH 2/4] fix lint --- src/pages/workspace/WorkspaceInitialPage.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index e95e46f29599..27cd2cb7e9b7 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -86,7 +86,7 @@ function dismissError(policyID: string, pendingAction: PendingAction | undefined function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: WorkspaceInitialPageProps) { const styles = useThemeStyles(); const policy = policyDraft?.id ? policyDraft : policyProp; - const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policy?.id ?? '-1'); + const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policy?.id ?? CONST.DEFAULT_NUMBER_ID.toString()); const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useState(false); const hasPolicyCreationError = !!(policy?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD && !isEmptyObject(policy.errors)); const [cardFeeds] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`); @@ -94,7 +94,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`); const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy?.id}`); const [currentUserLogin] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.email}); - const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route.params?.policyID ?? '-1'}`); + const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route.params?.policyID ?? CONST.DEFAULT_NUMBER_ID}`); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const {login, accountID} = useCurrentUserPersonalDetails(); const hasSyncError = PolicyUtils.shouldShowSyncError(policy, isConnectionInProgress(connectionSyncProgress, policy)); @@ -104,7 +104,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac const {translate} = useLocalize(); const {isOffline} = useNetwork(); const wasRendered = useRef(false); - const currentUserPolicyExpenseChatReportID = getPolicyExpenseChat(accountID, policy?.id ?? '-1')?.reportID ?? '-1'; + const currentUserPolicyExpenseChatReportID = getPolicyExpenseChat(accountID, policy?.id ?? CONST.DEFAULT_NUMBER_ID.toString())?.reportID ?? CONST.DEFAULT_NUMBER_ID; const [currentUserPolicyExpenseChat] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${currentUserPolicyExpenseChatReportID}`); const {reportPendingAction} = getReportOfflinePendingActionAndErrors(currentUserPolicyExpenseChat); const isPolicyExpenseChatEnabled = !!policy?.isPolicyExpenseChatEnabled; @@ -142,7 +142,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac }, [fetchPolicyData]), ); - const policyID = policy?.id ?? '-1'; + const policyID = policy?.id ?? CONST.DEFAULT_NUMBER_ID.toString(); const policyName = policy?.name ?? ''; useEffect(() => { @@ -382,7 +382,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac source: avatar, name: policy?.name ?? '', type: CONST.ICON_TYPE_WORKSPACE, - id: policy.id ?? '-1', + id: policy.id ?? CONST.DEFAULT_NUMBER_ID, }; }, [policy]); @@ -451,7 +451,12 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac title={getReportName(currentUserPolicyExpenseChat)} description={translate('workspace.common.workspace')} icon={getIcons(currentUserPolicyExpenseChat, personalDetails)} - onPress={() => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(currentUserPolicyExpenseChat?.reportID ?? '-1'), CONST.NAVIGATION.TYPE.UP)} + onPress={() => + Navigation.navigate( + ROUTES.REPORT_WITH_ID.getRoute(currentUserPolicyExpenseChat?.reportID ?? CONST.DEFAULT_NUMBER_ID.toString()), + CONST.NAVIGATION.TYPE.UP, + ) + } shouldShowRightIcon wrapperStyle={[styles.br2, styles.pl2, styles.pr0, styles.pv3, styles.mt1, styles.alignItemsCenter]} shouldShowSubscriptAvatar From 64ec5b4b6a732d9967f6137f7b16aea0afc66f8e Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Fri, 20 Dec 2024 17:40:14 +0700 Subject: [PATCH 3/4] fix lint --- src/libs/PolicyUtils.ts | 2 +- src/libs/ReportUtils.ts | 5 ++++- src/pages/workspace/WorkspaceInitialPage.tsx | 15 ++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 4982e8660dec..f44f5605b5d8 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -1093,7 +1093,7 @@ function getCurrentTaxID(policy: OnyxEntry, taxID: string): string | und return Object.keys(policy?.taxRates?.taxes ?? {}).find((taxIDKey) => policy?.taxRates?.taxes?.[taxIDKey].previousTaxCode === taxID || taxIDKey === taxID); } -function getWorkspaceAccountID(policyID: string) { +function getWorkspaceAccountID(policyID: string | undefined) { const policy = getPolicy(policyID); if (!policy) { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c20ec7386b0a..ae828a14aaeb 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6771,7 +6771,10 @@ function getInvoiceChatByParticipants(policyID: string, receiverID: string | num /** * Attempts to find a policy expense report in onyx that is owned by ownerAccountID in a given policy */ -function getPolicyExpenseChat(ownerAccountID: number, policyID: string): OnyxEntry { +function getPolicyExpenseChat(ownerAccountID: number, policyID: string | undefined): OnyxEntry { + if (!policyID) { + return; + } return Object.values(allReports ?? {}).find((report: OnyxEntry) => { // If the report has been deleted, then skip it if (!report) { diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 27cd2cb7e9b7..2b6ad017f6cd 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -86,7 +86,7 @@ function dismissError(policyID: string, pendingAction: PendingAction | undefined function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: WorkspaceInitialPageProps) { const styles = useThemeStyles(); const policy = policyDraft?.id ? policyDraft : policyProp; - const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policy?.id ?? CONST.DEFAULT_NUMBER_ID.toString()); + const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policy?.id); const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useState(false); const hasPolicyCreationError = !!(policy?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD && !isEmptyObject(policy.errors)); const [cardFeeds] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`); @@ -104,7 +104,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac const {translate} = useLocalize(); const {isOffline} = useNetwork(); const wasRendered = useRef(false); - const currentUserPolicyExpenseChatReportID = getPolicyExpenseChat(accountID, policy?.id ?? CONST.DEFAULT_NUMBER_ID.toString())?.reportID ?? CONST.DEFAULT_NUMBER_ID; + const currentUserPolicyExpenseChatReportID = getPolicyExpenseChat(accountID, policy?.id)?.reportID; const [currentUserPolicyExpenseChat] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${currentUserPolicyExpenseChatReportID}`); const {reportPendingAction} = getReportOfflinePendingActionAndErrors(currentUserPolicyExpenseChat); const isPolicyExpenseChatEnabled = !!policy?.isPolicyExpenseChatEnabled; @@ -142,9 +142,9 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac }, [fetchPolicyData]), ); - const policyID = policy?.id ?? CONST.DEFAULT_NUMBER_ID.toString(); - const policyName = policy?.name ?? ''; + const policyID = `${policy?.id ?? CONST.DEFAULT_NUMBER_ID}`; + const policyName = policy?.name ?? ''; useEffect(() => { if (!isCurrencyModalOpen || policy?.outputCurrency !== CONST.CURRENCY.USD) { return; @@ -382,7 +382,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac source: avatar, name: policy?.name ?? '', type: CONST.ICON_TYPE_WORKSPACE, - id: policy.id ?? CONST.DEFAULT_NUMBER_ID, + id: policy.id, }; }, [policy]); @@ -452,10 +452,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac description={translate('workspace.common.workspace')} icon={getIcons(currentUserPolicyExpenseChat, personalDetails)} onPress={() => - Navigation.navigate( - ROUTES.REPORT_WITH_ID.getRoute(currentUserPolicyExpenseChat?.reportID ?? CONST.DEFAULT_NUMBER_ID.toString()), - CONST.NAVIGATION.TYPE.UP, - ) + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(`${currentUserPolicyExpenseChat?.reportID ?? CONST.DEFAULT_NUMBER_ID}`), CONST.NAVIGATION.TYPE.UP) } shouldShowRightIcon wrapperStyle={[styles.br2, styles.pl2, styles.pr0, styles.pv3, styles.mt1, styles.alignItemsCenter]} From ce45bf71ba1abf0c3a52318429c6340caf0e581b Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Fri, 20 Dec 2024 17:51:21 +0700 Subject: [PATCH 4/4] fix lint --- src/pages/workspace/WorkspaceInitialPage.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 2b6ad017f6cd..54ea4e8e8e5a 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -94,7 +94,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`); const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy?.id}`); const [currentUserLogin] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.email}); - const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route.params?.policyID ?? CONST.DEFAULT_NUMBER_ID}`); + const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route.params?.policyID}`); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const {login, accountID} = useCurrentUserPersonalDetails(); const hasSyncError = PolicyUtils.shouldShowSyncError(policy, isConnectionInProgress(connectionSyncProgress, policy)); @@ -143,7 +143,6 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac ); const policyID = `${policy?.id ?? CONST.DEFAULT_NUMBER_ID}`; - const policyName = policy?.name ?? ''; useEffect(() => { if (!isCurrencyModalOpen || policy?.outputCurrency !== CONST.CURRENCY.USD) {