Skip to content

Commit 4cc8421

Browse files
Pass boolean to check whether payment is configured to reduce code duplication
1 parent 4d9049c commit 4cc8421

File tree

6 files changed

+15
-31
lines changed

6 files changed

+15
-31
lines changed

apps/web/src/app/admin-console/organizations/collections/vault.component.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,11 @@ export class VaultComponent implements OnInit, OnDestroy {
641641
]),
642642
),
643643
map(([org, sub, metadata]) =>
644-
this.trialFlowService.organizationHasUpcomingPaymentIssues(org, sub, metadata),
644+
this.trialFlowService.checkForOrgsWithUpcomingPaymentIssues(
645+
org,
646+
sub,
647+
metadata.isPaymentMethodConfigured,
648+
),
645649
),
646650
filter((result) => result !== null),
647651
);

apps/web/src/app/billing/organizations/payment-method/organization-payment-method.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class OrganizationPaymentMethodComponent implements OnDestroy {
144144
this.freeTrialData = this.trialFlowService.checkForOrgsWithUpcomingPaymentIssues(
145145
this.organization,
146146
this.organizationSubscriptionResponse,
147-
paymentSource,
147+
!!paymentSource,
148148
);
149149
}
150150
this.isUnpaid = this.subscriptionStatus === "unpaid" ?? false;

apps/web/src/app/billing/services/trial-flow.service.ts

+2-26
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ import { lastValueFrom } from "rxjs";
77
import { OrganizationApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization-api.service.abstraction";
88
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
99
import { BillingApiServiceAbstraction } from "@bitwarden/common/billing/abstractions/billing-api.service.abstraction";
10-
import { BillingSourceResponse } from "@bitwarden/common/billing/models/response/billing.response";
1110
import { OrganizationBillingMetadataResponse } from "@bitwarden/common/billing/models/response/organization-billing-metadata.response";
1211
import { OrganizationSubscriptionResponse } from "@bitwarden/common/billing/models/response/organization-subscription.response";
13-
import { PaymentSourceResponse } from "@bitwarden/common/billing/models/response/payment-source.response";
1412
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
1513
import { DialogService } from "@bitwarden/components";
1614

@@ -32,33 +30,11 @@ export class TrialFlowService {
3230
checkForOrgsWithUpcomingPaymentIssues(
3331
organization: Organization,
3432
organizationSubscription: OrganizationSubscriptionResponse,
35-
paymentSource: BillingSourceResponse | PaymentSourceResponse,
33+
isPaymentConfigured: boolean,
3634
): FreeTrial {
3735
const trialEndDate = organizationSubscription?.subscription?.trialEndDate;
3836
const displayBanner =
39-
!paymentSource &&
40-
organization?.isOwner &&
41-
organizationSubscription?.subscription?.status === "trialing";
42-
const trialRemainingDays = trialEndDate ? this.calculateTrialRemainingDays(trialEndDate) : 0;
43-
const freeTrialMessage = this.getFreeTrialMessage(trialRemainingDays);
44-
45-
return {
46-
remainingDays: trialRemainingDays,
47-
message: freeTrialMessage,
48-
shownBanner: displayBanner,
49-
organizationId: organization.id,
50-
organizationName: organization.name,
51-
};
52-
}
53-
54-
organizationHasUpcomingPaymentIssues(
55-
organization: Organization,
56-
organizationSubscription: OrganizationSubscriptionResponse,
57-
metadata: OrganizationBillingMetadataResponse,
58-
): FreeTrial {
59-
const trialEndDate = organizationSubscription?.subscription?.trialEndDate;
60-
const displayBanner =
61-
metadata.isPaymentMethodConfigured === false &&
37+
isPaymentConfigured === false &&
6238
organization?.isOwner &&
6339
organizationSubscription?.subscription?.status === "trialing";
6440
const trialRemainingDays = trialEndDate ? this.calculateTrialRemainingDays(trialEndDate) : 0;

apps/web/src/app/billing/shared/payment-method.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export class PaymentMethodComponent implements OnInit, OnDestroy {
209209
this.freeTrialData = this.trialFlowService.checkForOrgsWithUpcomingPaymentIssues(
210210
this.organization,
211211
this.org,
212-
this.billing?.paymentSource,
212+
!!this.billing?.paymentSource,
213213
);
214214
}
215215

apps/web/src/app/vault/individual-vault/vault.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ export class VaultComponent implements OnInit, OnDestroy {
225225
this.trialFlowService.checkForOrgsWithUpcomingPaymentIssues(
226226
org,
227227
subscription,
228-
paymentSource,
228+
!!paymentSource,
229229
),
230230
),
231231
),

bitwarden_license/bit-web/src/app/secrets-manager/overview/overview.component.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ export class OverviewComponent implements OnInit, OnDestroy {
174174
]),
175175
),
176176
map(([org, sub, paymentSource]) => {
177-
return this.trialFlowService.checkForOrgsWithUpcomingPaymentIssues(org, sub, paymentSource);
177+
return this.trialFlowService.checkForOrgsWithUpcomingPaymentIssues(
178+
org,
179+
sub,
180+
!!paymentSource,
181+
);
178182
}),
179183
filter((result) => result !== null),
180184
takeUntil(this.destroy$),

0 commit comments

Comments
 (0)