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
5 changes: 3 additions & 2 deletions src/hooks/useAccountTabIndicatorStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function useAccountTabIndicatorStatus(): AccountTabIndicatorStatusResult {
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true});
const [stripeCustomerId] = useOnyx(ONYXKEYS.NVP_PRIVATE_STRIPE_CUSTOMER_ID, {canBeMissing: true});
const [retryBillingSuccessful] = useOnyx(ONYXKEYS.SUBSCRIPTION_RETRY_BILLING_STATUS_SUCCESSFUL, {canBeMissing: true});
const [billingDisputePending] = useOnyx(ONYXKEYS.NVP_PRIVATE_BILLING_DISPUTE_PENDING, {canBeMissing: true});
// All of the error & info-checking methods are put into an array. This is so that using _.some() will return
// early as soon as the first error / info condition is returned. This makes the checks very efficient since
// we only care if a single error / info condition exists anywhere.
Expand All @@ -41,12 +42,12 @@ function useAccountTabIndicatorStatus(): AccountTabIndicatorStatusResult {
[CONST.INDICATOR_STATUS.HAS_WALLET_TERMS_ERRORS]: Object.keys(walletTerms?.errors ?? {}).length > 0 && !walletTerms?.chatReportID,
[CONST.INDICATOR_STATUS.HAS_CARD_CONNECTION_ERROR]: hasBrokenFeedConnection,
[CONST.INDICATOR_STATUS.HAS_PHONE_NUMBER_ERROR]: !!privatePersonalDetails?.errorFields?.phoneNumber,
[CONST.INDICATOR_STATUS.HAS_SUBSCRIPTION_ERRORS]: hasSubscriptionRedDotError(stripeCustomerId, retryBillingSuccessful),
[CONST.INDICATOR_STATUS.HAS_SUBSCRIPTION_ERRORS]: hasSubscriptionRedDotError(stripeCustomerId, retryBillingSuccessful, billingDisputePending),
};

const infoChecking: Partial<Record<AccountTabIndicatorStatus, boolean>> = {
[CONST.INDICATOR_STATUS.HAS_LOGIN_LIST_INFO]: !!loginList && hasLoginListInfo(loginList, session?.email),
[CONST.INDICATOR_STATUS.HAS_SUBSCRIPTION_INFO]: hasSubscriptionGreenDotInfo(stripeCustomerId, retryBillingSuccessful),
[CONST.INDICATOR_STATUS.HAS_SUBSCRIPTION_INFO]: hasSubscriptionGreenDotInfo(stripeCustomerId, retryBillingSuccessful, billingDisputePending),
};

const [error] = Object.entries(errorChecking).find(([, value]) => value) ?? [];
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useIndicatorStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function useIndicatorStatus(): IndicatorStatusResult {
const [allCards] = useOnyx(`${ONYXKEYS.CARD_LIST}`, {canBeMissing: true});
const [stripeCustomerId] = useOnyx(ONYXKEYS.NVP_PRIVATE_STRIPE_CUSTOMER_ID, {canBeMissing: true});
const [retryBillingSuccessful] = useOnyx(ONYXKEYS.SUBSCRIPTION_RETRY_BILLING_STATUS_SUCCESSFUL, {canBeMissing: true});
const [billingDisputePending] = useOnyx(ONYXKEYS.NVP_PRIVATE_BILLING_DISPUTE_PENDING, {canBeMissing: true});
const hasBrokenFeedConnection = checkIfFeedConnectionIsBroken(allCards, CONST.EXPENSIFY_CARD.BANK);
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true});

