Skip to content

Commit

Permalink
fix: remove button for approved dupes
Browse files Browse the repository at this point in the history
  • Loading branch information
daledah committed Aug 28, 2024
1 parent 2d895c7 commit 128cd29
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function MoneyRequestPreviewContent({
);

// Remove settled transactions from duplicates
const duplicates = useMemo(() => TransactionUtils.removeSettledTransactions(allDuplicates), [allDuplicates]);
const duplicates = useMemo(() => TransactionUtils.removeSettledAndApprovedTransactions(allDuplicates), [allDuplicates]);

// When there are no settled transactions in duplicates, show the "Keep this one" button
const shouldShowKeepButton = allDuplicates.length === duplicates.length;
Expand Down
14 changes: 9 additions & 5 deletions src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,8 +905,12 @@ type FieldsToChange = {
reimbursable?: Array<boolean | undefined>;
};

function removeSettledTransactions(transactionIDs: string[]) {
return transactionIDs.filter((transactionID) => !ReportUtils.isSettled(allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]?.reportID));
function removeSettledAndApprovedTransactions(transactionIDs: string[]) {
return transactionIDs.filter(
(transactionID) =>
!ReportUtils.isSettled(allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]?.reportID) &&
!ReportUtils.isReportApproved(allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]?.reportID),
);
}

/**
Expand All @@ -930,7 +934,7 @@ function removeSettledTransactions(transactionIDs: string[]) {
function compareDuplicateTransactionFields(transactionID: string): {keep: Partial<ReviewDuplicates>; change: FieldsToChange} {
const transactionViolations = allTransactionViolations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`];
const duplicates = transactionViolations?.find((violation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION)?.data?.duplicates ?? [];
const transactions = removeSettledTransactions([transactionID, ...duplicates]).map((item) => getTransaction(item));
const transactions = removeSettledAndApprovedTransactions([transactionID, ...duplicates]).map((item) => getTransaction(item));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const keep: Record<string, any> = {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -1044,7 +1048,7 @@ function buildTransactionsMergeParams(reviewDuplicates: OnyxEntry<ReviewDuplicat
currency: getCurrency(originalTransaction as OnyxEntry<Transaction>),
created: getFormattedCreated(originalTransaction as OnyxEntry<Transaction>),
transactionID: reviewDuplicates?.transactionID ?? '',
transactionIDList: removeSettledTransactions(reviewDuplicates?.duplicates ?? []),
transactionIDList: removeSettledAndApprovedTransactions(reviewDuplicates?.duplicates ?? []),
billable: reviewDuplicates?.billable ?? false,
reimbursable: reviewDuplicates?.reimbursable ?? false,
category: reviewDuplicates?.category ?? '',
Expand Down Expand Up @@ -1130,7 +1134,7 @@ export {
buildTransactionsMergeParams,
getReimbursable,
isPayAtEndExpense,
removeSettledTransactions,
removeSettledAndApprovedTransactions,
getCardName,
};

Expand Down
4 changes: 2 additions & 2 deletions src/pages/TransactionDuplicate/Review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function TransactionDuplicateReview() {
Navigation.goBack();
};

const hasSettledTransaction = transactions.some((transaction) => ReportUtils.isSettled(transaction?.reportID));
const hasSettledOrApprovedTransaction = transactions.some((transaction) => ReportUtils.isSettled(transaction?.reportID) || ReportUtils.isReportApproved(transaction?.reportID));

return (
<ScreenWrapper testID={TransactionDuplicateReview.displayName}>
Expand All @@ -55,7 +55,7 @@ function TransactionDuplicateReview() {
text={translate('iou.keepAll')}
onPress={keepAll}
/>
{!!hasSettledTransaction && <Text style={[styles.textNormal, styles.colorMuted, styles.mt3]}>{translate('iou.someDuplicatesArePaid')}</Text>}
{!!hasSettledOrApprovedTransaction && <Text style={[styles.textNormal, styles.colorMuted, styles.mt3]}>{translate('iou.someDuplicatesArePaid')}</Text>}
</View>
<DuplicateTransactionsList transactions={transactions} />
</FullPageNotFoundView>
Expand Down

0 comments on commit 128cd29

Please sign in to comment.