Skip to content

Commit

Permalink
Merge pull request #28918 from BeeMargarida/feat/28766-submit_button_…
Browse files Browse the repository at this point in the history
…report_preview

[NoQA] feat: show submit button in Report preview for open/draft reports
  • Loading branch information
mountiny authored Oct 6, 2023
2 parents 73dcafd + 90e8b8c commit 2f60c27
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/components/ReportActionItem/ReportPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
import Text from '../Text';
import Button from '../Button';
import Icon from '../Icon';
import Text from '../Text';
import * as Expensicons from '../Icon/Expensicons';
import styles from '../../styles/styles';
import reportActionPropTypes from '../../pages/home/report/reportActionPropTypes';
Expand All @@ -20,6 +21,7 @@ import * as CurrencyUtils from '../../libs/CurrencyUtils';
import * as ReportUtils from '../../libs/ReportUtils';
import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
import useLocalize from '../../hooks/useLocalize';
import SettlementButton from '../SettlementButton';
import * as IOU from '../../libs/actions/IOU';
import refPropTypes from '../refPropTypes';
Expand Down Expand Up @@ -105,6 +107,8 @@ const defaultProps = {
};

function ReportPreview(props) {
const {translate} = useLocalize();

const managerID = props.iouReport.managerID || 0;
const isCurrentUserManager = managerID === lodashGet(props.session, 'accountID');
const reportTotal = ReportUtils.getMoneyRequestTotal(props.iouReport);
Expand All @@ -113,6 +117,8 @@ function ReportPreview(props) {
const iouCanceled = ReportUtils.isArchivedRoom(props.chatReport);
const numberOfRequests = ReportActionUtils.getNumberOfMoneyRequests(props.action);
const moneyRequestComment = lodashGet(props.action, 'childLastMoneyRequestComment', '');
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(props.chatReport);
const isReportDraft = isPolicyExpenseChat && ReportUtils.isReportDraft(props.iouReport);

const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(props.iouReportID);
const numberOfScanningReceipts = _.filter(transactionsWithReceipts, (transaction) => TransactionUtils.isReceiptBeingScanned(transaction)).length;
Expand Down Expand Up @@ -157,14 +163,14 @@ function ReportPreview(props) {
if (ReportUtils.isControlPolicyExpenseChat(props.chatReport) && ReportUtils.isReportApproved(props.iouReport)) {
return props.translate('iou.managerApproved', {manager: ReportUtils.getDisplayNameForParticipant(managerID, true)});
}
const managerName = ReportUtils.isPolicyExpenseChat(props.chatReport) ? ReportUtils.getPolicyName(props.chatReport) : ReportUtils.getDisplayNameForParticipant(managerID, true);
const managerName = isPolicyExpenseChat ? ReportUtils.getPolicyName(props.chatReport) : ReportUtils.getDisplayNameForParticipant(managerID, true);
return props.translate(iouSettled || props.iouReport.isWaitingOnBankAccount ? 'iou.payerPaid' : 'iou.payerOwes', {payer: managerName});
};

const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport);
const shouldShowSettlementButton = ReportUtils.isControlPolicyExpenseChat(props.chatReport)
? props.policy.role === CONST.POLICY.ROLE.ADMIN && ReportUtils.isReportApproved(props.iouReport) && !iouSettled && !iouCanceled
: !_.isEmpty(props.iouReport) && isCurrentUserManager && !iouSettled && !iouCanceled && !props.iouReport.isWaitingOnBankAccount && reportTotal !== 0;
: !_.isEmpty(props.iouReport) && isCurrentUserManager && !isReportDraft && !iouSettled && !iouCanceled && !props.iouReport.isWaitingOnBankAccount && reportTotal !== 0;

return (
<View style={[styles.chatItemMessage, ...props.containerStyles]}>
Expand Down Expand Up @@ -236,6 +242,15 @@ function ReportPreview(props) {
}}
/>
)}
{isReportDraft && (
<Button
medium
success={props.chatReport.isOwnPolicyExpenseChat}
text={translate('common.submit')}
style={styles.requestPreviewBox}
onPress={() => IOU.submitReport(props.iouReport)}
/>
)}
</View>
</View>
</PressableWithoutFeedback>
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export default {
resend: 'Resend',
save: 'Save',
saveChanges: 'Save changes',
submit: 'Submit',
rotate: 'Rotate',
zoom: 'Zoom',
password: 'Password',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default {
resend: 'Reenviar',
save: 'Guardar',
saveChanges: 'Guardar cambios',
submit: 'Enviar',
rotate: 'Rotar',
zoom: 'Zoom',
password: 'Contraseña',
Expand Down
9 changes: 9 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3769,6 +3769,14 @@ function getIOUReportActionDisplayMessage(reportAction) {
return displayMessage;
}

/**
* @param {Object} report
* @returns {Boolean}
*/
function isReportDraft(report) {
return lodashGet(report, 'stateNum') === CONST.REPORT.STATE_NUM.OPEN && lodashGet(report, 'statusNum') === CONST.REPORT.STATUS.OPEN;
}

export {
getReportParticipantsTitle,
isReportMessageAttachment,
Expand Down Expand Up @@ -3912,4 +3920,5 @@ export {
hasMissingSmartscanFields,
getIOUReportActionDisplayMessage,
isWaitingForTaskCompleteFromAssignee,
isReportDraft,
};
5 changes: 5 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -2302,6 +2302,10 @@ function navigateToNextPage(iou, iouType, report, path = '') {
Navigation.navigate(ROUTES.MONEY_REQUEST_PARTICIPANTS.getRoute(iouType));
}

function submitReport() {
// Will be implemented in https://github.com/Expensify/App/issues/28763
}

export {
createDistanceRequest,
editMoneyRequest,
Expand Down Expand Up @@ -2332,4 +2336,5 @@ export {
navigateToNextPage,
updateDistanceRequest,
replaceReceipt,
submitReport,
};

0 comments on commit 2f60c27

Please sign in to comment.