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 edit request button to the report action context menu #25429

Merged
merged 15 commits into from
Aug 25, 2023
100 changes: 42 additions & 58 deletions src/components/ReportActionItem/MoneyRequestAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import styles from '../../styles/styles';
import * as IOUUtils from '../../libs/IOUUtils';
import * as ReportUtils from '../../libs/ReportUtils';
import * as Report from '../../libs/actions/Report';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import * as ReportActionsUtils from '../../libs/ReportActionsUtils';
import refPropTypes from '../refPropTypes';
import RenderHTML from '../RenderHTML';
import * as PersonalDetailsUtils from '../../libs/PersonalDetailsUtils';
import reportPropTypes from '../../pages/reportPropTypes';
import useLocalize from '../../hooks/useLocalize';

const propTypes = {
/** All the data of the action */
Expand Down Expand Up @@ -58,17 +58,9 @@ const propTypes = {

network: networkPropTypes.isRequired,

/** Session info for the currently logged in user. */
session: PropTypes.shape({
/** Currently logged in user email */
email: PropTypes.string,
}),

/** Styles to be assigned to Container */
// eslint-disable-next-line react/forbid-prop-types
style: PropTypes.arrayOf(PropTypes.object),

...withLocalizePropTypes,
};

const defaultProps = {
Expand All @@ -78,77 +70,73 @@ const defaultProps = {
iouReport: {},
reportActions: {},
isHovered: false,
session: {
email: null,
},
style: [],
};

function MoneyRequestAction(props) {
const isSplitBillAction = lodashGet(props.action, 'originalMessage.type', '') === CONST.IOU.REPORT_ACTION_TYPE.SPLIT;
function MoneyRequestAction({
action,
chatReportID,
requestReportID,
isMostRecentIOUReportAction,
contextMenuAnchor,
checkIfContextMenuActive,
chatReport,
iouReport,
reportActions,
isHovered,
network,
style,
}) {
const {translate} = useLocalize();
const isSplitBillAction = lodashGet(action, 'originalMessage.type', '') === CONST.IOU.REPORT_ACTION_TYPE.SPLIT;

const onMoneyRequestPreviewPressed = () => {
if (isSplitBillAction) {
const reportActionID = lodashGet(props.action, 'reportActionID', '0');
Navigation.navigate(ROUTES.getSplitBillDetailsRoute(props.chatReportID, reportActionID));
const reportActionID = lodashGet(action, 'reportActionID', '0');
Navigation.navigate(ROUTES.getSplitBillDetailsRoute(chatReportID, reportActionID));
return;
}

// If the childReportID is not present, we need to create a new thread
const childReportID = lodashGet(props.action, 'childReportID', '0');
if (childReportID === '0') {
const participantAccountIDs = _.uniq([props.session.accountID, Number(props.action.actorAccountID)]);
const thread = ReportUtils.buildOptimisticChatReport(
participantAccountIDs,
ReportUtils.getTransactionReportName(props.action),
'',
lodashGet(props.iouReport, 'policyID', CONST.POLICY.OWNER_EMAIL_FAKE),
CONST.POLICY.OWNER_ACCOUNT_ID_FAKE,
false,
'',
undefined,
undefined,
CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
props.action.reportActionID,
props.requestReportID,
);

const childReportID = lodashGet(action, 'childReportID', 0);
if (!childReportID) {
const thread = ReportUtils.buildTransactionThread(action);
const userLogins = PersonalDetailsUtils.getLoginsByAccountIDs(thread.participantAccountIDs);
Report.openReport(thread.reportID, userLogins, thread, props.action.reportActionID);
Report.openReport(thread.reportID, userLogins, thread, action.reportActionID);
Navigation.navigate(ROUTES.getReportRoute(thread.reportID));
} else {
Report.openReport(childReportID);
Navigation.navigate(ROUTES.getReportRoute(childReportID));
return;
}
Report.openReport(childReportID);
Navigation.navigate(ROUTES.getReportRoute(childReportID));
};

let shouldShowPendingConversionMessage = false;
const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(props.action);
const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(action);
if (
!_.isEmpty(props.iouReport) &&
!_.isEmpty(props.reportActions) &&
props.chatReport.hasOutstandingIOU &&
props.isMostRecentIOUReportAction &&
props.action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD &&
props.network.isOffline
!_.isEmpty(iouReport) &&
!_.isEmpty(reportActions) &&
chatReport.hasOutstandingIOU &&
isMostRecentIOUReportAction &&
action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD &&
network.isOffline
) {
shouldShowPendingConversionMessage = IOUUtils.isIOUReportPendingCurrencyConversion(props.iouReport);
shouldShowPendingConversionMessage = IOUUtils.isIOUReportPendingCurrencyConversion(iouReport);
}

return isDeletedParentAction ? (
<RenderHTML html={`<comment>${props.translate('parentReportAction.deletedRequest')}</comment>`} />
<RenderHTML html={`<comment>${translate('parentReportAction.deletedRequest')}</comment>`} />
) : (
<MoneyRequestPreview
iouReportID={props.requestReportID}
chatReportID={props.chatReportID}
iouReportID={requestReportID}
chatReportID={chatReportID}
isBillSplit={isSplitBillAction}
action={props.action}
contextMenuAnchor={props.contextMenuAnchor}
checkIfContextMenuActive={props.checkIfContextMenuActive}
action={action}
contextMenuAnchor={contextMenuAnchor}
checkIfContextMenuActive={checkIfContextMenuActive}
shouldShowPendingConversionMessage={shouldShowPendingConversionMessage}
onPreviewPressed={onMoneyRequestPreviewPressed}
containerStyles={[styles.cursorPointer, props.isHovered ? styles.reportPreviewBoxHoverBorder : undefined, ...props.style]}
isHovered={props.isHovered}
containerStyles={[styles.cursorPointer, isHovered ? styles.reportPreviewBoxHoverBorder : undefined, ...style]}
isHovered={isHovered}
/>
);
}
Expand All @@ -158,7 +146,6 @@ MoneyRequestAction.defaultProps = defaultProps;
MoneyRequestAction.displayName = 'MoneyRequestAction';

export default compose(
withLocalize,
withOnyx({
chatReport: {
key: ({chatReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`,
Expand All @@ -170,9 +157,6 @@ export default compose(
key: ({chatReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`,
canEvict: false,
},
session: {
key: ONYXKEYS.SESSION,
},
}),
withNetwork(),
)(MoneyRequestAction);
26 changes: 2 additions & 24 deletions src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import PropTypes from 'prop-types';
import reportPropTypes from '../../pages/reportPropTypes';
import ONYXKEYS from '../../ONYXKEYS';
import ROUTES from '../../ROUTES';
import * as Policy from '../../libs/actions/Policy';
import Navigation from '../../libs/Navigation/Navigation';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes} from '../withCurrentUserPersonalDetails';
import compose from '../../libs/compose';
Expand Down Expand Up @@ -36,21 +35,6 @@ const propTypes = {
/** The expense report or iou report (only will have a value if this is a transaction thread) */
parentReport: iouReportPropTypes,

/** The policy object for the current route */
policy: PropTypes.shape({
/** The name of the policy */
name: PropTypes.string,

/** The URL for the policy avatar */
avatar: PropTypes.string,
}),

/** Session info for the currently logged in user. */
session: PropTypes.shape({
/** Currently logged in user email */
email: PropTypes.string,
}),

/** The transaction associated with the transactionThread */
transaction: transactionPropTypes,

Expand All @@ -62,18 +46,14 @@ const propTypes = {

const defaultProps = {
parentReport: {},
policy: null,
session: {
email: null,
},
transaction: {
amount: 0,
currency: CONST.CURRENCY.USD,
comment: {comment: ''},
},
};

function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, policy, session, transaction}) {
function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, transaction}) {
const {isSmallScreenWidth} = useWindowDimensions();
const {translate} = useLocalize();

Expand All @@ -89,9 +69,7 @@ function MoneyRequestView({report, parentReport, shouldShowHorizontalRule, polic
const formattedTransactionAmount = transactionAmount && transactionCurrency && CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency);

const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID);
const isAdmin = Policy.isAdminOfFreePolicy([policy]) && ReportUtils.isExpenseReport(moneyRequestReport);
const isRequestor = ReportUtils.isMoneyRequestReport(moneyRequestReport) && lodashGet(session, 'accountID', null) === parentReportAction.actorAccountID;
const canEdit = !isSettled && (isAdmin || isRequestor);
const canEdit = ReportUtils.canEditMoneyRequest(parentReportAction);

let description = `${translate('iou.amount')} • ${translate('iou.cash')}`;
if (isSettled) {
Expand Down
2 changes: 1 addition & 1 deletion src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export default {
copyEmailToClipboard: 'Copy email to clipboard',
markAsUnread: 'Mark as unread',
markAsRead: 'Mark as read',
editComment: 'Edit comment',
editAction: ({action}) => `Edit ${ReportActionsUtils.isMoneyRequestAction(action) ? 'request' : 'comment'}`,
deleteAction: ({action}) => `Delete ${ReportActionsUtils.isMoneyRequestAction(action) ? 'request' : 'comment'}`,
deleteConfirmation: ({action}) => `Are you sure you want to delete this ${ReportActionsUtils.isMoneyRequestAction(action) ? 'request' : 'comment'}?`,
onlyVisible: 'Only visible to',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export default {
copyEmailToClipboard: 'Copiar email al portapapeles',
markAsUnread: 'Marcar como no leído',
markAsRead: 'Marcar como leído',
editComment: 'Editar comentario',
editAction: ({action}) => `Edit ${ReportActionsUtils.isMoneyRequestAction(action) ? 'pedido' : 'comentario'}`,
deleteAction: ({action}) => `Eliminar ${ReportActionsUtils.isMoneyRequestAction(action) ? 'pedido' : 'comentario'}`,
deleteConfirmation: ({action}) => `¿Estás seguro de que quieres eliminar este ${ReportActionsUtils.isMoneyRequestAction(action) ? 'pedido' : 'comentario'}`,
onlyVisible: 'Visible sólo para',
Expand Down
Loading
Loading