Skip to content

Commit

Permalink
fixing eslint errors ||
Browse files Browse the repository at this point in the history
  • Loading branch information
abzokhattab committed Jan 11, 2025
1 parent 75d0171 commit 219cb0e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 29 deletions.
6 changes: 5 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5504,7 +5504,11 @@ function completeSplitBill(chatReportID: string, reportAction: OnyxTypes.ReportA
Report.notifyNewAction(chatReportID, sessionAccountID);
}

function setDraftSplitTransaction(transactionID: string, transactionChanges: TransactionChanges = {}, policy?: OnyxEntry<OnyxTypes.Policy>) {
function setDraftSplitTransaction(transactionID: string | undefined, transactionChanges: TransactionChanges = {}, policy?: OnyxEntry<OnyxTypes.Policy>) {
if (!transactionID) {
return;
}

let draftSplitTransaction = allDraftSplitTransactions[`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`];

if (!draftSplitTransaction) {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/ReportActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function clearReportActionErrors(reportID: string, reportAction: ReportAction, k

// If there's a linked transaction, delete that too
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const linkedTransactionID = ReportActionUtils.getLinkedTransactionID(reportAction.reportActionID, originalReportID || '-1');
const linkedTransactionID = ReportActionUtils.getLinkedTransactionID(reportAction.reportActionID, originalReportID);
if (linkedTransactionID) {
Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${linkedTransactionID}`, null);
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${reportAction.childReportID}`, null);
Expand Down Expand Up @@ -105,7 +105,7 @@ function clearAllRelatedReportActionErrors(reportID: string | undefined, reportA
const childActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportAction.childReportID}`] ?? {};
Object.values(childActions).forEach((action) => {
const childErrorKeys = Object.keys(action.errors ?? {}).filter((err) => errorKeys.includes(err));
clearAllRelatedReportActionErrors(reportAction.childReportID ?? '-1', action, 'parent', childErrorKeys);
clearAllRelatedReportActionErrors(reportAction.childReportID, action, 'parent', childErrorKeys);
});
}
}
Expand Down
70 changes: 48 additions & 22 deletions src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,21 +355,31 @@ function updateWaypoints(transactionID: string, waypoints: WaypointCollection, i
function dismissDuplicateTransactionViolation(transactionIDs: string[], dissmissedPersonalDetails: PersonalDetails) {
const currentTransactionViolations = transactionIDs.map((id) => ({transactionID: id, violations: allTransactionViolation?.[id] ?? []}));
const currentTransactions = transactionIDs.map((id) => allTransactions?.[id]);
const transactionsReportActions = currentTransactions.map((transaction) => ReportActionsUtils.getIOUActionForReportID(transaction.reportID ?? '', transaction.transactionID ?? ''));
const transactionsReportActions = currentTransactions.map((transaction) => ReportActionsUtils.getIOUActionForReportID(transaction.reportID, transaction.transactionID));
const optimisticDissmidedViolationReportActions = transactionsReportActions.map(() => {
return buildOptimisticDismissedViolationReportAction({reason: 'manual', violationName: CONST.VIOLATIONS.DUPLICATED_TRANSACTION});
});

const optimisticData: OnyxUpdate[] = [];
const failureData: OnyxUpdate[] = [];

const optimisticReportActions: OnyxUpdate[] = transactionsReportActions.map((action, index) => ({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${action?.childReportID ?? '-1'}`,
value: {
[optimisticDissmidedViolationReportActions.at(index)?.reportActionID ?? '']: optimisticDissmidedViolationReportActions.at(index) as ReportAction,
},
}));
const optimisticReportActions = transactionsReportActions
.map((action, index) => {
const reportAction = optimisticDissmidedViolationReportActions.at(index);
const reportActionID = reportAction?.reportActionID;
if (!reportActionID) {
return;
}
return {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${action?.childReportID}`,
value: {
[reportActionID]: reportAction as ReportAction,
},
};
})
.filter(Boolean) as OnyxUpdate[];

const optimisticDataTransactionViolations: OnyxUpdate[] = currentTransactionViolations.map((transactionViolations) => ({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionViolations.transactionID}`,
Expand Down Expand Up @@ -411,25 +421,41 @@ function dismissDuplicateTransactionViolation(transactionIDs: string[], dissmiss
},
}));

const failureReportActions: OnyxUpdate[] = transactionsReportActions.map((action, index) => ({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${action?.childReportID ?? '-1'}`,
value: {
[optimisticDissmidedViolationReportActions.at(index)?.reportActionID ?? '']: null,
},
}));
const failureReportActions = transactionsReportActions
.map((action, index) => {
const reportActionID = optimisticDissmidedViolationReportActions.at(index)?.reportActionID;
if (!reportActionID) {
return;
}
return {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${action?.childReportID}`,
value: {
[reportActionID]: null,
},
};
})
.filter(Boolean) as OnyxUpdate[];

failureData.push(...failureDataTransactionViolations);
failureData.push(...failureDataTransaction);
failureData.push(...failureReportActions);

const successData: OnyxUpdate[] = transactionsReportActions.map((action, index) => ({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${action?.childReportID ?? '-1'}`,
value: {
[optimisticDissmidedViolationReportActions.at(index)?.reportActionID ?? '']: null,
},
}));
const successData = transactionsReportActions
.map((action, index) => {
const reportActionID = optimisticDissmidedViolationReportActions.at(index)?.reportActionID;
if (!reportActionID) {
return;
}
return {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${action?.childReportID}`,
value: {
[reportActionID]: null,
},
};
})
.filter(Boolean) as OnyxUpdate[];
// We are creating duplicate resolved report actions for each duplicate transactions and all the report actions
// should be correctly linked with their parent report but the BE is sometimes linking report actions to different
// parent reports than the one we set optimistically, resulting in duplicate report actions. Therefore, we send the BE
Expand Down
8 changes: 4 additions & 4 deletions src/pages/iou/SplitBillDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ function SplitBillDetailsPage({route, report, reportAction}: SplitBillDetailsPag
const {translate} = useLocalize();
const theme = useTheme();

const reportID = report?.reportID ?? '-1';
const reportID = report?.reportID;
const originalMessage = reportAction && ReportActionsUtils.isMoneyRequestAction(reportAction) ? ReportActionsUtils.getOriginalMessage(reportAction) : undefined;
const IOUTransactionID = originalMessage?.IOUTransactionID ? originalMessage.IOUTransactionID : '-1';
const IOUTransactionID = originalMessage?.IOUTransactionID;
const participantAccountIDs = originalMessage?.participantAccountIDs ?? [];

const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${IOUTransactionID}`);
Expand All @@ -57,7 +57,7 @@ function SplitBillDetailsPage({route, report, reportAction}: SplitBillDetailsPag
} else {
participants = participantAccountIDs.map((accountID) => OptionsListUtils.getParticipantsOption({accountID, selected: true, reportID: ''}, personalDetails));
}
const actorAccountID = reportAction?.actorAccountID ?? -1;
const actorAccountID = reportAction?.actorAccountID ?? CONST.DEFAULT_NUMBER_ID;
const payeePersonalDetails = personalDetails?.[actorAccountID];
const participantsExcludingPayee = participants.filter((participant) => participant.accountID !== reportAction?.actorAccountID);

Expand Down Expand Up @@ -137,7 +137,7 @@ function SplitBillDetailsPage({route, report, reportAction}: SplitBillDetailsPag
policyID={ReportUtils.isPolicyExpenseChat(report) ? report?.policyID : undefined}
action={isEditingSplitBill ? CONST.IOU.ACTION.EDIT : CONST.IOU.ACTION.CREATE}
onToggleBillable={(billable) => {
IOU.setDraftSplitTransaction(transaction?.transactionID ?? '-1', {billable});
IOU.setDraftSplitTransaction(transaction?.transactionID, {billable});
}}
isConfirmed={isConfirmed}
/>
Expand Down

0 comments on commit 219cb0e

Please sign in to comment.