Open History to see the last commit
1import { useAuth } from "@clerk/react";
2import { Link } from "@tanstack/react-router";
3
4import { hasCloudPublicConfig } from "~/cloud/publicConfig";
5import { useT3ConnectAuthPrompt } from "../clerk/useT3ConnectAuthPrompt";
6import { Button } from "../ui/button";
7import { ScopedSwitch } from "./ScopedSwitch";
8import { SettingsPageContainer, SettingsRow, SettingsSection } from "./settingsLayout";
9import { searchableSetting } from "./settingsSearch";
10import { LegacyFeaturesSection } from "./SettingsPanels";
11import { useScopedSettings, useUpdateScopedSettings } from "./useScopedSettings";
12
13/** Features still settling in, and legacy behavior kept for people who rely on it. */
14export function LabsSettingsPanel() {
15 return (
16 <SettingsPageContainer>
17 <SettingsSection id="beta" title="Beta">
18 {/* Clerk is only mounted when this build has T3 Connect. */}
19 {hasCloudPublicConfig() ? <GuestLinksRowWithSignIn /> : <GuestLinksRow />}
20 </SettingsSection>
21 <LegacyFeaturesSection />
22 </SettingsPageContainer>
23 );
24}
25
26/** Signed out of T3 Connect, the row offers to sign in instead of its switch. */
27function GuestLinksRowWithSignIn() {
28 const { isSignedIn } = useAuth();
29 const { openAuthPrompt } = useT3ConnectAuthPrompt();
30 // `isSignedIn` is undefined until Clerk loads.
31 if (isSignedIn !== false) return <GuestLinksRow />;
32 return (
33 <SettingsRow
34 {...searchableSetting("guest-links")}
35 description="Share a thread with a guest who watches it live in their browser and sends messages you approve. Sign in to T3 Connect to use guest links."
36 control={
37 <Button size="sm" variant="outline" onClick={openAuthPrompt}>
38 Sign in
39 </Button>
40 }
41 />
42 );
43}
44
45function GuestLinksRow() {
46 const settings = useScopedSettings();
47 const updateSettings = useUpdateScopedSettings();
48 return (
49 <SettingsRow
50 serverScoped
51 {...searchableSetting("guest-links")}
52 settingKeys={["guestSharingEnabled"]}
53 description={
54 <>
55 Share a thread with a guest who watches it live in their browser and sends messages you
56 approve. Needs T3 Connect: sign in and link this machine in{" "}
57 <Link to="/settings/access" className="underline underline-offset-2">
58 Sharing & access
59 </Link>
60 . While it is off, every guest link stops working.
61 </>
62 }
63 control={
64 <ScopedSwitch
65 settingKeys={["guestSharingEnabled"]}
66 checked={settings.guestSharingEnabled}
67 onCheckedChange={(checked) => updateSettings({ guestSharingEnabled: Boolean(checked) })}
68 aria-label="Guest links"
69 />
70 }
71 />
72 );
73}