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

ProjectsSettings.tsx

79 lines2.9 KB

1import { EnvironmentId } from "@t3tools/contracts";
2import { Link } from "@tanstack/react-router";
3import { T, useGT } from "gt-react";
4import { LayersIcon } from "lucide-react";
5​
6import { Button } from "../ui/button";
7import { ProjectActionsSettings } from "./ProjectActionsSettings";
8import { ProjectSettingsPanel } from "./ProjectSettingsPanel";
9import { useSettingsScope } from "./SettingsScopeContext";
10import { SettingsScopeNotice } from "./SettingsScopeNotice";
11import { SettingsPageContainer, SettingsRow } from "./settingsLayout";
12import { ALL_ENVIRONMENTS_VALUE, selectEnvironmentAxis } from "./settingsScopeAxis";
13​
14export function ProjectsSettings() {
15 const gt = useGT();
16 const { search: value, scope, selectScope, environment } = useSettingsScope();
17 const unavailable =
18 scope.kind === "unavailable" ? (
19 <SettingsPageContainer>
20 <div className="flex flex-col items-start gap-3">
21 <p className="text-sm text-muted-foreground">{scope.message}</p>
22 {value.machine || value.checkout ? (
23 <Button
24 variant="outline"
25 size="xs"
26 onClick={() => selectScope(selectEnvironmentAxis(value, ALL_ENVIRONMENTS_VALUE))}
27 >
28 <LayersIcon />
29 <T>Show all environments</T>
30 </Button>
31 ) : null}
32 </div>
33 </SettingsPageContainer>
34 ) : null;
35 // Keep the panel mounted so it can follow members when regrouping changes the project key.
36 const projectScope =
37 scope.kind === "project" ||
38 scope.kind === "checkout" ||
39 (scope.kind === "unavailable" &&
40 (scope.reason === "project-missing" || scope.reason === "checkout-missing"));
41 return (
42 <div className="flex min-h-0 flex-1 flex-col">
43 {environment ? (
44 <div className="shrink-0 border-b border-border/60 px-6 py-3">
45 <SettingsRow
46 title={gt`Import projects and their threads`}
47 description={environment.label}
48 control={
49 <Button
50 size="sm"
51 variant="outline"
52 render={<Link to="/welcome" hash={`projects:${environment.environmentId}`} />}
53 >
54 <T context="verb, opens a page">Open</T>
55 </Button>
56 }
57 />
58 </div>
59 ) : null}
60 {value.project && projectScope ? (
61 <ProjectSettingsPanel
62 projectKey={value.project}
63 environmentId={value.machine ? EnvironmentId.make(value.machine) : null}
64 checkoutKey={value.checkout ?? null}
65 unavailable={unavailable}
66 />
67 ) : unavailable ? (
68 unavailable
69 ) : (
70 <SettingsPageContainer className="gap-6">
71 <ProjectActionsSettings />
72 <SettingsScopeNotice inline target="project">
73 {gt`Choose a project to manage its name, icon, checkouts and actions.`}
74 </SettingsScopeNotice>
75 </SettingsPageContainer>
76 )}
77 </div>
78 );