Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action for anonymous user #22321

Merged
merged 15 commits into from
Jul 14, 2023
5 changes: 5 additions & 0 deletions src/components/ContextMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -45,6 +48,7 @@ const defaultProps = {
successText: '',
autoReset: true,
description: '',
isAnonymousAction: false,
};

class ContextMenuItem extends Component {
Expand Down Expand Up @@ -97,6 +101,7 @@ class ContextMenuItem extends Component {
description={this.props.description}
descriptionTextStyle={styles.breakAll}
style={getContextMenuItemStyles(this.props.windowWidth)}
isAnonymousAction={this.props.isAnonymousAction}
/>
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/MenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const defaultProps = {
hoverAndPressStyle: [],
furtherDetails: '',
furtherDetailsIcon: undefined,
isAnonymousAction: false,
isSmallAvatarSubscriptMenu: false,
title: '',
numberOfLinesTitle: 1,
Expand Down Expand Up @@ -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}
Expand Down
3 changes: 3 additions & 0 deletions src/components/menuItemPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
5 changes: 3 additions & 2 deletions src/libs/actions/Session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions src/pages/ReportDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)),
},
];
Expand All @@ -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));
},
Expand All @@ -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));
},
Expand All @@ -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),
});
}
Expand Down Expand Up @@ -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}
/>
Expand Down
2 changes: 2 additions & 0 deletions src/pages/ShareCodePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class ShareCodePage extends React.Component {

<View style={{marginTop: 36}}>
<ContextMenuItem
isAnonymousAction
text={this.props.translate('qrCodes.copyUrlToClipboard')}
shouldShowRightIcon
icon={Expensicons.Copy}
Expand All @@ -85,6 +86,7 @@ class ShareCodePage extends React.Component {

{isNative && (
<MenuItem
isAnonymousAction
title={this.props.translate('common.download')}
icon={Expensicons.Download}
// eslint-disable-next-line es/no-optional-chaining
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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}
/>
);
})}
Expand Down
14 changes: 14 additions & 0 deletions src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}) => {
Expand Down Expand Up @@ -85,6 +86,7 @@ export default [
},
},
{
isAnonymousAction: true,
textTranslateKey: 'common.download',
icon: Expensicons.Download,
successTextTranslateKey: 'common.download',
Expand All @@ -110,6 +112,7 @@ export default [
getDescription: () => {},
},
{
isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.replyInThread',
icon: Expensicons.ChatBubble,
successTextTranslateKey: '',
Expand All @@ -130,6 +133,7 @@ export default [
getDescription: () => {},
},
{
isAnonymousAction: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this issue, we decided to allow anonymous user to copy url and email.

textTranslateKey: 'reportActionContextMenu.copyURLToClipboard',
icon: Expensicons.Copy,
successTextTranslateKey: 'reportActionContextMenu.copied',
Expand All @@ -142,6 +146,7 @@ export default [
getDescription: (selection) => selection,
},
{
isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.copyEmailToClipboard',
icon: Expensicons.Copy,
successTextTranslateKey: 'reportActionContextMenu.copied',
Expand All @@ -154,6 +159,7 @@ export default [
getDescription: (selection) => selection.replace('mailto:', ''),
},
{
isAnonymousAction: true,
textTranslateKey: 'reportActionContextMenu.copyToClipboard',
icon: Expensicons.Copy,
successTextTranslateKey: 'reportActionContextMenu.copied',
Expand Down Expand Up @@ -198,6 +204,7 @@ export default [
},

{
isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.copyLink',
icon: Expensicons.LinkCopy,
successIcon: Expensicons.Checkmark,
Expand All @@ -221,6 +228,7 @@ export default [
},

{
isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.markAsUnread',
icon: Expensicons.Mail,
successIcon: Expensicons.Checkmark,
Expand All @@ -236,6 +244,7 @@ export default [
},

{
isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.markAsRead',
icon: Expensicons.Mail,
successIcon: Expensicons.Checkmark,
Expand All @@ -250,6 +259,7 @@ export default [
},

{
isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.editComment',
icon: Expensicons.Pencil,
shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport) =>
Expand All @@ -269,6 +279,7 @@ export default [
getDescription: () => {},
},
{
isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.deleteAction',
icon: Expensicons.Trashcan,
shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport, reportID) =>
Expand All @@ -291,6 +302,7 @@ export default [
getDescription: () => {},
},
{
isAnonymousAction: false,
textTranslateKey: 'common.pin',
icon: Expensicons.Pin,
shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat) =>
Expand All @@ -304,6 +316,7 @@ export default [
getDescription: () => {},
},
{
isAnonymousAction: false,
textTranslateKey: 'common.unPin',
icon: Expensicons.Pin,
shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat) =>
Expand All @@ -317,6 +330,7 @@ export default [
getDescription: () => {},
},
{
isAnonymousAction: false,
textTranslateKey: 'reportActionContextMenu.flagAsOffensive',
icon: Expensicons.Flag,
shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport, reportID) =>
Expand Down
Loading