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
54 changes: 36 additions & 18 deletions src/components/MoneyRequestHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import * as TransactionUtils from '../libs/TransactionUtils';
import reportActionPropTypes from '../pages/home/report/reportActionPropTypes';
import transactionPropTypes from './transactionPropTypes';
import useWindowDimensions from '../hooks/useWindowDimensions';
import themeColors from '../styles/themes/default';
import * as Report from '../libs/actions/Report';
import * as Session from '../libs/actions/Session';

const propTypes = {
/** The report currently being looked at */
Expand Down Expand Up @@ -80,7 +83,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 +92,46 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction,

setIsDeleteModalVisible(false);
}, [canModifyRequest]);
const threeDotsMenuItems = [];
if (!report.isPinned) {
threeDotsMenuItems.push({
icon: Expensicons.Pin,
iconFill: themeColors.icon,
text: translate('common.pin'),
onSelected: Session.checkIfActionIsAllowed(() => Report.togglePinnedState(report.reportID, report.isPinned)),
});
} else {
threeDotsMenuItems.push({
icon: Expensicons.Pin,
iconFill: themeColors.icon,
text: translate('common.unPin'),
onSelected: Session.checkIfActionIsAllowed(() => Report.togglePinnedState(report.reportID, report.isPinned)),
});
}

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
Loading