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 MoneyReportHeader when report is in draft #28998

Merged
Show file tree
Hide file tree
Changes from 4 commits
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
39 changes: 32 additions & 7 deletions src/components/MoneyReportHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, report
const isPolicyAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && lodashGet(policy, 'role') === CONST.POLICY.ROLE.ADMIN;
const isManager = ReportUtils.isMoneyRequestReport(moneyRequestReport) && lodashGet(session, 'accountID', null) === moneyRequestReport.managerID;
const isPayer = policyType === CONST.POLICY.TYPE.CORPORATE ? isPolicyAdmin && isApproved : isPolicyAdmin || (ReportUtils.isMoneyRequestReport(moneyRequestReport) && isManager);
const isDraft = ReportUtils.isReportDraft(moneyRequestReport);
const shouldShowSettlementButton = useMemo(
() => isPayer && !isSettled && !moneyRequestReport.isWaitingOnBankAccount && reportTotal !== 0 && !ReportUtils.isArchivedRoom(chatReport),
[isPayer, isSettled, moneyRequestReport, reportTotal, chatReport],
() => isPayer && !isDraft && !isSettled && !moneyRequestReport.isWaitingOnBankAccount && reportTotal !== 0 && !ReportUtils.isArchivedRoom(chatReport),
[isPayer, isDraft, isSettled, moneyRequestReport, reportTotal, chatReport],
);
const shouldShowApproveButton = useMemo(() => {
if (policyType !== CONST.POLICY.TYPE.CORPORATE) {
return false;
}
return isManager && !isApproved && !isSettled;
}, [policyType, isManager, isApproved, isSettled]);
return isManager && !isDraft && !isApproved && !isSettled;
}, [policyType, isManager, isDraft, isApproved, isSettled]);
const shouldShowSubmitButton = isDraft;
Copy link
Contributor

Choose a reason for hiding this comment

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

Admin can submit and approve it is own report when Prevent self approval is enabled. So we should have prevented submitting it, ref: #36425

const shouldShowAnyButton = shouldShowSettlementButton || shouldShowApproveButton || shouldShowSubmitButton;
const bankAccountRoute = ReportUtils.getBankAccountRoute(chatReport);
const formattedAmount = CurrencyUtils.convertToDisplayString(reportTotal, moneyRequestReport.currency);

Expand All @@ -93,10 +96,10 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, report
personalDetails={personalDetails}
shouldShowBackButton={isSmallScreenWidth}
onBackButtonPress={() => Navigation.goBack(ROUTES.HOME, false, true)}
shouldShowBorderBottom={!shouldShowSettlementButton || !isSmallScreenWidth}
shouldShowBorderBottom={!shouldShowAnyButton || !isSmallScreenWidth}
>
{shouldShowSettlementButton && !isSmallScreenWidth && (
<View style={[styles.pv2]}>
<View style={styles.pv2}>
<SettlementButton
currency={moneyRequestReport.currency}
policyID={moneyRequestReport.policyID}
Expand All @@ -116,7 +119,7 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, report
</View>
)}
{shouldShowApproveButton && !isSmallScreenWidth && (
<View style={[styles.pv2]}>
<View style={styles.pv2}>
<Button
success
medium
Expand All @@ -126,6 +129,17 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, report
/>
</View>
)}
{shouldShowSubmitButton && !isSmallScreenWidth && (
<View style={styles.pv2}>
<Button
medium
success={moneyRequestReport.isOwnPolicyExpenseChat}
BeeMargarida marked this conversation as resolved.
Show resolved Hide resolved
text={translate('common.submit')}
style={[styles.mnw120, styles.pv2, styles.pr0]}
onPress={() => IOU.submitReport(moneyRequestReport)}
/>
</View>
)}
</HeaderWithBackButton>
{shouldShowSettlementButton && isSmallScreenWidth && (
<View style={[styles.ph5, styles.pb2, isSmallScreenWidth && styles.borderBottom]}>
Expand Down Expand Up @@ -153,6 +167,17 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, report
/>
</View>
)}
{shouldShowSubmitButton && isSmallScreenWidth && (
<View style={[styles.ph5, styles.pb2, isSmallScreenWidth && styles.borderBottom]}>
<Button
medium
success={moneyRequestReport.isOwnPolicyExpenseChat}
BeeMargarida marked this conversation as resolved.
Show resolved Hide resolved
text={translate('common.submit')}
style={[styles.w100, styles.pr0]}
BeeMargarida marked this conversation as resolved.
Show resolved Hide resolved
onPress={() => IOU.submitReport(moneyRequestReport)}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not exported right now I believe, wont we get complains about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's being exported from lib/actions/IOU

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I must have seen some commit diff then, sorry.

/>
</View>
)}
</View>
);
}
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;
}
BeeMargarida marked this conversation as resolved.
Show resolved Hide resolved

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() {
BeeMargarida marked this conversation as resolved.
Show resolved Hide resolved
// 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,
};
Loading