Skip to content

Commit b9776d1

Browse files
committed
Port changes from core 3
1 parent 85fea1d commit b9776d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+293
-38
lines changed

.changeset/nice-loops-fail.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@clerk/localizations': minor
3+
'@clerk/clerk-js': minor
4+
'@clerk/shared': minor
5+
---
6+
7+
Display message in `TaskChooseOrganization` when user is not allowed to create organizations
Lines changed: 85 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { useClerk, useSession, useUser } from '@clerk/shared/react';
2-
import { useState } from 'react';
2+
import { type ComponentType, useState } from 'react';
33

44
import { useSignOutContext, withCoreSessionSwitchGuard } from '@/ui/contexts';
55
import { descriptors, Flex, Flow, localizationKeys, Spinner } from '@/ui/customizables';
66
import { Card } from '@/ui/elements/Card';
77
import { withCardStateProvider } from '@/ui/elements/contexts';
8+
import { Header } from '@/ui/elements/Header';
89
import { useMultipleSessions } from '@/ui/hooks/useMultipleSessions';
910
import { useOrganizationListInView } from '@/ui/hooks/useOrganizationListInView';
1011

@@ -13,24 +14,10 @@ import { ChooseOrganizationScreen } from './ChooseOrganizationScreen';
1314
import { CreateOrganizationScreen } from './CreateOrganizationScreen';
1415

1516
const TaskChooseOrganizationInternal = () => {
16-
const { signOut } = useClerk();
17-
const { user } = useUser();
18-
const { session } = useSession();
1917
const { userMemberships, userSuggestions, userInvitations } = useOrganizationListInView();
20-
const { otherSessions } = useMultipleSessions({ user });
21-
const { navigateAfterSignOut, navigateAfterMultiSessionSingleSignOutUrl } = useSignOutContext();
22-
23-
const handleSignOut = () => {
24-
if (otherSessions.length === 0) {
25-
return signOut(navigateAfterSignOut);
26-
}
27-
28-
return signOut(navigateAfterMultiSessionSingleSignOutUrl, { sessionId: session?.id });
29-
};
3018

3119
const isLoading = userMemberships?.isLoading || userInvitations?.isLoading || userSuggestions?.isLoading;
3220
const hasExistingResources = !!(userMemberships?.count || userInvitations?.count || userSuggestions?.count);
33-
const identifier = user?.primaryEmailAddress?.emailAddress ?? user?.username;
3421

3522
return (
3623
<Flow.Root flow='taskChooseOrganization'>
@@ -58,34 +45,56 @@ const TaskChooseOrganizationInternal = () => {
5845
)}
5946
</Card.Content>
6047

61-
<Card.Footer>
62-
<Card.Action
63-
elementId='signOut'
64-
gap={2}
65-
justify='center'
66-
sx={() => ({ width: '100%' })}
67-
>
68-
{identifier && (
69-
<Card.ActionText
70-
truncate
71-
localizationKey={localizationKeys('taskChooseOrganization.signOut.actionText', {
72-
identifier,
73-
})}
74-
/>
75-
)}
76-
<Card.ActionLink
77-
sx={() => ({ flexShrink: 0 })}
78-
onClick={handleSignOut}
79-
localizationKey={localizationKeys('taskChooseOrganization.signOut.actionLink')}
80-
/>
81-
</Card.Action>
82-
</Card.Footer>
48+
<TaskChooseOrganizationCardFooter />
8349
</Card.Root>
8450
</Flow.Part>
8551
</Flow.Root>
8652
);
8753
};
8854

55+
const TaskChooseOrganizationCardFooter = () => {
56+
const { signOut } = useClerk();
57+
const { user } = useUser();
58+
const { session } = useSession();
59+
const { otherSessions } = useMultipleSessions({ user });
60+
const { navigateAfterSignOut, navigateAfterMultiSessionSingleSignOutUrl } = useSignOutContext();
61+
62+
const handleSignOut = () => {
63+
if (otherSessions.length === 0) {
64+
return signOut(navigateAfterSignOut);
65+
}
66+
67+
return signOut(navigateAfterMultiSessionSingleSignOutUrl, { sessionId: session?.id });
68+
};
69+
70+
const identifier = user?.primaryEmailAddress?.emailAddress ?? user?.username;
71+
72+
return (
73+
<Card.Footer>
74+
<Card.Action
75+
elementId='signOut'
76+
gap={2}
77+
justify='center'
78+
sx={() => ({ width: '100%' })}
79+
>
80+
{identifier && (
81+
<Card.ActionText
82+
truncate
83+
localizationKey={localizationKeys('taskChooseOrganization.signOut.actionText', {
84+
identifier,
85+
})}
86+
/>
87+
)}
88+
<Card.ActionLink
89+
sx={() => ({ flexShrink: 0 })}
90+
onClick={handleSignOut}
91+
localizationKey={localizationKeys('taskChooseOrganization.signOut.actionLink')}
92+
/>
93+
</Card.Action>
94+
</Card.Footer>
95+
);
96+
};
97+
8998
type TaskChooseOrganizationFlowsProps = {
9099
initialFlow: 'create' | 'choose';
91100
};
@@ -104,6 +113,44 @@ const TaskChooseOrganizationFlows = withCardStateProvider((props: TaskChooseOrga
104113
return <ChooseOrganizationScreen onCreateOrganizationClick={() => setCurrentFlow('create')} />;
105114
});
106115

