Skip to content

Commit 8227110

Browse files
committed
refactor: add ConfirmWhisperContent
1 parent 735d6a6 commit 8227110

5 files changed

Lines changed: 83 additions & 42 deletions

File tree

src/libs/actions/Report/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5312,7 +5312,7 @@ function resolveActionableMentionWhisper(
53125312

53135313
function resolveActionableMentionConfirmWhisper(
53145314
report: OnyxEntry<Report>,
5315-
reportAction: OnyxEntry<ReportAction>,
5315+
reportAction: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_MENTION_INVITE_TO_SUBMIT_EXPENSE_CONFIRM_WHISPER>,
53165316
resolution: ValueOf<typeof CONST.REPORT.ACTIONABLE_MENTION_INVITE_TO_SUBMIT_EXPENSE_CONFIRM_WHISPER>,
53175317
isReportArchived: boolean,
53185318
) {

src/pages/inbox/report/PureReportActionItem.tsx

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,7 @@ import variables from '@styles/variables';
236236
import {openPersonalBankAccountSetupView} from '@userActions/BankAccounts';
237237
import type {IgnoreDirection} from '@userActions/ClearReportActionErrors';
238238
import {hideEmojiPicker, isActive} from '@userActions/EmojiPickerAction';
239-
import {
240-
createTransactionThreadReport,
241-
expandURLPreview,
242-
resolveActionableMentionConfirmWhisper,
243-
resolveConciergeCategoryOptions,
244-
resolveConciergeDescriptionOptions,
245-
} from '@userActions/Report';
239+
import {createTransactionThreadReport, expandURLPreview, resolveConciergeCategoryOptions, resolveConciergeDescriptionOptions} from '@userActions/Report';
246240
import {isAnonymousUser, signOutAndRedirectToSignIn} from '@userActions/Session';
247241
import {isBlockedFromConcierge} from '@userActions/User';
248242
import CONST from '@src/CONST';
@@ -252,6 +246,7 @@ import type SCREENS from '@src/SCREENS';
252246
import type * as OnyxTypes from '@src/types/onyx';
253247
import type {Errors} from '@src/types/onyx/OnyxCommon';
254248
import {isEmptyObject, isEmptyValueObject} from '@src/types/utils/EmptyObject';
249+
import ConfirmWhisperContent from './actionContents/ConfirmWhisperContent';
255250
import FraudAlertContent from './actionContents/FraudAlertContent';
256251
import JoinRequestContent from './actionContents/JoinRequestContent';
257252
import MentionWhisperContent from './actionContents/MentionWhisperContent';
@@ -585,9 +580,8 @@ function PureReportActionItem({
585580
const prevDraftMessage = usePrevious(draftMessage);
586581
const isReportActionLinked = linkedReportActionID && action.reportActionID && linkedReportActionID === action.reportActionID;
587582
const [isReportActionActive, setIsReportActionActive] = useState(!!isReportActionLinked);
588-
const isActionableWhisper = isActionableMentionInviteToSubmitExpenseConfirmWhisper(action) || isActionableTrackExpense(action);
589583
const isReportArchived = useReportIsArchived(reportID);
590-
const isOriginalReportArchived = useReportIsArchived(originalReportID);
584+
591585
const isHarvestCreatedExpenseReport = isHarvestCreatedExpenseReportUtils(reportNameValuePairsOrigin, reportNameValuePairsOriginalID);
592586
const expensifyIcons = useMemoizedLazyExpensifyIcons(['Eye']);
593587
const {environmentURL} = useEnvironment();
@@ -949,12 +943,8 @@ function PureReportActionItem({
949943
}
950944
}
951945

952-
if (!isActionableWhisper) {
953-
return [];
954-
}
955-
956-
const reportActionReportID = originalReportID ?? reportID;
957946
if (isActionableTrackExpense(action)) {
947+
const reportActionReportID = originalReportID ?? reportID;
958948
const options = [
959949
{
960950
text: 'actionableMentionTrackExpense.submit',
@@ -1034,38 +1024,19 @@ function PureReportActionItem({
10341024
return options;
10351025
}
10361026

1037-
if (isActionableMentionInviteToSubmitExpenseConfirmWhisper(action)) {
1038-
return [
1039-
{
1040-
text: 'common.buttonConfirm',
1041-
key: `${action.reportActionID}-actionableReportMentionConfirmWhisper-${CONST.REPORT.ACTIONABLE_MENTION_INVITE_TO_SUBMIT_EXPENSE_CONFIRM_WHISPER.DONE}`,
1042-
onPress: () =>
1043-
resolveActionableMentionConfirmWhisper(
1044-
reportActionReport,
1045-
action,
1046-
CONST.REPORT.ACTIONABLE_MENTION_INVITE_TO_SUBMIT_EXPENSE_CONFIRM_WHISPER.DONE,
1047-
isOriginalReportArchived,
1048-
),
1049-
isPrimary: true,
1050-
},
1051-
];
1052-
}
1053-
10541027
return [];
10551028
}, [
10561029
action,
10571030
userBillingFundID,
10581031
originalReportID,
10591032
reportID,
1060-
isActionableWhisper,
10611033
currentUserAccountID,
10621034
currentUserEmail,
10631035
personalDetail.timezone,
10641036
createDraftTransactionAndNavigateToParticipantSelector,
10651037
isRestrictedToPreferredPolicy,
10661038
preferredPolicyID,
10671039
dismissTrackExpenseActionableWhisper,
1068-
isOriginalReportArchived,
10691040
introSelected,
10701041
draftTransactionIDs,
10711042
activePolicy,
@@ -1586,7 +1557,7 @@ function PureReportActionItem({
15861557
policy={policy}
15871558
currentUserAccountID={currentUserAccountID}
15881559
personalPolicyID={personalPolicyID}
1589-
isOriginalReportArchived={isOriginalReportArchived}
1560+
originalReportID={originalReportID}
15901561
resolveActionableMentionWhisper={resolveActionableMentionWhisper}
15911562
/>
15921563
);
@@ -1601,6 +1572,16 @@ function PureReportActionItem({
16011572
resolveActionableReportMentionWhisper={resolveActionableReportMentionWhisper}
16021573
/>
16031574
);
1575+
} else if (isActionableMentionInviteToSubmitExpenseConfirmWhisper(action)) {
1576+
children = (
1577+
<ConfirmWhisperContent
1578+
action={action}
1579+
reportID={reportID}
1580+
report={report}
1581+
originalReport={originalReport}
1582+
originalReportID={originalReportID}
1583+
/>
1584+
);
16041585
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.LEAVE_ROOM) || isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.LEAVE_ROOM)) {
16051586
children = <ReportActionItemBasicMessage message={translate('report.actions.type.leftTheChat')} />;
16061587
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.DEMOTED_FROM_WORKSPACE)) {
@@ -1765,11 +1746,6 @@ function PureReportActionItem({
17651746
</Text>
17661747
</Button>
17671748
)}
1768-
{/**
1769-
These are the actionable buttons that appear at the bottom of a Concierge message
1770-
for example: Invite a user mentioned but not a member of the room
1771-
https://github.com/Expensify/App/issues/32741
1772-
*/}
17731749
{actionableItemButtons.length > 0 && (
17741750
<ActionableItemButtons
17751751
items={actionableItemButtons}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from 'react';
2+
import {View} from 'react-native';
3+
import type {OnyxEntry} from 'react-native-onyx';
4+
import type {ActionableItem} from '@components/ReportActionItem/ActionableItemButtons';
5+
import ActionableItemButtons from '@components/ReportActionItem/ActionableItemButtons';
6+
import useReportIsArchived from '@hooks/useReportIsArchived';
7+
import {resolveActionableMentionConfirmWhisper} from '@libs/actions/Report';
8+
import ReportActionItemMessage from '@pages/inbox/report/ReportActionItemMessage';
9+
import CONST from '@src/CONST';
10+
import type {Report, ReportAction} from '@src/types/onyx';
11+
12+
type ConfirmWhisperContentProps = {
13+
action: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_MENTION_INVITE_TO_SUBMIT_EXPENSE_CONFIRM_WHISPER>;
14+
reportID: string | undefined;
15+
originalReportID: string | undefined;
16+
report: OnyxEntry<Report>;
17+
originalReport: OnyxEntry<Report>;
18+
};
19+
20+
function ConfirmWhisperContent({action, reportID, originalReportID, report, originalReport}: ConfirmWhisperContentProps) {
21+
const reportActionReport = originalReport ?? report;
22+
const isOriginalReportArchived = useReportIsArchived(originalReportID);
23+
24+
const buttons: ActionableItem[] = [
25+
{
26+
text: 'common.buttonConfirm',
27+
key: `${action.reportActionID}-actionableReportMentionConfirmWhisper-${CONST.REPORT.ACTIONABLE_MENTION_INVITE_TO_SUBMIT_EXPENSE_CONFIRM_WHISPER.DONE}`,
28+
onPress: () =>
29+
resolveActionableMentionConfirmWhisper(reportActionReport, action, CONST.REPORT.ACTIONABLE_MENTION_INVITE_TO_SUBMIT_EXPENSE_CONFIRM_WHISPER.DONE, isOriginalReportArchived),
30+
isPrimary: true,
31+
},
32+
];
33+
34+
return (
35+
<View>
36+
<ReportActionItemMessage
37+
action={action}
38+
reportID={reportID}
39+
displayAsGroup
40+
/>
41+
<ActionableItemButtons
42+
items={buttons}
43+
shouldUseLocalization
44+
layout="horizontal"
45+
/>
46+
</View>
47+
);
48+
}
49+
50+
ConfirmWhisperContent.displayName = 'ConfirmWhisperContent';
51+
52+
export default ConfirmWhisperContent;

src/pages/inbox/report/actionContents/MentionWhisperContent.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import RenderHTML from '@components/RenderHTML';
55
import type {ActionableItem} from '@components/ReportActionItem/ActionableItemButtons';
66
import ActionableItemButtons from '@components/ReportActionItem/ActionableItemButtons';
77
import useLocalize from '@hooks/useLocalize';
8+
import useReportIsArchived from '@hooks/useReportIsArchived';
89
import {isPolicyAdmin, isPolicyMember, isPolicyOwner} from '@libs/PolicyUtils';
910
import {getActionableMentionWhisperMessage, getOriginalMessage, isSystemUserMentioned} from '@libs/ReportActionsUtils';
1011
import ReportActionItemBasicMessage from '@pages/inbox/report/ReportActionItemBasicMessage';
@@ -18,7 +19,7 @@ type MentionWhisperContentProps = {
1819
policy: OnyxEntry<Policy>;
1920
currentUserAccountID: number;
2021
personalPolicyID: string | undefined;
21-
isOriginalReportArchived: boolean;
22+
originalReportID: string | undefined;
2223
resolveActionableMentionWhisper: (
2324
report: OnyxEntry<Report>,
2425
reportAction: OnyxEntry<ReportAction>,
@@ -34,10 +35,11 @@ function MentionWhisperContent({
3435
policy,
3536
currentUserAccountID,
3637
personalPolicyID,
37-
isOriginalReportArchived,
38+
originalReportID,
3839
resolveActionableMentionWhisper,
3940
}: MentionWhisperContentProps) {
4041
const {translate} = useLocalize();
42+
const isOriginalReportArchived = useReportIsArchived(originalReportID);
4143

4244
const reportActionReport = originalReport ?? report;
4345
const reportPolicyID = report?.policyID;

tests/ui/PureReportActionItemTest.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,17 @@ describe('PureReportActionItem', () => {
20102010
expect(screen.getByText(translateLocal('common.no'))).toBeOnTheScreen();
20112011
});
20122012

2013+
it('isActionableMentionInviteToSubmitExpenseConfirmWhisper renders message and confirm button', async () => {
2014+
const action = createReportAction(CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_MENTION_INVITE_TO_SUBMIT_EXPENSE_CONFIRM_WHISPER, {});
2015+
const messageText = "Great, you chose to invite them to the workspace! I've invited user and they'll submit expenses in their expense chat.";
2016+
action.message = [{type: 'COMMENT', html: messageText, text: messageText}];
2017+
renderItemWithAction(action);
2018+
await waitForBatchedUpdatesWithAct();
2019+
2020+
expect(screen.getByText(/Great, you chose to invite them/)).toBeOnTheScreen();
2021+
expect(screen.getByText(translateLocal('common.buttonConfirm'))).toBeOnTheScreen();
2022+
});
2023+
20132024
it('isCardIssuedAction renders card issued message', async () => {
20142025
const action = createReportAction(CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED, {});
20152026
renderItemWithAction(action);

0 commit comments

Comments
 (0)