-
Notifications
You must be signed in to change notification settings - Fork 402
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
Merged
wobsoriano
merged 14 commits into
main
from
rob/eco-182-custom-pages-for-organizationprofile-component
Sep 5, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
04e05f8
feat(astro): Add OrganizationProfile custom pages and links
wobsoriano 1aa93a5
chore(astro): Update component exports
wobsoriano a77d8df
feat(astro): Add OrganizationProfile custom pages and links inside Or…
wobsoriano 222d964
chore(astro): clean up exports
wobsoriano 6ddc845
chore(astro): Ensure custom pages are available before adding new items
wobsoriano b095d5e
chore(astro): Fix reordering keys
wobsoriano b84fc7f
test(astro): Test custom pages and links for organization profile
wobsoriano 368f797
chore(astro): Remove unused vars
wobsoriano 76bc0f9
chore(astro): Add changeset
wobsoriano 4c2c9c7
chore(astro): Add reusable custom profile page renderer
wobsoriano 8909c77
chore(astro): Remove Astro v3 peer dependency
wobsoriano dd4b15d
chore(astro): revert previous commit
wobsoriano 3718334
Merge branch 'main' into rob/eco-182-custom-pages-for-organizationpro…
wobsoriano 6059484
run format
wobsoriano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
22 changes: 0 additions & 22 deletions
22
integration/templates/astro-node/src/pages/custom-pages.astro
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
integration/templates/astro-node/src/pages/custom-pages/organization-profile.astro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
22 changes: 22 additions & 0 deletions
22
integration/templates/astro-node/src/pages/custom-pages/user-profile.astro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/astro/src/astro-components/interactive/CustomProfilePageRenderer.astro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
8 changes: 0 additions & 8 deletions
8
packages/astro/src/astro-components/interactive/OrganizationProfile.astro
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
...ages/astro/src/astro-components/interactive/OrganizationProfile/OrganizationProfile.astro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 /> |
14 changes: 14 additions & 0 deletions
14
.../astro/src/astro-components/interactive/OrganizationProfile/OrganizationProfileLink.astro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
24 changes: 24 additions & 0 deletions
24
.../astro/src/astro-components/interactive/OrganizationProfile/OrganizationProfilePage.astro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
8 changes: 8 additions & 0 deletions
8
packages/astro/src/astro-components/interactive/OrganizationProfile/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| }); |
14 changes: 14 additions & 0 deletions
14
...astro/src/astro-components/interactive/OrganizationSwitcher/OrganizationProfileLink.astro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
24 changes: 24 additions & 0 deletions
24
...astro/src/astro-components/interactive/OrganizationSwitcher/OrganizationProfilePage.astro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 />