-
Notifications
You must be signed in to change notification settings - Fork 419
fix(clerk-js): Display past due subscriptions properly #6309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
panteliselef
merged 45 commits into
main
from
elef/com-1036-display-past-due-subscriptions-properly
Jul 14, 2025
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
234ce35
wip
panteliselef 2041111
wip 2
panteliselef e7a3f26
create the layout and functionality
panteliselef 7af1561
display button for annual to switch to monthly as well
panteliselef a64ed1d
Merge branch 'refs/heads/main' into elef/com-835-split-up-plandetails…
panteliselef 99607d7
implement new UI
panteliselef 0af7fb9
add unit tests
panteliselef a2303b6
address issue with animation
panteliselef e0f8e1a
add more test cases
panteliselef 1b75fe1
use box shadow instead of border
panteliselef a8db78f
Merge branch 'main' into elef/com-835-split-up-plandetails-and-subscr…
panteliselef 3a0907c
remove unnecessary context
panteliselef 1ddd06b
handle missing avatar url
panteliselef d84f755
add descriptors
panteliselef 99f4342
Merge branch 'refs/heads/main' into elef/com-835-split-up-plandetails…
panteliselef aaf814c
add more descriptors
panteliselef 55f1ba3
handle localizations
panteliselef 962e8d5
fix issues from conflicts
panteliselef 84528d0
finishing touches on subscription details
panteliselef dc926ab
add unit tests for PlanDetails
panteliselef 79b3c79
remove old file
panteliselef 958fdd9
replace experimental with internal apis
panteliselef c5dafc4
Update packages/types/src/clerk.ts
panteliselef bd9984f
address pr comments
panteliselef 587f2b8
wip
panteliselef af6a28b
Revert "wip"
panteliselef 1c161cc
address pr feedback
panteliselef 0ed99f1
bump
panteliselef 39100a9
wip subscription items
panteliselef 7db88a9
Revert "wip subscription items"
panteliselef 257a3cc
wip changeset
panteliselef 3753dee
bundlewatch.config.json
panteliselef 477d3f5
Merge branch 'refs/heads/main' into elef/com-835-split-up-plandetails…
panteliselef 28d86b4
fix lint
panteliselef 38fa5f6
fix build issue
panteliselef f536952
Adds past due at
panteliselef 63b60ce
chore(clerk-js, types, localization): Handle past due subscription
panteliselef e010868
add unit tests
panteliselef 0664cfd
Merge branch 'main' into elef/handle-past-due-items
panteliselef 5a730fe
Merge branch 'main' into elef/com-1036-display-past-due-subscriptions…
panteliselef 639e180
add changeset
panteliselef 497df84
address rabbit feedback
panteliselef 778349e
Update packages/localizations/src/en-US.ts
panteliselef 4c75e78
Merge branch 'main' into elef/com-1036-display-past-due-subscriptions…
panteliselef 522a357
update test
panteliselef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@clerk/localizations': minor | ||
| '@clerk/clerk-js': minor | ||
| '@clerk/types': minor | ||
| --- | ||
|
|
||
| Display past due subscriptions properly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -729,4 +729,74 @@ describe('SubscriptionDetails', () => { | |
| ); | ||
| }); | ||
| }); | ||
|
|
||
| it('past due subscription shows correct status and disables actions', async () => { | ||
| const { wrapper, fixtures } = await createFixtures(f => { | ||
| f.withUser({ email_addresses: ['[email protected]'] }); | ||
| }); | ||
|
|
||
| const plan = { | ||
| id: 'plan_monthly', | ||
| name: 'Monthly Plan', | ||
| amount: 1000, | ||
| amountFormatted: '10.00', | ||
| annualAmount: 9000, | ||
| annualAmountFormatted: '90.00', | ||
| annualMonthlyAmount: 750, | ||
| annualMonthlyAmountFormatted: '7.50', | ||
| currencySymbol: '$', | ||
| description: 'Monthly Plan', | ||
| hasBaseFee: true, | ||
| isRecurring: true, | ||
| currency: 'USD', | ||
| isDefault: false, | ||
| payerType: ['user'], | ||
| publiclyVisible: true, | ||
| slug: 'monthly-plan', | ||
| avatarUrl: '', | ||
| features: [], | ||
| }; | ||
|
|
||
| fixtures.clerk.billing.getSubscriptions.mockResolvedValue({ | ||
| data: [ | ||
| { | ||
| id: 'sub_past_due', | ||
| plan, | ||
| createdAt: new Date('2021-01-01'), | ||
| periodStartDate: new Date('2021-01-01'), | ||
| periodEndDate: new Date('2021-02-01'), | ||
| canceledAtDate: null, | ||
| paymentSourceId: 'src_123', | ||
| planPeriod: 'month' as const, | ||
| status: 'past_due' as const, | ||
| pastDueAt: new Date('2021-01-15'), | ||
| }, | ||
| ], | ||
| total_count: 1, | ||
| }); | ||
|
|
||
| const { getByRole, getByText, queryByText, queryByRole } = render( | ||
| <Drawer.Root | ||
| open | ||
| onOpenChange={() => {}} | ||
| > | ||
| <SubscriptionDetails /> | ||
| </Drawer.Root>, | ||
| { wrapper }, | ||
| ); | ||
|
|
||
| await waitFor(() => { | ||
| expect(getByRole('heading', { name: /Subscription/i })).toBeVisible(); | ||
| expect(getByText('Monthly Plan')).toBeVisible(); | ||
| expect(getByText('Past due')).toBeVisible(); | ||
| expect(getByText('$10.00 / Month')).toBeVisible(); | ||
|
|
||
| expect(queryByText('Subscribed on')).toBeNull(); | ||
| expect(getByText('Past due on')).toBeVisible(); | ||
| expect(getByText('January 15, 2021')).toBeVisible(); | ||
|
|
||
| // Menu button should be present but disabled | ||
| expect(queryByRole('button', { name: /Open menu/i })).toBeNull(); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/clerk-js/src/ui/components/Subscriptions/badge.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import type { CommerceSubscriptionResource } from '@clerk/types'; | ||
|
|
||
| import { Badge, localizationKeys } from '@/ui/customizables'; | ||
| import type { ElementDescriptor } from '@/ui/customizables/elementDescriptors'; | ||
|
|
||
| const keys = { | ||
| active: 'badge__activePlan', | ||
| upcoming: 'badge__upcomingPlan', | ||
| past_due: 'badge__pastDuePlan', | ||
| }; | ||
|
|
||
| const colors = { | ||
| active: 'secondary', | ||
| upcoming: 'primary', | ||
| past_due: 'warning', | ||
| }; | ||
|
|
||
| export const SubscriptionBadge = ({ | ||
| subscription, | ||
| elementDescriptor, | ||
| }: { | ||
| subscription: CommerceSubscriptionResource; | ||
| elementDescriptor?: ElementDescriptor; | ||
| }) => { | ||
| return ( | ||
| <Badge | ||
| elementDescriptor={elementDescriptor} | ||
| colorScheme={ | ||
| // @ts-expect-error `ended` is included | ||
| colors[subscription.status] | ||
| } | ||
| localizationKey={localizationKeys( | ||
| // @ts-expect-error `ended` is included | ||
| keys[subscription.status], | ||
| )} | ||
| /> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.