Skip to content

Commit ef34eed

Browse files
committed
Replace useOrganization with useOrganizationContext
1 parent edbd18c commit ef34eed

File tree

7 files changed

+28
-23
lines changed

7 files changed

+28
-23
lines changed

.changeset/cuddly-cougars-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Internal change, not user facing: Replace `useOrganization` within billing components with `useOrganizationContext`

packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useClerk, useOrganization } from '@clerk/shared/react';
1+
import { useClerk, useOrganizationContext } from '@clerk/shared/react';
22
import type { BillingSubscriptionItemResource } from '@clerk/shared/types';
33
import useSWR from 'swr';
44

@@ -29,7 +29,7 @@ import { useRouter } from '../../router';
2929
export const PaymentAttemptPage = () => {
3030
const { params, navigate } = useRouter();
3131
const subscriberType = useSubscriberTypeContext();
32-
const { organization } = useOrganization();
32+
const organizationCtx = useOrganizationContext();
3333
const localizationRoot = useSubscriberTypeLocalizationRoot();
3434
const { t, translateError } = useLocalizations();
3535
const clerk = useClerk();
@@ -43,13 +43,13 @@ export const PaymentAttemptPage = () => {
4343
? {
4444
type: 'payment-attempt',
4545
id: params.paymentAttemptId,
46-
orgId: subscriberType === 'organization' ? organization?.id : undefined,
46+
orgId: subscriberType === 'organization' ? organizationCtx?.organization?.id : undefined,
4747
}
4848
: null,
4949
() =>
5050
clerk.billing.getPaymentAttempt({
5151
id: params.paymentAttemptId,
52-
orgId: subscriberType === 'organization' ? organization?.id : undefined,
52+
orgId: subscriberType === 'organization' ? organizationCtx?.organization?.id : undefined,
5353
}),
5454
);
5555

packages/clerk-js/src/ui/components/PaymentMethods/PaymentMethods.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useClerk, useOrganization } from '@clerk/shared/react';
1+
import { useClerk, useOrganizationContext } from '@clerk/shared/react';
22
import type { BillingPaymentMethodResource } from '@clerk/shared/types';
33
import { Fragment, useMemo, useRef } from 'react';
44

