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 next steps for draft reports #29309

Merged
merged 11 commits into from
Oct 19, 2023
1 change: 1 addition & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ const ONYXKEYS = {
SECURITY_GROUP: 'securityGroup_',
TRANSACTION: 'transactions_',
PRIVATE_NOTES_DRAFT: 'privateNotesDraft_',
NEXT_STEP: 'reportNextStep_',

// Manual request tab selector
SELECTED_TAB: 'selectedTab_',
Expand Down
99 changes: 59 additions & 40 deletions src/components/MoneyReportHeader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useMemo} from 'react';
import _ from 'underscore';
import {withOnyx} from 'react-native-onyx';
import {View} from 'react-native';
import PropTypes from 'prop-types';
Expand All @@ -15,11 +16,13 @@ import Navigation from '../libs/Navigation/Navigation';
import ROUTES from '../ROUTES';
import ONYXKEYS from '../ONYXKEYS';
import CONST from '../CONST';
import MoneyReportHeaderStatusBar from './MoneyReportHeaderStatusBar';
import SettlementButton from './SettlementButton';
import Button from './Button';
import * as IOU from '../libs/actions/IOU';
import * as CurrencyUtils from '../libs/CurrencyUtils';
import reportPropTypes from '../pages/reportPropTypes';
import nextStepPropTypes from '../pages/nextStepPropTypes';

