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/org-general-panel-cardstate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/ui': patch
---

Fix `OrganizationProfileGeneralPanel` (from `@clerk/ui/experimental`) throwing "CardState not found" when opening the leave-organization or delete-organization confirmation in its default, no-children page mode. The panel now provides the same root `CardStateProvider` that a mounted `<OrganizationProfile />` supplies.
10 changes: 9 additions & 1 deletion packages/ui/src/composed/OrganizationProfile/General.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ function GeneralComposed({ children }: PropsWithChildren): ReactNode {

export function OrganizationProfileGeneralPanel({ children }: PropsWithChildren): ReactNode {
if (!children) {
return <OrganizationGeneralPage />;
// Unlike AccountPage/SecurityPage, OrganizationGeneralPage does not self-wrap in a
// CardStateProvider. Mounted <OrganizationProfile /> supplies one at its root, so the
// leave/delete confirmation forms (useLeaveWithRevalidations -> useCardState) resolve it.
// The composed panel is a standalone entry point, so it must provide the same root here.
return (
<CardStateProvider>
<OrganizationGeneralPage />
</CardStateProvider>
);
}

// The section confirmation forms (leave/delete) call useCardState(), so children must be wrapped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,25 @@ describe('OrganizationProfile composed sections', () => {
});
});

describe('General — default page mode (no children)', () => {
it('provides CardState so the leave-organization confirmation can open', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
f.withOrganizations();
f.withUser({ email_addresses: ['test@clerk.com'], organization_memberships: [{ name: 'TestOrg' }] });
});

fixtures.clerk.organization?.getDomains.mockReturnValue(Promise.resolve({ data: [], total_count: 0 }));

const { userEvent } = render(<OrganizationProfileGeneralPanel />, { wrapper });

// Before the fix, LeaveOrganizationForm's useLeaveWithRevalidations() calls useCardState()
// with no ancestor CardStateProvider and throws "CardState not found".
await userEvent.click(await screen.findByRole('button', { name: /leave organization/i }));

await waitFor(() => expect(screen.getByRole('button', { name: /cancel/i })).toBeInTheDocument());
});
});

describe('General — section outside page', () => {
it('useRequirePage throws when rendered outside a page component', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
Expand Down
Loading