import { useState } from "react" import { FolderOpen } from "@phosphor-icons/react" import type { ProjectRecord } from "@shared/types" import { useT } from "../../i18n" import { unwrap } from "../../lib/desktop" import { ActionButton, Field, InlineNotice, Input, Select } from "../ui" import { describeActionError } from "./execution-utils" export function WorkspaceCreator({ companyId, projects, onSaved }: { companyId: string; projects: ProjectRecord[]; onSaved: () => Promise }) { const t = useT() const [name, setName] = useState(""); const [localPath, setLocalPath] = useState(""); const [repoUrl, setRepoUrl] = useState(""); const [repoRef, setRepoRef] = useState("") const [projectId, setProjectId] = useState(projects[0]?.id ?? ""); const [submitError, setSubmitError] = useState(null); const [submitting, setSubmitting] = useState(false) async function handleChooseDirectory() { setSubmitError(null); const result = await window.agentCompany.pickDirectory(); if (!result.ok) { setSubmitError(result.error.message); return }; if (result.data) setLocalPath(result.data) } async function handleSaveWorkspace() { setSubmitError(null); setSubmitting(true); try { unwrap(await window.agentCompany.saveWorkspace({ companyId, name, localPath, repoUrl, repoRef, projectId: projectId || null, isPrimary: false })); setName(""); setLocalPath(""); setRepoUrl(""); setRepoRef(""); await onSaved() } catch (e) { setSubmitError(describeActionError(e)) } finally { setSubmitting(false) } } return (
void handleChooseDirectory()} icon={FolderOpen} />