From 89d3363a081a046ee797861a96a8416d6a7af6e1 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 5 Jul 2023 10:09:37 +0700 Subject: [PATCH 01/10] accept the anonymous user go to share code page --- src/components/MenuItem.js | 3 ++- src/components/menuItemPropTypes.js | 3 +++ src/libs/actions/Session/index.js | 4 ++-- src/pages/ReportDetailsPage.js | 6 +++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/components/MenuItem.js b/src/components/MenuItem.js index a59dd6d7b971..6ccae8f5bcb6 100644 --- a/src/components/MenuItem.js +++ b/src/components/MenuItem.js @@ -67,6 +67,7 @@ const defaultProps = { hoverAndPressStyle: [], furtherDetails: '', furtherDetailsIcon: undefined, + isAnonymousAction: false }; function MenuItem(props) { @@ -109,7 +110,7 @@ function MenuItem(props) { } props.onPress(e); - })} + }, props.isAnonymousAction)} onPressIn={() => props.shouldBlockSelection && props.isSmallScreenWidth && DeviceCapabilities.canUseTouchScreen() && ControlSelection.block()} onPressOut={ControlSelection.unblock} onSecondaryInteraction={props.onSecondaryInteraction} diff --git a/src/components/menuItemPropTypes.js b/src/components/menuItemPropTypes.js index 3909f446c907..4a0d2e9accea 100644 --- a/src/components/menuItemPropTypes.js +++ b/src/components/menuItemPropTypes.js @@ -119,6 +119,9 @@ const propTypes = { /** An icon to display under the main item */ furtherDetailsIcon: PropTypes.oneOfType([PropTypes.elementType, PropTypes.string]), + + /** The action accept for anonymous user or not */ + isAnonymousAction: PropTypes.bool }; export default propTypes; diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index b1671cc46f7d..fac9e6c9246d 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -108,8 +108,8 @@ function signOutAndRedirectToSignIn() { * @param {Function} callback The callback to execute if the action is allowed * @returns {Function} same callback if the action is allowed, otherwise a function that signs out and redirects to sign in */ -function checkIfActionIsAllowed(callback) { - if (isAnonymousUser()) { +function checkIfActionIsAllowed(callback, isAnonymousAction = false) { + if (isAnonymousUser() && !isAnonymousAction) { return () => signOutAndRedirectToSignIn(); } return callback; diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index cb727d9e3eae..751c85db5dcc 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -78,6 +78,7 @@ function ReportDetailsPage(props) { key: CONST.REPORT_DETAILS_MENU_ITEM.SHARE_CODE, translationKey: 'common.shareCode', icon: Expensicons.QrCode, + isAnonymousAction: true, action: () => Navigation.navigate(ROUTES.getReportShareCodeRoute(props.report.reportID)), }, ]; @@ -121,6 +122,8 @@ function ReportDetailsPage(props) { return items; }, [props.report.reportID, participants, isArchivedRoom, isPolicyExpenseChat, isChatRoom, isThread, isUserCreatedPolicyRoom, canLeaveRoom]); + console.log("123") + const displayNamesWithTooltips = useMemo(() => { const hasMultipleParticipants = participants.length > 1; return ReportUtils.getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs(participants, props.personalDetails), hasMultipleParticipants); @@ -179,7 +182,8 @@ function ReportDetailsPage(props) { title={props.translate(item.translationKey)} subtitle={item.subtitle} icon={item.icon} - onPress={Session.checkIfActionIsAllowed(item.action)} + onPress={item.action} + isAnonymousAction={item.isAnonymousAction || false} shouldShowRightIcon brickRoadIndicator={brickRoadIndicator} /> From 238bbc70a05a7ee368a06ff16a144e7c79329f8c Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 6 Jul 2023 10:54:29 +0700 Subject: [PATCH 02/10] add anonymous action --- src/pages/ReportDetailsPage.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index 39d3de25c281..925e0e42274f 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -93,6 +93,7 @@ function ReportDetailsPage(props) { translationKey: 'common.members', icon: Expensicons.Users, subtitle: participants.length, + isAnonymousAction: false, action: () => { Navigation.navigate(ROUTES.getReportParticipantsRoute(props.report.reportID)); }, @@ -104,6 +105,7 @@ function ReportDetailsPage(props) { key: CONST.REPORT_DETAILS_MENU_ITEM.SETTINGS, translationKey: 'common.settings', icon: Expensicons.Gear, + isAnonymousAction: false, action: () => { Navigation.navigate(ROUTES.getReportSettingsRoute(props.report.reportID)); }, @@ -115,6 +117,7 @@ function ReportDetailsPage(props) { key: CONST.REPORT_DETAILS_MENU_ITEM.LEAVE_ROOM, translationKey: isThread ? 'common.leaveThread' : 'common.leaveRoom', icon: Expensicons.Exit, + isAnonymousAction: false, action: () => Report.leaveRoom(props.report.reportID), }); } @@ -183,7 +186,7 @@ function ReportDetailsPage(props) { subtitle={item.subtitle} icon={item.icon} onPress={item.action} - isAnonymousAction={item.isAnonymousAction || false} + isAnonymousAction={item.isAnonymousAction} shouldShowRightIcon brickRoadIndicator={brickRoadIndicator} /> From 0979f31ef062d53dacaccb339676065011bdc366 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 6 Jul 2023 11:06:23 +0700 Subject: [PATCH 03/10] fix lint --- src/pages/ReportDetailsPage.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index 925e0e42274f..e65307c6322c 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -17,7 +17,6 @@ import * as OptionsListUtils from '../libs/OptionsListUtils'; import * as ReportUtils from '../libs/ReportUtils'; import * as PolicyUtils from '../libs/PolicyUtils'; import * as Report from '../libs/actions/Report'; -import * as Session from '../libs/actions/Session'; import participantPropTypes from '../components/participantPropTypes'; import * as Expensicons from '../components/Icon/Expensicons'; import ROUTES from '../ROUTES'; @@ -125,8 +124,6 @@ function ReportDetailsPage(props) { return items; }, [props.report.reportID, participants, isArchivedRoom, isPolicyExpenseChat, isChatRoom, isThread, isUserCreatedPolicyRoom, canLeaveRoom]); - console.log("123") - const displayNamesWithTooltips = useMemo(() => { const hasMultipleParticipants = participants.length > 1; return ReportUtils.getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs(participants, props.personalDetails), hasMultipleParticipants); From 20e1b0813cf7f02bc8db598e98f47c230e4d4f1c Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 6 Jul 2023 11:11:52 +0700 Subject: [PATCH 04/10] add JSDoc for parameter isAnonymousAction --- src/libs/actions/Session/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index fac9e6c9246d..628fac4d08b8 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -106,6 +106,7 @@ function signOutAndRedirectToSignIn() { /** * @param {Function} callback The callback to execute if the action is allowed + * @param {Boolean} isAnonymousAction The action is allowed for anonymous or not * @returns {Function} same callback if the action is allowed, otherwise a function that signs out and redirects to sign in */ function checkIfActionIsAllowed(callback, isAnonymousAction = false) { From 62d61aa6c264ae31263c390ed41876920ae197e8 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 6 Jul 2023 11:16:07 +0700 Subject: [PATCH 05/10] format code --- src/components/MenuItem.js | 2 +- src/components/menuItemPropTypes.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/MenuItem.js b/src/components/MenuItem.js index 6ccae8f5bcb6..8a5c8cad06e0 100644 --- a/src/components/MenuItem.js +++ b/src/components/MenuItem.js @@ -67,7 +67,7 @@ const defaultProps = { hoverAndPressStyle: [], furtherDetails: '', furtherDetailsIcon: undefined, - isAnonymousAction: false + isAnonymousAction: false, }; function MenuItem(props) { diff --git a/src/components/menuItemPropTypes.js b/src/components/menuItemPropTypes.js index 4a0d2e9accea..695b974c423c 100644 --- a/src/components/menuItemPropTypes.js +++ b/src/components/menuItemPropTypes.js @@ -121,7 +121,7 @@ const propTypes = { furtherDetailsIcon: PropTypes.oneOfType([PropTypes.elementType, PropTypes.string]), /** The action accept for anonymous user or not */ - isAnonymousAction: PropTypes.bool + isAnonymousAction: PropTypes.bool, }; export default propTypes; From f985777d2c76b8463bb8aa8a02f6b0d3851411ab Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 11 Jul 2023 21:06:35 +0700 Subject: [PATCH 06/10] add anonymous action for context menu --- src/components/menuItemPropTypes.js | 2 +- .../ContextMenu/BaseReportActionContextMenu.js | 9 +++++---- .../home/report/ContextMenu/ContextMenuActions.js | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/components/menuItemPropTypes.js b/src/components/menuItemPropTypes.js index ac4db3b44ded..2a9398c96554 100644 --- a/src/components/menuItemPropTypes.js +++ b/src/components/menuItemPropTypes.js @@ -125,7 +125,7 @@ const propTypes = { /** The action accept for anonymous user or not */ isAnonymousAction: PropTypes.bool, - + /** Whether we should use small avatar subscript sizing the for menu item */ isSmallAvatarSubscriptMenu: PropTypes.bool, diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js index 0a1846cfb324..f3304356c2d2 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js @@ -66,13 +66,14 @@ class BaseReportActionContextMenu extends React.Component { ); /** - * Checks if user is anonymous. If true, hides the context menu and + * Checks if user is anonymous. If true and the action doesn't accept for anonymous user, hides the context menu and * shows the sign in modal. Else, executes the callback. * * @param {Function} callback + * @param {Boolean} isAnonymousAction */ - const interceptAnonymousUser = (callback) => { - if (Session.isAnonymousUser()) { + const interceptAnonymousUser = (callback, isAnonymousAction = false) => { + if (Session.isAnonymousUser() && !isAnonymousAction) { hideContextMenu(false); InteractionManager.runAfterInteractions(() => { @@ -118,7 +119,7 @@ class BaseReportActionContextMenu extends React.Component { successText={contextAction.successTextTranslateKey ? this.props.translate(contextAction.successTextTranslateKey) : undefined} isMini={this.props.isMini} key={contextAction.textTranslateKey} - onPress={() => interceptAnonymousUser(() => contextAction.onPress(closePopup, payload))} + onPress={() => interceptAnonymousUser(() => contextAction.onPress(closePopup, payload), contextAction.isAnonymousAction)} description={contextAction.getDescription(this.props.selection, this.props.isSmallScreenWidth)} autoReset={contextAction.autoReset} /> diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 10c9103fbdd9..cc63680869ed 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -41,6 +41,7 @@ const CONTEXT_MENU_TYPES = { // A list of all the context actions in this menu. export default [ { + isAnonymousAction: false, shouldKeepOpen: true, shouldShow: (type, reportAction) => type === CONTEXT_MENU_TYPES.REPORT_ACTION && _.has(reportAction, 'message') && !ReportActionUtils.isMessageDeleted(reportAction), renderContent: (closePopover, {reportID, reportAction, close: closeManually, openContextMenu}) => { @@ -85,6 +86,7 @@ export default [ }, }, { + isAnonymousAction: true, textTranslateKey: 'common.download', icon: Expensicons.Download, successTextTranslateKey: 'common.download', @@ -110,6 +112,7 @@ export default [ getDescription: () => {}, }, { + isAnonymousAction: false, textTranslateKey: 'reportActionContextMenu.replyInThread', icon: Expensicons.ChatBubble, successTextTranslateKey: '', @@ -130,6 +133,7 @@ export default [ getDescription: () => {}, }, { + isAnonymousAction: false, textTranslateKey: 'reportActionContextMenu.copyURLToClipboard', icon: Expensicons.Copy, successTextTranslateKey: 'reportActionContextMenu.copied', @@ -142,6 +146,7 @@ export default [ getDescription: (selection) => selection, }, { + isAnonymousAction: false, textTranslateKey: 'reportActionContextMenu.copyEmailToClipboard', icon: Expensicons.Copy, successTextTranslateKey: 'reportActionContextMenu.copied', @@ -154,6 +159,7 @@ export default [ getDescription: (selection) => selection.replace('mailto:', ''), }, { + isAnonymousAction: true, textTranslateKey: 'reportActionContextMenu.copyToClipboard', icon: Expensicons.Copy, successTextTranslateKey: 'reportActionContextMenu.copied', @@ -198,6 +204,7 @@ export default [ }, { + isAnonymousAction: false, textTranslateKey: 'reportActionContextMenu.copyLink', icon: Expensicons.LinkCopy, successIcon: Expensicons.Checkmark, @@ -221,6 +228,7 @@ export default [ }, { + isAnonymousAction: false, textTranslateKey: 'reportActionContextMenu.markAsUnread', icon: Expensicons.Mail, successIcon: Expensicons.Checkmark, @@ -236,6 +244,7 @@ export default [ }, { + isAnonymousAction: false, textTranslateKey: 'reportActionContextMenu.markAsRead', icon: Expensicons.Mail, successIcon: Expensicons.Checkmark, @@ -250,6 +259,7 @@ export default [ }, { + isAnonymousAction: false, textTranslateKey: 'reportActionContextMenu.editComment', icon: Expensicons.Pencil, shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport) => @@ -269,6 +279,7 @@ export default [ getDescription: () => {}, }, { + isAnonymousAction: false, textTranslateKey: 'reportActionContextMenu.deleteAction', icon: Expensicons.Trashcan, shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport, reportID) => @@ -291,6 +302,7 @@ export default [ getDescription: () => {}, }, { + isAnonymousAction: false, textTranslateKey: 'common.pin', icon: Expensicons.Pin, shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat) => @@ -304,6 +316,7 @@ export default [ getDescription: () => {}, }, { + isAnonymousAction: false, textTranslateKey: 'common.unPin', icon: Expensicons.Pin, shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat) => @@ -317,6 +330,7 @@ export default [ getDescription: () => {}, }, { + isAnonymousAction: false, textTranslateKey: 'reportActionContextMenu.flagAsOffensive', icon: Expensicons.Flag, shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport, reportID) => From 0afd55ba5d87c3d08300f3e0cf73536b3573a595 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 12 Jul 2023 11:05:49 +0700 Subject: [PATCH 07/10] fix anonymous action on native --- src/components/ContextMenuItem.js | 4 ++++ .../home/report/ContextMenu/BaseReportActionContextMenu.js | 1 + 2 files changed, 5 insertions(+) diff --git a/src/components/ContextMenuItem.js b/src/components/ContextMenuItem.js index a3604f60c3fb..d1b9a9d709ab 100644 --- a/src/components/ContextMenuItem.js +++ b/src/components/ContextMenuItem.js @@ -36,6 +36,9 @@ const propTypes = { /** A description text to show under the title */ description: PropTypes.string, + /** The action accept for anonymous user or not */ + isAnonymousAction: PropTypes.bool, + ...withDelayToggleButtonStatePropTypes, }; @@ -97,6 +100,7 @@ class ContextMenuItem extends Component { description={this.props.description} descriptionTextStyle={styles.breakAll} style={getContextMenuItemStyles(this.props.windowWidth)} + isAnonymousAction={this.props.isAnonymousAction} /> ); } diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js index f3304356c2d2..a32d2af472be 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js @@ -122,6 +122,7 @@ class BaseReportActionContextMenu extends React.Component { onPress={() => interceptAnonymousUser(() => contextAction.onPress(closePopup, payload), contextAction.isAnonymousAction)} description={contextAction.getDescription(this.props.selection, this.props.isSmallScreenWidth)} autoReset={contextAction.autoReset} + isAnonymousAction={contextAction.isAnonymousAction} /> ); })} From e6007ea944a366a2e62511a34e599cb97cce87d8 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 12 Jul 2023 11:06:22 +0700 Subject: [PATCH 08/10] add default prop --- src/components/ContextMenuItem.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/ContextMenuItem.js b/src/components/ContextMenuItem.js index d1b9a9d709ab..b413985c64ab 100644 --- a/src/components/ContextMenuItem.js +++ b/src/components/ContextMenuItem.js @@ -48,6 +48,7 @@ const defaultProps = { successText: '', autoReset: true, description: '', + isAnonymousAction: false, }; class ContextMenuItem extends Component { From a61d7b0d3b57aa2b430cbff5d02f3182474563fc Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 13 Jul 2023 09:51:05 +0700 Subject: [PATCH 09/10] accept action in share code page for anonymous user --- src/pages/ShareCodePage.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/ShareCodePage.js b/src/pages/ShareCodePage.js index 548cbb53dd1d..0480649f4f47 100644 --- a/src/pages/ShareCodePage.js +++ b/src/pages/ShareCodePage.js @@ -75,6 +75,7 @@ class ShareCodePage extends React.Component { Date: Thu, 13 Jul 2023 12:15:16 +0700 Subject: [PATCH 10/10] fix lint --- src/pages/ShareCodePage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/ShareCodePage.js b/src/pages/ShareCodePage.js index 0480649f4f47..a81d02c60b36 100644 --- a/src/pages/ShareCodePage.js +++ b/src/pages/ShareCodePage.js @@ -75,7 +75,7 @@ class ShareCodePage extends React.Component {