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 pin icon in the IOU report page of request amount #29078

Merged
merged 12 commits into from
Oct 12, 2023
36 changes: 18 additions & 18 deletions src/components/MoneyRequestHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import ConfirmModal from './ConfirmModal';
import useLocalize from '../hooks/useLocalize';
import MoneyRequestHeaderStatusBar from './MoneyRequestHeaderStatusBar';
import * as TransactionUtils from '../libs/TransactionUtils';
import * as HeaderUtils from '../libs/HeaderUtils';
import reportActionPropTypes from '../pages/home/report/reportActionPropTypes';
import transactionPropTypes from './transactionPropTypes';
import useWindowDimensions from '../hooks/useWindowDimensions';
Expand Down Expand Up @@ -80,7 +81,6 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction,
}, [parentReportAction, setIsDeleteModalVisible]);

const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction);

const canModifyRequest = isActionOwner && !isSettled && !isApproved;

useEffect(() => {
Expand All @@ -90,30 +90,30 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction,

setIsDeleteModalVisible(false);
}, [canModifyRequest]);
const threeDotsMenuItems = [HeaderUtils.getPinMenuItem(report)];
if (canModifyRequest) {
if (!TransactionUtils.hasReceipt(transaction)) {
threeDotsMenuItems.push({
icon: Expensicons.Receipt,
text: translate('receipt.addReceipt'),
onSelected: () => Navigation.navigate(ROUTES.EDIT_REQUEST.getRoute(report.reportID, CONST.EDIT_REQUEST_FIELD.RECEIPT)),
});
}
threeDotsMenuItems.push({
icon: Expensicons.Trashcan,
text: translate('reportActionContextMenu.deleteAction', {action: parentReportAction}),
onSelected: () => setIsDeleteModalVisible(true),
});
}

return (
<>
<View style={[styles.pl0]}>
<HeaderWithBackButton
shouldShowAvatarWithDisplay
shouldShowPinButton={false}
shouldShowThreeDotsButton={canModifyRequest}
threeDotsMenuItems={[
...(TransactionUtils.hasReceipt(transaction)
? []
: [
{
icon: Expensicons.Receipt,
text: translate('receipt.addReceipt'),
onSelected: () => Navigation.navigate(ROUTES.EDIT_REQUEST.getRoute(report.reportID, CONST.EDIT_REQUEST_FIELD.RECEIPT)),
},
]),
{
icon: Expensicons.Trashcan,
text: translate('reportActionContextMenu.deleteAction', {action: parentReportAction}),
onSelected: () => setIsDeleteModalVisible(true),
},
]}
shouldShowThreeDotsButton
threeDotsMenuItems={threeDotsMenuItems}
threeDotsAnchorPosition={styles.threeDotsPopoverOffsetNoCloseButton(windowWidth)}
report={{
...report,
Expand Down
31 changes: 31 additions & 0 deletions src/libs/HeaderUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as Localize from './Localize';
import themeColors from '../styles/themes/default';
import * as Session from './actions/Session';
import * as Report from './actions/Report';
import * as Expensicons from '../components/Icon/Expensicons';

/**
* @param {Object} report
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
* @returns {Object} pin/unpin object
*/
function getPinMenuItem(report) {
if (!report.isPinned) {
return {
icon: Expensicons.Pin,
iconFill: themeColors.icon,
text: Localize.translateLocal('common.pin'),
onSelected: Session.checkIfActionIsAllowed(() => Report.togglePinnedState(report.reportID, report.isPinned)),
};
}
return {
icon: Expensicons.Pin,
iconFill: themeColors.icon,
text: Localize.translateLocal('common.unPin'),
onSelected: Session.checkIfActionIsAllowed(() => Report.togglePinnedState(report.reportID, report.isPinned)),
};
}

export {
// eslint-disable-next-line import/prefer-default-export
getPinMenuItem,
};
18 changes: 2 additions & 16 deletions src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import participantPropTypes from '../../components/participantPropTypes';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../components/withWindowDimensions';
import * as OptionsListUtils from '../../libs/OptionsListUtils';
import * as HeaderUtils from '../../libs/HeaderUtils';
import * as ReportActionsUtils from '../../libs/ReportActionsUtils';
import * as ReportUtils from '../../libs/ReportUtils';
import * as Link from '../../libs/actions/Link';
import * as Report from '../../libs/actions/Report';
import * as Session from '../../libs/actions/Session';
import * as Task from '../../libs/actions/Task';
import compose from '../../libs/compose';
import styles from '../../styles/styles';
Expand Down Expand Up @@ -135,21 +135,7 @@ function HeaderView(props) {
}
}

if (!props.report.isPinned) {
threeDotMenuItems.push({
icon: Expensicons.Pin,
iconFill: themeColors.icon,
text: props.translate('common.pin'),
onSelected: Session.checkIfActionIsAllowed(() => Report.togglePinnedState(props.report.reportID, props.report.isPinned)),
});
} else {
threeDotMenuItems.push({
icon: Expensicons.Pin,
iconFill: themeColors.icon,
text: props.translate('common.unPin'),
onSelected: Session.checkIfActionIsAllowed(() => Report.togglePinnedState(props.report.reportID, props.report.isPinned)),
});
}
threeDotMenuItems.push(HeaderUtils.getPinMenuItem(props.report));

if (isConcierge && props.guideCalendarLink) {
threeDotMenuItems.push({
Expand Down
Loading