Skip to content

Commit 1839271

Browse files
authored
fix(sdk): handle null upcoming invoice due date (#531)
* fix: use period_end_at if due_date is null in upcoming invoice * feat: show plan interval with plan name in upcoming invoice * chore: add daily as interval label
1 parent e1eff97 commit 1839271

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

sdks/js/packages/core/react/components/organization/billing/upcoming-billing-cycle.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import line from '~/react/assets/line.svg';
1010
import Amount from '../../helpers/Amount';
1111
import dayjs from 'dayjs';
1212
import { InfoCircledIcon } from '@radix-ui/react-icons';
13+
import { IntervalKeys, IntervalLabelMap } from '~/src/types';
1314

1415
function LabeledBillingData({
1516
label,
@@ -140,7 +141,8 @@ export const UpcomingBillingCycle = () => {
140141
}
141142
}, [client, billingAccount?.org_id, billingAccount?.id]);
142143

143-
const planName = plan?.title;
144+
const interval = IntervalLabelMap[plan?.interval as IntervalKeys];
145+
const planName = `${plan?.title} (${interval})`;
144146

145147
const planInfo = activeSubscription
146148
? {
@@ -169,9 +171,11 @@ export const UpcomingBillingCycle = () => {
169171
isMemberCountLoading ||
170172
isPlansLoading;
171173

174+
const due_date = upcomingInvoice?.due_date || upcomingInvoice?.period_end_at;
175+
172176
return isLoading ? (
173177
<Skeleton />
174-
) : upcomingInvoice && upcomingInvoice?.due_date ? (
178+
) : due_date ? (
175179
<Flex
176180
align={'center'}
177181
justify={'between'}
@@ -182,7 +186,7 @@ export const UpcomingBillingCycle = () => {
182186
<Flex gap="medium">
183187
<LabeledBillingData
184188
label="Next billing"
185-
value={dayjs(upcomingInvoice?.due_date).format(config.dateFormat)}
189+
value={dayjs(due_date).format(config.dateFormat)}
186190
/>
187191
{/* @ts-ignore */}
188192
<Image src={line} alt="line" />

sdks/js/packages/core/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export interface FrontierProviderProps {
6666
}
6767

6868
export const IntervalLabelMap = {
69+
daily: 'Daily',
6970
month: 'Monthly',
7071
year: 'Yearly'
7172
} as const;

0 commit comments

Comments
 (0)