diff --git a/src/components/ContextMenuItem.js b/src/components/ContextMenuItem.js index a3604f60c3fb..b413985c64ab 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, }; @@ -45,6 +48,7 @@ const defaultProps = { successText: '', autoReset: true, description: '', + isAnonymousAction: false, }; class ContextMenuItem extends Component { @@ -97,6 +101,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/components/MenuItem.js b/src/components/MenuItem.js index ff26c0f6e7e4..38bad613ea65 100644 --- a/src/components/MenuItem.js +++ b/src/components/MenuItem.js @@ -68,6 +68,7 @@ const defaultProps = { hoverAndPressStyle: [], furtherDetails: '', furtherDetailsIcon: undefined, + isAnonymousAction: false, isSmallAvatarSubscriptMenu: false, title: '', numberOfLinesTitle: 1, @@ -114,7 +115,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 b8b28d15ddc6..2a9398c96554 100644 --- a/src/components/menuItemPropTypes.js +++ b/src/components/menuItemPropTypes.js @@ -123,6 +123,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, + /** Whether we should use small avatar subscript sizing the for menu item */ isSmallAvatarSubscriptMenu: PropTypes.bool, diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index b1671cc46f7d..628fac4d08b8 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -106,10 +106,11 @@ 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) { - 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 f55070796fb0..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'; @@ -78,6 +77,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)), }, ]; @@ -92,6 +92,7 @@ function ReportDetailsPage(props) { translationKey: 'common.members', icon: Expensicons.Users, subtitle: participants.length, + isAnonymousAction: false, action: () => { Navigation.navigate(ROUTES.getReportParticipantsRoute(props.report.reportID)); }, @@ -103,6 +104,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)); }, @@ -114,6 +116,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), }); } @@ -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} shouldShowRightIcon brickRoadIndicator={brickRoadIndicator} /> diff --git a/src/pages/ShareCodePage.js b/src/pages/ShareCodePage.js index 548cbb53dd1d..a81d02c60b36 100644 --- a/src/pages/ShareCodePage.js +++ b/src/pages/ShareCodePage.js @@ -75,6 +75,7 @@ class ShareCodePage extends React.Component { { - if (Session.isAnonymousUser()) { + const interceptAnonymousUser = (callback, isAnonymousAction = false) => { + if (Session.isAnonymousUser() && !isAnonymousAction) { hideContextMenu(false); InteractionManager.runAfterInteractions(() => { @@ -118,9 +119,10 @@ 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} + isAnonymousAction={contextAction.isAnonymousAction} /> ); })} 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) =>