const propTypes = {
/** The report currently being looked at */
Expand All @@ -40,6 +43,9 @@ const propTypes = {
/** The chat report this report is linked to */
chatReport: reportPropTypes,

/** The next step for the report */
nextStep: nextStepPropTypes,

/** Personal details so we can get the ones for the report participants */
personalDetails: PropTypes.objectOf(participantPropTypes).isRequired,

Expand All @@ -54,13 +60,14 @@ const propTypes = {

const defaultProps = {
chatReport: {},
nextStep: {},
session: {
email: null,
},
policy: {},
};

function MoneyReportHeader({session, personalDetails, policy, chatReport, report: moneyRequestReport, isSmallScreenWidth}) {
function MoneyReportHeader({session, personalDetails, policy, chatReport, nextStep, report: moneyRequestReport, isSmallScreenWidth}) {
const {translate} = useLocalize();
const reportTotal = ReportUtils.getMoneyRequestTotal(moneyRequestReport);
const isApproved = ReportUtils.isReportApproved(moneyRequestReport);
Expand All @@ -81,7 +88,8 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, report
return isManager && !isDraft && !isApproved && !isSettled;
}, [policyType, isManager, isDraft, isApproved, isSettled]);
const shouldShowSubmitButton = isDraft && reportTotal !== 0;
const shouldShowAnyButton = shouldShowSettlementButton || shouldShowApproveButton || shouldShowSubmitButton;
const shouldShowNextSteps = isDraft && nextStep && (!_.isEmpty(nextStep.message) || !_.isEmpty(nextStep.expenseMessage));
const shouldShowAnyButton = shouldShowSettlementButton || shouldShowApproveButton || shouldShowSubmitButton || shouldShowNextSteps;
const bankAccountRoute = ReportUtils.getBankAccountRoute(chatReport);
const formattedAmount = CurrencyUtils.convertToDisplayString(reportTotal, moneyRequestReport.currency);

Expand All @@ -96,7 +104,8 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, report
personalDetails={personalDetails}
shouldShowBackButton={isSmallScreenWidth}
onBackButtonPress={() => Navigation.goBack(ROUTES.HOME, false, true)}
shouldShowBorderBottom={!shouldShowAnyButton || !isSmallScreenWidth}
// Shows border if no buttons or next steps are showing below the header
shouldShowBorderBottom={!(shouldShowAnyButton && isSmallScreenWidth) && !(shouldShowNextSteps && !isSmallScreenWidth)}
>
{shouldShowSettlementButton && !isSmallScreenWidth && (
<View style={styles.pv2}>
Expand Down Expand Up @@ -141,43 +150,50 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, report
</View>
)}
</HeaderWithBackButton>
{shouldShowSettlementButton && isSmallScreenWidth && (
<View style={[styles.ph5, styles.pb2, isSmallScreenWidth && styles.borderBottom]}>
<SettlementButton
currency={moneyRequestReport.currency}
policyID={moneyRequestReport.policyID}
chatReportID={moneyRequestReport.chatReportID}
iouReport={moneyRequestReport}
onPress={(paymentType) => IOU.payMoneyRequest(paymentType, chatReport, moneyRequestReport)}
enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS}
addBankAccountRoute={bankAccountRoute}
shouldShowPaymentOptions
formattedAmount={formattedAmount}
/>
</View>
)}
{shouldShowApproveButton && isSmallScreenWidth && (
<View style={[styles.ph5, styles.pb2, isSmallScreenWidth && styles.borderBottom]}>
<Button
success
medium
text={translate('iou.approve')}
style={[styles.w100, styles.pr0]}
onPress={() => IOU.approveMoneyRequest(moneyRequestReport)}
/>
</View>
)}
{shouldShowSubmitButton && isSmallScreenWidth && (
<View style={[styles.ph5, styles.pb2, isSmallScreenWidth && styles.borderBottom]}>
<Button
medium
success={chatReport.isOwnPolicyExpenseChat}
text={translate('common.submit')}
style={[styles.w100, styles.pr0]}
onPress={() => IOU.submitReport(moneyRequestReport)}
/>
</View>
)}
<View style={[styles.dFlex, styles.flexColumn, styles.borderBottom]}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last nitpick 🤓 @koko57 This leads to double bottom border if there is no next steps:

image image

{shouldShowNextSteps && (
<View style={[styles.ph5, styles.pb2]}>
<MoneyReportHeaderStatusBar nextStep={nextStep} />
</View>
)}
{shouldShowSettlementButton && isSmallScreenWidth && (
<View style={[styles.ph5, styles.pb2]}>
<SettlementButton
currency={moneyRequestReport.currency}
policyID={moneyRequestReport.policyID}
chatReportID={moneyRequestReport.chatReportID}
iouReport={moneyRequestReport}
onPress={(paymentType) => IOU.payMoneyRequest(paymentType, chatReport, moneyRequestReport)}
enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS}
addBankAccountRoute={bankAccountRoute}
shouldShowPaymentOptions
formattedAmount={formattedAmount}
/>
</View>
)}
{shouldShowApproveButton && isSmallScreenWidth && (
<View style={[styles.ph5, styles.pb2]}>
<Button
success
medium
text={translate('iou.approve')}
style={[styles.w100, styles.pr0]}
onPress={() => IOU.approveMoneyRequest(moneyRequestReport)}
/>
</View>
)}
{shouldShowSubmitButton && isSmallScreenWidth && (
<View style={[styles.ph5, styles.pb2]}>
<Button
medium
success={chatReport.isOwnPolicyExpenseChat}
text={translate('common.submit')}
style={[styles.w100, styles.pr0]}
onPress={() => IOU.submitReport(moneyRequestReport)}
/>
</View>
)}
</View>
</View>
);
}
Expand All @@ -192,6 +208,9 @@ export default compose(
chatReport: {
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report.chatReportID}`,
},
nextStep: {
key: ({report}) => `${ONYXKEYS.COLLECTION.NEXT_STEP}${report.reportID}`,
},
session: {
key: ONYXKEYS.SESSION,
},
Expand Down
53 changes: 53 additions & 0 deletions src/components/MoneyReportHeaderStatusBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, {useMemo} from 'react';
import {Text, View} from 'react-native';
import _ from 'underscore';
import Str from 'expensify-common/lib/str';
import styles from '../styles/styles';
import useLocalize from '../hooks/useLocalize';
import nextStepPropTypes from '../pages/nextStepPropTypes';
import RenderHTML from './RenderHTML';

const propTypes = {
/** The next step for the report */
nextStep: nextStepPropTypes,
};

const defaultProps = {
nextStep: {},
};

function MoneyReportHeaderStatusBar({nextStep}) {
const {translate} = useLocalize();

const messageContent = useMemo(() => {
let nextStepHTML = '';

const messageArray = _.isEmpty(nextStep.expenseMessage) ? nextStep.message : nextStep.expenseMessage;
_.each(messageArray, (part) => {
const tagType = part.type || 'span';
nextStepHTML += `<${tagType}>${Str.safeEscape(part.text)}</${tagType}>`;
});

return nextStepHTML
mountiny marked this conversation as resolved.
Show resolved Hide resolved
.replace(/%expenses/g, 'this expense')
.replace(/%Expenses/g, 'This expense')
.replace(/%tobe/g, 'is');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should move this to some Utils file. Maybe NextStepUtils.js and create a parseMessage method there

}, [nextStep.expenseMessage, nextStep.message]);

return (
<View style={[styles.dFlex, styles.flexRow, styles.alignItemsCenter, styles.overflowHidden, styles.w100]}>
<View style={styles.moneyRequestHeaderStatusBarBadge}>
<Text style={[styles.textStrong, styles.textLabel]}>{translate('iou.nextSteps')}</Text>
</View>
<View style={[styles.dFlex, styles.flexRow, styles.flexShrink1]}>
<RenderHTML html={messageContent} />
</View>
</View>
);
}

MoneyReportHeaderStatusBar.displayName = 'MoneyReportHeaderStatusBar';
MoneyReportHeaderStatusBar.propTypes = propTypes;
MoneyReportHeaderStatusBar.defaultProps = defaultProps;

export default MoneyReportHeaderStatusBar;
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ export default {
settledElsewhere: 'Paid elsewhere',
settleExpensify: ({formattedAmount}: SettleExpensifyCardParams) => `Pay ${formattedAmount} with Expensify`,
payElsewhere: 'Pay elsewhere',
nextSteps: 'Next Steps',
requestAmount: ({amount}: RequestAmountParams) => `request ${amount}`,
requestedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `requested ${formattedAmount}${comment ? ` for ${comment}` : ''}`,
splitAmount: ({amount}: SplitAmountParams) => `split ${amount}`,
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ export default {
settledElsewhere: 'Pagado de otra forma',
settleExpensify: ({formattedAmount}: SettleExpensifyCardParams) => `Pagar ${formattedAmount} con Expensify`,
payElsewhere: 'Pagar de otra forma',
nextSteps: 'Pasos Siguientes',
requestAmount: ({amount}: RequestAmountParams) => `solicitar ${amount}`,
requestedAmount: ({formattedAmount, comment}: RequestedAmountMessageParams) => `solicité ${formattedAmount}${comment ? ` para ${comment}` : ''}`,
splitAmount: ({amount}: SplitAmountParams) => `dividir ${amount}`,
Expand Down
48 changes: 48 additions & 0 deletions src/pages/nextStepPropTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import PropTypes from 'prop-types';

const messagePropType = PropTypes.shape({
text: PropTypes.string,
type: PropTypes.string,
action: PropTypes.string,
});

export default PropTypes.shape({
/** The message parts of the next step */
message: PropTypes.arrayOf(messagePropType),

/** The title for the next step */
title: PropTypes.string,

/** Whether the the user must take some sort of action in order to unblock the report */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** Whether the the user must take some sort of action in order to unblock the report */
/** Whether the user should take some sort of action in order to unblock the report */

requiresUserAction: PropTypes.bool,

/** The type of next step */
type: PropTypes.oneOf(['neutral', 'alert', null]),

/** If the "Undo submit" button should be visible */
showUndoSubmit: PropTypes.bool,

/** If the next step should be displayed on mobile */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** If the next step should be displayed on mobile */
/** Deprecated - If the next step should be displayed on mobile, related to OldApp */

showForMobile: PropTypes.bool,

/** If the next step should be displayed at the expense level */
showForExpense: PropTypes.bool,

/** An optional alternate message to display on expenses instead of what is provided in the "message" field */
expenseMessage: PropTypes.arrayOf(messagePropType),

/** The next person in the approval chain of the report */
nextReceiver: PropTypes.string,

/** An array of buttons to be displayed next to the next step */
buttons: PropTypes.arrayOf(
PropTypes.shape({
text: PropTypes.string,
tooltip: PropTypes.string,
disabled: PropTypes.bool,
hidden: PropTypes.bool,
// eslint-disable-next-line react/forbid-prop-types
data: PropTypes.array,
}),
),
});
Loading