Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
10e34a6
disable submit button when user is self approving but self approval i…
barros001 Feb 26, 2024
1bd040a
do not show pay buttons if report is not yet approved
barros001 Feb 26, 2024
b129002
disable approve button if user is self approving but self approval is…
barros001 Feb 26, 2024
fc76700
build optimistic next step message saying you are not allowed to appr…
barros001 Feb 27, 2024
0c353fd
remove isAllowedToApproveExpenseReport method
barros001 Feb 27, 2024
cb61086
updated shouldDisableSettlementButton logic
barros001 Feb 27, 2024
03c5f52
added isAllowedToApproveExpenseReport; added test case for nextStep
barros001 Feb 27, 2024
eea5225
updated shouldDisableSettlementButton logic
barros001 Feb 27, 2024
56872fc
Merge branch 'main' into fix/36425
barros001 Feb 29, 2024
bc58fb2
Merge branch 'main' into fix/36425
barros001 Mar 8, 2024
7bafaae
reverted unnecessary logic to show/hide pay button; reverted optimist…
barros001 Mar 8, 2024
8919284
reverted unnecessary logic to show/hide pay button
barros001 Mar 8, 2024
68ba966
disable submit button on report preview
barros001 Mar 8, 2024
e72e69a
updated logic to detect self approval
barros001 Mar 8, 2024
7ddf041
updated logic to determine when a user is allowed to submit expense
barros001 Mar 8, 2024
c52294d
reverted indentation
barros001 Mar 8, 2024
9f92147
disable approve button
barros001 Mar 11, 2024
1a3bfef
Merge branch 'main' into fix/36425
barros001 Mar 11, 2024
c7cb1ac
rename preventSelfApprovalEnabled to preventSelfApproval
barros001 Mar 11, 2024
900a775
disable only Approve option when settlement button has multiple options
barros001 Mar 11, 2024
3315d49
add line break
barros001 Mar 11, 2024
991ceff
stop using isPreventSelfApprovalEnabled
barros001 Mar 13, 2024
847cac1
Merge branch 'main' into fix/36425
barros001 Mar 13, 2024
359a565
Merge branch 'main' into fix/36425
barros001 Mar 20, 2024
97f1df6
removed conflict left over
barros001 Mar 20, 2024
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
2 changes: 1 addition & 1 deletion src/components/ButtonWithDropdownMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function ButtonWithDropdownMenu<IValueType>({
success={success}
ref={buttonRef}
pressOnEnter={pressOnEnter}
isDisabled={isDisabled}
isDisabled={isDisabled || !!options[0].disabled}
style={[styles.w100, style]}
isLoading={isLoading}
text={selectedItem.text}
Expand Down
1 change: 1 addition & 0 deletions src/components/ButtonWithDropdownMenu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type DropdownOption<TValueType> = {
iconHeight?: number;
iconDescription?: string;
onSelected?: () => void;
disabled?: boolean;
};

type ButtonWithDropdownMenuProps<TValueType> = {
Expand Down
7 changes: 7 additions & 0 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money

const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(moneyRequestReport, chatReport, policy), [moneyRequestReport, chatReport, policy]);

const shouldDisableApproveButton = shouldShowApproveButton && !ReportUtils.isAllowedToApproveExpenseReport(moneyRequestReport);

const shouldShowSettlementButton = shouldShowPayButton || shouldShowApproveButton;

const shouldShowSubmitButton = isDraft && reimbursableSpend !== 0;
const shouldDisableSubmitButton = shouldShowSubmitButton && !ReportUtils.isAllowedToSubmitDraftExpenseReport(moneyRequestReport);
const isFromPaidPolicy = policyType === CONST.POLICY.TYPE.TEAM || policyType === CONST.POLICY.TYPE.CORPORATE;
const shouldShowNextStep = !ReportUtils.isClosedExpenseReportWithNoExpenses(moneyRequestReport) && isFromPaidPolicy && !!nextStep?.message?.length;
const shouldShowAnyButton = shouldShowSettlementButton || shouldShowApproveButton || shouldShowSubmitButton || shouldShowNextStep;
Expand Down Expand Up @@ -121,6 +124,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money
addBankAccountRoute={bankAccountRoute}
shouldHidePaymentOptions={!shouldShowPayButton}
shouldShowApproveButton={shouldShowApproveButton}
shouldDisableApproveButton={shouldDisableApproveButton}
style={[styles.pv2]}
formattedAmount={formattedAmount}
isDisabled={!canAllowSettlement}
Expand All @@ -135,6 +139,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money
text={translate('common.submit')}
style={[styles.mnw120, styles.pv2, styles.pr0]}
onPress={() => IOU.submitReport(moneyRequestReport)}
isDisabled={shouldDisableSubmitButton}
/>
</View>
)}
Expand All @@ -153,6 +158,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money
addBankAccountRoute={bankAccountRoute}
shouldHidePaymentOptions={!shouldShowPayButton}
shouldShowApproveButton={shouldShowApproveButton}
shouldDisableApproveButton={shouldDisableApproveButton}
formattedAmount={formattedAmount}
isDisabled={!canAllowSettlement}
/>
Expand All @@ -166,6 +172,7 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money
text={translate('common.submit')}
style={[styles.w100, styles.pr0]}
onPress={() => IOU.submitReport(moneyRequestReport)}
isDisabled={shouldDisableSubmitButton}
/>
</View>
)}
Expand Down
4 changes: 4 additions & 0 deletions src/components/PopoverMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ type PopoverMenuItem = MenuItemProps & {

/** Sub menu items to be rendered after a menu item is selected */
subMenuItems?: PopoverMenuItem[];

/** Determines whether the menu item is disabled or not */
disabled?: boolean;
};

