Skip to content

Commit 85a8202

Browse files
committed
ref: Use narrower type for next bill preview API
1 parent 589b5cb commit 85a8202

3 files changed

Lines changed: 21 additions & 12 deletions

File tree

static/gsApp/utils/billing.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ import type {
3232
BillingMetricHistory,
3333
BillingStatTotal,
3434
EventBucket,
35-
InvoiceItem,
35+
InvoiceItemType,
3636
Plan,
37-
PreviewInvoiceItem,
3837
ProductTrial,
3938
Subscription,
4039
} from 'getsentry/types';
@@ -798,10 +797,10 @@ export const RETENTION_SETTINGS_CATEGORIES = new Set([
798797
DataCategory.TRANSACTIONS,
799798
]);
800799

801-
export function getCredits({
800+
export function getCredits<T extends {amount: number; type: InvoiceItemType}>({
802801
invoiceItems,
803802
}: {
804-
invoiceItems: InvoiceItem[] | PreviewInvoiceItem[];
803+
invoiceItems: T[];
805804
}) {
806805
return invoiceItems.filter(
807806
item =>
@@ -820,7 +819,7 @@ export function getCreditApplied({
820819
invoiceItems,
821820
}: {
822821
creditApplied: number;
823-
invoiceItems: InvoiceItem[] | PreviewInvoiceItem[];
822+
invoiceItems: Array<{amount: number; type: InvoiceItemType}>;
824823
}) {
825824
const credits = getCredits({invoiceItems});
826825
if (credits.some(item => item.type === 'balance_change')) {
@@ -833,10 +832,10 @@ export function getCreditApplied({
833832
* Returns extra fees included in the invoice or preview data, such as tax
834833
* or cancellation fees.
835834
*/
836-
export function getFees({
835+
export function getFees<T extends {amount: number; type: InvoiceItemType}>({
837836
invoiceItems,
838837
}: {
839-
invoiceItems: InvoiceItem[] | PreviewInvoiceItem[];
838+
invoiceItems: T[];
840839
}) {
841840
return invoiceItems.filter(
842841
item =>
@@ -848,10 +847,10 @@ export function getFees({
848847
/**
849848
* Returns ondemand invoice items from the invoice or preview data.
850849
*/
851-
export function getOnDemandItems({
850+
export function getOnDemandItems<T extends {amount: number; type: InvoiceItemType}>({
852851
invoiceItems,
853852
}: {
854-
invoiceItems: InvoiceItem[] | PreviewInvoiceItem[];
853+
invoiceItems: T[];
855854
}) {
856855
return invoiceItems.filter(item => item.type.startsWith('ondemand'));
857856
}

static/gsApp/views/amCheckout/components/checkoutSuccess.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ export function CheckoutSuccess({
519519

520520
const isImmediateCharge = !!invoice; // if they paid for something now, the changes are effective immediately
521521
const data = isImmediateCharge ? invoice : previewData;
522-
const invoiceItems = isImmediateCharge
522+
const invoiceItems: Array<InvoiceItem | PreviewInvoiceItem> = isImmediateCharge
523523
? invoice.items
524524
: (previewData?.invoiceItems ?? []);
525525
const planItem = invoiceItems.find(item => item.type === 'subscription');

static/gsApp/views/subscriptionPage/headerCards/nextBillCard.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {getApiUrl} from 'sentry/utils/api/getApiUrl';
1212
import {getDaysSinceDate} from 'sentry/utils/getDaysSinceDate';
1313
import {useApiQuery} from 'sentry/utils/queryClient';
1414

15-
import type {PreviewData, Subscription} from 'getsentry/types';
15+
import type {PreviewInvoiceItem, Subscription} from 'getsentry/types';
1616
import {
1717
displayBudgetName,
1818
getCreditApplied,
@@ -22,6 +22,16 @@ import {
2222
import {displayPriceWithCents} from 'getsentry/views/amCheckout/utils';
2323
import {SubscriptionHeaderCard} from 'getsentry/views/subscriptionPage/headerCards/subscriptionHeaderCard';
2424

25+
type NextBillInvoiceItem = Pick<PreviewInvoiceItem, 'amount' | 'type' | 'description'>;
26+
27+
type NextBillPreview = {
28+
billedAmount: number;
29+
creditApplied: number;
30+
effectiveAt: string;
31+
invoiceItems: NextBillInvoiceItem[];
32+
isAnnual: boolean;
33+
};
34+
2535
export function NextBillCard({
2636
subscription,
2737
organization,
@@ -33,7 +43,7 @@ export function NextBillCard({
3343
data: nextBill,
3444
isLoading,
3545
isError,
36-
} = useApiQuery<PreviewData>(
46+
} = useApiQuery<NextBillPreview>(
3747
[
3848
getApiUrl('/customers/$organizationIdOrSlug/subscription/next-bill/', {
3949
path: {organizationIdOrSlug: organization.slug},

0 commit comments

Comments
 (0)