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: report header not shown #49542

Merged
merged 9 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
30 changes: 15 additions & 15 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import SettlementButton from './SettlementButton';

type MoneyReportHeaderProps = {
/** The report currently being looked at */
report: OnyxTypes.Report;
report: OnyxEntry<OnyxTypes.Report>;

/** The policy tied to the expense report */
policy: OnyxEntry<OnyxTypes.Policy>;
Expand All @@ -61,8 +61,8 @@ type MoneyReportHeaderProps = {
};

function MoneyReportHeader({policy, report: moneyRequestReport, transactionThreadReportID, reportActions, shouldUseNarrowLayout = false, onBackButtonPress}: MoneyReportHeaderProps) {
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReport.chatReportID}`);
const [nextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport.reportID}`);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReport?.chatReportID ?? ''}`);
daledah marked this conversation as resolved.
Show resolved Hide resolved
const [nextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport?.reportID ?? ''}`);
daledah marked this conversation as resolved.
Show resolved Hide resolved
const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`);
const [session] = useOnyx(ONYXKEYS.SESSION);
const requestParentReportAction = useMemo(() => {
Expand Down Expand Up @@ -109,10 +109,10 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
const hasOnlyPendingTransactions = allTransactions.length > 0 && allTransactions.every((t) => TransactionUtils.isExpensifyCardTransaction(t) && TransactionUtils.isPending(t));
const transactionIDs = allTransactions.map((t) => t.transactionID);
const hasAllPendingRTERViolations = TransactionUtils.allHavePendingRTERViolation([transaction?.transactionID ?? '-1']);
const hasOnlyHeldExpenses = ReportUtils.hasOnlyHeldExpenses(moneyRequestReport.reportID);
const hasOnlyHeldExpenses = ReportUtils.hasOnlyHeldExpenses(moneyRequestReport?.reportID ?? '');
const isPayAtEndExpense = TransactionUtils.isPayAtEndExpense(transaction);
const isArchivedReport = ReportUtils.isArchivedRoomWithID(moneyRequestReport?.reportID);
const [archiveReason] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport.reportID}`, {selector: ReportUtils.getArchiveReason});
const [archiveReason] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport?.reportID ?? ''}`, {selector: ReportUtils.getArchiveReason});
daledah marked this conversation as resolved.
Show resolved Hide resolved

const shouldShowPayButton = useMemo(
() => IOU.canIOUBePaid(moneyRequestReport, chatReport, policy, transaction ? [transaction] : undefined),
Expand All @@ -137,9 +137,9 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
const shouldShowAnyButton =
shouldShowSettlementButton || shouldShowApproveButton || shouldShowSubmitButton || shouldShowNextStep || hasAllPendingRTERViolations || shouldShowExportIntegrationButton;
const bankAccountRoute = ReportUtils.getBankAccountRoute(chatReport);
const formattedAmount = CurrencyUtils.convertToDisplayString(reimbursableSpend, moneyRequestReport.currency);
const formattedAmount = CurrencyUtils.convertToDisplayString(reimbursableSpend, moneyRequestReport?.currency);
const [nonHeldAmount, fullAmount] = ReportUtils.getNonHeldAndFullAmount(moneyRequestReport, policy);
const isAnyTransactionOnHold = ReportUtils.hasHeldExpenses(moneyRequestReport.reportID);
const isAnyTransactionOnHold = ReportUtils.hasHeldExpenses(moneyRequestReport?.reportID);
const displayedAmount = isAnyTransactionOnHold && canAllowSettlement ? nonHeldAmount : formattedAmount;
const isMoreContentShown = shouldShowNextStep || shouldShowStatusBar || (shouldShowAnyButton && shouldUseNarrowLayout);
const {isDelegateAccessRestricted, delegatorEmail} = useDelegateUserDetails();
Expand Down Expand Up @@ -292,9 +292,9 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
{shouldShowSettlementButton && !shouldUseNarrowLayout && (
<View style={styles.pv2}>
<SettlementButton
currency={moneyRequestReport.currency}
currency={moneyRequestReport?.currency}
confirmApproval={confirmApproval}
policyID={moneyRequestReport.policyID}
policyID={moneyRequestReport?.policyID}
chatReportID={chatReport?.reportID}
iouReport={moneyRequestReport}
onPress={confirmPayment}
Expand All @@ -319,7 +319,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
/>
</View>
)}
{shouldShowSubmitButton && !shouldUseNarrowLayout && (
{shouldShowSubmitButton && !shouldUseNarrowLayout && moneyRequestReport && (
daledah marked this conversation as resolved.
Show resolved Hide resolved
<View style={styles.pv2}>
<Button
success={isWaitingForSubmissionFromCurrentUser}
Expand All @@ -345,10 +345,10 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
<View style={[styles.dFlex, styles.flexColumn, styles.gap3, styles.pb3, styles.ph5, styles.borderBottom]}>
{shouldShowSettlementButton && shouldUseNarrowLayout && (
<SettlementButton
currency={moneyRequestReport.currency}
currency={moneyRequestReport?.currency}
confirmApproval={confirmApproval}
policyID={moneyRequestReport.policyID}
chatReportID={moneyRequestReport.chatReportID}
policyID={moneyRequestReport?.policyID}
chatReportID={moneyRequestReport?.chatReportID}
iouReport={moneyRequestReport}
onPress={confirmPayment}
enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS}
Expand All @@ -368,7 +368,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
connectionName={connectedIntegration}
/>
)}
{shouldShowSubmitButton && shouldUseNarrowLayout && (
{shouldShowSubmitButton && shouldUseNarrowLayout && moneyRequestReport && (
daledah marked this conversation as resolved.
Show resolved Hide resolved
<Button
success={isWaitingForSubmissionFromCurrentUser}
text={translate('common.submit')}
Expand All @@ -394,7 +394,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
)}
</View>
)}
{isHoldMenuVisible && requestType !== undefined && (
{isHoldMenuVisible && moneyRequestReport && requestType !== undefined && (
daledah marked this conversation as resolved.
Show resolved Hide resolved
<ProcessMoneyReportHoldMenu
nonHeldAmount={!hasOnlyHeldExpenses ? nonHeldAmount : undefined}
requestType={requestType}
Expand Down
14 changes: 8 additions & 6 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import ProcessMoneyRequestHoldMenu from './ProcessMoneyRequestHoldMenu';

type MoneyRequestHeaderProps = {
/** The report currently being looked at */
report: Report;
report: OnyxEntry<Report>;

/** The policy which the report is tied to */
policy: OnyxEntry<Policy>;
Expand All @@ -43,7 +43,7 @@ type MoneyRequestHeaderProps = {
};

function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrowLayout = false, onBackButtonPress}: MoneyRequestHeaderProps) {
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`);
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID ?? ''}`);
daledah marked this conversation as resolved.
Show resolved Hide resolved
const [transaction] = useOnyx(
`${ONYXKEYS.COLLECTION.TRANSACTION}${
ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction)?.IOUTransactionID ?? -1 : -1
Expand All @@ -58,12 +58,13 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow
const [shouldShowHoldMenu, setShouldShowHoldMenu] = useState(false);
const isOnHold = TransactionUtils.isOnHold(transaction);
const isDuplicate = TransactionUtils.isDuplicate(transaction?.transactionID ?? '');
const reportID = report?.reportID;