type PopoverModalProps = Pick<ModalProps, 'animationIn' | 'animationOut' | 'animationInTiming'>;
Expand Down Expand Up @@ -205,6 +208,7 @@ function PopoverMenu({
displayInDefaultIconColor={item.displayInDefaultIconColor}
shouldShowRightIcon={item.shouldShowRightIcon}
shouldPutLeftPaddingWhenNoIcon={item.shouldPutLeftPaddingWhenNoIcon}
disabled={item.disabled}
/>
))}
</View>
Expand Down
5 changes: 5 additions & 0 deletions src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function ReportPreview({
});

const shouldShowSubmitButton = isOpenExpenseReport && reimbursableSpend !== 0;
const shouldDisableSubmitButton = shouldShowSubmitButton && !ReportUtils.isAllowedToSubmitDraftExpenseReport(iouReport);

// The submit button should be success green colour only if the user is submitter and the policy does not have Scheduled Submit turned on
const isWaitingForSubmissionFromCurrentUser = useMemo(
Expand Down Expand Up @@ -209,6 +210,8 @@ function ReportPreview({

const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(iouReport, chatReport, policy), [iouReport, chatReport, policy]);

const shouldDisableApproveButton = shouldShowApproveButton && !ReportUtils.isAllowedToApproveExpenseReport(iouReport);

const shouldShowSettlementButton = shouldShowPayButton || shouldShowApproveButton;

const shouldPromptUserToAddBankAccount = ReportUtils.hasMissingPaymentMethod(userWallet, iouReportID);
Expand Down Expand Up @@ -307,6 +310,7 @@ function ReportPreview({
addBankAccountRoute={bankAccountRoute}
shouldHidePaymentOptions={!shouldShowPayButton}
shouldShowApproveButton={shouldShowApproveButton}
shouldDisableApproveButton={shouldDisableApproveButton}
kycWallAnchorAlignment={{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
Expand All @@ -324,6 +328,7 @@ function ReportPreview({
success={isWaitingForSubmissionFromCurrentUser}
text={translate('common.submit')}
onPress={() => iouReport && IOU.submitReport(iouReport)}
isDisabled={shouldDisableSubmitButton}
/>
)}
</View>
Expand Down
5 changes: 5 additions & 0 deletions src/components/SettlementButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type SettlementButtonProps = SettlementButtonOnyxProps & {
/** Should we show the payment options? */
shouldShowApproveButton?: boolean;

/** Should approve button be disabled? */
shouldDisableApproveButton?: boolean;

/** The policyID of the report we are paying */
policyID?: string;

Expand Down Expand Up @@ -124,6 +127,7 @@ function SettlementButton({
policyID = '',
shouldHidePaymentOptions = false,
shouldShowApproveButton = false,
shouldDisableApproveButton = false,
style,
shouldShowPersonalBankAccountOption = false,
enterKeyEventListenerPriority = 0,
Expand Down Expand Up @@ -166,6 +170,7 @@ function SettlementButton({
text: translate('iou.approve'),
icon: Expensicons.ThumbsUp,
value: CONST.IOU.REPORT_ACTION_TYPE.APPROVE,
disabled: !!shouldDisableApproveButton,
};
const canUseWallet = !isExpenseReport && currency === CONST.CURRENCY.USD;

Expand Down
18 changes: 18 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5402,6 +5402,22 @@ function canBeAutoReimbursed(report: OnyxEntry<Report>, policy: OnyxEntry<Policy
return isAutoReimbursable;
}

function isAllowedToApproveExpenseReport(report: OnyxEntry<Report>, approverAccountID?: number): boolean {
const policy = getPolicy(report?.policyID);
const {preventSelfApproval} = policy;

const isOwner = (approverAccountID ?? currentUserAccountID) === report?.ownerAccountID;

return !(preventSelfApproval && isOwner);
}

function isAllowedToSubmitDraftExpenseReport(report: OnyxEntry<Report>): boolean {
const policy = getPolicy(report?.policyID);
const {submitsTo} = policy;

return isAllowedToApproveExpenseReport(report, submitsTo);
}

/**
* What missing payment method does this report action indicate, if any?
*/
Expand Down Expand Up @@ -5652,6 +5668,8 @@ export {
canEditRoomVisibility,
canEditPolicyDescription,
getPolicyDescriptionText,
isAllowedToSubmitDraftExpenseReport,
isAllowedToApproveExpenseReport,
findSelfDMReportID,
getIndicatedMissingPaymentMethod,
isJoinRequestInAdminRoom,
Expand Down