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

Add RBR to Search action button #52333

Merged
merged 11 commits into from
Dec 12, 2024
Merged
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
7 changes: 5 additions & 2 deletions src/components/SelectionList/Search/ActionCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,19 @@ function ActionCell({
);
}

if (action === CONST.SEARCH.ACTION_TYPES.VIEW || shouldUseViewAction) {
if (action === CONST.SEARCH.ACTION_TYPES.VIEW || action === CONST.SEARCH.ACTION_TYPES.REVIEW || shouldUseViewAction) {
return isLargeScreenWidth ? (
<Button
text={translate(actionTranslationsMap[CONST.SEARCH.ACTION_TYPES.VIEW])}
text={translate(actionTranslationsMap[action])}
onPress={goToItem}
small
style={[styles.w100]}
innerStyles={getButtonInnerStyles(false)}
link={isChildListItem}
shouldUseDefaultHover={!isChildListItem}
icon={!isChildListItem && action === CONST.SEARCH.ACTION_TYPES.REVIEW ? Expensicons.DotIndicator : undefined}
iconFill={theme.danger}
iconHoverFill={theme.dangerHover}
/>
) : null;
}
Expand Down
6 changes: 6 additions & 0 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ function getAction(data: OnyxTypes.SearchResults['data'], key: string): SearchTr
const transaction = isTransaction ? data[key] : undefined;
const report = isTransaction ? data[`${ONYXKEYS.COLLECTION.REPORT}${transaction?.reportID}`] : data[key];

// We need to check both options for a falsy value since the transaction might not have an error but the report associated with it might
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
if (transaction?.hasError || report.hasError) {
return CONST.SEARCH.ACTION_TYPES.REVIEW;
}

if (ReportUtils.isSettled(report)) {
return CONST.SEARCH.ACTION_TYPES.PAID;
}
Expand Down
46 changes: 23 additions & 23 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,52 +237,52 @@ function holdMoneyRequestOnSearch(hash: number, transactionIDList: string[], com
}

function approveMoneyRequestOnSearch(hash: number, reportIDList: string[], transactionIDList?: string[]) {
const createActionLoadingData = (isLoading: boolean): OnyxUpdate[] => [
const createOnyxData = (update: Partial<SearchTransaction> | Partial<SearchReport>): OnyxUpdate[] => [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`,
value: {
data: transactionIDList
? (Object.fromEntries(
transactionIDList.map((transactionID) => [`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {isActionLoading: isLoading}]),
) as Partial<SearchTransaction>)
: (Object.fromEntries(reportIDList.map((reportID) => [`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {isActionLoading: isLoading}])) as Partial<SearchReport>),
? (Object.fromEntries(transactionIDList.map((transactionID) => [`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, update])) as Partial<SearchTransaction>)
: (Object.fromEntries(reportIDList.map((reportID) => [`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, update])) as Partial<SearchReport>),
},
},
];
const optimisticData: OnyxUpdate[] = createActionLoadingData(true);
const finallyData: OnyxUpdate[] = createActionLoadingData(false);
const optimisticData: OnyxUpdate[] = createOnyxData({isActionLoading: true});
const failureData: OnyxUpdate[] = createOnyxData({hasError: true});
const finallyData: OnyxUpdate[] = createOnyxData({isActionLoading: false});

API.write(WRITE_COMMANDS.APPROVE_MONEY_REQUEST_ON_SEARCH, {hash, reportIDList}, {optimisticData, finallyData});
API.write(WRITE_COMMANDS.APPROVE_MONEY_REQUEST_ON_SEARCH, {hash, reportIDList}, {optimisticData, failureData, finallyData});
}

function payMoneyRequestOnSearch(hash: number, paymentData: PaymentData[], transactionIDList?: string[]) {
const createActionLoadingData = (isLoading: boolean): OnyxUpdate[] => [
const createOnyxData = (update: Partial<SearchTransaction> | Partial<SearchReport>): OnyxUpdate[] => [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`,
value: {
data: transactionIDList
? (Object.fromEntries(
transactionIDList.map((transactionID) => [`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {isActionLoading: isLoading}]),
) as Partial<SearchTransaction>)
: (Object.fromEntries(paymentData.map((item) => [`${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`, {isActionLoading: isLoading}])) as Partial<SearchReport>),
? (Object.fromEntries(transactionIDList.map((transactionID) => [`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, update])) as Partial<SearchTransaction>)
: (Object.fromEntries(paymentData.map((item) => [`${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`, update])) as Partial<SearchReport>),
},
},
];

const optimisticData: OnyxUpdate[] = createActionLoadingData(true);
const finallyData: OnyxUpdate[] = createActionLoadingData(false);
const optimisticData: OnyxUpdate[] = createOnyxData({isActionLoading: true});
const failureData: OnyxUpdate[] = createOnyxData({hasError: true});
const finallyData: OnyxUpdate[] = createOnyxData({isActionLoading: false});

// eslint-disable-next-line rulesdir/no-api-side-effects-method
API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.PAY_MONEY_REQUEST_ON_SEARCH, {hash, paymentData: JSON.stringify(paymentData)}, {optimisticData, finallyData}).then(
(response) => {
if (response?.jsonCode !== CONST.JSON_CODE.SUCCESS) {
return;
}
playSound(SOUNDS.SUCCESS);
},
);
API.makeRequestWithSideEffects(
SIDE_EFFECT_REQUEST_COMMANDS.PAY_MONEY_REQUEST_ON_SEARCH,
{hash, paymentData: JSON.stringify(paymentData)},
{optimisticData, failureData, finallyData},
).then((response) => {
if (response?.jsonCode !== CONST.JSON_CODE.SUCCESS) {
return;
}
playSound(SOUNDS.SUCCESS);
});
}

function unholdMoneyRequestOnSearch(hash: number, transactionIDList: string[]) {
Expand Down
6 changes: 6 additions & 0 deletions src/types/onyx/SearchResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ type SearchReport = {

/** Whether the action is loading */
isActionLoading?: boolean;

/** Whether the report has violations or errors */
hasError?: boolean;
};

/** Model of report action search result */
Expand Down Expand Up @@ -344,6 +347,9 @@ type SearchTransaction = {

/** Whether the action is loading */
isActionLoading?: boolean;

/** Whether the transaction has violations or errors */
hasError?: boolean;
};

/** Types of searchable transactions */
Expand Down
Loading