-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add markAsCash button with wired up action for dismissing the rter violation #41835
Changes from 11 commits
00b7a54
f4b356c
011190f
ef73856
c8cb397
6750c63
13e8335
873ae52
a19ce44
bd9efb1
3c619d0
44c1473
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type MarkAsCashParams = { | ||
transactionID: string; | ||
reportActionID: string; | ||
}; | ||
|
||
export default MarkAsCashParams; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,14 @@ import lodashHas from 'lodash/has'; | |
import type {OnyxEntry} from 'react-native-onyx'; | ||
import Onyx from 'react-native-onyx'; | ||
import * as API from '@libs/API'; | ||
import type {GetRouteParams} from '@libs/API/parameters'; | ||
import {READ_COMMANDS} from '@libs/API/types'; | ||
import type {GetRouteParams, MarkAsCashParams} from '@libs/API/parameters'; | ||
import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; | ||
import * as CollectionUtils from '@libs/CollectionUtils'; | ||
import {buildOptimisticDismissedViolationReportAction} from '@libs/ReportUtils'; | ||
import * as TransactionUtils from '@libs/TransactionUtils'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {RecentWaypoint, Transaction} from '@src/types/onyx'; | ||
import type {RecentWaypoint, ReportActions, Transaction, TransactionViolation, TransactionViolations} from '@src/types/onyx'; | ||
import type {OnyxData} from '@src/types/onyx/Request'; | ||
import type {WaypointCollection} from '@src/types/onyx/Transaction'; | ||
|
||
|
@@ -32,6 +33,12 @@ Onyx.connect({ | |
}, | ||
}); | ||
|
||
let allTransactionViolations: TransactionViolations = []; | ||
Onyx.connect({ | ||
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, | ||
callback: (val) => (allTransactionViolations = val ?? []), | ||
}); | ||
|
||
function createInitialWaypoints(transactionID: string) { | ||
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, { | ||
comment: { | ||
|
@@ -264,4 +271,52 @@ function clearError(transactionID: string) { | |
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {errors: null}); | ||
} | ||
|
||
export {addStop, createInitialWaypoints, saveWaypoint, removeWaypoint, getRoute, updateWaypoints, clearError}; | ||
function markAsCash(transactionID: string, transactionThreadReportID: string) { | ||
const optimisticReportAction = buildOptimisticDismissedViolationReportAction({ | ||
reason: 'manual', | ||
violationName: CONST.VIOLATIONS.RTER, | ||
}); | ||
const optimisticReportActions = { | ||
[optimisticReportAction.reportActionID]: optimisticReportAction, | ||
}; | ||
const onyxData: OnyxData = { | ||
optimisticData: [ | ||
// Optimistically dismissing the violation, removing it from the list of violations | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`, | ||
value: allTransactionViolations.filter((violation: TransactionViolation) => violation.name !== CONST.VIOLATIONS.RTER), | ||
}, | ||
// Optimistically adding the system message indicating we dismissed the violation | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, | ||
value: optimisticReportActions as ReportActions, | ||
}, | ||
], | ||
failureData: [ | ||
// Rolling back the dismissal of the violation | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`, | ||
value: allTransactionViolations, | ||
}, | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, | ||
value: { | ||
[optimisticReportAction.reportActionID]: null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just want to make sure: which offline pattern do we follow here? Is it B (Optimistic WITH Feedback Pattern)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's from the other branch that has already been merged, but @yuwenmemon probably has more context regarding this action |
||
}, | ||
}, | ||
], | ||
}; | ||
|
||
const parameters: MarkAsCashParams = { | ||
transactionID, | ||
reportActionID: optimisticReportAction.reportActionID, | ||
}; | ||
|
||
return API.write(WRITE_COMMANDS.MARK_AS_CASH, parameters, onyxData); | ||
} | ||
|
||
export {addStop, createInitialWaypoints, saveWaypoint, removeWaypoint, getRoute, updateWaypoints, clearError, markAsCash}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ import React, {memo, useCallback, useEffect, useMemo, useRef, useState} from 're | |
import {DeviceEventEmitter, InteractionManager} from 'react-native'; | ||
import type {LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent, StyleProp, ViewStyle} from 'react-native'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import Onyx from 'react-native-onyx'; | ||
import Animated, {useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated'; | ||
import InvertedFlatList from '@components/InvertedFlatList'; | ||
import {AUTOSCROLL_TO_TOP_THRESHOLD} from '@components/InvertedFlatList/BaseInvertedFlatList'; | ||
|
@@ -27,7 +26,6 @@ import type {CentralPaneNavigatorParamList} from '@navigation/types'; | |
import variables from '@styles/variables'; | ||
import * as Report from '@userActions/Report'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
import type SCREENS from '@src/SCREENS'; | ||
import type * as OnyxTypes from '@src/types/onyx'; | ||
|
@@ -191,28 +189,6 @@ function ReportActionsList({ | |
const lastVisibleActionCreatedRef = useRef(report.lastVisibleActionCreated); | ||
const lastReadTimeRef = useRef(report.lastReadTime); | ||
// Single MoneyRequest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is showing as a change, because ola removed it in her PR and this branch was based on it |
||
// eslint-disable-next-line rulesdir/prefer-actions-set-data | ||
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}6196867412357270168`, {cardID: 1, merchant: 'single MoneyRequest test'}); | ||
// eslint-disable-next-line rulesdir/prefer-actions-set-data | ||
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}6196867412357270168`, [{type: 'test', name: CONST.VIOLATIONS.RTER, data: {pendingPattern: true}}]); | ||
// Multiple MoneyRequests test | ||
// eslint-disable-next-line rulesdir/prefer-actions-set-data | ||
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}1304796714991934480`, {cardID: 1, merchant: 'multiple MoneyRequests test 1'}); | ||
// eslint-disable-next-line rulesdir/prefer-actions-set-data | ||
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}1304796714991934480`, [{type: 'test', name: CONST.VIOLATIONS.RTER, data: {pendingPattern: true}}]); | ||
// eslint-disable-next-line rulesdir/prefer-actions-set-data | ||
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}6286508495235425496`, {cardID: 1, merchant: 'multiple MoneyRequests test 2'}); | ||
// eslint-disable-next-line rulesdir/prefer-actions-set-data | ||
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}6286508495235425496`, [{type: 'test', name: CONST.VIOLATIONS.RTER, data: {pendingPattern: true}}]); | ||
// eslint-disable-next-line rulesdir/prefer-actions-set-data | ||
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}2150079702326626524`, {cardID: 1, merchant: 'multiple MoneyRequests test 3'}); | ||
// eslint-disable-next-line rulesdir/prefer-actions-set-data | ||
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}2150079702326626524`, [{type: 'test', name: CONST.VIOLATIONS.RTER, data: {pendingPattern: true}}]); | ||
// One-Expense Chat test | ||
// eslint-disable-next-line rulesdir/prefer-actions-set-data | ||
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}2438117170083649063`, {cardID: 1, merchant: 'One-Expense Chat test'}); | ||
// eslint-disable-next-line rulesdir/prefer-actions-set-data | ||
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}2438117170083649063`, [{type: 'test', name: CONST.VIOLATIONS.RTER, data: {pendingPattern: true}}]); | ||
|
||
const sortedVisibleReportActions = useMemo( | ||
() => | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to extract this to a local function because it is used twice and in the last commit only one instance was updated.