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

[NoQA] feat: show submit button in Report preview for open/draft reports #28918

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 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,7 @@ function ReportPreview(props) {
const iouCanceled = ReportUtils.isArchivedRoom(props.chatReport);
const numberOfRequests = ReportActionUtils.getNumberOfMoneyRequests(props.action);
const moneyRequestComment = lodashGet(props.action, 'childLastMoneyRequestComment', '');
const isReportDraft = ReportUtils.isReportDraft(props.iouReport);
BeeMargarida marked this conversation as resolved.
Show resolved Hide resolved

const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(props.iouReportID);
const numberOfScanningReceipts = _.filter(transactionsWithReceipts, (transaction) => TransactionUtils.isReceiptBeingScanned(transaction)).length;
Expand Down Expand Up @@ -164,7 +169,7 @@ function ReportPreview(props) {
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 @@ -232,6 +237,15 @@ function ReportPreview(props) {
style={[styles.requestPreviewBox]}
/>
)}
{isReportDraft && (
<Button
success
medium
text={translate('common.submit')}
style={[styles.requestPreviewBox]}
BeeMargarida marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -3796,6 +3796,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 @@ -3940,4 +3948,5 @@ export {
hasMissingSmartscanFields,
getIOUReportActionDisplayMessage,
isWaitingForTaskCompleteFromAssignee,
isReportDraft,
};
3 changes: 3 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -2302,6 +2302,8 @@ function navigateToNextPage(iou, iouType, report, path = '') {
Navigation.navigate(ROUTES.MONEY_REQUEST_PARTICIPANTS.getRoute(iouType));
}

function submitReport() {}
BeeMargarida marked this conversation as resolved.
Show resolved Hide resolved

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