Expand All @@ -58,7 +59,7 @@ function useIndicatorStatus(): IndicatorStatusResult {
[CONST.INDICATOR_STATUS.HAS_USER_WALLET_ERRORS]: Object.keys(userWallet?.errors ?? {}).length > 0,
[CONST.INDICATOR_STATUS.HAS_PAYMENT_METHOD_ERROR]: hasPaymentMethodError(bankAccountList, fundList),
...(Object.fromEntries(Object.entries(policyErrors).map(([error, policy]) => [error, !!policy])) as Record<keyof typeof policyErrors, boolean>),
[CONST.INDICATOR_STATUS.HAS_SUBSCRIPTION_ERRORS]: hasSubscriptionRedDotError(stripeCustomerId, retryBillingSuccessful),
[CONST.INDICATOR_STATUS.HAS_SUBSCRIPTION_ERRORS]: hasSubscriptionRedDotError(stripeCustomerId, retryBillingSuccessful, billingDisputePending),
[CONST.INDICATOR_STATUS.HAS_REIMBURSEMENT_ACCOUNT_ERRORS]: Object.keys(reimbursementAccount?.errors ?? {}).length > 0,
[CONST.INDICATOR_STATUS.HAS_LOGIN_LIST_ERROR]: !!loginList && hasLoginListError(loginList),
// Wallet term errors that are not caused by an IOU (we show the red brick indicator for those in the LHN instead)
Expand All @@ -69,7 +70,7 @@ function useIndicatorStatus(): IndicatorStatusResult {

const infoChecking: Partial<Record<IndicatorStatus, boolean>> = {
[CONST.INDICATOR_STATUS.HAS_LOGIN_LIST_INFO]: !!loginList && hasLoginListInfo(loginList, session?.email),
[CONST.INDICATOR_STATUS.HAS_SUBSCRIPTION_INFO]: hasSubscriptionGreenDotInfo(stripeCustomerId, retryBillingSuccessful),
[CONST.INDICATOR_STATUS.HAS_SUBSCRIPTION_INFO]: hasSubscriptionGreenDotInfo(stripeCustomerId, retryBillingSuccessful, billingDisputePending),
};

const [error] = Object.entries(errorChecking).find(([, value]) => value) ?? [];
Expand Down
24 changes: 11 additions & 13 deletions src/libs/SubscriptionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ Onyx.connect({
callback: (value) => (amountOwed = value),
});

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

let billingStatus: OnyxEntry<BillingStatus>;
Onyx.connect({
key: ONYXKEYS.NVP_PRIVATE_BILLING_STATUS,
Expand Down Expand Up @@ -185,7 +179,7 @@ function hasCardAuthenticatedError(stripeCustomerId: OnyxEntry<StripeCustomerID>
/**
* @returns Whether there is a billing dispute pending.
*/
function hasBillingDisputePending() {
function hasBillingDisputePending(billingDisputePending: number | undefined) {
return !!billingDisputePending;
}

Expand Down Expand Up @@ -319,7 +313,11 @@ type SubscriptionStatus = {
/**
* @returns The subscription status.
*/
function getSubscriptionStatus(stripeCustomerId: OnyxEntry<StripeCustomerID>, retryBillingSuccessful: boolean | undefined): SubscriptionStatus | undefined {
function getSubscriptionStatus(
stripeCustomerId: OnyxEntry<StripeCustomerID>,
retryBillingSuccessful: boolean | undefined,
billingDisputePending: number | undefined,
): SubscriptionStatus | undefined {
if (hasOverdueGracePeriod()) {
if (hasAmountOwed()) {
// 1. Policy owner with amount owed, within grace period
Expand Down Expand Up @@ -356,7 +354,7 @@ function getSubscriptionStatus(stripeCustomerId: OnyxEntry<StripeCustomerID>, re
}
}
// 5. Billing disputed by cardholder
if (hasBillingDisputePending()) {
if (hasBillingDisputePending(billingDisputePending)) {
return {
status: PAYMENT_STATUS.BILLING_DISPUTE_PENDING,
isError: true,
Expand Down Expand Up @@ -416,15 +414,15 @@ function getSubscriptionStatus(stripeCustomerId: OnyxEntry<StripeCustomerID>, re
/**
* @returns Whether there is a subscription red dot error.
*/
function hasSubscriptionRedDotError(stripeCustomerId: OnyxEntry<StripeCustomerID>, retryBillingSuccessful: boolean | undefined): boolean {
return getSubscriptionStatus(stripeCustomerId, retryBillingSuccessful)?.isError ?? false;
function hasSubscriptionRedDotError(stripeCustomerId: OnyxEntry<StripeCustomerID>, retryBillingSuccessful: boolean | undefined, billingDisputePending: number | undefined): boolean {
return getSubscriptionStatus(stripeCustomerId, retryBillingSuccessful, billingDisputePending)?.isError ?? false;
}

/**
* @returns Whether there is a subscription green dot info.
*/
function hasSubscriptionGreenDotInfo(stripeCustomerId: OnyxEntry<StripeCustomerID>, retryBillingSuccessful: boolean | undefined): boolean {
return getSubscriptionStatus(stripeCustomerId, retryBillingSuccessful)?.isError === false;
function hasSubscriptionGreenDotInfo(stripeCustomerId: OnyxEntry<StripeCustomerID>, retryBillingSuccessful: boolean | undefined, billingDisputePending: number | undefined): boolean {
return getSubscriptionStatus(stripeCustomerId, retryBillingSuccessful, billingDisputePending)?.isError === false;
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/pages/settings/InitialSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false});
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
const [retryBillingSuccessful] = useOnyx(ONYXKEYS.SUBSCRIPTION_RETRY_BILLING_STATUS_SUCCESSFUL, {canBeMissing: true});

const [billingDisputePending] = useOnyx(ONYXKEYS.NVP_PRIVATE_BILLING_DISPUTE_PENDING, {canBeMissing: true});
const {shouldUseNarrowLayout} = useResponsiveLayout();
const network = useNetwork();
const theme = useTheme();
Expand Down Expand Up @@ -199,7 +199,9 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
icon: Expensicons.CreditCard,
screenName: SCREENS.SETTINGS.SUBSCRIPTION.ROOT,
brickRoadIndicator:
!!privateSubscription?.errors || hasSubscriptionRedDotError(stripeCustomerId, retryBillingSuccessful) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
!!privateSubscription?.errors || hasSubscriptionRedDotError(stripeCustomerId, retryBillingSuccessful, billingDisputePending)
? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR
: undefined,
badgeText: freeTrialText,
badgeStyle: freeTrialText ? styles.badgeSuccess : undefined,
action: () => Navigation.navigate(ROUTES.SETTINGS_SUBSCRIPTION.route),
Expand All @@ -226,6 +228,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
stripeCustomerId,
freeTrialText,
retryBillingSuccessful,
billingDisputePending,
]);

/**
Expand Down
4 changes: 4 additions & 0 deletions src/pages/settings/Subscription/CardSection/CardSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function CardSection() {
[purchaseList],
);
const [firstDayFreeTrial] = useOnyx(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, {canBeMissing: true});
const [billingDisputePending] = useOnyx(ONYXKEYS.NVP_PRIVATE_BILLING_DISPUTE_PENDING, {canBeMissing: true});
const requestRefund = useCallback(() => {
requestRefundByUser();
setIsRequestRefundModalVisible(false);
Expand All @@ -84,6 +85,7 @@ function CardSection() {
accountData: defaultCard?.accountData ?? {},
purchase: purchaseList?.[0],
retryBillingSuccessful: subscriptionRetryBillingStatusSuccessful,
billingDisputePending,
}),
);

Expand All @@ -103,6 +105,7 @@ function CardSection() {
accountData: defaultCard?.accountData ?? {},
purchase: purchaseList?.[0],
retryBillingSuccessful: subscriptionRetryBillingStatusSuccessful,
billingDisputePending,
}),
);
}, [
Expand All @@ -113,6 +116,7 @@ function CardSection() {
defaultCard?.accountData,
privateStripeCustomerID,
purchaseList,
billingDisputePending,
]);

const handleRetryPayment = () => {
Expand Down
5 changes: 3 additions & 2 deletions src/pages/settings/Subscription/CardSection/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ type GetBillingStatusProps = {
accountData?: AccountData;
purchase?: Purchase;
retryBillingSuccessful: OnyxEntry<boolean>;
billingDisputePending: number | undefined;
};

function getBillingStatus({translate, stripeCustomerId, accountData, purchase, retryBillingSuccessful}: GetBillingStatusProps): BillingStatusResult | undefined {
function getBillingStatus({translate, stripeCustomerId, accountData, purchase, retryBillingSuccessful, billingDisputePending}: GetBillingStatusProps): BillingStatusResult | undefined {
const cardEnding = (accountData?.cardNumber ?? '')?.slice(-4);

const amountOwed = getAmountOwed();

const subscriptionStatus = getSubscriptionStatus(stripeCustomerId, retryBillingSuccessful);
const subscriptionStatus = getSubscriptionStatus(stripeCustomerId, retryBillingSuccessful, billingDisputePending);

const endDate = getOverdueGracePeriodDate();

Expand Down
Loading