Skip to content

fix: Payer section goes missing from payed money request preview #60168

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

Merged
merged 8 commits into from
Apr 21, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ function MoneyRequestReportPreview({
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`, {canBeMissing: true});
const [invoiceReceiverPolicy] = useOnyx(
`${ONYXKEYS.COLLECTION.POLICY}${chatReport?.invoiceReceiver && 'policyID' in chatReport.invoiceReceiver ? chatReport.invoiceReceiver.policyID : CONST.DEFAULT_NUMBER_ID}`,
`${ONYXKEYS.COLLECTION.POLICY}${chatReport?.invoiceReceiver && 'policyID' in chatReport.invoiceReceiver ? chatReport.invoiceReceiver.policyID : undefined}`,
{canBeMissing: true},
);
const [invoiceReceiverPersonalDetail] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {
selector: (personalDetails) =>
personalDetails?.[chatReport?.invoiceReceiver && 'accountID' in chatReport.invoiceReceiver ? chatReport.invoiceReceiver.accountID : CONST.DEFAULT_NUMBER_ID],
canBeMissing: true,
});
const [iouReport, transactions, violations] = useReportWithTransactionsAndViolations(iouReportID);
const policy = usePolicy(policyID);
Expand Down Expand Up @@ -70,6 +72,7 @@ function MoneyRequestReportPreview({
wrapperStyle={reportPreviewStyles.transactionPreviewStyle}
containerStyles={[styles.h100, containerStyles]}
transactionID={item.transactionID}
reportPreviewAction={action}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function TransactionPreviewContent({
sessionAccountID,
walletTermsErrors,
routeName,
reportPreviewAction,
shouldHideOnDelete = true,
}: TransactionPreviewContentProps) {
const theme = useTheme();
Expand All @@ -66,8 +67,8 @@ function TransactionPreviewContent({
};

const transactionDetails = useMemo<Partial<TransactionDetails>>(() => getTransactionDetails(transaction) ?? {}, [transaction]);
const managerID = iouReport?.managerID ?? CONST.DEFAULT_NUMBER_ID;
const ownerAccountID = iouReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID;
const managerID = iouReport?.managerID ?? reportPreviewAction?.childManagerAccountID ?? CONST.DEFAULT_NUMBER_ID;
const ownerAccountID = iouReport?.ownerAccountID ?? reportPreviewAction?.childOwnerAccountID ?? CONST.DEFAULT_NUMBER_ID;
const isReportAPolicyExpenseChat = isPolicyExpenseChat(chatReport);
const {amount: requestAmount, comment: requestComment, merchant, tag, category, currency: requestCurrency} = transactionDetails;

Expand Down Expand Up @@ -131,7 +132,7 @@ function TransactionPreviewContent({
const showCashOrCard = getTranslatedText(previewText.showCashOrCard);
const displayDeleteAmountText = getTranslatedText(previewText.displayDeleteAmountText);

const iouData = getIOUData(managerID, ownerAccountID, iouReport, personalDetails);
const iouData = getIOUData(managerID, ownerAccountID, personalDetails);
const {from, to} = iouData ?? {from: null, to: null};
const isDeleted = action?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
const shouldShowCategoryOrTag = shouldShowCategory || shouldShowTag;
Expand Down Expand Up @@ -215,9 +216,9 @@ function TransactionPreviewContent({
<UserInfoCellsWithArrow
shouldDisplayArrowIcon
participantFrom={from}
participantFromDisplayName={from.displayName ?? from.login ?? ''}
participantFromDisplayName={from.displayName ?? from.login ?? translate('common.hidden')}
participantToDisplayName={to.displayName ?? to.login ?? translate('common.hidden')}
participantTo={to}
participantToDisplayName={to.displayName ?? to.login ?? ''}
avatarSize="mid-subscript"
infoCellsTextStyle={{...styles.textMicroBold, lineHeight: 14}}
infoCellsAvatarStyle={styles.pr1}
Expand Down
15 changes: 8 additions & 7 deletions src/components/ReportActionItem/TransactionPreview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ const getOriginalTransactionIfBillIsSplit = (transaction: OnyxEntry<Transaction>
function TransactionPreview(props: TransactionPreviewProps) {
const {action, chatReportID, reportID, contextMenuAnchor, checkIfContextMenuActive = () => {}, shouldDisplayContextMenu, iouReportID, transactionID: transactionIDFromProps} = props;

const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`);
const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`, {canBeMissing: true});
const route = useRoute<PlatformStackRouteProp<TransactionDuplicateNavigatorParamList, typeof SCREENS.TRANSACTION_DUPLICATE.REVIEW>>();
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${route.params?.threadReportID}`);
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${route.params?.threadReportID}`, {canBeMissing: true});
const isMoneyRequestAction = isMoneyRequestActionReportActionsUtils(action);
const transactionID = transactionIDFromProps ?? (isMoneyRequestAction ? getOriginalMessage(action)?.IOUTransactionID : null);
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`);
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {canBeMissing: true});
const violations = useTransactionViolations(transaction?.transactionID);
const [walletTerms] = useOnyx(ONYXKEYS.WALLET_TERMS);
const [session] = useOnyx(ONYXKEYS.SESSION);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [walletTerms] = useOnyx(ONYXKEYS.WALLET_TERMS, {canBeMissing: true});
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true});
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`, {canBeMissing: true});
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: true});

// Get transaction violations for given transaction id from onyx, find duplicated transactions violations and get duplicates
const allDuplicates = useMemo(() => violations?.find((violation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION)?.data?.duplicates ?? [], [violations]);
Expand Down Expand Up @@ -88,6 +88,7 @@ function TransactionPreview(props: TransactionPreviewProps) {
sessionAccountID={sessionAccountID}
walletTermsErrors={walletTerms?.errors}
routeName={route.name}
reportPreviewAction={props.reportPreviewAction}
/>
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/components/ReportActionItem/TransactionPreview/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type TransactionPreviewProps = {

/** In the case where we have access to the transactionID in the parent */
transactionID?: string;

/** The action to be displayed in the preview */
reportPreviewAction?: ReportAction;
};

type TransactionPreviewContentProps = {
Expand Down Expand Up @@ -122,6 +125,9 @@ type TransactionPreviewContentProps = {

/** Determine whether to hide the component's children if deletion is pending */
shouldHideOnDelete?: boolean;

/** The action to be displayed in the preview */
reportPreviewAction?: ReportAction;
};

export type {TransactionPreviewProps, TransactionPreviewContentProps, TransactionPreviewStyleType};
11 changes: 3 additions & 8 deletions src/libs/TransactionPreviewUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import DateUtils from './DateUtils';
import type {PlatformStackRouteProp} from './Navigation/PlatformStackNavigation/types';
import type {TransactionDuplicateNavigatorParamList} from './Navigation/types';
import {getOriginalMessage, getReportAction, isMessageDeleted, isMoneyRequestAction} from './ReportActionsUtils';
import {isIOUReport, isPaidGroupPolicy, isPaidGroupPolicyExpenseReport, isReportApproved, isSettled} from './ReportUtils';
import {isPaidGroupPolicy, isPaidGroupPolicyExpenseReport, isReportApproved, isSettled} from './ReportUtils';
import type {TransactionDetails} from './ReportUtils';
import StringUtils from './StringUtils';
import {
Expand Down Expand Up @@ -42,16 +42,11 @@ const emptyPersonalDetails: OnyxTypes.PersonalDetails = {
login: undefined,
};

function getIOUData(
managerID: number,
ownerAccountID: number,
reportOrID: OnyxTypes.OnyxInputOrEntry<OnyxTypes.Report> | string | undefined,
personalDetails: OnyxTypes.PersonalDetailsList | undefined,
) {
function getIOUData(managerID: number, ownerAccountID: number, personalDetails: OnyxTypes.PersonalDetailsList | undefined) {
const fromID = managerID;
const toID = ownerAccountID;

return reportOrID && isIOUReport(reportOrID)
return fromID && toID
? {
from: personalDetails ? personalDetails[fromID] : emptyPersonalDetails,
to: personalDetails ? personalDetails[toID] : emptyPersonalDetails,
Expand Down