-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Hide replace option for the request that cannot edit #28373
Changes from all commits
ad58522
6b6c0d5
7a2d072
f1b685f
08b323f
05d5b8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import React, {useState, useCallback, useRef} from 'react'; | ||
import React, {useState, useCallback, useRef, useMemo} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {View, Animated, Keyboard} from 'react-native'; | ||
import Str from 'expensify-common/lib/str'; | ||
import lodashGet from 'lodash/get'; | ||
import lodashExtend from 'lodash/extend'; | ||
import _ from 'underscore'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import CONST from '../CONST'; | ||
import Modal from './Modal'; | ||
import AttachmentView from './Attachments/AttachmentView'; | ||
|
@@ -30,6 +31,10 @@ import useWindowDimensions from '../hooks/useWindowDimensions'; | |
import Navigation from '../libs/Navigation/Navigation'; | ||
import ROUTES from '../ROUTES'; | ||
import useNativeDriver from '../libs/useNativeDriver'; | ||
import * as ReportUtils from '../libs/ReportUtils'; | ||
import * as ReportActionsUtils from '../libs/ReportActionsUtils'; | ||
import ONYXKEYS from '../ONYXKEYS'; | ||
import * as Policy from '../libs/actions/Policy'; | ||
import useNetwork from '../hooks/useNetwork'; | ||
|
||
/** | ||
|
@@ -326,6 +331,37 @@ function AttachmentModal(props) { | |
|
||
const sourceForAttachmentView = props.source || source; | ||
|
||
const threeDotsMenuItems = useMemo(() => { | ||
if (!isAttachmentReceipt || !props.parentReport || !props.parentReportActions) { | ||
return []; | ||
} | ||
const menuItems = []; | ||
const parentReportAction = props.parentReportActions[props.report.parentReportActionID]; | ||
const isDeleted = ReportActionsUtils.isDeletedAction(parentReportAction); | ||
const isSettled = ReportUtils.isSettled(props.parentReport.reportID); | ||
|
||
const isAdmin = Policy.isAdminOfFreePolicy([props.policy]) && ReportUtils.isExpenseReport(props.parentReport); | ||
const isRequestor = ReportUtils.isMoneyRequestReport(props.parentReport) && lodashGet(props.session, 'accountID', null) === parentReportAction.actorAccountID; | ||
const canEdit = !isSettled && !isDeleted && (isAdmin || isRequestor); | ||
if (canEdit) { | ||
menuItems.push({ | ||
icon: Expensicons.Camera, | ||
text: props.translate('common.replace'), | ||
onSelected: () => { | ||
onModalHideCallbackRef.current = () => Navigation.navigate(ROUTES.getEditRequestRoute(props.report.reportID, CONST.EDIT_REQUEST_FIELD.RECEIPT)); | ||
closeModal(); | ||
}, | ||
}); | ||
} | ||
menuItems.push({ | ||
icon: Expensicons.Download, | ||
text: props.translate('common.download'), | ||
onSelected: () => downloadAttachment(source), | ||
}); | ||
return menuItems; | ||
Comment on lines
+356
to
+360
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't show download button when offline attachments are not available when offline |
||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [isAttachmentReceipt, props.parentReport, props.parentReportActions, props.policy]); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return ( | ||
<> | ||
<Modal | ||
|
@@ -360,21 +396,7 @@ function AttachmentModal(props) { | |
onCloseButtonPress={closeModal} | ||
shouldShowThreeDotsButton={isAttachmentReceipt} | ||
threeDotsAnchorPosition={styles.threeDotsPopoverOffsetAttachmentModal(windowWidth)} | ||
threeDotsMenuItems={[ | ||
{ | ||
icon: Expensicons.Camera, | ||
text: props.translate('common.replace'), | ||
onSelected: () => { | ||
onModalHideCallbackRef.current = () => Navigation.navigate(ROUTES.EDIT_REQUEST.getRoute(props.report.reportID, CONST.EDIT_REQUEST_FIELD.RECEIPT)); | ||
closeModal(); | ||
}, | ||
}, | ||
{ | ||
icon: Expensicons.Download, | ||
text: props.translate('common.download'), | ||
onSelected: () => downloadAttachment(source), | ||
}, | ||
]} | ||
threeDotsMenuItems={threeDotsMenuItems} | ||
shouldOverlay | ||
/> | ||
<View style={styles.imageModalImageCenterContainer}> | ||
|
@@ -444,4 +466,22 @@ function AttachmentModal(props) { | |
AttachmentModal.propTypes = propTypes; | ||
AttachmentModal.defaultProps = defaultProps; | ||
AttachmentModal.displayName = 'AttachmentModal'; | ||
export default compose(withWindowDimensions, withLocalize)(AttachmentModal); | ||
export default compose( | ||
withWindowDimensions, | ||
withLocalize, | ||
withOnyx({ | ||
parentReport: { | ||
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report ? report.parentReportID : '0'}`, | ||
}, | ||
policy: { | ||
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, | ||
}, | ||
parentReportActions: { | ||
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : '0'}`, | ||
canEvict: false, | ||
}, | ||
session: { | ||
key: ONYXKEYS.SESSION, | ||
}, | ||
}), | ||
)(AttachmentModal); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@burczu @Li357 I missed updating the route here after
ROUTES
is refactored. That makes the app crash when clicking on the replace option now. Raise another PR #28890 to quickly fix this.