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

Feat/dupe detection confirmation #42571

Merged
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
faf6155
feat: add confirm screen
kubabutkiewicz May 16, 2024
d0e0f45
Merge branch 'feat/dupe-detection-review-fields' of github.com:kubabu…
kubabutkiewicz May 16, 2024
07f8709
Merge branch 'feat/dupe-detection-review-fields' of github.com:kubabu…
kubabutkiewicz May 16, 2024
9f66c61
feat: added new props to MoneyRequestView to show noneditable version
kubabutkiewicz May 16, 2024
b361da2
Merge branch 'feat/dupe-detection-review-fields' of github.com:kubabu…
kubabutkiewicz May 16, 2024
b9d088b
fix: wip
kubabutkiewicz May 17, 2024
d44f993
Merge branch 'feat/dupe-detection-review-fields' of github.com:kubabu…
kubabutkiewicz May 20, 2024
6cbbcc9
Merge branch 'feat/dupe-detection-review-fields' of github.com:kubabu…
kubabutkiewicz May 20, 2024
e1f30d0
Merge branch 'feat/dupe-detection-review-fields' of github.com:kubabu…
kubabutkiewicz May 20, 2024
449aae5
feat: remove review duplicates onyx key when moving away from review …
kubabutkiewicz May 21, 2024
573c1f0
feat: after abandoing review duplicates flow, remove key from onyx, a…
kubabutkiewicz May 21, 2024
56eeff7
fix: adjusted api command name, added parameters type
kubabutkiewicz May 21, 2024
75df93d
Merge branch 'feat/dupe-detection-review-fields' of github.com:kubabu…
kubabutkiewicz May 22, 2024
9bb346b
wip
kubabutkiewicz May 22, 2024
4821e0a
Merge branch 'feat/dupe-detection-review-fields' of github.com:kubabu…
kubabutkiewicz May 23, 2024
4c20950
fix: ts and lint errors
kubabutkiewicz May 24, 2024
419a1ee
Merge branch 'feat/dupe-detection-review-fields' of github.com:kubabu…
kubabutkiewicz May 24, 2024
9b44dec
fix: lint
kubabutkiewicz May 24, 2024
60541d8
fix: type
kubabutkiewicz May 24, 2024
c7755e4
fix: typecheck
kubabutkiewicz May 24, 2024
86f1a18
fix: lint
kubabutkiewicz May 24, 2024
1b7bedb
Merge branch 'feat/dupe-detection-review-fields' of github.com:kubabu…
kubabutkiewicz May 27, 2024
d4214a2
fix: transaction merge params
kubabutkiewicz May 28, 2024
47f18be
Merge branch 'feat/dupe-detection-review-fields' of github.com:kubabu…
kubabutkiewicz Jun 3, 2024
6e2ca1c
Merge branch 'feat/dupe-detection-review-fields' of github.com:kubabu…
kubabutkiewicz Jun 5, 2024
47af699
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into f…
kubabutkiewicz Jul 8, 2024
56ce616
fix: lint and ts
kubabutkiewicz Jul 8, 2024
6fa1ed8
fix: fix bug which was discovered in previous pr
kubabutkiewicz Jul 8, 2024
afdc17e
fix: remove logs
kubabutkiewicz Jul 8, 2024
4f72959
fix: resolve comments
kubabutkiewicz Jul 9, 2024
e85116e
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into f…
kubabutkiewicz Jul 9, 2024
3542f53
fix: ts and lint
kubabutkiewicz Jul 9, 2024
90299bd
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into f…
kubabutkiewicz Jul 11, 2024
d775ab0
fix: naviagte to not found page after clicking on receipt and stop us…
kubabutkiewicz Jul 11, 2024
a060f37
fix: for displaying tax amount
kubabutkiewicz Jul 15, 2024
1a5337f
Merge branch 'main' of https://github.com/VickyStash/Expensify into f…
kubabutkiewicz Jul 15, 2024
79cf046
fix: ts
kubabutkiewicz Jul 15, 2024
a79f424
fix: displaying not correct merchant and tag
kubabutkiewicz Jul 16, 2024
306a44c
Merge branch 'main' of https://github.com/VickyStash/Expensify into f…
kubabutkiewicz Jul 16, 2024
0a59279
fix: ts
kubabutkiewicz Jul 16, 2024
957f1ae
fix: add comment
kubabutkiewicz Jul 16, 2024
e3d7dd5
fix: do not show violations when in readonly mode
kubabutkiewicz Jul 16, 2024
9c0518c
Merge branch 'main' of github.com:MrRefactor/App into feat/dupe-detec…
kubabutkiewicz Jul 17, 2024
66ee120
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into f…
kubabutkiewicz Jul 17, 2024
7cb3314
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into f…
kubabutkiewicz Jul 17, 2024
6a0b99e
fix: ts
kubabutkiewicz Jul 17, 2024
95f946a
fix: redirection to not found page when you click on receipt preview
kubabutkiewicz Jul 18, 2024
38fb56b
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into f…
kubabutkiewicz Jul 18, 2024
df00611
fix: for sending amount param if there is no receipt
kubabutkiewicz Jul 18, 2024
944ea4b
fix: apply suggestions
kubabutkiewicz Jul 19, 2024
4873418
possible fix for currency
kubabutkiewicz Jul 19, 2024
a352bfb
Merge branch 'main' of github.com:kubabutkiewicz/expensify-app into f…
kubabutkiewicz Jul 19, 2024
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
10 changes: 7 additions & 3 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,10 @@ const ROUTES = {
getRoute: (threadReportID: string) => `r/${threadReportID}/duplicates/review/tax-code` as const,
},
TRANSACTION_DUPLICATE_REVIEW_DESCRIPTION_PAGE: {
route: 'r/:threadReportID/duplicates/confirm',
getRoute: (threadReportID: string) => `r/${threadReportID}/duplicates/confirm` as const,
route: 'r/:threadReportID/duplicates/review/description',
getRoute: (threadReportID: string) => `r/${threadReportID}/duplicates/review/description` as const,
},