116+
export const withOrganizationCreationEnabledGuard = <T extends object>(Component: ComponentType<T>) => {
117+
return (props: T) => {
118+
const { user } = useUser();
119+
120+
if (!user?.createOrganizationEnabled) {
121+
return <OrganizationCreationDisabledScreen />;
122+
}
123+
124+
return <Component {...props} />;
125+
};
126+
};
127+
128+
function OrganizationCreationDisabledScreen() {
129+
return (
130+
<Flow.Root flow='taskChooseOrganization'>
131+
<Flow.Part part='organizationCreationDisabled'>
132+
<Card.Root>
133+
<Card.Content>
134+
<Header.Root showLogo>
135+
<Header.Title
136+
localizationKey={localizationKeys('taskChooseOrganization.organizationCreationDisabled.title')}
137+
/>
138+
<Header.Subtitle
139+
localizationKey={localizationKeys('taskChooseOrganization.organizationCreationDisabled.subtitle')}
140+
/>
141+
</Header.Root>
142+
</Card.Content>
143+
144+
<TaskChooseOrganizationCardFooter />
145+
</Card.Root>
146+
</Flow.Part>
147+
</Flow.Root>
148+
);
149+
}
150+
107151
export const TaskChooseOrganization = withCoreSessionSwitchGuard(
108-
withTaskGuard(withCardStateProvider(TaskChooseOrganizationInternal), 'choose-organization'),
152+
withTaskGuard(
153+
withCardStateProvider(withOrganizationCreationEnabledGuard(TaskChooseOrganizationInternal)),
154+
'choose-organization',
155+
),
109156
);

packages/clerk-js/src/ui/elements/contexts/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export type FlowMetadata = {
128128
| 'complete'
129129
| 'accountSwitcher'
130130
| 'chooseOrganization'
131+
| 'organizationCreationDisabled'
131132
| 'enterpriseConnections'
132133
| 'chooseWallet';
133134
};

packages/localizations/src/ar-SA.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,10 @@ export const arSA: LocalizationResource = {
867867
subtitle: undefined,
868868
title: undefined,
869869
},
870+
organizationCreationDisabled: {
871+
title: 'يجب أن تنتمي إلى منظمة',
872+
subtitle: 'تواصل مع مسؤول منظمتك للحصول على دعوة.',
873+
},
870874
signOut: {
871875
actionLink: undefined,
872876
actionText: undefined,

packages/localizations/src/be-BY.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,10 @@ export const beBY: LocalizationResource = {
875875
subtitle: undefined,
876876
title: undefined,
877877
},
878+
organizationCreationDisabled: {
879+
title: 'Вы павінны належаць да арганізацыі',
880+
subtitle: 'Звярніцеся да адміністратара вашай арганізацыі для атрымання запрашэння.',
881+
},
878882
signOut: {
879883
actionLink: undefined,
880884
actionText: undefined,

packages/localizations/src/bg-BG.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,10 @@ export const bgBG: LocalizationResource = {
871871
subtitle: undefined,
872872
title: undefined,
873873
},
874+
organizationCreationDisabled: {
875+
title: 'Трябва да принадлежите към организация',
876+
subtitle: 'Свържете се с администратора на вашата организация за покана.',
877+
},
874878
signOut: {
875879
actionLink: undefined,
876880
actionText: undefined,

packages/localizations/src/bn-IN.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,10 @@ export const bnIN: LocalizationResource = {
875875
subtitle: undefined,
876876
title: undefined,
877877
},
878+
organizationCreationDisabled: {
879+
title: 'আপনাকে অবশ্যই একটি সংগঠনের অন্তর্ভুক্ত হতে হবে',
880+
subtitle: 'আমন্ত্রণের জন্য আপনার সংগঠনের প্রশাসকের সাথে যোগাযোগ করুন।',
881+
},
878882
signOut: {
879883
actionLink: undefined,
880884
actionText: undefined,

packages/localizations/src/ca-ES.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,10 @@ export const caES: LocalizationResource = {
870870
subtitle: undefined,
871871
title: undefined,
872872
},
873+
organizationCreationDisabled: {
874+
title: 'Heu de pertànyer a una organització',
875+
subtitle: "Contacteu amb l'administrador de la vostra organització per obtenir una invitació.",
876+
},
873877
signOut: {
874878
actionLink: undefined,
875879
actionText: undefined,

packages/localizations/src/cs-CZ.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,10 @@ export const csCZ: LocalizationResource = {
881881
subtitle: undefined,
882882
title: undefined,
883883
},
884+
organizationCreationDisabled: {
885+
title: 'Musíte patřit do organizace',
886+
subtitle: 'Kontaktujte administrátora vaší organizace pro pozvánku.',
887+
},
884888
signOut: {
885889
actionLink: undefined,
886890
actionText: undefined,

packages/localizations/src/da-DK.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,10 @@ export const daDK: LocalizationResource = {
868868
subtitle: undefined,
869869
title: undefined,
870870
},
871+
organizationCreationDisabled: {
872+
title: 'Du skal tilhøre en organisation',
873+
subtitle: 'Kontakt din organisationsadministrator for en invitation.',
874+
},
871875
signOut: {
872876
actionLink: undefined,
873877
actionText: undefined,

0 commit comments

Comments
 (0)