Skip to content

Commit da17a96

Browse files
authored
fix(clerk-js): Incremental improvements for account funds (#5705)
1 parent 83ef1dc commit da17a96

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

.changeset/silver-symbols-worry.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Incremental improvements for account funds in checkout.
6+
7+
- Fixes CLS issues when rendering account funds
8+
- Renames "accounts funds" to "payment sources" for consistency
9+
- Auto opes the "Add a new payment source" drawer only if no payments sources exist

packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx

+10-7
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ const CheckoutFormElements = ({
9393
const { __experimental_commerce } = useClerk();
9494
const { organization } = useOrganization();
9595
const { subscriberType } = useCheckoutContext();
96-
const [openAccountFundsDropDown, setOpenAccountFundsDropDown] = useState(true);
97-
const [openAddNewSourceDropDown, setOpenAddNewSourceDropDown] = useState(true);
98-
const [isSubmitting, setIsSubmitting] = useState(false);
99-
const [submitError, setSubmitError] = useState<ClerkRuntimeError | ClerkAPIError | string | undefined>();
10096

10197
const { data } = useFetch(
10298
__experimental_commerce?.getPaymentSources,
@@ -106,6 +102,12 @@ const CheckoutFormElements = ({
106102
undefined,
107103
'commerce-payment-sources',
108104
);
105+
106+
const [openAccountFundsDropDown, setOpenAccountFundsDropDown] = useState(true);
107+
const [openAddNewSourceDropDown, setOpenAddNewSourceDropDown] = useState((data?.data.length || 0) === 0);
108+
const [isSubmitting, setIsSubmitting] = useState(false);
109+
const [submitError, setSubmitError] = useState<ClerkRuntimeError | ClerkAPIError | string | undefined>();
110+
109111
const { data: paymentSources } = data || { data: [] };
110112

111113
const confirmCheckout = async ({ paymentSourceId }: { paymentSourceId: string }) => {
@@ -160,7 +162,7 @@ const CheckoutFormElements = ({
160162
onOpenChange={setOpenAccountFundsDropDown}
161163
>
162164
{/* TODO(@Commerce): needs localization */}
163-
<Disclosure.Trigger text='Account Funds' />
165+
<Disclosure.Trigger text='Payment Sources' />
164166
<Disclosure.Content>
165167
<Col gap={3}>
166168
<PaymentSourceMethods
@@ -181,8 +183,9 @@ const CheckoutFormElements = ({
181183
open={openAddNewSourceDropDown}
182184
onOpenChange={setOpenAddNewSourceDropDown}
183185
>
184-
{/* TODO(@Commerce): needs localization */}
185-
<Disclosure.Trigger text='Add a New Payment Source' />
186+
<Disclosure.Trigger
187+
text={localizationKeys('userProfile.__experimental_billingPage.paymentSourcesSection.add')}
188+
/>
186189
<Disclosure.Content>
187190
<__experimental_PaymentSourcesContext.Provider value={{ componentName: 'PaymentSources', subscriberType }}>
188191
<AddPaymentSource

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

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useClerk } from '@clerk/shared/react';
1+
import { useClerk, useOrganization } from '@clerk/shared/react';
22
import type {
33
__experimental_CommercePlanResource,
44
__experimental_CommerceSubscriptionPlanPeriod,
@@ -7,13 +7,15 @@ import type {
77
import { useState } from 'react';
88

99
import { usePlansContext, usePricingTableContext } from '../../contexts';
10+
import { useFetch } from '../../hooks/useFetch';
1011
import { PricingTableDefault } from './PricingTableDefault';
1112
import { PricingTableMatrix } from './PricingTableMatrix';
1213

1314
const PricingTable = (props: __experimental_PricingTableProps) => {
1415
const clerk = useClerk();
15-
const { mode = 'mounted' } = usePricingTableContext();
16+
const { mode = 'mounted', subscriberType } = usePricingTableContext();
1617
const isCompact = mode === 'modal';
18+
const { organization } = useOrganization();
1719

1820
const { plans, handleSelectPlan } = usePlansContext();
1921

@@ -27,6 +29,17 @@ const PricingTable = (props: __experimental_PricingTableProps) => {
2729
handleSelectPlan({ mode, plan, planPeriod });
2830
};
2931

32+
const { __experimental_commerce } = useClerk();
33+
34+
useFetch(
35+
__experimental_commerce?.getPaymentSources,
36+
{
37+
...(subscriberType === 'org' ? { orgId: organization?.id } : {}),
38+
},
39+
undefined,
40+
'commerce-payment-sources',
41+
);
42+
3043
return (
3144
<>
3245
{mode !== 'modal' && props.layout === 'matrix' ? (

0 commit comments

Comments
 (0)