Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

BetaSettingsPanel.tsx

127 lines4.6 KB

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("new-design")}
28 description="Try the quieter design: gray sidebar icons, dimmer read threads, and simpler composer controls."
29 resetAction={
30 settings.redesignEnabled !== DEFAULT_UNIFIED_SETTINGS.redesignEnabled ? (
31 <SettingResetButton
32 label="new design"
33 onClick={() =>
34 updateSettings({ redesignEnabled: DEFAULT_UNIFIED_SETTINGS.redesignEnabled })
35 }
36 />
37 ) : null
38 }
39 control={
40 <Switch
41 checked={settings.redesignEnabled}
42 onCheckedChange={(checked) => updateSettings({ redesignEnabled: Boolean(checked) })}
43 aria-label="New design"
44 />
45 }
46 />
47 <SettingsRow
48 {...searchableSetting("working-shelf")}
49 description="Fold working and monitoring threads into a Working section. They return to the top of the inbox when they need you."
50 resetAction={
51 settings.sidebarWorkingShelfEnabled !==
52 DEFAULT_UNIFIED_SETTINGS.sidebarWorkingShelfEnabled ? (
53 <SettingResetButton
54 label="working section"
55 onClick={() =>
56 updateSettings({
57 sidebarWorkingShelfEnabled: DEFAULT_UNIFIED_SETTINGS.sidebarWorkingShelfEnabled,
58 })
59 }
60 />
61 ) : null
62 }
63 control={
64 <Switch
65 checked={settings.sidebarWorkingShelfEnabled}
66 onCheckedChange={(checked) =>
67 updateSettings({ sidebarWorkingShelfEnabled: Boolean(checked) })
68 }
69 aria-label="Working section"
70 />
71 }
72 />
73 {/* Clerk is only mounted when this build has T3 Connect. */}
74 {hasCloudPublicConfig() ? <GuestLinksRowWithSignIn /> : <GuestLinksRow />}
75 </SettingsSection>
76 </SettingsPageContainer>
77 );
79​
80/** Signed out of T3 Connect, the row offers to sign in instead of its switch. */
81function GuestLinksRowWithSignIn() {
82 const { isSignedIn } = useAuth();
83 const { openAuthPrompt } = useT3ConnectAuthPrompt();
84 // `isSignedIn` is undefined until Clerk loads.
85 if (isSignedIn !== false) return <GuestLinksRow />;
86 return (
87 <SettingsRow
88 {...searchableSetting("guest-links")}
89 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."
90 control={
91 <Button size="sm" variant="outline" onClick={openAuthPrompt}>
92 Sign in
93 </Button>
94 }
95 />
96 );
98​
99function GuestLinksRow() {
100 const settings = useScopedSettings();
101 const updateSettings = useUpdateScopedSettings();
102 return (
103 <SettingsRow
104 serverScoped
105 {...searchableSetting("guest-links")}
106 settingKeys={["guestSharingEnabled"]}
107 description={
108 <>
109 Share a thread with a guest who watches it live in their browser and sends messages you
110 approve. Needs T3 Connect: sign in and link this machine in{" "}
111 <Link to="/settings/connections" className="underline underline-offset-2">
112 Connections
113 </Link>
114 . While it is off, every guest link stops working.
115 </>
116 }
117 control={
118 <ScopedSwitch
119 settingKeys={["guestSharingEnabled"]}
120 checked={settings.guestSharingEnabled}
121 onCheckedChange={(checked) => updateSettings({ guestSharingEnabled: Boolean(checked) })}
122 aria-label="Guest links"
123 />
124 }
125 />
126 );