Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
const personalDetails = usePersonalDetails();
const defaultExpensePolicy = useDefaultExpensePolicy();
const activePolicyExpenseChat = getPolicyExpenseChat(accountID, defaultExpensePolicy?.id);
const [ownerBillingGraceEndPeriod] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [userBillingGraceEndPeriods] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReport?.chatReportID}`);
const [nextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport?.reportID}`);
Expand Down Expand Up @@ -995,11 +996,12 @@
policy,
userBillingGraceEndPeriods,
amountOwed,
ownerBillingGraceEndPeriod,
undefined,
undefined,
lastDistanceExpenseType,
),
[moneyRequestReport?.reportID, policy, userBillingGraceEndPeriods, amountOwed, lastDistanceExpenseType, expensifyIcons, translate],
[moneyRequestReport?.reportID, policy, userBillingGraceEndPeriods, amountOwed, lastDistanceExpenseType, expensifyIcons, translate, ownerBillingGraceEndPeriod],
);

const exportSubmenuOptions: Record<string, DropdownOption<string>> = useMemo(() => {
Expand Down Expand Up @@ -1644,7 +1646,7 @@

Navigation.setNavigationActionToMicrotaskQueue(() => {
Navigation.goBack(backToRoute);
InteractionManager.runAfterInteractions(() => {

Check failure on line 1649 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`runAfterInteractions` is deprecated
deleteAppReport(moneyRequestReport, selfDMReport, email ?? '', accountID, reportTransactions, allTransactionViolations, bankAccountList, currentSearchHash);
});
});
Expand Down Expand Up @@ -1716,7 +1718,7 @@
if (!moneyRequestReport?.reportID) {
return;
}
if (policy && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriods)) {
if (policy && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriods, ownerBillingGraceEndPeriod)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand Down Expand Up @@ -1850,7 +1852,7 @@
}
return option;
});
}, [originalSelectedTransactionsOptions, showDeleteModal, dismissedRejectUseExplanation]);

Check warning on line 1855 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useMemo has missing dependencies: 'isDelegateAccessRestricted' and 'showDelegateNoAccessModal'. Either include them or remove the dependency array

Check warning on line 1855 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useMemo has missing dependencies: 'isDelegateAccessRestricted' and 'showDelegateNoAccessModal'. Either include them or remove the dependency array

