Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/ Add bank account button in invoice report remains after bank account is added #52224

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 48 additions & 0 deletions src/pages/home/report/AddBankAccountActionButton.tsx
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;
23 changes: 2 additions & 21 deletions src/pages/home/report/ReportActionItemMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ import React from 'react';
import type {StyleProp, TextStyle, ViewStyle} from 'react-native';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import Button from '@components/Button';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {ReportAction} from '@src/types/onyx';
import AddBankAccountActionButton from './AddBankAccountActionButton';
import TextCommentFragment from './comment/TextCommentFragment';
import ReportActionItemFragment from './ReportActionItemFragment';

Expand Down Expand Up @@ -121,29 +119,12 @@ function ReportActionItemMessage({action, displayAsGroup, reportID, style, isHid
return shouldWrapInText ? <Text style={styles.ltr}>{reportActionItemFragments}</Text> : reportActionItemFragments;
};

const openWorkspaceInvoicesPage = () => {
const policyID = ReportUtils.getReport(reportID)?.policyID;

if (!policyID) {
return;
}

Navigation.navigate(ROUTES.WORKSPACE_INVOICES.getRoute(policyID));
};

return (
<View style={[styles.chatItemMessage, style]}>
{!isHidden ? (
<>
{renderReportActionItemFragments(isApprovedOrSubmittedReportAction)}
{action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && ReportUtils.hasMissingInvoiceBankAccount(reportID) && (
<Button
style={[styles.mt2, styles.alignSelfStart]}
success
text={translate('workspace.invoices.paymentMethods.addBankAccount')}
onPress={openWorkspaceInvoicesPage}
/>
)}
{action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && <AddBankAccountActionButton reportID={reportID} />}
</>
) : (
<Text style={[styles.textLabelSupporting, styles.lh20]}>{translate('moderation.flaggedContent')}</Text>
Expand Down
Loading