MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / useCreateWorkspace

Function useCreateWorkspace

ui/src/hooks/useCreateWorkspace.ts:55–89  ·  view source on GitHub ↗
(opts: UseCreateWorkspaceOpts)

Source from the content-addressed store, hash-verified

53 * converge on that one source of truth.
54 */
55export function useCreateWorkspace(opts: UseCreateWorkspaceOpts): UseCreateWorkspaceState {
56 const [tag, setTag] = useState('')
57 const [creating, setCreating] = useState(false)
58 const [error, setError] = useState<string | null>(null)
59
60 const submit = useCallback(async (): Promise<void> => {
61 const t = tag.trim()
62 if (!TAG_RE.test(t)) {
63 setError(`invalid tag (${TAG_HINT})`)
64 return
65 }
66 if (opts.template === '') {
67 setError('no template selected')
68 return
69 }
70 setCreating(true)
71 setError(null)
72 const result = await createWorkspace(t, opts.template)
73 setCreating(false)
74 if (result.ok) {
75 setTag('')
76 opts.onCreated(result.workspace)
77 } else {
78 const msg = result.error.message ?? result.error.error ?? `HTTP ${result.status}`
79 setError(msg)
80 }
81 }, [tag, opts])
82
83 const reset = useCallback((): void => {
84 setTag('')
85 setError(null)
86 }, [])
87
88 return { tag, setTag, creating, error, submit, reset }
89}

Callers 1

CreateWorkspaceFormFunction · 0.90

Calls 1

createWorkspaceFunction · 0.90

Tested by

no test coverage detected