Skip to content

Commit eef3b6b

Browse files
committed
Apply handling for OrganizationList
1 parent 4bb6f78 commit eef3b6b

File tree

3 files changed

+44
-28
lines changed

3 files changed

+44
-28
lines changed

packages/clerk-js/src/ui/components/OrganizationList/OrganizationListPage.tsx

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ const CreateOrganizationButton = ({
4949
};
5050

5151
export const OrganizationListPage = withCardStateProvider(() => {
52-
const card = useCardState();
5352
const { userMemberships, userSuggestions, userInvitations } = useOrganizationListInView();
5453
const isLoading = userMemberships?.isLoading || userInvitations?.isLoading || userSuggestions?.isLoading;
5554
const hasAnyData = !!(userMemberships?.count || userInvitations?.count || userSuggestions?.count);
@@ -59,7 +58,6 @@ export const OrganizationListPage = withCardStateProvider(() => {
5958
return (
6059
<Card.Root>
6160
<Card.Content sx={t => ({ padding: `${t.space.$8} ${t.space.$none} ${t.space.$none}` })}>
62-
<Card.Alert sx={t => ({ margin: `${t.space.$none} ${t.space.$5}` })}>{card.error}</Card.Alert>
6361
{isLoading && (
6462
<Flex
6563
direction={'row'}
@@ -86,6 +84,7 @@ export const OrganizationListPage = withCardStateProvider(() => {
8684
});
8785

8886
const OrganizationListFlows = ({ showListInitially }: { showListInitially: boolean }) => {
87+
const card = useCardState();
8988
const { navigateAfterCreateOrganization, skipInvitationScreen, hideSlug } = useOrganizationListContext();
9089
const [isCreateOrganizationFlow, setCreateOrganizationFlow] = useState(!showListInitially);
9190
return (
@@ -95,30 +94,35 @@ const OrganizationListFlows = ({ showListInitially }: { showListInitially: boole
9594
)}
9695

9796
{isCreateOrganizationFlow && (
98-
<Box
99-
sx={t => ({
100-
padding: `${t.space.$none} ${t.space.$5} ${t.space.$5}`,
101-
})}
102-
>
103-
<CreateOrganizationForm
104-
flow='organizationList'
105-
startPage={{ headerTitle: localizationKeys('organizationList.createOrganization') }}
106-
skipInvitationScreen={skipInvitationScreen}
107-
navigateAfterCreateOrganization={org =>
108-
navigateAfterCreateOrganization(org).then(() => setCreateOrganizationFlow(false))
109-
}
110-
onCancel={
111-
showListInitially && isCreateOrganizationFlow ? () => setCreateOrganizationFlow(false) : undefined
112-
}
113-
hideSlug={hideSlug}
114-
/>
115-
</Box>
97+
<>
98+
<Card.Alert sx={t => ({ margin: `${t.space.$none} ${t.space.$5}` })}>{card.error}</Card.Alert>
99+
100+
<Box
101+
sx={t => ({
102+
padding: `${t.space.$none} ${t.space.$5} ${t.space.$5}`,
103+
})}
104+
>
105+
<CreateOrganizationForm
106+
flow='organizationList'
107+
startPage={{ headerTitle: localizationKeys('organizationList.createOrganization') }}
108+
skipInvitationScreen={skipInvitationScreen}
109+
navigateAfterCreateOrganization={org =>
110+
navigateAfterCreateOrganization(org).then(() => setCreateOrganizationFlow(false))
111+
}
112+
onCancel={
113+
showListInitially && isCreateOrganizationFlow ? () => setCreateOrganizationFlow(false) : undefined
114+
}
115+
hideSlug={hideSlug}
116+
/>
117+
</Box>
118+
</>
116119
)}
117120
</>
118121
);
119122
};
120123

121124
export const OrganizationListPageList = (props: { onCreateOrganizationClick: () => void }) => {
125+
const card = useCardState();
122126
const environment = useEnvironment();
123127

124128
const { ref, userMemberships, userSuggestions, userInvitations } = useOrganizationListInView();
@@ -128,6 +132,9 @@ export const OrganizationListPageList = (props: { onCreateOrganizationClick: ()
128132
const hasNextPage = userMemberships?.hasNextPage || userInvitations?.hasNextPage || userSuggestions?.hasNextPage;
129133

130134
const onCreateOrganizationClick = () => {
135+
// Clean error originated from the list when switching to form
136+
card.setError(undefined);
137+
131138
props.onCreateOrganizationClick();
132139
};
133140

@@ -154,6 +161,7 @@ export const OrganizationListPageList = (props: { onCreateOrganizationClick: ()
154161
})}
155162
/>
156163
</Header.Root>
164+
<Card.Alert sx={t => ({ margin: `${t.space.$none} ${t.space.$5}` })}>{card.error}</Card.Alert>
157165
<Col elementDescriptor={descriptors.main}>
158166
<PreviewListItems>
159167
<Actions role='menu'>

packages/clerk-js/src/ui/components/OrganizationList/UserMembershipList.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,35 @@ import { sharedMainIdentifierSx } from '@/ui/common/organizations/OrganizationPr
55
import { useCardState, withCardStateProvider } from '@/ui/elements/contexts';
66
import { OrganizationPreview } from '@/ui/elements/OrganizationPreview';
77
import { PersonalWorkspacePreview } from '@/ui/elements/PersonalWorkspacePreview';
8+
import { handleError } from '@/ui/utils/errorHandler';
89

910
import { useOrganizationListContext } from '../../contexts';
1011
import { localizationKeys } from '../../localization';
1112
import { OrganizationListPreviewButton } from './shared';
1213

13-
export const MembershipPreview = withCardStateProvider((props: { organization: OrganizationResource }) => {
14+
export const MembershipPreview = (props: { organization: OrganizationResource }) => {
1415
const card = useCardState();
1516
const { navigateAfterSelectOrganization } = useOrganizationListContext();
1617
const { isLoaded, setActive } = useOrganizationList();
1718

1819
if (!isLoaded) {
1920
return null;
2021
}
22+
2123
const handleOrganizationClicked = (organization: OrganizationResource) => {
2224
return card.runAsync(async () => {
23-
await setActive({
24-
organization,
25-
});
25+
try {
26+
await setActive({
27+
organization,
28+
});
2629

27-
await navigateAfterSelectOrganization(organization);
30+
await navigateAfterSelectOrganization(organization);
31+
} catch (err) {
32+
handleError(err, [], card.setError);
33+
}
2834
});
2935
};
36+
3037
return (
3138
<OrganizationListPreviewButton onClick={() => handleOrganizationClicked(props.organization)}>
3239
<OrganizationPreview
@@ -36,7 +43,8 @@ export const MembershipPreview = withCardStateProvider((props: { organization: O
3643
/>
3744
</OrganizationListPreviewButton>
3845
);
39-
});
46+
};
47+
4048
export const PersonalAccountPreview = withCardStateProvider(() => {
4149
const card = useCardState();
4250
const { hidePersonal, navigateAfterSelectPersonal } = useOrganizationListContext();

packages/clerk-js/src/ui/components/SessionTasks/tasks/TaskChooseOrganization/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useClerk, useSession, useUserContext } from '@clerk/shared/react';
1+
import { useClerk, useSession, useUser, useUser } from '@clerk/shared/react';
22
import { useState } from 'react';
33

44
import { useSignOutContext, withCoreSessionSwitchGuard } from '@/ui/contexts';
@@ -14,7 +14,7 @@ import { CreateOrganizationScreen } from './CreateOrganizationScreen';
1414

1515
const TaskChooseOrganizationInternal = () => {
1616
const { signOut } = useClerk();
17-
const user = useUserContext();
17+
const { user } = useUser();
1818
const { session } = useSession();
1919
const { userMemberships, userSuggestions, userInvitations } = useOrganizationListInView();
2020
const { otherSessions } = useMultipleSessions({ user });

0 commit comments

Comments
 (0)