From 06043e17fb4f22ab81d846e57b3fb632c52b60ee Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Thu, 28 Dec 2023 02:07:29 +0530 Subject: [PATCH 01/13] WIP v1 --- src/CONST.ts | 6 +++ .../ReportActionItem/ActionItemButttons.tsx | 38 ++++++++++++++++ src/languages/en.ts | 4 ++ src/languages/es.ts | 5 +++ src/libs/Permissions.ts | 2 +- src/libs/actions/Report.ts | 44 +++++++++++++++++++ src/pages/home/report/ReportActionItem.js | 18 ++++++++ src/types/onyx/OriginalMessage.ts | 13 ++++++ 8 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 src/components/ReportActionItem/ActionItemButttons.tsx diff --git a/src/CONST.ts b/src/CONST.ts index 0fc684347243..13792d01449a 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -523,6 +523,7 @@ const CONST = { TASKCOMPLETED: 'TASKCOMPLETED', TASKEDITED: 'TASKEDITED', TASKREOPENED: 'TASKREOPENED', + MENTIONWHISPER: 'ACTIONABLEMENTIONWHISPER', POLICYCHANGELOG: { ADD_APPROVER_RULE: 'POLICYCHANGELOG_ADD_APPROVER_RULE', ADD_BUDGET: 'POLICYCHANGELOG_ADD_BUDGET', @@ -595,6 +596,11 @@ const CONST = { }, }, }, + RESOLUTIONS: { + INVITE: 'invited', + NOTHING: 'nothing', + UNRESOLVED: 'unresolved', + }, ARCHIVE_REASON: { DEFAULT: 'default', ACCOUNT_CLOSED: 'accountClosed', diff --git a/src/components/ReportActionItem/ActionItemButttons.tsx b/src/components/ReportActionItem/ActionItemButttons.tsx new file mode 100644 index 000000000000..77f018d11698 --- /dev/null +++ b/src/components/ReportActionItem/ActionItemButttons.tsx @@ -0,0 +1,38 @@ +import React from 'react'; +import {View} from 'react-native'; +import Button from '@components/Button'; +import useThemeStyles from '@hooks/useThemeStyles'; + +type ActionItem = { + isPrimary: boolean; + key: string; + onPress: () => void; + text: string; +}; + +type ActionItemButttonsProps = { + items: ActionItem[]; +}; + +function ActionItemButttons(props: ActionItemButttonsProps) { + const styles = useThemeStyles(); + + return ( + + {props.items?.map((item) => ( + )} + {lodashGet(props, 'action.actionName', '') === CONST.REPORT.ACTIONS.TYPE.MENTIONWHISPER && !lodashGet(props, 'action.originalMessage.resolution', null) && ( + Report.resolveMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.RESOLUTIONS.INVITE), + isPrimary: true, + }, + { + text: props.translate('actionableWhisperItems.nothing'), + key: 'nothing', + onPress: () => Report.resolveMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.RESOLUTIONS.NOTHING), + }, + ]} + /> + )} ) : ( ; type OriginalMessageApproved = { actionName: typeof CONST.REPORT.ACTIONS.TYPE.APPROVED; @@ -109,6 +110,17 @@ type OriginalMessageAddComment = { }; }; +type OriginalMessageActionableWhisper = { + actionName: typeof CONST.REPORT.ACTIONS.TYPE.MENTIONWHISPER; + originalMessage: { + inviteeAccountIDs: number[]; + inviteeEmails: string; + lastModified: string; + reportID: number; + whisperedTo?: number[]; + }; +}; + type OriginalMessageSubmitted = { actionName: typeof CONST.REPORT.ACTIONS.TYPE.SUBMITTED; originalMessage: unknown; @@ -239,6 +251,7 @@ type OriginalMessage = | OriginalMessageApproved | OriginalMessageIOU | OriginalMessageAddComment + | OriginalMessageActionableWhisper | OriginalMessageSubmitted | OriginalMessageClosed | OriginalMessageCreated From 1ee0a4de857227bd88c9ebc2b32ae20f2d5edf58 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Thu, 28 Dec 2023 02:21:05 +0530 Subject: [PATCH 02/13] lint error fix --- src/libs/Permissions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index 239d790581ba..9cde613ebb5a 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -3,7 +3,7 @@ import CONST from '@src/CONST'; import Beta from '@src/types/onyx/Beta'; function canUseAllBetas(betas: OnyxEntry): boolean { - return true; + return !!betas?.includes(CONST.BETAS.ALL); } function canUseChronos(betas: OnyxEntry): boolean { From dfc4437ced35ece42469ea96b87bf60522f69ec3 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Tue, 2 Jan 2024 12:35:22 +0530 Subject: [PATCH 03/13] clean up --- src/CONST.ts | 3 +-- ...nItemButttons.tsx => ActionItemButtons.tsx} | 8 ++++---- src/languages/en.ts | 2 +- src/languages/es.ts | 7 +++---- src/libs/actions/Report.ts | 8 ++++---- src/pages/home/report/ReportActionItem.js | 18 +++++++++--------- src/types/onyx/OriginalMessage.ts | 6 +++--- 7 files changed, 25 insertions(+), 27 deletions(-) rename src/components/ReportActionItem/{ActionItemButttons.tsx => ActionItemButtons.tsx} (80%) diff --git a/src/CONST.ts b/src/CONST.ts index 13792d01449a..dd0f607ac08c 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -523,7 +523,7 @@ const CONST = { TASKCOMPLETED: 'TASKCOMPLETED', TASKEDITED: 'TASKEDITED', TASKREOPENED: 'TASKREOPENED', - MENTIONWHISPER: 'ACTIONABLEMENTIONWHISPER', + ACTIONABLEMENTIONWHISPER: 'ACTIONABLEMENTIONWHISPER', POLICYCHANGELOG: { ADD_APPROVER_RULE: 'POLICYCHANGELOG_ADD_APPROVER_RULE', ADD_BUDGET: 'POLICYCHANGELOG_ADD_BUDGET', @@ -599,7 +599,6 @@ const CONST = { RESOLUTIONS: { INVITE: 'invited', NOTHING: 'nothing', - UNRESOLVED: 'unresolved', }, ARCHIVE_REASON: { DEFAULT: 'default', diff --git a/src/components/ReportActionItem/ActionItemButttons.tsx b/src/components/ReportActionItem/ActionItemButtons.tsx similarity index 80% rename from src/components/ReportActionItem/ActionItemButttons.tsx rename to src/components/ReportActionItem/ActionItemButtons.tsx index 77f018d11698..0dd4c75b9771 100644 --- a/src/components/ReportActionItem/ActionItemButttons.tsx +++ b/src/components/ReportActionItem/ActionItemButtons.tsx @@ -10,11 +10,11 @@ type ActionItem = { text: string; }; -type ActionItemButttonsProps = { +type ActionItemButtonsProps = { items: ActionItem[]; }; -function ActionItemButttons(props: ActionItemButttonsProps) { +function ActionItemButtons(props: ActionItemButtonsProps) { const styles = useThemeStyles(); return ( @@ -33,6 +33,6 @@ function ActionItemButttons(props: ActionItemButttonsProps) { ); } -ActionItemButttons.displayName = 'ActionItemButtton'; +ActionItemButtons.displayName = 'ActionItemButtton'; -export default ActionItemButttons; +export default ActionItemButtons; diff --git a/src/languages/en.ts b/src/languages/en.ts index e357feb8e3b2..56c9608f2f46 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1931,7 +1931,7 @@ export default { levelTwoResult: 'Message hidden from channel, plus anonymous warning and message is reported for review.', levelThreeResult: 'Message removed from channel plus anonymous warning and message is reported for review.', }, - actionableWhisperItems: { + actionableMentionWhisperOptions: { invite: 'Invite them', nothing: 'Do nothing', }, diff --git a/src/languages/es.ts b/src/languages/es.ts index 5cba65d03f09..73fef57d811a 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -2395,10 +2395,9 @@ export default { copy: 'Copiar', copied: '¡Copiado!', }, - actionableWhisperItems: { - // Todo: ask for translation - invite: 'Invite them', - nothing: 'Do nothing', + actionableMentionWhisperOptions: { + invite: 'Invitar', + nothing: 'No hacer nada', }, moderation: { flagDescription: 'Todos los mensajes marcados se enviarán a un moderador para su revisión.', diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index e7795d750e19..4c6bbe88d36c 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2522,7 +2522,7 @@ function clearNewRoomFormError() { }); } -function resolveMentionWhisper(reportId: string, reportActionID: string, resolution: ValueOf) { +function resolveActionableMentionWhisper(reportId: string, reportActionID: string, resolution: ValueOf) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -2551,12 +2551,12 @@ function resolveMentionWhisper(reportId: string, reportActionID: string, resolut }, ]; - type ResolveMentionWhisperParameters = { + type ResolveActionableMentionWhisperParams = { reportActionID: string; resolution: ValueOf; }; - const parameters: ResolveMentionWhisperParameters = { + const parameters: ResolveActionableMentionWhisperParams = { reportActionID, resolution, }; @@ -2625,5 +2625,5 @@ export { savePrivateNotesDraft, getDraftPrivateNote, clearNewRoomFormError, - resolveMentionWhisper, + resolveActionableMentionWhisper, }; diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 35736d007a04..b86f259695c5 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -17,7 +17,7 @@ import PressableWithSecondaryInteraction from '@components/PressableWithSecondar import EmojiReactionsPropTypes from '@components/Reactions/EmojiReactionsPropTypes'; import ReportActionItemEmojiReactions from '@components/Reactions/ReportActionItemEmojiReactions'; import RenderHTML from '@components/RenderHTML'; -import ActionItemButttons from '@components/ReportActionItem/ActionItemButttons'; +import ActionItemButtons from '@components/ReportActionItem/ActionItemButtons'; import ChronosOOOListActions from '@components/ReportActionItem/ChronosOOOListActions'; import MoneyReportView from '@components/ReportActionItem/MoneyReportView'; import MoneyRequestAction from '@components/ReportActionItem/MoneyRequestAction'; @@ -468,19 +468,19 @@ function ReportActionItem(props) { )} - {lodashGet(props, 'action.actionName', '') === CONST.REPORT.ACTIONS.TYPE.MENTIONWHISPER && !lodashGet(props, 'action.originalMessage.resolution', null) && ( - Report.resolveMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.RESOLUTIONS.INVITE), + text: props.translate('actionableMentionWhisperOptions.invite'), + key: `${props.action.reportActionID}-actionableMentionWhisper-${CONST.REPORT.RESOLUTIONS.INVITE}`, + onPress: () => Report.resolveActionableMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.RESOLUTIONS.INVITE), isPrimary: true, }, { - text: props.translate('actionableWhisperItems.nothing'), - key: 'nothing', - onPress: () => Report.resolveMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.RESOLUTIONS.NOTHING), + text: props.translate('actionableMentionWhisperOptions.nothing'), + key: `${props.action.reportActionID}-actionableMentionWhisper-${CONST.REPORT.RESOLUTIONS.NOTHING}`, + onPress: () => Report.resolveActionableMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.RESOLUTIONS.NOTHING), }, ]} /> diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 8ee10ea88fd8..1f565f5ae251 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -110,8 +110,8 @@ type OriginalMessageAddComment = { }; }; -type OriginalMessageActionableWhisper = { - actionName: typeof CONST.REPORT.ACTIONS.TYPE.MENTIONWHISPER; +type OriginalMessageActionableMentionWhisper = { + actionName: typeof CONST.REPORT.ACTIONS.TYPE.ACTIONABLEMENTIONWHISPER; originalMessage: { inviteeAccountIDs: number[]; inviteeEmails: string; @@ -251,7 +251,7 @@ type OriginalMessage = | OriginalMessageApproved | OriginalMessageIOU | OriginalMessageAddComment - | OriginalMessageActionableWhisper + | OriginalMessageActionableMentionWhisper | OriginalMessageSubmitted | OriginalMessageClosed | OriginalMessageCreated From 241b0fb7d5ada60794dcfffaeda5fac8f0f60582 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Tue, 2 Jan 2024 12:40:57 +0530 Subject: [PATCH 04/13] lint fix --- src/libs/actions/Report.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 4c6bbe88d36c..14f5261b54c4 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2560,6 +2560,7 @@ function resolveActionableMentionWhisper(reportId: string, reportActionID: strin reportActionID, resolution, }; + API.write('ResolveActionableMentionWhisper', parameters, {optimisticData, failureData}); } From 8366b87a2cd6a717bca23f1ea9db38dcaa07783a Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Tue, 2 Jan 2024 12:46:33 +0530 Subject: [PATCH 05/13] prettier diffs --- src/pages/home/report/ReportActionItem.js | 35 ++++++++++++----------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index b86f259695c5..21ce6c33a3a5 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -468,23 +468,24 @@ function ReportActionItem(props) { )} - {lodashGet(props, 'action.actionName', '') === CONST.REPORT.ACTIONS.TYPE.ACTIONABLEMENTIONWHISPER && !lodashGet(props, 'action.originalMessage.resolution', null) && ( - Report.resolveActionableMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.RESOLUTIONS.INVITE), - isPrimary: true, - }, - { - text: props.translate('actionableMentionWhisperOptions.nothing'), - key: `${props.action.reportActionID}-actionableMentionWhisper-${CONST.REPORT.RESOLUTIONS.NOTHING}`, - onPress: () => Report.resolveActionableMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.RESOLUTIONS.NOTHING), - }, - ]} - /> - )} + {lodashGet(props, 'action.actionName', '') === CONST.REPORT.ACTIONS.TYPE.ACTIONABLEMENTIONWHISPER && + !lodashGet(props, 'action.originalMessage.resolution', null) && ( + Report.resolveActionableMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.RESOLUTIONS.INVITE), + isPrimary: true, + }, + { + text: props.translate('actionableMentionWhisperOptions.nothing'), + key: `${props.action.reportActionID}-actionableMentionWhisper-${CONST.REPORT.RESOLUTIONS.NOTHING}`, + onPress: () => Report.resolveActionableMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.RESOLUTIONS.NOTHING), + }, + ]} + /> + )} ) : ( Date: Tue, 2 Jan 2024 19:13:20 +0530 Subject: [PATCH 06/13] added requested changes --- src/CONST.ts | 2 +- ...mButtons.tsx => ActionableItemButtons.tsx} | 21 +++++---- src/libs/ReportActionsUtils.ts | 22 +++++++++ src/libs/actions/Report.ts | 4 +- src/pages/home/report/ReportActionItem.js | 46 +++++++++++-------- src/types/onyx/OriginalMessage.ts | 1 + 6 files changed, 65 insertions(+), 31 deletions(-) rename src/components/ReportActionItem/{ActionItemButtons.tsx => ActionableItemButtons.tsx} (53%) diff --git a/src/CONST.ts b/src/CONST.ts index 8110d63f2cdf..bc3c3c84a41d 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -597,7 +597,7 @@ const CONST = { }, THREAD_DISABLED: ['CREATED'], }, - RESOLUTIONS: { + ACTIONABLE_MENTION_WHISPER_RESOLUTION: { INVITE: 'invited', NOTHING: 'nothing', }, diff --git a/src/components/ReportActionItem/ActionItemButtons.tsx b/src/components/ReportActionItem/ActionableItemButtons.tsx similarity index 53% rename from src/components/ReportActionItem/ActionItemButtons.tsx rename to src/components/ReportActionItem/ActionableItemButtons.tsx index 0dd4c75b9771..8b4775ee34ce 100644 --- a/src/components/ReportActionItem/ActionItemButtons.tsx +++ b/src/components/ReportActionItem/ActionableItemButtons.tsx @@ -1,20 +1,22 @@ import React from 'react'; import {View} from 'react-native'; import Button from '@components/Button'; +import withLocalize, {WithLocalizeProps} from '@components/withLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; +import {TranslationPaths} from '@src/languages/types'; -type ActionItem = { - isPrimary: boolean; +type ActionableItem = { + isPrimary?: boolean; key: string; onPress: () => void; - text: string; + text: TranslationPaths; }; -type ActionItemButtonsProps = { - items: ActionItem[]; +type ActionableItemButtonsProps = WithLocalizeProps & { + items: ActionableItem[]; }; -function ActionItemButtons(props: ActionItemButtonsProps) { +function ActionableItemButtons(props: ActionableItemButtonsProps) { const styles = useThemeStyles(); return ( @@ -24,7 +26,7 @@ function ActionItemButtons(props: ActionItemButtonsProps) { key={item.key} style={[styles.mt2]} onPress={item.onPress} - text={item.text} + text={props.translate(item.text)} small success={item.isPrimary} /> @@ -33,6 +35,7 @@ function ActionItemButtons(props: ActionItemButtonsProps) { ); } -ActionItemButtons.displayName = 'ActionItemButtton'; +ActionableItemButtons.displayName = 'ActionableItemButtton'; -export default ActionItemButtons; +export default withLocalize(ActionableItemButtons); +export type {ActionableItem}; diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 4847eee2c8c6..a3bf5bea1e7c 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -3,12 +3,14 @@ import lodashFindLast from 'lodash/findLast'; import Onyx, {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import OnyxUtils from 'react-native-onyx/lib/utils'; import {ValueOf} from 'type-fest'; +import {ActionableItem} from '@components/ReportActionItem/ActionableItemButtons'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import {ActionName, ChangeLog} from '@src/types/onyx/OriginalMessage'; import Report from '@src/types/onyx/Report'; import ReportAction, {Message, ReportActions} from '@src/types/onyx/ReportAction'; import {EmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject'; +import {resolveActionableMentionWhisper} from './actions/Report'; import * as CollectionUtils from './CollectionUtils'; import * as Environment from './Environment/Environment'; import isReportMessageAttachment from './isReportMessageAttachment'; @@ -776,6 +778,25 @@ function hasRequestFromCurrentAccount(reportID: string, currentAccountID: number return reportActions.some((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.actorAccountID === currentAccountID); } +function getActionableItemButtons(reportAction: ReportAction, reportID: string): ActionableItem[] { + if (!(reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLEMENTIONWHISPER && !reportAction.originalMessage?.resolution)) { + return []; + } + return [ + { + text: 'actionableMentionWhisperOptions.invite', + key: `${reportAction.reportActionID}-actionableMentionWhisper-${CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.INVITE}`, + onPress: () => resolveActionableMentionWhisper(reportID, reportAction.reportActionID, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.INVITE), + isPrimary: true, + }, + { + text: 'actionableMentionWhisperOptions.nothing', + key: `${reportAction.reportActionID}-actionableMentionWhisper-${CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.NOTHING}`, + onPress: () => resolveActionableMentionWhisper(reportID, reportAction.reportActionID, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.NOTHING), + }, + ]; +} + export { extractLinksFromMessageHtml, getAllReportActions, @@ -823,6 +844,7 @@ export { getMemberChangeMessageFragment, getMemberChangeMessagePlainText, isReimbursementDeQueuedAction, + getActionableItemButtons, }; export type {LastVisibleMessage}; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 329211d17f52..ae6da06f61b2 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2546,7 +2546,7 @@ function clearNewRoomFormError() { }); } -function resolveActionableMentionWhisper(reportId: string, reportActionID: string, resolution: ValueOf) { +function resolveActionableMentionWhisper(reportId: string, reportActionID: string, resolution: ValueOf) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -2577,7 +2577,7 @@ function resolveActionableMentionWhisper(reportId: string, reportActionID: strin type ResolveActionableMentionWhisperParams = { reportActionID: string; - resolution: ValueOf; + resolution: ValueOf; }; const parameters: ResolveActionableMentionWhisperParams = { diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 2c7e65ff9119..bc1016f9a434 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -17,7 +17,7 @@ import PressableWithSecondaryInteraction from '@components/PressableWithSecondar import EmojiReactionsPropTypes from '@components/Reactions/EmojiReactionsPropTypes'; import ReportActionItemEmojiReactions from '@components/Reactions/ReportActionItemEmojiReactions'; import RenderHTML from '@components/RenderHTML'; -import ActionItemButtons from '@components/ReportActionItem/ActionItemButtons'; +import ActionableItemButtons from '@components/ReportActionItem/ActionableItemButtons'; import ChronosOOOListActions from '@components/ReportActionItem/ChronosOOOListActions'; import MoneyReportView from '@components/ReportActionItem/MoneyReportView'; import MoneyRequestAction from '@components/ReportActionItem/MoneyRequestAction'; @@ -302,6 +302,25 @@ function ReportActionItem(props) { [props.report, props.action, toggleContextMenuFromActiveReportAction], ); + const actionableItemButtons = useMemo(() => { + if (!(props.action.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLEMENTIONWHISPER && !lodashGet(props.action, 'originalMessage.resolution', null))) { + return []; + } + return [ + { + text: 'actionableMentionWhisperOptions.invite', + key: `${props.action.reportActionID}-actionableMentionWhisper-${CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.INVITE}`, + onPress: () => Report.resolveActionableMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.INVITE), + isPrimary: true, + }, + { + text: 'actionableMentionWhisperOptions.nothing', + key: `${props.action.reportActionID}-actionableMentionWhisper-${CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.NOTHING}`, + onPress: () => Report.resolveActionableMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.NOTHING), + } + ] + }, [props.action, props.report]); + /** * Get the content of ReportActionItem * @param {Boolean} hovered whether the ReportActionItem is hovered @@ -462,24 +481,13 @@ function ReportActionItem(props) { )} - {lodashGet(props, 'action.actionName', '') === CONST.REPORT.ACTIONS.TYPE.ACTIONABLEMENTIONWHISPER && - !lodashGet(props, 'action.originalMessage.resolution', null) && ( - Report.resolveActionableMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.RESOLUTIONS.INVITE), - isPrimary: true, - }, - { - text: props.translate('actionableMentionWhisperOptions.nothing'), - key: `${props.action.reportActionID}-actionableMentionWhisper-${CONST.REPORT.RESOLUTIONS.NOTHING}`, - onPress: () => Report.resolveActionableMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.RESOLUTIONS.NOTHING), - }, - ]} - /> - )} + {/** + These are the actionable buttons that appear at the bottom of a Concierge message + for example: Invite a user mentioned but not a member of the room + https://github.com/Expensify/App/issues/32741 + */} + {actionableItemButtons.length > 0 + && } ) : ( | null; whisperedTo?: number[]; }; }; From 0c931c33a70fad1b935ff3c24821eb2df8bd4a74 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Tue, 2 Jan 2024 19:23:04 +0530 Subject: [PATCH 07/13] clean up --- src/libs/ReportActionsUtils.ts | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index a3bf5bea1e7c..dafb16018016 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -778,25 +778,6 @@ function hasRequestFromCurrentAccount(reportID: string, currentAccountID: number return reportActions.some((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.actorAccountID === currentAccountID); } -function getActionableItemButtons(reportAction: ReportAction, reportID: string): ActionableItem[] { - if (!(reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ACTIONABLEMENTIONWHISPER && !reportAction.originalMessage?.resolution)) { - return []; - } - return [ - { - text: 'actionableMentionWhisperOptions.invite', - key: `${reportAction.reportActionID}-actionableMentionWhisper-${CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.INVITE}`, - onPress: () => resolveActionableMentionWhisper(reportID, reportAction.reportActionID, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.INVITE), - isPrimary: true, - }, - { - text: 'actionableMentionWhisperOptions.nothing', - key: `${reportAction.reportActionID}-actionableMentionWhisper-${CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.NOTHING}`, - onPress: () => resolveActionableMentionWhisper(reportID, reportAction.reportActionID, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.NOTHING), - }, - ]; -} - export { extractLinksFromMessageHtml, getAllReportActions, @@ -844,7 +825,6 @@ export { getMemberChangeMessageFragment, getMemberChangeMessagePlainText, isReimbursementDeQueuedAction, - getActionableItemButtons, }; export type {LastVisibleMessage}; From 8bfe553c31efa94bb288029de0b443f42cc5d634 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Tue, 2 Jan 2024 19:26:31 +0530 Subject: [PATCH 08/13] lint fix remove unused imports --- src/libs/ReportActionsUtils.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index dafb16018016..4847eee2c8c6 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -3,14 +3,12 @@ import lodashFindLast from 'lodash/findLast'; import Onyx, {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import OnyxUtils from 'react-native-onyx/lib/utils'; import {ValueOf} from 'type-fest'; -import {ActionableItem} from '@components/ReportActionItem/ActionableItemButtons'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import {ActionName, ChangeLog} from '@src/types/onyx/OriginalMessage'; import Report from '@src/types/onyx/Report'; import ReportAction, {Message, ReportActions} from '@src/types/onyx/ReportAction'; import {EmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject'; -import {resolveActionableMentionWhisper} from './actions/Report'; import * as CollectionUtils from './CollectionUtils'; import * as Environment from './Environment/Environment'; import isReportMessageAttachment from './isReportMessageAttachment'; From 017b4fab7adae001d6cfeb5e1df22a4a122a01ce Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Tue, 2 Jan 2024 19:55:09 +0530 Subject: [PATCH 09/13] prettier diffs --- src/pages/home/report/ReportActionItem.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index bc1016f9a434..33e2134a5a80 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -317,8 +317,8 @@ function ReportActionItem(props) { text: 'actionableMentionWhisperOptions.nothing', key: `${props.action.reportActionID}-actionableMentionWhisper-${CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.NOTHING}`, onPress: () => Report.resolveActionableMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.NOTHING), - } - ] + }, + ]; }, [props.action, props.report]); /** @@ -486,8 +486,7 @@ function ReportActionItem(props) { for example: Invite a user mentioned but not a member of the room https://github.com/Expensify/App/issues/32741 */} - {actionableItemButtons.length > 0 - && } + {actionableItemButtons.length > 0 && } ) : ( Date: Thu, 4 Jan 2024 11:55:40 +0530 Subject: [PATCH 10/13] added requested changes --- src/libs/actions/Report.ts | 20 ++++++++++++++++---- src/pages/home/report/ReportActionItem.js | 11 ++++++++--- src/types/onyx/ReportAction.ts | 3 +++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index ae6da06f61b2..1ec6838cd491 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2546,13 +2546,24 @@ function clearNewRoomFormError() { }); } -function resolveActionableMentionWhisper(reportId: string, reportActionID: string, resolution: ValueOf) { +function resolveActionableMentionWhisper(reportId: string, reportAction: OnyxEntry, resolution: ValueOf) { + const message = reportAction?.message?.[0]; + if (!message) { + return; + } + + const updatedMessage: Message = { + ...message, + resolution, + }; + const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportId}`, value: { - [reportActionID]: { + [reportAction.reportActionID]: { + message: [updatedMessage], originalMessage: { resolution, }, @@ -2566,7 +2577,8 @@ function resolveActionableMentionWhisper(reportId: string, reportActionID: strin onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportId}`, value: { - [reportActionID]: { + [reportAction.reportActionID]: { + message: [message], originalMessage: { resolution: null, }, @@ -2581,7 +2593,7 @@ function resolveActionableMentionWhisper(reportId: string, reportActionID: strin }; const parameters: ResolveActionableMentionWhisperParams = { - reportActionID, + reportActionID: reportAction.reportActionID, resolution, }; diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 33e2134a5a80..08d5447067f3 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -310,13 +310,13 @@ function ReportActionItem(props) { { text: 'actionableMentionWhisperOptions.invite', key: `${props.action.reportActionID}-actionableMentionWhisper-${CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.INVITE}`, - onPress: () => Report.resolveActionableMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.INVITE), + onPress: () => Report.resolveActionableMentionWhisper(props.report.reportID, props.action, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.INVITE), isPrimary: true, }, { text: 'actionableMentionWhisperOptions.nothing', key: `${props.action.reportActionID}-actionableMentionWhisper-${CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.NOTHING}`, - onPress: () => Report.resolveActionableMentionWhisper(props.report.reportID, props.action.reportActionID, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.NOTHING), + onPress: () => Report.resolveActionableMentionWhisper(props.report.reportID, props.action, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.NOTHING), }, ]; }, [props.action, props.report]); @@ -486,7 +486,12 @@ function ReportActionItem(props) { for example: Invite a user mentioned but not a member of the room https://github.com/Expensify/App/issues/32741 */} - {actionableItemButtons.length > 0 && } + {actionableItemButtons.length > 0 && ( + + )} ) : ( | null; }; type ImageMetadata = { From 2d75fb8fdbf1bc5f33bc4e4fe1286890c971ec49 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Sat, 6 Jan 2024 10:00:00 +0530 Subject: [PATCH 11/13] fix lint --- .../ReportActionItem/ActionableItemButtons.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/ReportActionItem/ActionableItemButtons.tsx b/src/components/ReportActionItem/ActionableItemButtons.tsx index 8b4775ee34ce..d78d7d7c48b9 100644 --- a/src/components/ReportActionItem/ActionableItemButtons.tsx +++ b/src/components/ReportActionItem/ActionableItemButtons.tsx @@ -1,9 +1,9 @@ import React from 'react'; import {View} from 'react-native'; import Button from '@components/Button'; -import withLocalize, {WithLocalizeProps} from '@components/withLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import {TranslationPaths} from '@src/languages/types'; +import useLocalize from '@hooks/useLocalize'; type ActionableItem = { isPrimary?: boolean; @@ -12,12 +12,13 @@ type ActionableItem = { text: TranslationPaths; }; -type ActionableItemButtonsProps = WithLocalizeProps & { +type ActionableItemButtonsProps = { items: ActionableItem[]; }; function ActionableItemButtons(props: ActionableItemButtonsProps) { const styles = useThemeStyles(); + const {translate} = useLocalize(); return ( @@ -26,7 +27,7 @@ function ActionableItemButtons(props: ActionableItemButtonsProps) { key={item.key} style={[styles.mt2]} onPress={item.onPress} - text={props.translate(item.text)} + text={translate(item.text)} small success={item.isPrimary} /> @@ -37,5 +38,5 @@ function ActionableItemButtons(props: ActionableItemButtonsProps) { ActionableItemButtons.displayName = 'ActionableItemButtton'; -export default withLocalize(ActionableItemButtons); +export default ActionableItemButtons; export type {ActionableItem}; From 9856e91256d4d262da9593256171e416cdcbd7ad Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Sat, 6 Jan 2024 10:03:13 +0530 Subject: [PATCH 12/13] fix lint --- src/components/ReportActionItem/ActionableItemButtons.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/ActionableItemButtons.tsx b/src/components/ReportActionItem/ActionableItemButtons.tsx index d78d7d7c48b9..86407ae0000f 100644 --- a/src/components/ReportActionItem/ActionableItemButtons.tsx +++ b/src/components/ReportActionItem/ActionableItemButtons.tsx @@ -2,7 +2,7 @@ import React from 'react'; import {View} from 'react-native'; import Button from '@components/Button'; import useThemeStyles from '@hooks/useThemeStyles'; -import {TranslationPaths} from '@src/languages/types'; +import type {TranslationPaths} from '@src/languages/types'; import useLocalize from '@hooks/useLocalize'; type ActionableItem = { From 5d42ef7a42b37ddd97c51eada30c518f48186f65 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Sat, 6 Jan 2024 11:29:49 +0530 Subject: [PATCH 13/13] fix lint --- src/components/ReportActionItem/ActionableItemButtons.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/ActionableItemButtons.tsx b/src/components/ReportActionItem/ActionableItemButtons.tsx index 86407ae0000f..d1f169d2f409 100644 --- a/src/components/ReportActionItem/ActionableItemButtons.tsx +++ b/src/components/ReportActionItem/ActionableItemButtons.tsx @@ -1,9 +1,9 @@ import React from 'react'; import {View} from 'react-native'; import Button from '@components/Button'; +import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import type {TranslationPaths} from '@src/languages/types'; -import useLocalize from '@hooks/useLocalize'; type ActionableItem = { isPrimary?: boolean;