Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 470
feat(astro): Add OrganizationProfile custom pages and links#4096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
04e05f81aa93a5a77d8df222d9646ddc845b095d5eb84fc7f368f79776bc0f94c2c9c78909c77dd4b15d37183346059484File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@clerk/astro": minor | ||
| --- | ||
| Add support for custom pages and links in the `<OrganizationProfile />` Astro component. |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| --- | ||
| import { | ||
| OrganizationProfile as OrganizationProfileAstro, | ||
| OrganizationSwitcher | ||
| } from "@clerk/astro/components"; | ||
| import Layout from "../../layouts/Layout.astro"; | ||
| // Added a dedicatedPage query param to conditionally render the OrganizationProfile | ||
| // as for some reason, the menu items in the OrganizationSwitcher | ||
| // goes out of bounds in test environment. | ||
| const dedicatedPage = Astro.url.searchParams.get('dedicatedPage') === 'true'; | ||
| --- | ||
| <Layout title="Custom Pages"> | ||
| <div class="w-full flex justify-center"> | ||
| <OrganizationSwitcher> | ||
| { | ||
| !dedicatedPage && ( | ||
| <OrganizationSwitcher.OrganizationProfilePage label="Terms" url="terms"> | ||
| <div slot="label-icon">Icon</div> | ||
| <div> | ||
| <h1>Custom Terms Page</h1> | ||
| <p>This is the custom terms page</p> | ||
| </div> | ||
| </OrganizationSwitcher.OrganizationProfilePage> | ||
| <OrganizationSwitcher.OrganizationProfileLink label="Homepage" url="/"> | ||
| <div slot="label-icon">Icon</div> | ||
| </OrganizationSwitcher.OrganizationProfileLink> | ||
| <OrganizationSwitcher.OrganizationProfilePage label="members" /> | ||
| ) | ||
| } | ||
| </OrganizationSwitcher> | ||
| { | ||
| dedicatedPage && ( | ||
| <OrganizationProfileAstro path="/custom-pages/organization-profile"> | ||
| <OrganizationProfileAstro.Page label="Terms" url="terms"> | ||
| <div slot="label-icon">Icon</div> | ||
| <div> | ||
| <h1>Custom Terms Page</h1> | ||
| <p>This is the custom terms page</p> | ||
| </div> | ||
| </OrganizationProfileAstro.Page> | ||
| <OrganizationProfileAstro.Link label="Homepage" url="/"> | ||
| <div slot="label-icon">Icon</div> | ||
| </OrganizationProfileAstro.Link> | ||
| <OrganizationProfileAstro.Page label="general" /> | ||
| </OrganizationProfileAstro> | ||
| ) | ||
| } | ||
| </div> | ||
| </Layout> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| import { UserProfile as UserProfileAstro } from "@clerk/astro/components"; | ||
| import Layout from "../../layouts/Layout.astro"; | ||
| --- | ||
| <Layout title="Custom Pages"> | ||
| <div class="w-full flex justify-center"> | ||
| <UserProfileAstro path="/custom-pages/user-profile"> | ||
| <UserProfileAstro.Page label="Terms" url="terms"> | ||
| <div slot="label-icon">Icon</div> | ||
| <div> | ||
| <h1>Custom Terms Page</h1> | ||
| <p>This is the custom terms page</p> | ||
| </div> | ||
| </UserProfileAstro.Page> | ||
| <UserProfileAstro.Link label="Homepage" url="/"> | ||
| <div slot="label-icon">Icon</div> | ||
| </UserProfileAstro.Link> | ||
| <UserProfileAstro.Page label="security" /> | ||
| </UserProfileAstro> | ||
| </div> | ||
| </Layout> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| --- | ||
| interface Props { | ||
| url: string | ||
| label: string | ||
| type: 'page' | 'link' | ||
| component: 'organization-profile' | 'user-profile' | 'organization-switcher' | ||
| reorderItemsLabels?: Readonly<Array<string>> | ||
| } | ||
| const { url, label, type, component, reorderItemsLabels = [] } = Astro.props | ||
| let labelIcon = ''; | ||
| let content = '' | ||
| if (Astro.slots.has('label-icon')) { | ||
| labelIcon = await Astro.slots.render('label-icon'); | ||
| } | ||
| if (Astro.slots.has('default') && type === 'page') { | ||
| content = await Astro.slots.render('default'); | ||
| } | ||
| --- | ||
| <script is:inline define:vars={{ url, label, content, labelIcon, type, component, reorderItemsLabels }}> | ||
| // Get the component map from window that we set in the `<InternalUIComponentRenderer />`. | ||
| const clerkComponentMap = window.__astro_clerk_component_props.get(component); | ||
| const componentElement = document.querySelector(`[data-clerk-id^="clerk-${component}"]`); | ||
| const safeId = componentElement.getAttribute('data-clerk-id'); | ||
| const currentOptions = clerkComponentMap.get(safeId); | ||
| const isReorderItem = reorderItemsLabels.includes(label); | ||
| let newCustomPage = { label } | ||
| if (!isReorderItem) { | ||
| newCustomPage = { | ||
| ...newCustomPage, | ||
| url, | ||
| mountIcon: (el) => { el.innerHTML = labelIcon }, | ||
| unmountIcon: () => { /* Implement cleanup if needed */ } | ||
| } | ||
| if (type === 'page') { | ||
| newCustomPage = { | ||
| ...newCustomPage, | ||
| mount: (el) => { el.innerHTML = content }, | ||
| unmount: () => { /* Implement cleanup if needed */ } | ||
| } | ||
| } | ||
| } | ||
| // Custom <OrganizationProfile /> pages can be added inside | ||
| // the <OrganizationSwitcher /> component. | ||
| if (component === 'organization-switcher') { | ||
| clerkComponentMap.set(safeId, { | ||
| ...currentOptions, | ||
| organizationProfileProps: { | ||
| ...currentOptions.organizationProfileProps, | ||
| customPages: [ | ||
| ...(currentOptions?.organizationProfileProps?.customPages ?? []), | ||
| newCustomPage | ||
| ] | ||
| } | ||
| }) | ||
| } else { | ||
| clerkComponentMap.set(safeId, { | ||
| ...currentOptions, | ||
| customPages: [ | ||
| ...(currentOptions?.customPages ?? []), | ||
| newCustomPage, | ||
| ] | ||
| }) | ||
| } | ||
| </script> |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| import type { OrganizationProfileProps, Without } from '@clerk/types' | ||
| type Props = Without<OrganizationProfileProps, 'customPages'> | ||
| import InternalUIComponentRenderer from '../InternalUIComponentRenderer.astro' | ||
| --- | ||
| <InternalUIComponentRenderer {...Astro.props} component="organization-profile" /> | ||
| <slot /> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| import CustomProfilePageRenderer from '../CustomProfilePageRenderer.astro' | ||
| interface Props { | ||
| url: string | ||
| label: string | ||
| } | ||
| const { url, label } = Astro.props | ||
| --- | ||
| <CustomProfilePageRenderer label={label} url={url} type="link" component="organization-profile"> | ||
| <slot name="label-icon" slot="label-icon" /> | ||
| </CustomProfilePageRenderer> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --- | ||
| import CustomProfilePageRenderer from '../CustomProfilePageRenderer.astro' | ||
| const reorderItemsLabels = ['general', 'members'] as const; | ||
| type ReorderItemsLabels = typeof reorderItemsLabels[number]; | ||
| type Props<Label extends string> = { | ||
| label: Label | ||
| } & (Label extends ReorderItemsLabels | ||
| ? { | ||
| url?: string | ||
| } | ||
| : { | ||
| url: string | ||
| } | ||
| ) | ||
| const { url, label } = Astro.props | ||
| --- | ||
| <CustomProfilePageRenderer label={label} url={url} type="page" component="organization-profile" reorderItemsLabels={reorderItemsLabels}> | ||
| <slot name="label-icon" slot="label-icon" /> | ||
| <slot /> | ||
| </CustomProfilePageRenderer> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import _OrganizationProfile from './OrganizationProfile.astro'; | ||
| import OrganizationProfileLink from './OrganizationProfileLink.astro'; | ||
| import OrganizationProfilePage from './OrganizationProfilePage.astro'; | ||
| export const OrganizationProfile = Object.assign(_OrganizationProfile, { | ||
| Page: OrganizationProfilePage, | ||
| Link: OrganizationProfileLink, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| import CustomProfilePageRenderer from '../CustomProfilePageRenderer.astro' | ||
| interface Props { | ||
| url: string | ||
| label: string | ||
| } | ||
| const { url, label } = Astro.props | ||
| --- | ||
| <CustomProfilePageRenderer label={label} url={url} type="link" component="organization-switcher"> | ||
| <slot name="label-icon" slot="label-icon" /> | ||
| </CustomProfilePageRenderer> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --- | ||
| import CustomProfilePageRenderer from '../CustomProfilePageRenderer.astro' | ||
| const reorderItemsLabels = ['general', 'members'] as const; | ||
| type ReorderItemsLabels = typeof reorderItemsLabels[number]; | ||
| type Props<Label extends string> = { | ||
| label: Label | ||
| } & (Label extends ReorderItemsLabels | ||
| ? { | ||
| url?: string | ||
| } | ||
| : { | ||
| url: string | ||
| } | ||
| ) | ||
| const { url, label } = Astro.props | ||
| --- | ||
| <CustomProfilePageRenderer label={label} url={url} type="page" component="organization-switcher" reorderItemsLabels={reorderItemsLabels}> | ||
| <slot name="label-icon" slot="label-icon" /> | ||
| <slot /> | ||
| </CustomProfilePageRenderer> |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This component serves as the custom profile page renderer for
<OrganizationProfile />(dedicated page)<OrganizationProfile />(inside<OrganizationSwitcher />)<UserProfile />