Skip to content

Commit

Permalink
fewer params for isPayer,simplify paidPolicy check
Browse files Browse the repository at this point in the history
  • Loading branch information
c3024 committed Mar 4, 2024
1 parent f0b7d00 commit e9306bd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
3 changes: 1 addition & 2 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ function MoneyReportHeader({session, policy, chatReport, nextStep, report: money
const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID);
const canAllowSettlement = ReportUtils.hasUpdatedTotal(moneyRequestReport);
const policyType = policy?.type;
const isPolicyAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && policy?.role === CONST.POLICY.ROLE.ADMIN;
const isAutoReimbursable = ReportUtils.canBeAutoReimbursed(moneyRequestReport, policy);
const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicy(moneyRequestReport);
const isManager = ReportUtils.isMoneyRequestReport(moneyRequestReport) && session?.accountID === moneyRequestReport.managerID;
const isPayer = ReportUtils.isPayer(policy, session, moneyRequestReport, isPaidGroupPolicy, isPolicyAdmin);
const isPayer = ReportUtils.isPayer(session, moneyRequestReport);
const isDraft = ReportUtils.isDraftExpenseReport(moneyRequestReport);
const [isConfirmModalVisible, setIsConfirmModalVisible] = useState(false);

Expand Down
4 changes: 1 addition & 3 deletions src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ function ReportPreview({
const managerID = iouReport?.managerID ?? 0;
const isCurrentUserManager = managerID === session?.accountID;
const {totalDisplaySpend, reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(iouReport);
const policyType = policy?.type;
const isAutoReimbursable = ReportUtils.canBeAutoReimbursed(iouReport, policy);

const iouSettled = ReportUtils.isSettled(iouReportID);
Expand Down Expand Up @@ -208,8 +207,7 @@ function ReportPreview({
const bankAccountRoute = ReportUtils.getBankAccountRoute(chatReport);

const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport);
const isPolicyAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && policy?.role === CONST.POLICY.ROLE.ADMIN;
const isPayer = ReportUtils.isPayer(policy, session, iouReport, isPaidGroupPolicy, isPolicyAdmin);
const isPayer = ReportUtils.isPayer(session, iouReport);
const isOnInstantSubmitPolicy = PolicyUtils.isInstantSubmitEnabled(policy);
const isOnSubmitAndClosePolicy = PolicyUtils.isSubmitAndClose(policy);
const shouldShowPayButton = useMemo(
Expand Down
2 changes: 1 addition & 1 deletion src/components/SettlementButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function SettlementButton({
const policy = ReportUtils.getPolicy(policyID);
const session = useSession();
const chatReport = ReportUtils.getReport(chatReportID);
const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicy(iouReport as OnyxEntry<Report>) || ReportUtils.isPaidGroupPolicyExpenseChat(chatReport as OnyxEntry<Report>);
const isPaidGroupPolicy = ReportUtils.isPaidGroupPolicyExpenseChat(chatReport as OnyxEntry<Report>);
const shouldShowPaywithExpensifyOption =
!isPaidGroupPolicy ||
(!shouldHidePaymentOptions && policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES && policy?.reimburserEmail === session?.email);
Expand Down
19 changes: 7 additions & 12 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1225,17 +1225,13 @@ function isOneOnOneChat(report: OnyxEntry<Report>): boolean {
* Checks if the current user is a payer of the request
*/

function isPayer(
policy: OnyxEntry<Policy> | EmptyObject,
session: OnyxEntry<Session>,
iouReport: OnyxEntry<Report>,
// eslint-disable-next-line @typescript-eslint/no-shadow
isPaidGroupPolicy: boolean,
isAdmin: boolean,
) {
function isPayer(session: OnyxEntry<Session>, iouReport: OnyxEntry<Report>) {
const isApproved = isReportApproved(iouReport);
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${iouReport?.policyID}`] ?? null;
const policyType = policy?.type;
const isAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && policy?.role === CONST.POLICY.ROLE.ADMIN;
const isManager = iouReport?.managerID === session?.accountID;
if (isPaidGroupPolicy) {
if (isPaidGroupPolicy(iouReport)) {
if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) {
const isReimburser = session?.email === policy?.reimburserEmail;
return isReimburser && (isApproved || isManager);
Expand Down Expand Up @@ -1630,10 +1626,9 @@ function getIcons(
name: personalDetails?.[report?.ownerAccountID ?? -1]?.displayName ?? '',
fallbackIcon: personalDetails?.[report?.ownerAccountID ?? -1]?.fallbackIcon,
};
// eslint-disable-next-line @typescript-eslint/no-shadow
const isPayer = currentUserAccountID === report?.managerID;
const isManager = currentUserAccountID === report?.managerID;

return isPayer ? [managerIcon, ownerIcon] : [ownerIcon, managerIcon];
return isManager ? [managerIcon, ownerIcon] : [ownerIcon, managerIcon];
}

return getIconsForParticipants(report?.participantAccountIDs ?? [], personalDetails);
Expand Down

0 comments on commit e9306bd

Please sign in to comment.