Skip to content

Commit

Permalink
Merge pull request #24071 from Expensify/cmartins-addConfirmationModa…
Browse files Browse the repository at this point in the history
…lToHeader

Add delete confirmation modal to money request header
  • Loading branch information
srikarparsi authored Aug 9, 2023
2 parents 1e22b21 + 2bde3aa commit ef004a7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 26 deletions.
67 changes: 41 additions & 26 deletions src/components/MoneyRequestHeader.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import React, {useCallback} from 'react';
import React, {useState, useCallback} from 'react';
import {withOnyx} from 'react-native-onyx';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import lodashGet from 'lodash/get';
import HeaderWithBackButton from './HeaderWithBackButton';
import iouReportPropTypes from '../pages/iouReportPropTypes';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import * as ReportUtils from '../libs/ReportUtils';
import * as Expensicons from './Icon/Expensicons';
import participantPropTypes from './participantPropTypes';
import styles from '../styles/styles';
import withWindowDimensions from './withWindowDimensions';
import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions';
import compose from '../libs/compose';
import Navigation from '../libs/Navigation/Navigation';
import ROUTES from '../ROUTES';
import * as Policy from '../libs/actions/Policy';
import ONYXKEYS from '../ONYXKEYS';
import * as IOU from '../libs/actions/IOU';
import * as ReportActionsUtils from '../libs/ReportActionsUtils';
import ConfirmModal from './ConfirmModal';
import useLocalize from '../hooks/useLocalize';

const propTypes = {
/** The report currently being looked at */
Expand All @@ -41,7 +42,7 @@ const propTypes = {
email: PropTypes.string,
}),

...withLocalizePropTypes,
...windowDimensionsPropTypes,
};

const defaultProps = {
Expand All @@ -52,6 +53,8 @@ const defaultProps = {
};

function MoneyRequestHeader(props) {
const {translate} = useLocalize();
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false);
const moneyRequestReport = props.parentReport;
const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID);
const policy = props.policies[`${ONYXKEYS.COLLECTION.POLICY}${props.report.policyID}`];
Expand All @@ -64,30 +67,43 @@ function MoneyRequestHeader(props) {

const deleteTransaction = useCallback(() => {
IOU.deleteMoneyRequest(parentReportAction.originalMessage.IOUTransactionID, parentReportAction, true);
}, [parentReportAction]);
setIsDeleteModalVisible(false);
}, [parentReportAction, setIsDeleteModalVisible]);

return (
<View style={[styles.pl0]}>
<HeaderWithBackButton
shouldShowAvatarWithDisplay
shouldShowPinButton={false}
shouldShowThreeDotsButton={!isPayer && !isSettled}
threeDotsMenuItems={[
{
icon: Expensicons.Trashcan,
text: props.translate('reportActionContextMenu.deleteAction', {action: parentReportAction}),
onSelected: deleteTransaction,
},
]}
threeDotsAnchorPosition={styles.threeDotsPopoverOffsetNoCloseButton(props.windowWidth)}
report={report}
policies={props.policies}
personalDetails={props.personalDetails}
shouldShowBackButton={props.isSmallScreenWidth}
onBackButtonPress={() => Navigation.goBack(ROUTES.HOME, false, true)}
shouldShowBorderBottom
<>
<View style={[styles.pl0]}>
<HeaderWithBackButton
shouldShowAvatarWithDisplay
shouldShowPinButton={false}
shouldShowThreeDotsButton={!isPayer && !isSettled}
threeDotsMenuItems={[
{
icon: Expensicons.Trashcan,
text: translate('reportActionContextMenu.deleteAction', {action: parentReportAction}),
onSelected: () => setIsDeleteModalVisible(true),
},
]}
threeDotsAnchorPosition={styles.threeDotsPopoverOffsetNoCloseButton(props.windowWidth)}
report={report}
policies={props.policies}
personalDetails={props.personalDetails}
shouldShowBackButton={props.isSmallScreenWidth}
onBackButtonPress={() => Navigation.goBack(ROUTES.HOME, false, true)}
shouldShowBorderBottom
/>
</View>
<ConfirmModal
title={translate('iou.deleteRequest')}
isVisible={isDeleteModalVisible}
onConfirm={deleteTransaction}
onCancel={() => setIsDeleteModalVisible(false)}
prompt={translate('iou.deleteConfirmation')}
confirmText={translate('common.delete')}
cancelText={translate('common.cancel')}
danger
/>
</View>
</>
);
}

Expand All @@ -97,7 +113,6 @@ MoneyRequestHeader.defaultProps = defaultProps;

export default compose(
withWindowDimensions,
withLocalize,
withOnyx({
session: {
key: ONYXKEYS.SESSION,
Expand Down
2 changes: 2 additions & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ export default {
pay: 'Pay',
viewDetails: 'View details',
pending: 'Pending',
deleteRequest: 'Delete request',
deleteConfirmation: 'Are you sure that you want to delete this request?',
settledExpensify: 'Paid',
settledElsewhere: 'Paid elsewhere',
settledPaypalMe: 'Paid using Paypal.me',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ export default {
pay: 'Pagar',
viewDetails: 'Ver detalles',
pending: 'Pendiente',
deleteRequest: 'Eliminar pedido',
deleteConfirmation: '¿Estás seguro de que quieres eliminar este pedido?',
settledExpensify: 'Pagado',
settledElsewhere: 'Pagado de otra forma',
settledPaypalMe: 'Pagado con PayPal.me',
Expand Down

0 comments on commit ef004a7

Please sign in to comment.