MCPcopy Create free account
hub / github.com/block/buzz / AddWorkspaceDialog

Function AddWorkspaceDialog

desktop/src/features/workspaces/ui/AddWorkspaceDialog.tsx:26–191  ·  view source on GitHub ↗
({
  open,
  onOpenChange,
  onSubmit,
}: AddWorkspaceDialogProps)

Source from the content-addressed store, hash-verified

24};
25
26export function AddWorkspaceDialog({
27 open,
28 onOpenChange,
29 onSubmit,
30}: AddWorkspaceDialogProps) {
31 const [name, setName] = React.useState("");
32 const [relayUrl, setRelayUrl] = React.useState("");
33 const [token, setToken] = React.useState("");
34 const [reposDir, setReposDir] = React.useState("");
35 const [reposDirError, setReposDirError] = React.useState<string | null>(null);
36
37 const handleClose = React.useCallback(() => {
38 onOpenChange(false);
39 setName("");
40 setRelayUrl("");
41 setToken("");
42 setReposDir("");
43 setReposDirError(null);
44 }, [onOpenChange]);
45
46 const handleSubmit = React.useCallback(
47 async (e: React.FormEvent) => {
48 e.preventDefault();
49 if (!relayUrl.trim()) {
50 return;
51 }
52
53 // Expand `~` before save — the backend rejects tilde paths. Empty input
54 // resolves to `undefined` so REPOS keeps its default location. Validate
55 // the expanded value (the bytes the backend canonicalizes) before save
56 // so a bad path is caught here instead of bricking a later boot.
57 const expandedReposDir = await expandTilde(reposDir);
58 try {
59 await validateReposDir(expandedReposDir ?? "");
60 } catch (error) {
61 setReposDirError(String(error));
62 return;
63 }
64
65 const workspace: Workspace = {
66 id: crypto.randomUUID(),
67 name: name.trim() || deriveWorkspaceName(relayUrl.trim()),
68 relayUrl: normalizeRelayUrl(relayUrl.trim()),
69 token: token.trim() || undefined,
70 reposDir: expandedReposDir,
71 addedAt: new Date().toISOString(),
72 };
73
74 onSubmit(workspace);
75 handleClose();
76 },
77 [name, relayUrl, token, reposDir, onSubmit, handleClose],
78 );
79
80 return (
81 <Dialog onOpenChange={onOpenChange} open={open}>
82 <DialogContent className="max-w-md">
83 <DialogHeader>

Callers

nothing calls this directly

Calls 5

expandTildeFunction · 0.90
validateReposDirFunction · 0.90
deriveWorkspaceNameFunction · 0.90
normalizeRelayUrlFunction · 0.90
handleSubmitFunction · 0.50

Tested by

no test coverage detected