-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/ Add bank account button in invoice report remains after bank acc…
…ount is added
- Loading branch information
1 parent
aedbbde
commit 0a33b1e
Showing
2 changed files
with
50 additions
and
21 deletions.
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,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 ( | ||
<Button | ||
style={[styles.mt2, styles.alignSelfStart]} | ||
success | ||
text={translate('workspace.invoices.paymentMethods.addBankAccount')} | ||
onPress={openWorkspaceInvoicesPage} | ||
/> | ||
); | ||
} | ||
|
||
export default AddBankAccountActionButton; |
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