Skip to content

Commit

Permalink
Merge pull request #28998 from BeeMargarida/feat/28765-submit_draft_m…
Browse files Browse the repository at this point in the history
…oney_request_header

[NoQA] feat: show submit button in MoneyReportHeader when report is in draft
  • Loading branch information
mountiny authored Oct 10, 2023
2 parents 67a2024 + 7bb0e0b commit 8c00c5e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
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;
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={chatReport.isOwnPolicyExpenseChat}
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={chatReport.isOwnPolicyExpenseChat}
text={translate('common.submit')}
style={[styles.w100, styles.pr0]}
onPress={() => IOU.submitReport(moneyRequestReport)}
/>
</View>
)}
</View>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3812,7 +3812,7 @@ function getIOUReportActionDisplayMessage(reportAction) {
* @returns {Boolean}
*/
function isReportDraft(report) {
return lodashGet(report, 'stateNum') === CONST.REPORT.STATE_NUM.OPEN && lodashGet(report, 'statusNum') === CONST.REPORT.STATUS.OPEN;
return isExpenseReport(report) && lodashGet(report, 'stateNum') === CONST.REPORT.STATE_NUM.OPEN && lodashGet(report, 'statusNum') === CONST.REPORT.STATUS.OPEN;
}

export {
Expand Down

0 comments on commit 8c00c5e

Please sign in to comment.