Skip to content
Draft
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
3 changes: 3 additions & 0 deletions src/components/ReportActionItem/MoneyRequestReceiptView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ function MoneyRequestReceiptView({

const [isLoading, setIsLoading] = useState(true);
const parentReportAction = report?.parentReportActionID ? parentReportActions?.[report.parentReportActionID] : undefined;
const [parentReportActionChildReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(parentReportAction?.childReportID)}`);

const originalReportID = useOriginalReportID(report?.reportID, parentReportAction);
const {iouReport, chatReport: chatIOUReport, isChatIOUReportArchived} = useGetIOUReportFromReportAction(parentReportAction);
const isTrackExpense = !mergeTransactionID && isTrackExpenseReportNew(report, parentReport, parentReportAction);
Expand Down Expand Up @@ -423,6 +425,7 @@ function MoneyRequestReceiptView({
transaction?.transactionID ?? linkedTransactionID,
parentReportAction,
report.reportID,
parentReportActionChildReport,
iouReport,
chatIOUReport,
isChatIOUReportArchived,
Expand Down
2 changes: 2 additions & 0 deletions src/components/Search/SearchList/ListItem/ChatListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function ChatListItem<TItem extends ListItem>({
}: ChatListItemProps<TItem>) {
const reportActionItem = item as unknown as ReportActionListItemType;
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportActionItem?.reportID}`);
const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportActionItem?.childReportID}`);
const personalDetails = usePersonalDetails();
const [userBillingFundID] = useOnyx(ONYXKEYS.NVP_BILLING_FUND_ID);
const styles = useThemeStyles();
Expand Down Expand Up @@ -76,6 +77,7 @@ function ChatListItem<TItem extends ListItem>({
>
<ReportActionItem
action={reportActionItem}
transactionThreadReport={transactionThreadReport}
report={report}
onPress={() => onSelectRow(item)}
parentReportAction={undefined}
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useExpenseActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic
const requestParentReportAction =
reportActions?.find((action): action is OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU> => action.reportActionID === transactionThreadReport?.parentReportActionID) ??
null;

const [requestParentReportActionChildReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(requestParentReportAction?.childReportID)}`);
const iouTransactionID = isMoneyRequestAction(requestParentReportAction) ? getOriginalMessage(requestParentReportAction)?.IOUTransactionID : undefined;
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(iouTransactionID)}`);
const [originalTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transaction?.comment?.originalTransactionID)}`);
Expand Down Expand Up @@ -510,6 +510,7 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic
const goBackRoute = getNavigationUrlOnMoneyRequestDelete(
transaction.transactionID,
requestParentReportAction,
requestParentReportActionChildReport,
iouReport,
chatIOUReport,
isChatIOUReportArchived,
Expand Down
28 changes: 20 additions & 8 deletions src/libs/actions/IOU/DeleteMoneyRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ function prepareToCleanUpMoneyRequest(
function getNavigationUrlOnMoneyRequestDelete(
transactionID: string | undefined,
reportAction: OnyxTypes.ReportAction,
transactionThreadReport: OnyxEntry<OnyxTypes.Report>,
iouReport: OnyxEntry<OnyxTypes.Report>,
chatReport: OnyxEntry<OnyxTypes.Report>,
isChatReportArchived: boolean | undefined,
Expand All @@ -257,9 +258,6 @@ function getNavigationUrlOnMoneyRequestDelete(
if (!transactionID) {
return undefined;
}
const allReports = getAllReports();
const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportAction.childReportID}`];

const {shouldDeleteTransactionThread, shouldDeleteIOUReport} = prepareToCleanUpMoneyRequest(
transactionID,
reportAction,
Expand Down Expand Up @@ -292,19 +290,25 @@ function cleanUpMoneyRequest(
transactionID: string,
reportAction: OnyxTypes.ReportAction,
reportID: string,
transactionThreadReport: OnyxEntry<OnyxTypes.Report>,
iouReport: OnyxEntry<OnyxTypes.Report>,
chatReport: OnyxEntry<OnyxTypes.Report>,
isChatIOUReportArchived: boolean | undefined,
originalReportID: string | undefined,
isSingleTransactionView = false,
) {
const allReports = getAllReports();
const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportAction.childReportID}`];

const {shouldDeleteTransactionThread, shouldDeleteIOUReport, updatedReportAction, updatedIOUReport, updatedReportPreviewAction, transactionThreadID, reportPreviewAction} =
prepareToCleanUpMoneyRequest(transactionID, reportAction, transactionThreadReport, iouReport, chatReport, isChatIOUReportArchived, false);

const urlToNavigateBack = getNavigationUrlOnMoneyRequestDelete(transactionID, reportAction, iouReport, chatReport, isChatIOUReportArchived, isSingleTransactionView);
const urlToNavigateBack = getNavigationUrlOnMoneyRequestDelete(
transactionID,
reportAction,
transactionThreadReport,
iouReport,
chatReport,
isChatIOUReportArchived,
isSingleTransactionView,
);
// build Onyx data

// Onyx operations to delete the transaction, update the IOU report action and chat report action
Expand Down Expand Up @@ -685,7 +689,15 @@ function deleteMoneyRequest({
selectedTransactionIDs,
);

const urlToNavigateBack = getNavigationUrlOnMoneyRequestDelete(transactionID, reportAction, iouReport, chatReport, isChatIOUReportArchived, isSingleTransactionView);
const urlToNavigateBack = getNavigationUrlOnMoneyRequestDelete(
transactionID,
reportAction,
transactionThreadReport,
iouReport,
chatReport,
isChatIOUReportArchived,
isSingleTransactionView,
);

// STEP 2: Build Onyx data
// The logic mostly resembles the cleanUpMoneyRequest function
Expand Down
4 changes: 3 additions & 1 deletion src/libs/actions/IOU/TrackExpense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2740,7 +2740,9 @@ function getNavigationUrlAfterTrackExpenseDelete(

// If not a self DM, handle it as a regular money request
if (!isSelfDM(chatReport)) {
return getNavigationUrlOnMoneyRequestDelete(transactionID, reportAction, iouReport, chatIOUReport, isChatReportArchived, isSingleTransactionView);
const allReports = getAllReports();
const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportAction.childReportID}`];
return getNavigationUrlOnMoneyRequestDelete(transactionID, reportAction, transactionThreadReport, iouReport, chatIOUReport, isChatReportArchived, isSingleTransactionView);
}

// Only navigate if in single transaction view and the thread will be deleted
Expand Down
32 changes: 26 additions & 6 deletions src/pages/Debug/ReportAction/DebugReportActionCreatePage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback, useState} from 'react';
import React, {useCallback, useMemo, useState} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import Button from '@components/Button';
Expand Down Expand Up @@ -28,6 +28,19 @@ import type {PersonalDetailsList, ReportAction, Session} from '@src/types/onyx';

type DebugReportActionCreatePageProps = PlatformStackScreenProps<DebugParamList, typeof SCREENS.DEBUG.REPORT_ACTION_CREATE>;

function isParsedReportAction(value: unknown): value is ReportAction {
return typeof value === 'object' && value !== null && 'reportActionID' in value;
}

function parseReportActionJSON(draftReportAction: string): ReportAction | null {
try {
const parsedReportAction: unknown = JSON.parse(draftReportAction.replaceAll('\n', ''));
return isParsedReportAction(parsedReportAction) ? parsedReportAction : null;
} catch {
return null;
}
}

const getInitialReportAction = (reportID: string, session: OnyxEntry<Session>, personalDetailsList: OnyxEntry<PersonalDetailsList>) =>
DebugUtils.stringifyJSON({
actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT,
Expand All @@ -53,15 +66,21 @@ function DebugReportActionCreatePage({
const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT);
const isTryNewDotNVPDismissed = !!tryNewDot?.classicRedirect?.dismissed;

const reportAction = useMemo(() => parseReportActionJSON(draftReportAction), [draftReportAction]);

const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportAction?.childReportID}`);

const [error, setError] = useState<string>();

const createReportAction = useCallback(() => {
const parsedReportAction = JSON.parse(draftReportAction.replaceAll('\n', '')) as ReportAction;
if (!reportAction) {
return;
}
Debug.mergeDebugData(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, {
[parsedReportAction.reportActionID]: parsedReportAction,
[reportAction.reportActionID]: reportAction,
});
Navigation.navigate(ROUTES.DEBUG_REPORT_TAB_ACTIONS.getRoute(reportID));
}, [draftReportAction, reportID]);
}, [reportAction, reportID]);

const editJSON = useCallback(
(updatedJSON: string) => {
Expand Down Expand Up @@ -108,9 +127,10 @@ function DebugReportActionCreatePage({
</View>
<View>
<Text style={[styles.textLabelSupporting, styles.mb2]}>{translate('debug.preview')}</Text>
{!error ? (
{!error && reportAction ? (
<ReportActionItem
action={JSON.parse(draftReportAction.replaceAll('\n', '')) as ReportAction}
action={reportAction}
transactionThreadReport={transactionThreadReport}
report={{reportID}}
parentReportAction={undefined}
displayAsGroup={false}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Debug/ReportAction/DebugReportActionPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ function DebugReportActionPreview({reportAction, reportID}: DebugReportActionPre
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT);
const isTryNewDotNVPDismissed = !!tryNewDot?.classicRedirect?.dismissed;

const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportAction?.childReportID}`);
return (
<ScrollView>
<ReportActionItem
action={reportAction ?? ({} as ReportAction)}
transactionThreadReport={transactionThreadReport}
report={report ?? ({} as Report)}
parentReportAction={undefined}
displayAsGroup={false}
Expand Down
2 changes: 2 additions & 0 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
return parentReportAction;
}, [caseID, parentReportAction, reportActions, transactionThreadReport?.parentReportActionID]);
const {iouReport, chatReport: chatIOUReport, isChatIOUReportArchived} = useGetIOUReportFromReportAction(requestParentReportAction);
const [requestParentReportActionChildReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(requestParentReportAction?.childReportID)}`);

const isActionOwner =
typeof requestParentReportAction?.actorAccountID === 'number' &&
Expand Down Expand Up @@ -995,6 +996,7 @@
urlToNavigateBack = getNavigationUrlOnMoneyRequestDelete(
iouTransactionID,
requestParentReportAction,
requestParentReportActionChildReport,
iouReport,
chatIOUReport,
isChatIOUReportArchived,
Expand All @@ -1009,7 +1011,7 @@
setDeleteTransactionNavigateBackUrl(urlToNavigateBack);
navigateBackOnDeleteTransaction(urlToNavigateBack as Route);
}
}, [requestParentReportAction, route.params.reportID, moneyRequestReport, iouTransactionID, iouReport, chatIOUReport, isChatIOUReportArchived, isSingleTransactionView]);

Check failure on line 1014 in src/pages/ReportDetailsPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useCallback has a missing dependency: 'requestParentReportActionChildReport'. Either include it or remove the dependency array

Check failure on line 1014 in src/pages/ReportDetailsPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useCallback has a missing dependency: 'requestParentReportActionChildReport'. Either include it or remove the dependency array

const showDeleteModal = useCallback(async () => {
const {action} = await showConfirmModal({
Expand Down
2 changes: 2 additions & 0 deletions src/pages/TransactionDuplicate/DuplicateTransactionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function DuplicateTransactionItem({transaction, index, onPreviewPressed}: Duplic
const originalReportID = getOriginalReportID(report?.reportID, action, reportActions);

const [draftMessage] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}`);
const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${action?.childReportID}`);

const [linkedTransactionRouteError] = useOnyx(
`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : undefined)}`,
Expand All @@ -64,6 +65,7 @@ function DuplicateTransactionItem({transaction, index, onPreviewPressed}: Duplic
<ReportActionItem
action={action}
report={report}
transactionThreadReport={transactionThreadReport}
parentReportAction={getReportAction(report?.parentReportID, report?.parentReportActionID)}
index={index}
displayAsGroup={false}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/inbox/report/PureReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type PureReportActionItemProps = {
report: OnyxEntry<OnyxTypes.Report>;

/** The transaction thread report associated with the report for this action, if any */
transactionThreadReport?: OnyxEntry<OnyxTypes.Report>;
transactionThreadReport: OnyxEntry<OnyxTypes.Report>;

/** Report action belonging to the report's parent */
parentReportAction: OnyxEntry<OnyxTypes.ReportAction>;
Expand Down Expand Up @@ -262,7 +262,7 @@ function PureReportActionItem({
const dismissError = () => {
const transactionID = isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : undefined;
if (isSendingMoney && transactionID && reportID) {
cleanUpMoneyRequest(transactionID, action, reportID, report, chatReport, undefined, originalReportID, true);
cleanUpMoneyRequest(transactionID, action, reportID, transactionThreadReport, report, chatReport, undefined, originalReportID, true);
return;
}
if (action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD && isReportActionLinked) {
Expand Down
1 change: 1 addition & 0 deletions tests/ui/ClearReportActionErrorsUITest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe('ClearReportActionErrors UI', () => {
<PortalProvider>
<PureReportActionItem
report={report}
transactionThreadReport={undefined}
parentReportAction={undefined}
action={action}
displayAsGroup={false}
Expand Down
Loading
Loading