@@ -60,7 +60,7 @@ const RemoveScreen = ({
6060
const { close } = useActionContext();
6161
const card = useCardState();
6262
const subscriberType = useSubscriberTypeContext();
63-
const { organization } = useOrganization();
63+
const organizationCtx = useOrganizationContext();
6464
const localizationRoot = useSubscriberTypeLocalizationRoot();
6565
const ref = useRef(
6666
`${paymentMethod.paymentType === 'card' ? paymentMethod.cardType : paymentMethod.paymentType} ${paymentMethod.paymentType === 'card' ? `⋯ ${paymentMethod.last4}` : '-'}`,
@@ -72,7 +72,7 @@ const RemoveScreen = ({
7272

7373
const removePaymentMethod = async () => {
7474
await paymentMethod
75-
.remove({ orgId: subscriberType === 'organization' ? organization?.id : undefined })
75+
.remove({ orgId: subscriberType === 'organization' ? organizationCtx?.organization?.id : undefined })
7676
.then(revalidate)
7777
.catch((error: Error) => {
7878
handleError(error, [], card.setError);
@@ -196,7 +196,7 @@ const PaymentMethodMenu = ({
196196
}) => {
197197
const { open } = useActionContext();
198198
const card = useCardState();
199-
const { organization } = useOrganization();
199+
const organizationCtx = useOrganizationContext();
200200
const subscriberType = useSubscriberTypeContext();
201201
const localizationRoot = useSubscriberTypeLocalizationRoot();
202202

@@ -215,7 +215,7 @@ const PaymentMethodMenu = ({
215215
isDestructive: false,
216216
onClick: () => {
217217
paymentMethod
218-
.makeDefault({ orgId: subscriberType === 'organization' ? organization?.id : undefined })
218+
.makeDefault({ orgId: subscriberType === 'organization' ? organizationCtx?.organization?.id : undefined })
219219
.then(revalidate)
220220
.catch((error: Error) => {
221221
handleError(error, [], card.setError);

packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useClerk, useOrganization, useSession } from '@clerk/shared/react';
1+
import { useClerk, useOrganizationContext, useSession } from '@clerk/shared/react';
22
import type { BillingPlanResource, BillingSubscriptionPlanPeriod, PricingTableProps } from '@clerk/shared/types';
33
import * as React from 'react';
44

@@ -104,7 +104,7 @@ function Card(props: CardProps) {
104104
const { isSignedIn } = useSession();
105105
const { mode = 'mounted', ctaPosition: ctxCtaPosition } = usePricingTableContext();
106106
const subscriberType = useSubscriberTypeContext();
107-
const { organization } = useOrganization();
107+
const organizationCtx = useOrganizationContext();
108108

109109
const ctaPosition = pricingTableProps.ctaPosition || ctxCtaPosition || 'bottom';
110110
const collapseFeatures = pricingTableProps.collapseFeatures || false;
@@ -137,7 +137,7 @@ function Card(props: CardProps) {
137137
plan,
138138
planPeriod,
139139
for: pricingTableProps.for,
140-
hasActiveOrganization: !!organization,
140+
hasActiveOrganization: !!organizationCtx?.organization,
141141
});
142142

143143
return (

packages/clerk-js/src/ui/components/Statements/StatementPage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useClerk, useOrganization } from '@clerk/shared/react';
1+
import { useClerk, useOrganizationContext } from '@clerk/shared/react';
22
import useSWR from 'swr';
33

44
import { Alert } from '@/ui/elements/Alert';
@@ -23,7 +23,7 @@ import { Statement } from './Statement';
2323
export const StatementPage = () => {
2424
const { params, navigate } = useRouter();
2525
const subscriberType = useSubscriberTypeContext();
26-
const { organization } = useOrganization();
26+
const organizationCtx = useOrganizationContext();
2727
const localizationRoot = useSubscriberTypeLocalizationRoot();
2828
const { t, translateError } = useLocalizations();
2929
const clerk = useClerk();
@@ -37,13 +37,13 @@ export const StatementPage = () => {
3737
? {
3838
type: 'statement',
3939
id: params.statementId,
40-
orgId: subscriberType === 'organization' ? organization?.id : undefined,
40+
orgId: subscriberType === 'organization' ? organizationCtx?.organization?.id : undefined,
4141
}
4242
: null,
4343
() =>
4444
clerk.billing.getStatement({
4545
id: params.statementId,
46-
orgId: subscriberType === 'organization' ? organization?.id : undefined,
46+
orgId: subscriberType === 'organization' ? organizationCtx?.organization?.id : undefined,
4747
}),
4848
);
4949

packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useClerk, useOrganization } from '@clerk/shared/react';
1+
import { useClerk, useOrganizationContext } from '@clerk/shared/react';
22
import type {
33
__internal_CheckoutProps,
44
__internal_SubscriptionDetailsProps,
@@ -173,7 +173,7 @@ const SubscriptionDetailsInternal = (props: __internal_SubscriptionDetailsProps)
173173

174174
const SubscriptionDetailsFooter = withCardStateProvider(() => {
175175
const subscriberType = useSubscriberTypeContext();
176-
const { organization } = useOrganization();
176+
const organizationCtx = useOrganizationContext();
177177
const { isLoading, error, setError, setLoading, setIdle } = useCardState();
178178
const {
179179
subscription: selectedSubscription,
@@ -195,7 +195,7 @@ const SubscriptionDetailsFooter = withCardStateProvider(() => {
195195
setLoading();
196196

197197
await selectedSubscription
198-
.cancel({ orgId: subscriberType === 'organization' ? organization?.id : undefined })
198+
.cancel({ orgId: subscriberType === 'organization' ? organizationCtx?.organization?.id : undefined })
199199
.then(() => {
200200
onSubscriptionCancel?.();
201201
if (setIsOpen) {
@@ -213,7 +213,7 @@ const SubscriptionDetailsFooter = withCardStateProvider(() => {
213213
setError,
214214
setLoading,
215215
subscriberType,
216-
organization?.id,
216+
organizationCtx?.organization?.id,
217217
onSubscriptionCancel,
218218
setIsOpen,
219219
setIdle,

packages/clerk-js/src/ui/contexts/components/Plans.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
__experimental_useStatements,
66
__experimental_useSubscription,
77
useClerk,
8-
useOrganization,
8+
useOrganizationContext,
99
useSession,
1010
} from '@clerk/shared/react';
1111
import type {
@@ -32,7 +32,7 @@ export function normalizeFormatted(formatted: string) {
3232

3333
const useBillingHookParams = () => {
3434
const subscriberType = useSubscriberTypeContext();
35-
const { organization } = useOrganization();
35+
const organizationCtx = useOrganizationContext();
3636
const allowBillingRoutes = useProtect(
3737
has =>
3838
has({
@@ -44,7 +44,7 @@ const useBillingHookParams = () => {
4444
for: subscriberType,
4545
keepPreviousData: true,
4646
// If the user is in an organization, only fetch billing data if they have the necessary permissions
47-
enabled: subscriberType === 'organization' ? Boolean(organization) && allowBillingRoutes : true,
47+
enabled: subscriberType === 'organization' ? Boolean(organizationCtx?.organization) && allowBillingRoutes : true,
4848
};
4949
};
5050

0 commit comments

Comments
 (0)