Skip to content
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

refactor(clerk-js,types): Remove virtual routing option from component types #4977

Merged
7 changes: 7 additions & 0 deletions .changeset/silent-ducks-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/clerk-js': patch
'@clerk/clerk-react': patch
'@clerk/types': patch
alexcarpenter marked this conversation as resolved.
Show resolved Hide resolved
---

Remove `virtual` routing option from components.
alexcarpenter marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { useOrganization } from '@clerk/shared/react';
import type { OrganizationProfileModalProps, OrganizationProfileProps } from '@clerk/types';
import React from 'react';
import type { __internal_RoutingOptions, OrganizationProfileCtx } from 'ui/types';

import { OrganizationProfileContext, withCoreUserGuard } from '../../contexts';
import { Flow, localizationKeys } from '../../customizables';
import { NavbarMenuButtonRow, ProfileCard, withCardStateProvider } from '../../elements';
import { Route, Switch } from '../../router';
import type { OrganizationProfileCtx } from '../../types';
import { OrganizationProfileNavbar } from './OrganizationProfileNavbar';
import { OrganizationProfileRoutes } from './OrganizationProfileRoutes';

const _OrganizationProfile = (_: OrganizationProfileProps) => {
const _OrganizationProfile = () => {
const { organization } = useOrganization();

if (!organization) {
Expand Down Expand Up @@ -48,6 +48,10 @@ const AuthenticatedRoutes = withCoreUserGuard(() => {

export const OrganizationProfile = withCardStateProvider(_OrganizationProfile);

const InternalOrganizationProfile: React.ComponentType<
Omit<OrganizationProfileProps, 'routing'> & __internal_RoutingOptions
> = withCardStateProvider(_OrganizationProfile);

export const OrganizationProfileModal = (props: OrganizationProfileModalProps): JSX.Element => {
const organizationProfileProps: OrganizationProfileCtx = {
...props,
Expand All @@ -61,7 +65,7 @@ export const OrganizationProfileModal = (props: OrganizationProfileModalProps):
<OrganizationProfileContext.Provider value={organizationProfileProps}>
{/*TODO: Used by InvisibleRootBox, can we simplify? */}
<div>
<OrganizationProfile {...organizationProfileProps} />
<InternalOrganizationProfile {...organizationProfileProps} />
</div>
</OrganizationProfileContext.Provider>
</Route>
Expand Down
6 changes: 5 additions & 1 deletion packages/clerk-js/src/ui/components/SignIn/SignIn.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useClerk } from '@clerk/shared/react';
import type { SignInModalProps, SignInProps } from '@clerk/types';
import React from 'react';
import type { __internal_RoutingOptions } from 'ui/types';

import { normalizeRoutingOptions } from '../../../utils/normalizeRoutingOptions';
import { SignInEmailLinkFlowComplete, SignUpEmailLinkFlowComplete } from '../../common/EmailLinkCompleteFlowCard';
Expand Down Expand Up @@ -165,6 +166,9 @@ SignInRoutes.displayName = 'SignIn';

export const SignIn: React.ComponentType<SignInProps> = withCoreSessionSwitchGuard(SignInRoot);

const InternalSignIn: React.ComponentType<Omit<SignInProps, 'routing'> & __internal_RoutingOptions> =
withCoreSessionSwitchGuard(SignInRoot);

export const SignInModal = (props: SignInModalProps): JSX.Element => {
const signInProps = {
signUpUrl: `/${VIRTUAL_ROUTER_BASE_PATH}/sign-up`,
Expand All @@ -184,7 +188,7 @@ export const SignInModal = (props: SignInModalProps): JSX.Element => {
>
{/*TODO: Used by InvisibleRootBox, can we simplify? */}
<div>
<SignIn
<InternalSignIn
{...signInProps}
routing='virtual'
/>
Expand Down
6 changes: 5 additions & 1 deletion packages/clerk-js/src/ui/components/SignUp/SignUp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useClerk } from '@clerk/shared/react';
import type { SignUpModalProps, SignUpProps } from '@clerk/types';
import React from 'react';
import type { __internal_RoutingOptions } from 'ui/types';

import { SignUpEmailLinkFlowComplete } from '../../common/EmailLinkCompleteFlowCard';
import { SignUpContext, useSignUpContext, withCoreSessionSwitchGuard } from '../../contexts';
Expand Down Expand Up @@ -89,6 +90,9 @@ SignUpRoutes.displayName = 'SignUp';

export const SignUp: React.ComponentType<SignUpProps> = withCoreSessionSwitchGuard(SignUpRoutes);

const InternalSignUp: React.ComponentType<Omit<SignUpProps, 'routing'> & __internal_RoutingOptions> =
withCoreSessionSwitchGuard(SignUpRoutes);

export const SignUpModal = (props: SignUpModalProps): JSX.Element => {
const signUpProps = {
signInUrl: `/${VIRTUAL_ROUTER_BASE_PATH}/sign-in`,
Expand All @@ -108,7 +112,7 @@ export const SignUpModal = (props: SignUpModalProps): JSX.Element => {
>
{/*TODO: Used by InvisibleRootBox, can we simplify? */}
<div>
<SignUp
<InternalSignUp
{...signUpProps}
routing='virtual'
/>
Expand Down
11 changes: 7 additions & 4 deletions packages/clerk-js/src/ui/components/UserProfile/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { UserProfileContext, withCoreUserGuard } from '../../contexts';
import { Flow, localizationKeys } from '../../customizables';
import { NavbarMenuButtonRow, ProfileCard, withCardStateProvider } from '../../elements';
import { Route, Switch } from '../../router';
import type { UserProfileCtx } from '../../types';
import type { __internal_RoutingOptions, UserProfileCtx } from '../../types';
import { UserProfileNavbar } from './UserProfileNavbar';
import { UserProfileRoutes } from './UserProfileRoutes';
import { VerificationSuccessPage } from './VerifyWithLink';

const _UserProfile = (_: UserProfileProps) => {
const _UserProfile = () => {
return (
<Flow.Root flow='userProfile'>
<Flow.Part>
Expand Down Expand Up @@ -42,7 +42,10 @@ const AuthenticatedRoutes = withCoreUserGuard(() => {
);
});

export const UserProfile = withCardStateProvider(_UserProfile);
export const UserProfile: React.ComponentType<UserProfileProps> = withCardStateProvider(_UserProfile);

const InternalUserProfile: React.ComponentType<Omit<UserProfileProps, 'routing'> & __internal_RoutingOptions> =
alexcarpenter marked this conversation as resolved.
Show resolved Hide resolved
withCardStateProvider(_UserProfile);

export const UserProfileModal = (props: UserProfileModalProps): JSX.Element => {
const userProfileProps: UserProfileCtx = {
Expand All @@ -57,7 +60,7 @@ export const UserProfileModal = (props: UserProfileModalProps): JSX.Element => {
<UserProfileContext.Provider value={userProfileProps}>
{/*TODO: Used by InvisibleRootBox, can we simplify? */}
<div>
<UserProfile {...userProfileProps} />
<InternalUserProfile {...userProfileProps} />
</div>
</UserProfileContext.Provider>
</Route>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { __internal_UserVerificationModalProps, __internal_UserVerificationProps } from '@clerk/types';
import React, { useEffect } from 'react';
import type { __internal_RoutingOptions } from 'ui/types';

import { UserVerificationContext, withCoreSessionSwitchGuard } from '../../contexts';
import { Flow } from '../../customizables';
Expand Down Expand Up @@ -31,8 +32,9 @@ function UserVerificationRoutes(): JSX.Element {

UserVerificationRoutes.displayName = 'UserVerification';

const UserVerification: React.ComponentType<__internal_UserVerificationProps> =
withCoreSessionSwitchGuard(UserVerificationRoutes);
const UserVerification: React.ComponentType<
Omit<__internal_UserVerificationProps, 'routing'> & __internal_RoutingOptions
> = withCoreSessionSwitchGuard(UserVerificationRoutes);

const UserVerificationModal = (props: __internal_UserVerificationModalProps): JSX.Element => {
return (
Expand Down
69 changes: 40 additions & 29 deletions packages/clerk-js/src/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
OrganizationListProps,
OrganizationProfileProps,
OrganizationSwitcherProps,
RoutingStrategy,
SignInProps,
SignUpProps,
UserButtonProps,
Expand Down Expand Up @@ -40,42 +41,48 @@ export type AvailableComponentProps =

type ComponentMode = 'modal' | 'mounted';

export type SignInCtx = SignInProps & {
componentName: 'SignIn';
mode?: ComponentMode;
};

export type UserVerificationCtx = __internal_UserVerificationProps & {
componentName: 'UserVerification';
mode?: ComponentMode;
};

export type UserProfileCtx = UserProfileProps & {
componentName: 'UserProfile';
mode?: ComponentMode;
};

export type SignUpCtx = SignUpProps & {
componentName: 'SignUp';
mode?: ComponentMode;
emailLinkRedirectUrl?: string;
ssoCallbackUrl?: string;
};
export type SignInCtx = Omit<SignInProps, 'routing'> &
__internal_RoutingOptions & {
componentName: 'SignIn';
mode?: ComponentMode;
};

export type UserVerificationCtx = Omit<__internal_UserVerificationProps, 'routing'> &
__internal_RoutingOptions & {
componentName: 'UserVerification';
mode?: ComponentMode;
};

export type UserProfileCtx = Omit<UserProfileProps, 'routing'> &
__internal_RoutingOptions & {
componentName: 'UserProfile';
mode?: ComponentMode;
};

export type SignUpCtx = Omit<SignUpProps, 'routing'> &
__internal_RoutingOptions & {
componentName: 'SignUp';
mode?: ComponentMode;
emailLinkRedirectUrl?: string;
ssoCallbackUrl?: string;
};

export type UserButtonCtx = UserButtonProps & {
componentName: 'UserButton';
mode?: ComponentMode;
};

export type OrganizationProfileCtx = OrganizationProfileProps & {
componentName: 'OrganizationProfile';
mode?: ComponentMode;
};
export type OrganizationProfileCtx = Omit<OrganizationProfileProps, 'routing'> &
__internal_RoutingOptions & {
componentName: 'OrganizationProfile';
mode?: ComponentMode;
};

export type CreateOrganizationCtx = CreateOrganizationProps & {
componentName: 'CreateOrganization';
mode?: ComponentMode;
};
export type CreateOrganizationCtx = Omit<CreateOrganizationProps, 'routing'> &
__internal_RoutingOptions & {
componentName: 'CreateOrganization';
mode?: ComponentMode;
};

export type OrganizationSwitcherCtx = OrganizationSwitcherProps & {
componentName: 'OrganizationSwitcher';
Expand Down Expand Up @@ -110,3 +117,7 @@ export type AvailableComponentCtx =
| WaitlistCtx;

export type AvailableComponentName = AvailableComponentCtx['componentName'];

export type __internal_RoutingOptions = {
routing?: RoutingStrategy;
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ describe('<OrganizationProfile/>', () => {
}).toMatchTypeOf<OrganizationProfileComponentProps>();
});

test('when path is filled, routing must only have path as value', () => {
expectTypeOf({
path: '/org',
routing: 'virtual' as const,
}).not.toMatchTypeOf<OrganizationProfileComponentProps>();

expectTypeOf({
path: '/org',
routing: 'hash' as const,
}).not.toMatchTypeOf<OrganizationProfileComponentProps>();
});
alexcarpenter marked this conversation as resolved.
Show resolved Hide resolved

test('when routing is hash or virtual path must be present', () => {
expectTypeOf({
routing: 'hash' as const,
Expand Down
12 changes: 0 additions & 12 deletions packages/react/src/components/__tests__/SignIn.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ describe('<SignIn/>', () => {
}).toMatchTypeOf<SignInComponentProps>();
});

test('when path is filled, routing must only have path as value', () => {
expectTypeOf({
path: '/sign-in',
routing: 'virtual' as const,
}).not.toMatchTypeOf<SignInComponentProps>();

expectTypeOf({
path: '/sign-in',
routing: 'hash' as const,
}).not.toMatchTypeOf<SignInComponentProps>();
});

test('when routing is hash or virtual path must be present', () => {
expectTypeOf({
routing: 'hash' as const,
Expand Down
12 changes: 0 additions & 12 deletions packages/react/src/components/__tests__/SignUp.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ describe('<SignUp/>', () => {
}).toMatchTypeOf<SignUpComponentProps>();
});

test('when path is filled, routing must only have path as value', () => {
expectTypeOf({
path: '/sign-up',
routing: 'virtual' as const,
}).not.toMatchTypeOf<SignUpComponentProps>();

expectTypeOf({
path: '/sign-up',
routing: 'hash' as const,
}).not.toMatchTypeOf<SignUpComponentProps>();
});

test('when routing is hash or virtual path must be present', () => {
expectTypeOf({
routing: 'hash' as const,
Expand Down
12 changes: 0 additions & 12 deletions packages/react/src/components/__tests__/UserProfile.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ describe('<UserProfile/>', () => {
}).toMatchTypeOf<UserProfileComponentProps>();
});

test('when path is filled, routing must only have path as value', () => {
expectTypeOf({
path: '/profile',
routing: 'virtual' as const,
}).not.toMatchTypeOf<UserProfileComponentProps>();

expectTypeOf({
path: '/profile',
routing: 'hash' as const,
}).not.toMatchTypeOf<UserProfileComponentProps>();
});

test('when routing is hash or virtual path must be present', () => {
expectTypeOf({
routing: 'hash' as const,
Expand Down
7 changes: 4 additions & 3 deletions packages/types/src/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,9 +890,10 @@ export type SetActiveParams = {

export type SetActive = (params: SetActiveParams) => Promise<void>;

export type RoutingOptions =
| { path: string | undefined; routing?: Extract<RoutingStrategy, 'path'> }
| { path?: never; routing?: Extract<RoutingStrategy, 'hash' | 'virtual'> };
alexcarpenter marked this conversation as resolved.
Show resolved Hide resolved
export type RoutingOptions = {
path?: string;
routing?: Exclude<RoutingStrategy, 'virtual'>;
jacekradko marked this conversation as resolved.
Show resolved Hide resolved
};

export type SignInProps = RoutingOptions & {
/**
Expand Down
Loading