Open History to see the last commit
1import { useAuth } from "@clerk/react";
2import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings";
3import { Link } from "@tanstack/react-router";
4
5import { hasCloudPublicConfig } from "~/cloud/publicConfig";
6import { useT3ConnectAuthPrompt } from "../clerk/useT3ConnectAuthPrompt";
7import { Button } from "../ui/button";
8import { Switch } from "../ui/switch";
9import { ScopedSwitch } from "./ScopedSwitch";
10import {
11 SettingResetButton,
12 SettingsPageContainer,
13 SettingsRow,
14 SettingsSection,
15} from "./settingsLayout";
16import { searchableSetting } from "./settingsSearch";
17import { useScopedSettings, useUpdateScopedSettings } from "./useScopedSettings";
18
19/** Features that are still settling in. Each is off until turned on here. */
20export function BetaSettingsPanel() {
21 const settings = useScopedSettings();
22 const updateSettings = useUpdateScopedSettings();
23 return (
24 <SettingsPageContainer>
25 <SettingsSection id="beta" title="Beta">
26 <SettingsRow
27 {...searchableSetting("working-shelf")}
28 description="Fold working and monitoring threads into a Working section. They return to the top of the inbox when they need you."
29 resetAction={
30 settings.sidebarWorkingShelfEnabled !==
31 DEFAULT_UNIFIED_SETTINGS.sidebarWorkingShelfEnabled ? (
32 <SettingResetButton
33 label="working section"
34 onClick={() =>
35 updateSettings({
36 sidebarWorkingShelfEnabled: DEFAULT_UNIFIED_SETTINGS.sidebarWorkingShelfEnabled,
37 })
38 }
39 />
40 ) : null
41 }
42 control={
43 <Switch
44 checked={settings.sidebarWorkingShelfEnabled}
45 onCheckedChange={(checked) =>
46 updateSettings({ sidebarWorkingShelfEnabled: Boolean(checked) })
47 }
48 aria-label="Working section"
49 />
50 }
51 />
52 {/* Clerk is only mounted when this build has T3 Connect. */}
53 {hasCloudPublicConfig() ? <GuestLinksRowWithSignIn /> : <GuestLinksRow />}
54 </SettingsSection>
55 </SettingsPageContainer>
56 );
57}
58
59/** Signed out of T3 Connect, the row offers to sign in instead of its switch. */
60function GuestLinksRowWithSignIn() {
61 const { isSignedIn } = useAuth();
62 const { openAuthPrompt } = useT3ConnectAuthPrompt();
63 // `isSignedIn` is undefined until Clerk loads.
64 if (isSignedIn !== false) return <GuestLinksRow />;
65 return (
66 <SettingsRow
67 {...searchableSetting("guest-links")}
68 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."
69 control={
70 <Button size="sm" variant="outline" onClick={openAuthPrompt}>
71 Sign in
72 </Button>
73 }
74 />
75 );
76}
77
78function GuestLinksRow() {
79 const settings = useScopedSettings();
80 const updateSettings = useUpdateScopedSettings();
81 return (
82 <SettingsRow
83 serverScoped
84 {...searchableSetting("guest-links")}
85 settingKeys={["guestSharingEnabled"]}
86 description={
87 <>
88 Share a thread with a guest who watches it live in their browser and sends messages you
89 approve. Needs T3 Connect: sign in and link this machine in{" "}
90 <Link to="/settings/connections" className="underline underline-offset-2">
91 Connections
92 </Link>
93 . While it is off, every guest link stops working.
94 </>
95 }
96 control={
97 <ScopedSwitch
98 settingKeys={["guestSharingEnabled"]}
99 checked={settings.guestSharingEnabled}
100 onCheckedChange={(checked) => updateSettings({ guestSharingEnabled: Boolean(checked) })}
101 aria-label="Guest links"
102 />
103 }
104 />
105 );
106}