Skip to content

Commit

Permalink
Merge pull request #52333 from Expensify/cmartins-addRBR
Browse files Browse the repository at this point in the history
Add RBR to Search action button
  • Loading branch information
arosiclair authored Dec 12, 2024
2 parents 7bde2de + 5b5c07a commit c2285e6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 25 deletions.
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 @@ -273,52 +273,52 @@ function submitMoneyRequestOnSearch(hash: number, reportList: SearchReport[], po
}

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 @@ -359,6 +362,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

0 comments on commit c2285e6

Please sign in to comment.