const hasAllPendingRTERViolations = TransactionUtils.allHavePendingRTERViolation([transaction?.transactionID ?? '-1']);

const markAsCash = useCallback(() => {
TransactionActions.markAsCash(transaction?.transactionID ?? '-1', report.reportID);
}, [report.reportID, transaction?.transactionID]);
TransactionActions.markAsCash(transaction?.transactionID ?? '-1', reportID ?? '');
}, [reportID, transaction?.transactionID]);

const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction);

Expand Down Expand Up @@ -129,6 +130,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow
shouldShowPinButton={false}
report={{
...report,
reportID: reportID ?? '',
ownerAccountID: parentReport?.ownerAccountID,
}}
policy={policy}
Expand All @@ -149,7 +151,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow
text={translate('iou.reviewDuplicates')}
style={[styles.p0, styles.ml2]}
onPress={() => {
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_PAGE.getRoute(report.reportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_PAGE.getRoute(reportID ?? ''));
}}
/>
)}
Expand All @@ -171,7 +173,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, shouldUseNarrow
text={translate('iou.reviewDuplicates')}
style={[styles.w100, styles.pr0]}
onPress={() => {
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_PAGE.getRoute(report.reportID));
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_PAGE.getRoute(reportID ?? ''));
}}
/>
</View>
Expand Down
6 changes: 3 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4119,12 +4119,12 @@ function getUploadingAttachmentHtml(file?: FileObject): string {
return `<a href="${file.uri}" ${dataAttributes}>${file.name}</a>`;
}

function getReportDescriptionText(report: Report): string {
if (!report.description) {
function getReportDescriptionText(report: OnyxEntry<Report>): string {
if (!report?.description) {
return '';
}

return Parser.htmlToText(report.description);
return Parser.htmlToText(report?.description);
}

function getPolicyDescriptionText(policy: OnyxEntry<Policy>): string {
Expand Down
Loading
Loading