Skip to content

Commit 469562f

Browse files
refactor(mosaic): apply review fixes to Waitlist (#10506)
1 parent 86e1706 commit 469562f

5 files changed

Lines changed: 11 additions & 27 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

‎packages/mosaic/src/features/waitlist/waitlist.controller.ts‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { UseFormResult } from '../../components/form';
21
import { useForm } from '../../components/form';
32
import { setup } from '../../machine/setup';
43
import { useMachine } from '../../machine/use-machine';
5-
import type { WaitlistModel, WaitlistStep, WaitlistValues } from './waitlist.types';
4+
import type { WaitlistModel } from './waitlist.types';
5+
import type { WaitlistViewProps } from './waitlist.view';
66

77
export const WAITLIST_REDIRECT_DELAY_MS = 2000;
88

@@ -25,27 +25,17 @@ const waitlistMachine = createMachine({
2525
joined: {
2626
after: {
2727
[WAITLIST_REDIRECT_DELAY_MS]: {
28-
target: 'redirected',
2928
guard: context => context.onRedirect !== undefined,
3029
actions: context => context.onRedirect?.(),
3130
},
3231
},
3332
},
34-
redirected: { type: 'final' },
3533
},
3634
});
3735

3836
export type WaitlistReadyModel = Extract<WaitlistModel, { status: 'ready' }>;
3937

40-
export interface WaitlistController {
41-
step: WaitlistStep;
42-
form: UseFormResult<WaitlistValues>;
43-
renderBranding: boolean;
44-
isRedirecting: boolean;
45-
onSignIn: () => void;
46-
}
47-
48-
export function useWaitlistController(model: WaitlistReadyModel): WaitlistController {
38+
export function useWaitlistController(model: WaitlistReadyModel): WaitlistViewProps {
4939
const { initialEmailAddress, renderBranding, onJoinWaitlist, onSignIn, onRedirect } = model;
5040
const [snapshot, send] = useMachine(waitlistMachine, { context: { onRedirect } });
5141
const form = useForm({

‎packages/mosaic/src/features/waitlist/waitlist.model.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ export type WaitlistModelOptions = Pick<WaitlistProps, 'afterJoinWaitlistUrl' |
1010

1111
const WAITLIST_FIELDS: readonly WaitlistField[] = ['emailAddress'];
1212

13-
function emailAddressFromQuery(): string {
14-
return new URLSearchParams(window.location.search).get('email_address') ?? '';
15-
}
16-
1713
export function useWaitlistModel(options: WaitlistModelOptions = {}): WaitlistModel {
1814
const clerk = useClerk();
1915
const environment = useMosaicEnvironment();
@@ -29,7 +25,7 @@ export function useWaitlistModel(options: WaitlistModelOptions = {}): WaitlistMo
2925

3026
return {
3127
status: 'ready',
32-
initialEmailAddress: emailAddressFromQuery(),
28+
initialEmailAddress: router.getSearchParams().get('email_address') ?? '',
3329
renderBranding: displayConfig.branded,
3430
onJoinWaitlist: emailAddress => save(() => clerk.joinWaitlist({ emailAddress }), WAITLIST_FIELDS),
3531
onSignIn: () => void router.navigate(clerk.buildUrlWithAuth(signInUrl)),

‎packages/swingset/src/app/(clerk)/live/live-overview.tsx‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

3-
import { useClerk, useUser } from '@clerk/nextjs';
4-
import type { EnvironmentResource } from '@clerk/shared/types';
3+
import { useMosaicEnvironment } from '@clerk/mosaic/hooks/use-mosaic-environment';
4+
import { useUser } from '@clerk/nextjs';
55
import { ExternalLinkIcon } from 'lucide-react';
66
import Link from 'next/link';
77

@@ -18,11 +18,8 @@ export function LiveOverview({
1818
dashboardUrl: string | null;
1919
deployment: { label: string; dashboardUrl: string | null } | null;
2020
}) {
21-
const clerk = useClerk();
2221
const { isLoaded, isSignedIn, user } = useUser();
23-
// The environment resource isn't part of the public Clerk interface; reach through the internal getter.
24-
const environment = (clerk as unknown as { __internal_environment?: EnvironmentResource | null })
25-
.__internal_environment;
22+
const environment = useMosaicEnvironment();
2623
const applicationName = environment?.displayConfig.applicationName;
2724

2825
return (

‎packages/swingset/src/app/(clerk)/live/misc/waitlist/page.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import { Button } from '@clerk/mosaic/components/button';
44
import { Waitlist } from '@clerk/mosaic/features/waitlist/waitlist';
5+
import { useMosaicEnvironment } from '@clerk/mosaic/hooks/use-mosaic-environment';
56
import { MosaicProvider } from '@clerk/mosaic/mosaic-provider';
67
import { useClerk } from '@clerk/nextjs';
7-
import type { EnvironmentResource } from '@clerk/shared/types';
88
import { useState } from 'react';
99

1010
import { LivePageHeader } from '../../../live-page-header';
@@ -13,8 +13,7 @@ export default function WaitlistLivePage() {
1313
const clerk = useClerk();
1414
const [redirect, setRedirect] = useState(false);
1515
const [demoKey, setDemoKey] = useState(0);
16-
const environment = (clerk as unknown as { __internal_environment?: EnvironmentResource | null })
17-
.__internal_environment;
16+
const environment = useMosaicEnvironment();
1817
const signUpMode = environment?.userSettings.signUp.mode;
1918

2019
return (

0 commit comments

Comments
 (0)