From 0a33b1edd921503a92f2fb35b3c8cab887c22f58 Mon Sep 17 00:00:00 2001 From: Abdelrahman Khattab Date: Thu, 7 Nov 2024 23:24:44 +0100 Subject: [PATCH] Fix/ Add bank account button in invoice report remains after bank account is added --- .../report/AddBankAccountActionButton.tsx | 48 +++++++++++++++++++ .../home/report/ReportActionItemMessage.tsx | 23 +-------- 2 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 src/pages/home/report/AddBankAccountActionButton.tsx diff --git a/src/pages/home/report/AddBankAccountActionButton.tsx b/src/pages/home/report/AddBankAccountActionButton.tsx new file mode 100644 index 000000000000..fe6b8a8f0d27 --- /dev/null +++ b/src/pages/home/report/AddBankAccountActionButton.tsx @@ -0,0 +1,48 @@ +import React, {useCallback, useEffect, useState} from 'react'; +import {useOnyx} from 'react-native-onyx'; +import Button from '@components/Button'; +import useLocalize from '@hooks/useLocalize'; +import useThemeStyles from '@hooks/useThemeStyles'; +import Navigation from '@libs/Navigation/Navigation'; +import * as ReportUtils from '@libs/ReportUtils'; +import ONYXKEYS from '@src/ONYXKEYS'; +import ROUTES from '@src/ROUTES'; + +type AddBankAccountActionButtonProps = { + /** The ID of the report */ + reportID: string; +}; + +function AddBankAccountActionButton({reportID}: AddBankAccountActionButtonProps) { + const {translate} = useLocalize(); + const styles = useThemeStyles(); + const [shouldShow, setShouldShow] = useState(false); + const [invoiceReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${invoiceReport?.policyID}`); + + useEffect(() => { + setShouldShow(ReportUtils.hasMissingInvoiceBankAccount(reportID)); + }, [reportID, policy]); + + const openWorkspaceInvoicesPage = useCallback(() => { + if (!policy) { + return; + } + Navigation.navigate(ROUTES.WORKSPACE_INVOICES.getRoute(policy.id)); + }, [policy]); + + if (!shouldShow) { + return null; + } + + return ( +