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: 5 additions & 0 deletions .changeset/nasty-emus-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Invalidate invoices after successful checkout.
2 changes: 1 addition & 1 deletion packages/clerk-js/src/ui/contexts/components/Invoices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const InvoicesContextProvider = ({
}) => {
const { __experimental_commerce } = useClerk();
const { organization } = useOrganization();

const { user } = useUser();

const { data, isLoading, revalidate } = useFetch(
__experimental_commerce?.__experimental_billing.getInvoices,
{ ...(subscriberType === 'org' ? { orgId: organization?.id } : {}) },
Expand Down
14 changes: 13 additions & 1 deletion packages/clerk-js/src/ui/contexts/components/Plans.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export const PlansContextProvider = ({
children: ReactNode;
}) => {
const { __experimental_commerce } = useClerk();

const { organization } = useOrganization();
const { user } = useUser();
const {
data: subscriptions,
isLoading: isLoadingSubscriptions,
Expand All @@ -57,10 +58,21 @@ export const PlansContextProvider = ({
'commerce-plans',
);

// Revalidates the next time the hooks gets mounted
const { revalidate: revalidateInvoices } = useFetch(
undefined,
{
...(subscriberType === 'org' ? { orgId: organization?.id } : {}),
},
undefined,
`commerce-invoices-${user?.id}`,
);

const revalidate = () => {
// Revalidate the plans and subscriptions
revalidateSubscriptions();
revalidatePlans();
revalidateInvoices();
};

return (
Expand Down