diff --git a/packages/clerk-js/src/ui/utils/createCustomPages.tsx b/packages/clerk-js/src/ui/utils/createCustomPages.tsx index c6b355a5c4..e72a909846 100644 --- a/packages/clerk-js/src/ui/utils/createCustomPages.tsx +++ b/packages/clerk-js/src/ui/utils/createCustomPages.tsx @@ -13,11 +13,11 @@ export type CustomPageContent = { unmount: (el?: HTMLDivElement) => void; }; -type UserProfileReorderItem = { +type ProfileReorderItem = { label: 'account' | 'security'; }; -type UserProfileCustomPage = { +type ProfileCustomPage = { label: string; url: string; mountIcon: (el: HTMLDivElement) => void; @@ -26,7 +26,7 @@ type UserProfileCustomPage = { unmount: (el?: HTMLDivElement) => void; }; -type UserProfileCustomLink = { +type ProfileCustomLink = { label: string; url: string; mountIcon: (el: HTMLDivElement) => void; @@ -178,7 +178,7 @@ const checkForDuplicateUsageOfReorderingItems = (customPages: CustomPage[], vali reorderItems.reduce((acc, cp) => { if (acc.includes(cp.label)) { console.error( - `Clerk: The "${cp.label}" item is used more than once when reordering UserProfile pages. This may cause unexpected behavior.`, + `Clerk: The "${cp.label}" item is used more than once when reordering pages. This may cause unexpected behavior.`, ); } return [...acc, cp.label]; @@ -199,15 +199,15 @@ const isValidPageItem = (cp: CustomPage, validReorderItems: string[]): cp is Cus return isCustomPage(cp) || isCustomLink(cp) || isReorderItem(cp, validReorderItems); }; -const isCustomPage = (cp: CustomPage): cp is UserProfileCustomPage => { +const isCustomPage = (cp: CustomPage): cp is ProfileCustomPage => { return !!cp.url && !!cp.label && !!cp.mount && !!cp.unmount && !!cp.mountIcon && !!cp.unmountIcon; }; -const isCustomLink = (cp: CustomPage): cp is UserProfileCustomLink => { +const isCustomLink = (cp: CustomPage): cp is ProfileCustomLink => { return !!cp.url && !!cp.label && !cp.mount && !cp.unmount && !!cp.mountIcon && !!cp.unmountIcon; }; -const isReorderItem = (cp: CustomPage, validItems: string[]): cp is UserProfileReorderItem => { +const isReorderItem = (cp: CustomPage, validItems: string[]): cp is ProfileReorderItem => { return ( !cp.url && !cp.mount && !cp.unmount && !cp.mountIcon && !cp.unmountIcon && validItems.some(v => v === cp.label) ); diff --git a/packages/react/src/components/uiComponents.tsx b/packages/react/src/components/uiComponents.tsx index b5303a816d..58650f3d59 100644 --- a/packages/react/src/components/uiComponents.tsx +++ b/packages/react/src/components/uiComponents.tsx @@ -25,7 +25,7 @@ import type { UserProfilePageProps, WithClerkProp, } from '../types'; -import { errorInDevMode, useOrganizationProfileCustomPages, useUserProfileCustomPages } from '../utils'; +import { logErrorInDevMode, useOrganizationProfileCustomPages, useUserProfileCustomPages } from '../utils'; import { withClerk } from './withClerk'; type UserProfileExportType = typeof _UserProfile & { @@ -141,13 +141,13 @@ export const SignUp = withClerk(({ clerk, ...props }: WithClerkProp }, 'SignUp'); export function UserProfilePage({ children }: PropsWithChildren) { - errorInDevMode(userProfilePageRenderedError); - return
{children}
; + logErrorInDevMode(userProfilePageRenderedError); + return <>{children}; } export function UserProfileLink({ children }: PropsWithChildren) { - errorInDevMode(userProfileLinkRenderedError); - return
{children}
; + logErrorInDevMode(userProfileLinkRenderedError); + return <>{children}; } const _UserProfile = withClerk( @@ -189,18 +189,18 @@ const _UserButton = withClerk( ); export const UserButton: UserButtonExportType = Object.assign(_UserButton, { - UserProfilePage: UserProfilePage, - UserProfileLink: UserProfileLink, + UserProfilePage, + UserProfileLink, }); export function OrganizationProfilePage({ children }: PropsWithChildren) { - errorInDevMode(organizationProfilePageRenderedError); - return
{children}
; + logErrorInDevMode(organizationProfilePageRenderedError); + return <>{children}; } export function OrganizationProfileLink({ children }: PropsWithChildren) { - errorInDevMode(organizationProfileLinkRenderedError); - return
{children}
; + logErrorInDevMode(organizationProfileLinkRenderedError); + return <>{children}; } const _OrganizationProfile = withClerk( @@ -253,8 +253,8 @@ const _OrganizationSwitcher = withClerk( ); export const OrganizationSwitcher: OrganizationSwitcherExportType = Object.assign(_OrganizationSwitcher, { - OrganizationProfilePage: OrganizationProfilePage, - OrganizationProfileLink: OrganizationProfileLink, + OrganizationProfilePage, + OrganizationProfileLink, }); export const OrganizationList = withClerk(({ clerk, ...props }: WithClerkProp) => { diff --git a/packages/react/src/utils/index.ts b/packages/react/src/utils/index.ts index 590e8b0801..816d275a5c 100644 --- a/packages/react/src/utils/index.ts +++ b/packages/react/src/utils/index.ts @@ -5,4 +5,4 @@ export { loadClerkJsScript } from './loadClerkJsScript'; export * from './useMaxAllowedInstancesGuard'; export * from './useCustomElementPortal'; export * from './useCustomPages'; -export * from './errorInDevMode'; +export * from './logErrorInDevMode'; diff --git a/packages/react/src/utils/errorInDevMode.ts b/packages/react/src/utils/logErrorInDevMode.ts similarity index 69% rename from packages/react/src/utils/errorInDevMode.ts rename to packages/react/src/utils/logErrorInDevMode.ts index dfa5fd09ba..8992e997d3 100644 --- a/packages/react/src/utils/errorInDevMode.ts +++ b/packages/react/src/utils/logErrorInDevMode.ts @@ -1,6 +1,6 @@ import { isDevelopmentEnvironment } from '@clerk/shared'; -export const errorInDevMode = (message: string) => { +export const logErrorInDevMode = (message: string) => { if (isDevelopmentEnvironment()) { console.error(message); } diff --git a/packages/react/src/utils/useCustomElementPortal.tsx b/packages/react/src/utils/useCustomElementPortal.tsx index 911977bdc2..72161b1035 100644 --- a/packages/react/src/utils/useCustomElementPortal.tsx +++ b/packages/react/src/utils/useCustomElementPortal.tsx @@ -19,19 +19,10 @@ export const useCustomElementPortal = (elements: UseCustomElementPortalParams[]) const initialState = Array(elements.length).fill(null); const [nodes, setNodes] = useState<(Element | null)[]>(initialState); - const portals: UseCustomElementPortalReturn[] = []; - - elements.forEach((el, index) => { - const mount = (node: Element) => { - setNodes(prevState => prevState.map((n, i) => (i === index ? node : n))); - }; - const unmount = () => { - setNodes(prevState => prevState.map((n, i) => (i === index ? null : n))); - }; - - const portal = () => <>{nodes[index] ? createPortal(el.component, nodes[index] as Element) : null}; - portals.push({ portal, mount, unmount, id: el.id }); - }); - - return portals; + return elements.map((el, index) => ({ + id: el.id, + mount: (node: Element) => setNodes(prevState => prevState.map((n, i) => (i === index ? node : n))), + unmount: () => setNodes(prevState => prevState.map((n, i) => (i === index ? null : n))), + portal: () => <>{nodes[index] ? createPortal(el.component, nodes[index] as Element) : null}, + })); }; diff --git a/packages/react/src/utils/useCustomPages.tsx b/packages/react/src/utils/useCustomPages.tsx index c92812ff26..97352e03ac 100644 --- a/packages/react/src/utils/useCustomPages.tsx +++ b/packages/react/src/utils/useCustomPages.tsx @@ -10,7 +10,7 @@ import { } from '../components/uiComponents'; import { customLinkWrongProps, customPagesIgnoredComponent, customPageWrongProps } from '../errors'; import type { UserProfilePageProps } from '../types'; -import { errorInDevMode } from './errorInDevMode'; +import { logErrorInDevMode } from './logErrorInDevMode'; import type { UseCustomElementPortalParams, UseCustomElementPortalReturn } from './useCustomElementPortal'; import { useCustomElementPortal } from './useCustomElementPortal'; @@ -62,7 +62,7 @@ const useCustomPages = ({ React.Children.forEach(children, child => { if (!isThatComponent(child, PageComponent) && !isThatComponent(child, LinkComponent)) { if (child) { - errorInDevMode(customPagesIgnoredComponent(componentName)); + logErrorInDevMode(customPagesIgnoredComponent(componentName)); } return; } @@ -79,7 +79,7 @@ const useCustomPages = ({ // this is a custom page validChildren.push({ label, labelIcon, children, url }); } else { - errorInDevMode(customPageWrongProps(componentName)); + logErrorInDevMode(customPageWrongProps(componentName)); return; } } @@ -89,7 +89,7 @@ const useCustomPages = ({ // This is an external link validChildren.push({ label, labelIcon, url }); } else { - errorInDevMode(customLinkWrongProps(componentName)); + logErrorInDevMode(customLinkWrongProps(componentName)); return; } } diff --git a/packages/types/src/clerk.ts b/packages/types/src/clerk.ts index 45a5425c77..86945caf58 100644 --- a/packages/types/src/clerk.ts +++ b/packages/types/src/clerk.ts @@ -694,13 +694,7 @@ export type UserProfileProps = { */ additionalOAuthScopes?: Partial>; /* - * Provide addition custom route items and pages to be rendered inside the UserProfile. - * e.g. - * - * C}> - *
Hello from custom page!
- *
- *
+ * Provide custom pages and links to be rendered inside the UserProfile. */ customPages?: CustomPage[]; }; @@ -726,13 +720,7 @@ export type OrganizationProfileProps = { */ appearance?: OrganizationProfileTheme; /* - * Provide addition custom route items and pages to be rendered inside the OrganizationProfile. - * e.g. - * - * C}> - *
Hello from custom page!
- *
- *
+ * Provide custom pages and links to be rendered inside the OrganizationProfile. */ customPages?: CustomPage[]; };