kubabutkiewicz marked this conversation as resolved.
Show resolved Hide resolved
TRANSACTION_DUPLICATE_REVIEW_REIMBURSABLE_PAGE: {
route: 'r/:threadReportID/duplicates/review/reimbursable',
getRoute: (threadReportID: string) => `r/${threadReportID}/duplicates/review/reimbursable` as const,
Expand All @@ -902,7 +903,10 @@ const ROUTES = {
route: 'r/:threadReportID/duplicates/review/billable',
getRoute: (threadReportID: string) => `r/${threadReportID}/duplicates/review/billable` as const,
},

TRANSACTION_DUPLICATE_CONFIRMATION_PAGE: {
route: 'r/:threadReportID/duplicates/confirm',
getRoute: (threadReportID: string) => `r/${threadReportID}/duplicates/confirm` as const,
},
POLICY_ACCOUNTING_XERO_IMPORT: {
route: 'settings/workspaces/:policyID/accounting/xero/import',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/xero/import` as const,
Expand Down
1 change: 1 addition & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ const SCREENS = {
TAX_CODE: 'Transaction_Duplicate_Tax_Code',
REIMBURSABLE: 'Transaction_Duplicate_Reimburable',
BILLABLE: 'Transaction_Duplicate_Billable',
CONFIRMATION: 'Transaction_Duplicate_Confirmation',
},

IOU_SEND: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function MoneyRequestPreviewContent({
} else if ('reimbursable' in comparisonResult.change) {
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_REIMBURSABLE_PAGE.getRoute(route.params?.threadReportID));
} else {
// Navigation to confirm screen will be done in seperate PR
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_CONFIRMATION_PAGE.getRoute(route.params?.threadReportID));
}
};

Expand Down
90 changes: 58 additions & 32 deletions src/components/ReportActionItem/MoneyRequestView.tsx

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/hooks/useReviewDuplicatesNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function useReviewDuplicatesNavigation(stepNames: string[], currentScreenName: S
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_REVIEW_BILLABLE_PAGE.getRoute(threadReportID));
break;
default:
// Navigation to confirm screen will be done in seperate PR
Navigation.navigate(ROUTES.TRANSACTION_DUPLICATE_CONFIRMATION_PAGE.getRoute(threadReportID));
break;
}
};
Expand Down
2 changes: 2 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3684,6 +3684,8 @@ export default {
categoryToKeep: 'Choose which category to keep',
isTransactionBillable: 'Choose if transaction is billable',
keepThisOne: 'Keep this one',
confirmDetails: `Confirm the details you're keeping`,
confirmDuplicatesInfo: `The duplicate requests you don't keep will be held for the member to delete`,
hold: 'Hold',
},
violationDismissal: {
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4194,6 +4194,8 @@ export default {
categoryToKeep: 'Elige qué categoría quieres conservar',
isTransactionBillable: 'Elige si la transacción es facturable',
keepThisOne: 'Mantener éste',
confirmDetails: 'Confirma los detalles que conserva',
confirmDuplicatesInfo: 'Los duplicados que no conserve se guardarán para que el usuario los elimine',
kubabutkiewicz marked this conversation as resolved.
Show resolved Hide resolved
hold: 'Bloqueado',
},
violationDismissal: {
Expand Down
17 changes: 17 additions & 0 deletions src/libs/API/parameters/TransactionMergeParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
type TransactionMergeParams = {
transactionID: string;
transactionIDList: string[];
created: string;
merchant: string;
amount: number;
currency: string;
category: string;
comment: string;
billable: boolean;
reimbursable: boolean;
tag: string;
receiptID: number;
reportID: string;
};

export default TransactionMergeParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export type {default as SearchParams} from './Search';
export type {default as SendInvoiceParams} from './SendInvoiceParams';
export type {default as PayInvoiceParams} from './PayInvoiceParams';
export type {default as MarkAsCashParams} from './MarkAsCashParams';
export type {default as TransactionMergeParams} from './TransactionMergeParams';
export type {default as UpdateSubscriptionTypeParams} from './UpdateSubscriptionTypeParams';
export type {default as SignUpUserParams} from './SignUpUserParams';
export type {default as UpdateSubscriptionAutoRenewParams} from './UpdateSubscriptionAutoRenewParams';
Expand Down
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ const WRITE_COMMANDS = {
SEND_INVOICE: 'SendInvoice',
PAY_INVOICE: 'PayInvoice',
MARK_AS_CASH: 'MarkAsCash',
TRANSACTION_MERGE: 'Transaction_Merge',
UPDATE_SUBSCRIPTION_TYPE: 'UpdateSubscriptionType',
SIGN_UP_USER: 'SignUpUser',
UPDATE_SUBSCRIPTION_AUTO_RENEW: 'UpdateSubscriptionAutoRenew',
Expand Down Expand Up @@ -505,6 +506,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.SEND_INVOICE]: Parameters.SendInvoiceParams;
[WRITE_COMMANDS.PAY_INVOICE]: Parameters.PayInvoiceParams;
[WRITE_COMMANDS.MARK_AS_CASH]: Parameters.MarkAsCashParams;
[WRITE_COMMANDS.TRANSACTION_MERGE]: Parameters.TransactionMergeParams;
[WRITE_COMMANDS.UPDATE_SUBSCRIPTION_TYPE]: Parameters.UpdateSubscriptionTypeParams;
[WRITE_COMMANDS.SIGN_UP_USER]: Parameters.SignUpUserParams;
[WRITE_COMMANDS.UPDATE_SUBSCRIPTION_AUTO_RENEW]: Parameters.UpdateSubscriptionAutoRenewParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ const TransactionDuplicateStackNavigator = createModalStackNavigator<Transaction
[SCREENS.TRANSACTION_DUPLICATE.TAX_CODE]: () => require<ReactComponentModule>('../../../../pages/TransactionDuplicate/ReviewTaxCode').default,
[SCREENS.TRANSACTION_DUPLICATE.BILLABLE]: () => require<ReactComponentModule>('../../../../pages/TransactionDuplicate/ReviewBillable').default,
[SCREENS.TRANSACTION_DUPLICATE.REIMBURSABLE]: () => require<ReactComponentModule>('../../../../pages/TransactionDuplicate/ReviewReimbursable').default,
[SCREENS.TRANSACTION_DUPLICATE.CONFIRMATION]: () => require<ReactComponentModule>('../../../../pages/TransactionDuplicate/Confirmation').default,
});

const SearchReportModalStackNavigator = createModalStackNavigator<SearchReportParamList>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import NoDropZone from '@components/DragAndDrop/NoDropZone';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import {abandonReviewDuplicateTransactions} from '@libs/actions/Transaction';
import {isSafari} from '@libs/Browser';
import ModalNavigatorScreenOptions from '@libs/Navigation/AppNavigator/ModalNavigatorScreenOptions';
import * as ModalStackNavigators from '@libs/Navigation/AppNavigator/ModalStackNavigators';
Expand All @@ -19,7 +20,7 @@ type RightModalNavigatorProps = StackScreenProps<AuthScreensParamList, typeof NA

const Stack = createStackNavigator<RightModalNavigatorParamList>();

function RightModalNavigator({navigation}: RightModalNavigatorProps) {
function RightModalNavigator({navigation, route}: RightModalNavigatorProps) {
const styles = useThemeStyles();
const styleUtils = useStyleUtils();
const {isSmallScreenWidth} = useWindowDimensions();
Expand Down Expand Up @@ -51,6 +52,15 @@ function RightModalNavigator({navigation}: RightModalNavigatorProps) {
<View style={styles.RHPNavigatorContainer(isSmallScreenWidth)}>
<Stack.Navigator
screenOptions={screenOptions}
screenListeners={{
blur: () => {
if (route.params?.screen !== SCREENS.RIGHT_MODAL.TRANSACTION_DUPLICATE) {
return;
}

abandonReviewDuplicateTransactions();
},
}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THis should be documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pecanoro I remember that we were talking about that on the slack, can we add it to doc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sounds good

id={NAVIGATORS.RIGHT_MODAL_NAVIGATOR}
>
<Stack.Screen
Expand Down
4 changes: 4 additions & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,10 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
path: ROUTES.TRANSACTION_DUPLICATE_REVIEW_BILLABLE_PAGE.route,
exact: true,
},
[SCREENS.TRANSACTION_DUPLICATE.CONFIRMATION]: {
path: ROUTES.TRANSACTION_DUPLICATE_CONFIRMATION_PAGE.route,
exact: true,
},
},
},
[SCREENS.RIGHT_MODAL.SPLIT_DETAILS]: {
Expand Down
46 changes: 45 additions & 1 deletion src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {Beta, OnyxInputOrEntry, Policy, RecentWaypoint, ReviewDuplicates, T
import type {Comment, Receipt, TransactionChanges, TransactionPendingFieldsKey, Waypoint, WaypointCollection} from '@src/types/onyx/Transaction';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type {IOURequestType} from './actions/IOU';
import type {TransactionMergeParams} from './API/parameters';
import {isCorporateCard, isExpensifyCard} from './CardUtils';
import {getCurrencyDecimals} from './CurrencyUtils';
import DateUtils from './DateUtils';
Expand Down Expand Up @@ -866,7 +867,20 @@ function compareDuplicateTransactionFields(transactionID: string): {keep: Partia
reimbursable: ['reimbursable'],
};

const getDifferentValues = (items: Array<OnyxEntry<Transaction>>, keys: Array<keyof Transaction>) => [...new Set(items.map((item) => keys.map((key) => item?.[key])).flat())];
const getDifferentValues = (items: Array<OnyxEntry<Transaction>>, keys: Array<keyof Transaction>) => [
...new Set(
items
.map((item) => {
// Prioritize modifiedMerchant over merchant
if (keys.includes('modifiedMerchant' as keyof Transaction) && keys.includes('merchant' as keyof Transaction)) {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
return item?.modifiedMerchant || item?.merchant;
}
return keys.map((key) => item?.[key]);
})
.flat(),
),
];

for (const fieldName in fieldsToCompare) {
if (Object.prototype.hasOwnProperty.call(fieldsToCompare, fieldName)) {
Expand Down Expand Up @@ -913,6 +927,34 @@ function getTransactionID(threadReportID: string): string {
return IOUTransactionID;
}

function buildNewTransactionAfterReviewingDuplicates(reviewDuplicateTransaction: OnyxEntry<ReviewDuplicates>): OnyxEntry<Transaction> {
const originalTransaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${reviewDuplicateTransaction?.transactionID}`] ?? null;
const {duplicates, ...restReviewDuplicateTransaction} = reviewDuplicateTransaction ?? {};

if (!originalTransaction) {
return undefined;
}
return {...originalTransaction, ...restReviewDuplicateTransaction, modifiedMerchant: reviewDuplicateTransaction?.merchant, comment: {comment: reviewDuplicateTransaction?.description}};
}

function buildTransactionsMergeParams(reviewDuplicates: OnyxEntry<ReviewDuplicates>, originalTransaction: OnyxEntry<Transaction>): TransactionMergeParams {
return {
amount: originalTransaction?.modifiedAmount ?? 0,
reportID: originalTransaction?.reportID ?? '',
receiptID: originalTransaction?.receipt?.receiptID ?? 0,
currency: originalTransaction?.currency ?? '',
created: originalTransaction?.created ?? '',
transactionID: reviewDuplicates?.transactionID ?? '',
transactionIDList: reviewDuplicates?.duplicates ?? [],
billable: reviewDuplicates?.billable ?? false,
reimbursable: reviewDuplicates?.reimbursable ?? false,
category: reviewDuplicates?.category ?? '',
tag: reviewDuplicates?.tag ?? '',
merchant: reviewDuplicates?.merchant ?? '',
comment: reviewDuplicates?.description ?? '',
};
}

export {
buildOptimisticTransaction,
calculateTaxAmount,
Expand Down Expand Up @@ -983,6 +1025,8 @@ export {
getTransaction,
compareDuplicateTransactionFields,
getTransactionID,
buildNewTransactionAfterReviewingDuplicates,
buildTransactionsMergeParams,
getReimbursable,
};

Expand Down
72 changes: 72 additions & 0 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
StartSplitBillParams,
SubmitReportParams,
TrackExpenseParams,
TransactionMergeParams,
UnapproveExpenseReportParams,
UpdateMoneyRequestParams,
} from '@libs/API/parameters';
Expand Down Expand Up @@ -7129,6 +7130,76 @@ function getIOURequestPolicyID(transaction: OnyxEntry<OnyxTypes.Transaction>, re
return workspaceSender?.policyID ?? report?.policyID ?? '-1';
}

function mergeDuplicates(params: TransactionMergeParams) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function mergeDuplicates(params: TransactionMergeParams) {
/** Merge several transactions into one by updating the fields of the one we want to keep and deleting the rest */
function mergeDuplicates(params: TransactionMergeParams) {

const originalSelectedTransaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${params.transactionID}`];

const optimisticTransactionData: OnyxUpdate = {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${params.transactionID}`,
value: {
...originalSelectedTransaction,
billable: params.billable,
comment: {
comment: params.comment,
},
category: params.category,
created: params.created,
currency: params.currency,
modifiedMerchant: params.merchant,
reimbursable: params.reimbursable,
tag: params.tag,
},
};

const failureTransactionData: OnyxUpdate = {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${params.transactionID}`,
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
value: originalSelectedTransaction as OnyxTypes.Transaction,
};

const optimisticTransactionDuplicatesData: OnyxUpdate[] = params.transactionIDList.map((id) => ({
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${id}`,
value: null,
}));

const failureTransactionDuplicatesData: OnyxUpdate[] = params.transactionIDList.map((id) => ({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${id}`,
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
value: allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`] as OnyxTypes.Transaction,
}));

const optimisticTransactionViolations: OnyxUpdate[] = [...params.transactionIDList, params.transactionID].map((id) => {
const violations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${id}`] ?? [];
return {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${id}`,
value: violations.filter((violation) => violation.name !== CONST.VIOLATIONS.DUPLICATED_TRANSACTION),
};
});

const failureTransactionViolations: OnyxUpdate[] = [...params.transactionIDList, params.transactionID].map((id) => {
const violations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${id}`] ?? [];
return {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${id}`,
value: violations,
};
});

const optimisticData: OnyxUpdate[] = [];

kubabutkiewicz marked this conversation as resolved.
Show resolved Hide resolved
optimisticData.push(optimisticTransactionData, ...optimisticTransactionDuplicatesData, ...optimisticTransactionViolations);

const failureData: OnyxUpdate[] = [];

kubabutkiewicz marked this conversation as resolved.
Show resolved Hide resolved
failureData.push(failureTransactionData, ...failureTransactionDuplicatesData, ...failureTransactionViolations);
kubabutkiewicz marked this conversation as resolved.
Show resolved Hide resolved

API.write(WRITE_COMMANDS.TRANSACTION_MERGE, params, {optimisticData, failureData});
}

export {
approveMoneyRequest,
unapproveExpenseReport,
Expand Down Expand Up @@ -7195,5 +7266,6 @@ export {
updateMoneyRequestTaxRate,
sendInvoice,
getIOURequestPolicyID,
mergeDuplicates,
};
export type {GPSPoint as GpsPoint, IOURequestType};
18 changes: 17 additions & 1 deletion src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ function setReviewDuplicatesKey(values: Partial<ReviewDuplicates>) {
});
}

function abandonReviewDuplicateTransactions() {
Onyx.set(ONYXKEYS.REVIEW_DUPLICATES, null);
}

function clearError(transactionID: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {errors: null, errorFields: {route: null}});
}
Expand Down Expand Up @@ -438,4 +442,16 @@ function markAsCash(transactionID: string, transactionThreadReportID: string) {
return API.write(WRITE_COMMANDS.MARK_AS_CASH, parameters, onyxData);
}

export {addStop, createInitialWaypoints, saveWaypoint, removeWaypoint, getRoute, updateWaypoints, clearError, markAsCash, dismissDuplicateTransactionViolation, setReviewDuplicatesKey};
export {
addStop,
createInitialWaypoints,
saveWaypoint,
removeWaypoint,
getRoute,
updateWaypoints,
clearError,
markAsCash,
dismissDuplicateTransactionViolation,
setReviewDuplicatesKey,
abandonReviewDuplicateTransactions,
};
Loading
Loading