const shouldShowSelectedTransactionsButton = !!selectedTransactionsOptions.length && !transactionThreadReportID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ function MoneyRequestReportTransactionList({
const isReportArchived = useReportIsArchived(report?.reportID);
const shouldShowAddExpenseButton = canAddTransaction(report, isReportArchived) && isCurrentUserSubmitter(report);
const [userBillingGraceEndPeriodCollection] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const [ownerBillingGraceEndPeriod] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [lastDistanceExpenseType] = useOnyx(ONYXKEYS.NVP_LAST_DISTANCE_EXPENSE_TYPE);
const [reportLayoutGroupBy] = useOnyx(ONYXKEYS.NVP_REPORT_LAYOUT_GROUP_BY);
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
Expand All @@ -195,8 +196,19 @@ function MoneyRequestReportTransactionList({

const addExpenseDropdownOptions = useMemo(
() =>
getAddExpenseDropdownOptions(translate, expensifyIcons, report?.reportID, policy, userBillingGraceEndPeriodCollection, amountOwed, undefined, undefined, lastDistanceExpenseType),
[translate, expensifyIcons, report?.reportID, policy, userBillingGraceEndPeriodCollection, amountOwed, lastDistanceExpenseType],
getAddExpenseDropdownOptions(
translate,
expensifyIcons,
report?.reportID,
policy,
userBillingGraceEndPeriodCollection,
amountOwed,
ownerBillingGraceEndPeriod,
undefined,
undefined,
lastDistanceExpenseType,
),
[translate, expensifyIcons, report?.reportID, policy, userBillingGraceEndPeriodCollection, amountOwed, lastDistanceExpenseType, ownerBillingGraceEndPeriod],
);

const hasPendingAction = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
const [userBillingGraceEndPeriods] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const [chatReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${chatReportID}`);
const [iouReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${iouReportID}`);
const [ownerBillingGraceEndPeriod] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [iouReportNextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReportID}`);
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
Expand Down Expand Up @@ -692,11 +693,23 @@
policy,
userBillingGraceEndPeriods,
amountOwed,
ownerBillingGraceEndPeriod,
chatReportID,
iouReport?.parentReportID,
lastDistanceExpenseType,
),
[translate, expensifyIcons, iouReport?.reportID, iouReport?.parentReportID, policy, userBillingGraceEndPeriods, amountOwed, chatReportID, lastDistanceExpenseType],
[
translate,
expensifyIcons,
iouReport?.reportID,
iouReport?.parentReportID,
policy,
userBillingGraceEndPeriods,
amountOwed,
chatReportID,
lastDistanceExpenseType,
ownerBillingGraceEndPeriod,
],
);

const isReportDeleted = action?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
Expand Down Expand Up @@ -878,7 +891,7 @@
{/* This will be fixed as follow up https://github.com/Expensify/App/pull/75357 */}
{/* eslint-disable-next-line @typescript-eslint/no-deprecated */}
{}
{getReportName({report: iouReport, reportAttributes}) || action.childReportName}

Check failure on line 894 in src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`getReportName` is deprecated. Moved to src/libs/ReportNameUtils.ts
</Text>
</Animated.View>
</View>
Expand Down
11 changes: 8 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1024 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1029,7 +1029,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1032 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1047,7 +1047,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1050 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (currentUserAccountID) {
Expand All @@ -1059,7 +1059,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1062 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1068,7 +1068,7 @@
let allPolicies: OnyxCollection<Policy>;
let hasPolicies: boolean;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1071 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1079,7 +1079,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1082 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1087,7 +1087,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1090 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1123,14 +1123,14 @@
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({

Check warning on line 1126 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let allTransactions: OnyxCollection<Transaction> = {};
let reportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1133 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -2413,7 +2413,7 @@
// since they are not a part of the company, and should not action it on their behalf.
if (report.policyID) {
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
const policy = getPolicy(report.policyID);

Check failure on line 2416 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`getPolicy` is deprecated. Get the data straight from Onyx - This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
if (!isExpensifyTeam(policy?.owner) && isExpensifyTeam(currentUserPersonalDetails?.login)) {
return false;
}
Expand All @@ -2427,7 +2427,7 @@
function isAuditor(report: OnyxEntry<Report>): boolean {
if (report?.policyID) {
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
const policy = getPolicy(report.policyID);

Check failure on line 2430 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`getPolicy` is deprecated. Get the data straight from Onyx - This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
return isPolicyAuditor(policy);
}

Expand Down Expand Up @@ -2837,7 +2837,7 @@
}

// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
const policy = getPolicy(moneyRequestReport?.policyID);

Check failure on line 2840 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`getPolicy` is deprecated. Get the data straight from Onyx - This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850

if (isExpenseReport(moneyRequestReport) && (!isCurrentUserSubmitter(moneyRequestReport) || !isPaidGroupPolicyPolicyUtils(policy))) {
return false;
Expand Down Expand Up @@ -2908,7 +2908,7 @@
) {
const reportActions = getAllReportActions(chatReport.reportID);
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
const policy = getPolicy(chatReport.policyID);

Check failure on line 2911 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`getPolicy` is deprecated. Get the data straight from Onyx - This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
return Object.values(reportActions).some((action) => {
const iouReportID = getIOUReportIDFromReportActionPreview(action);
if (
Expand Down Expand Up @@ -2939,7 +2939,7 @@
const canSubmit = !hasAutoRejectedTransactionsForManager && canSubmitReport(iouReport, policy, transactions, undefined, false, currentUserEmailParam, currentUserAccountIDParam);
const invoiceReceiverPolicyID = chatReport?.invoiceReceiver && 'policyID' in chatReport.invoiceReceiver ? chatReport.invoiceReceiver.policyID : undefined;
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
const invoiceReceiverPolicy = getPolicy(invoiceReceiverPolicyID);

Check failure on line 2942 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`getPolicy` is deprecated. Get the data straight from Onyx - This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
return (
canIOUBePaid(iouReport, chatReport, policy, bankAccountList, transactions, undefined, undefined, invoiceReceiverPolicy) ||
canApproveIOU(iouReport, policy, reportMetadata, transactions) ||
Expand All @@ -2962,6 +2962,7 @@
policy: OnyxEntry<Policy>,
userBillingGraceEndPeriodCollection: OnyxCollection<BillingGraceEndPeriod>,
amountOwed: OnyxEntry<number>,
ownerBillingGraceEndPeriod: OnyxEntry<number>,
iouRequestBackToReport?: string,
unreportedExpenseBackToReport?: string,
lastDistanceExpenseType?: IOURequestType,
Expand All @@ -2976,7 +2977,11 @@
if (!iouReportID) {
return;
}
if (policy && policy.type !== CONST.POLICY.TYPE.PERSONAL && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriodCollection, amountOwed)) {
if (
policy &&
policy.type !== CONST.POLICY.TYPE.PERSONAL &&
shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriodCollection, amountOwed, ownerBillingGraceEndPeriod)
) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand All @@ -2992,7 +2997,7 @@
if (!iouReportID) {
return;
}
if (policy && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriodCollection, amountOwed)) {
if (policy && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriodCollection, amountOwed, ownerBillingGraceEndPeriod)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand All @@ -3005,7 +3010,7 @@
icon: icons.ReceiptPlus,
sentryLabel: CONST.SENTRY_LABEL.MORE_MENU.ADD_EXPENSE_UNREPORTED,
onSelected: () => {
if (policy && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriodCollection, amountOwed)) {
if (policy && shouldRestrictUserBillableActions(policy.id, userBillingGraceEndPeriodCollection, amountOwed, ownerBillingGraceEndPeriod)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand Down Expand Up @@ -3561,7 +3566,7 @@
const receiverPolicyID = report?.invoiceReceiver?.policyID;

// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
const receiverPolicy = invoiceReceiverPolicy ?? getPolicy(receiverPolicyID);

Check failure on line 3569 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`getPolicy` is deprecated. Get the data straight from Onyx - This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
if (!isEmptyObject(receiverPolicy)) {
return [
{
Expand Down Expand Up @@ -3776,7 +3781,7 @@

const receiverPolicyID = invoiceRoomReport?.invoiceReceiver?.policyID;
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
const receiverPolicy = invoiceReceiverPolicy ?? getPolicy(receiverPolicyID);

Check failure on line 3784 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`getPolicy` is deprecated. Get the data straight from Onyx - This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850

if (!isEmptyObject(receiverPolicy)) {
icons.push({
Expand Down Expand Up @@ -3925,7 +3930,7 @@
let pronouns = user?.pronouns ?? undefined;
if (pronouns?.startsWith(CONST.PRONOUNS.PREFIX)) {
const pronounTranslationKey = pronouns.replace(CONST.PRONOUNS.PREFIX, '');
pronouns = translateLocal(`pronouns.${pronounTranslationKey}` as TranslationPaths);

Check failure on line 3933 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`translateLocal` is deprecated. This function uses imperative Onyx data access patterns, similar to `Onyx.connect`. Use `useLocalize` hook instead for reactive data access in React components
}

return {
Expand Down
53 changes: 15 additions & 38 deletions src/libs/SubscriptionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ Onyx.connect({
callback: (value) => (privateAmountOwed = value),
});

let ownerBillingGraceEndPeriod: OnyxEntry<number>;
let ownerBillingGraceEndPeriodDeprecated: OnyxEntry<number>;
Onyx.connect({
key: ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END,
callback: (value) => (ownerBillingGraceEndPeriod = value),
callback: (value) => (ownerBillingGraceEndPeriodDeprecated = value),
});

let deprecatedUserBillingGraceEndPeriodCollection: OnyxCollection<BillingGraceEndPeriod>;
Expand All @@ -86,30 +86,11 @@ Onyx.connect({
waitForCollectionCallback: true,
});

/**
* @returns The date when the grace period ends.
* @param gracePeriodEnd - Optional parameter to use instead of module-level value (for pure function usage).
*/
function getOverdueGracePeriodDate(gracePeriodEnd?: OnyxEntry<number>): OnyxEntry<number> {
return gracePeriodEnd ?? ownerBillingGraceEndPeriod;
}

/**
* @returns Whether the workspace owner has an overdue grace period.
* @param gracePeriodEnd - Optional parameter to use instead of module-level value (for pure function usage).
*/
function hasOverdueGracePeriod(gracePeriodEnd?: OnyxEntry<number>): boolean {
const value = gracePeriodEnd ?? ownerBillingGraceEndPeriod;
return !!value;
}

/**
* @returns Whether the workspace owner's grace period is overdue.
* @param gracePeriodEnd - Optional parameter to use instead of module-level value (for pure function usage).
*/
function hasGracePeriodOverdue(gracePeriodEnd?: OnyxEntry<number>): boolean {
const value = gracePeriodEnd ?? ownerBillingGraceEndPeriod;
return !!value && Date.now() > new Date(value).getTime();
function hasGracePeriodOverdue(gracePeriodEnd: OnyxEntry<number>): boolean {
return !!gracePeriodEnd && Date.now() > new Date(gracePeriodEnd).getTime();
}

/**
Expand Down Expand Up @@ -261,7 +242,6 @@ type SubscriptionStatus = {

/**
* @returns The subscription status.
* @param ownerBillingGraceEndPeriodParam - Optional parameter to use instead of module-level value (for pure function usage).
*/
function getSubscriptionStatus(
stripeCustomerId: OnyxEntry<StripeCustomerID>,
Expand All @@ -271,36 +251,36 @@ function getSubscriptionStatus(
fundList: OnyxEntry<FundList>,
billingStatus: OnyxEntry<BillingStatus>,
amountOwed: number,
ownerBillingGraceEndPeriodParam?: OnyxEntry<number>,
ownerBillingGraceEndPeriod: OnyxEntry<number>,
): SubscriptionStatus | undefined {
if (hasOverdueGracePeriod(ownerBillingGraceEndPeriodParam)) {
if (ownerBillingGraceEndPeriod) {
if (amountOwed !== 0) {
// 1. Policy owner with amount owed, within grace period
if (!hasGracePeriodOverdue(ownerBillingGraceEndPeriodParam)) {
if (!hasGracePeriodOverdue(ownerBillingGraceEndPeriod)) {
return {
status: PAYMENT_STATUS.POLICY_OWNER_WITH_AMOUNT_OWED,
isError: true,
};
}

// 2. Policy owner with amount owed, overdue (past grace period)
if (hasGracePeriodOverdue(ownerBillingGraceEndPeriodParam)) {
if (hasGracePeriodOverdue(ownerBillingGraceEndPeriod)) {
return {
isError: true,
status: PAYMENT_STATUS.POLICY_OWNER_WITH_AMOUNT_OWED_OVERDUE,
};
}
} else {
// 3. Owner of policy under invoicing, within grace period
if (!hasGracePeriodOverdue(ownerBillingGraceEndPeriodParam)) {
if (!hasGracePeriodOverdue(ownerBillingGraceEndPeriod)) {
return {
status: PAYMENT_STATUS.OWNER_OF_POLICY_UNDER_INVOICING,
isError: true,
};
}

// 4. Owner of policy under invoicing, overdue (past grace period)
if (hasGracePeriodOverdue(ownerBillingGraceEndPeriodParam)) {
if (hasGracePeriodOverdue(ownerBillingGraceEndPeriod)) {
return {
status: PAYMENT_STATUS.OWNER_OF_POLICY_UNDER_INVOICING_OVERDUE,
isError: true,
Expand Down Expand Up @@ -368,7 +348,6 @@ function getSubscriptionStatus(

/**
* @returns Whether there is a subscription red dot error.
* @param ownerBillingGraceEndPeriodParam - Optional parameter to use instead of module-level value (for pure function usage).
*/
function hasSubscriptionRedDotError(
stripeCustomerId: OnyxEntry<StripeCustomerID>,
Expand All @@ -378,17 +357,16 @@ function hasSubscriptionRedDotError(
fundList: OnyxEntry<FundList>,
billingStatus: OnyxEntry<BillingStatus>,
amountOwed: number,
ownerBillingGraceEndPeriodParam?: OnyxEntry<number>,
ownerBillingGraceEndPeriod: OnyxEntry<number>,
): boolean {
return (
getSubscriptionStatus(stripeCustomerId, retryBillingSuccessful, billingDisputePending, retryBillingFailed, fundList, billingStatus, amountOwed, ownerBillingGraceEndPeriodParam)
getSubscriptionStatus(stripeCustomerId, retryBillingSuccessful, billingDisputePending, retryBillingFailed, fundList, billingStatus, amountOwed, ownerBillingGraceEndPeriod)
?.isError ?? false
);
}

/**
* @returns Whether there is a subscription green dot info.
* @param ownerBillingGraceEndPeriodParam - Optional parameter to use instead of module-level value (for pure function usage).
*/
function hasSubscriptionGreenDotInfo(
stripeCustomerId: OnyxEntry<StripeCustomerID>,
Expand All @@ -398,10 +376,10 @@ function hasSubscriptionGreenDotInfo(
fundList: OnyxEntry<FundList>,
billingStatus: OnyxEntry<BillingStatus>,
amountOwed: number,
ownerBillingGraceEndPeriodParam?: OnyxEntry<number>,
ownerBillingGraceEndPeriod: OnyxEntry<number>,
): boolean {
return (
getSubscriptionStatus(stripeCustomerId, retryBillingSuccessful, billingDisputePending, retryBillingFailed, fundList, billingStatus, amountOwed, ownerBillingGraceEndPeriodParam)
getSubscriptionStatus(stripeCustomerId, retryBillingSuccessful, billingDisputePending, retryBillingFailed, fundList, billingStatus, amountOwed, ownerBillingGraceEndPeriod)
?.isError === false
);
}
Expand Down Expand Up @@ -493,6 +471,7 @@ function shouldRestrictUserBillableActions(
policyID: string,
userBillingGraceEndPeriodCollection: OnyxCollection<BillingGraceEndPeriod> = deprecatedUserBillingGraceEndPeriodCollection,
amountOwed: OnyxEntry<number> = privateAmountOwed,
ownerBillingGraceEndPeriod: OnyxEntry<number> = ownerBillingGraceEndPeriodDeprecated,
): boolean {
const currentDate = new Date();

Expand Down Expand Up @@ -623,11 +602,9 @@ export {
doesUserHavePaymentCardAdded,
getCardForSubscriptionBilling,
getFreeTrialText,
getOverdueGracePeriodDate,
getSubscriptionStatus,
hasCardAuthenticatedError,
hasGracePeriodOverdue,
hasOverdueGracePeriod,
hasRetryBillingError,
hasSubscriptionGreenDotInfo,
hasSubscriptionRedDotError,
Expand Down
Loading
Loading