mirror of
https://github.com/coder/coder.git
synced 2026-10-24 11:43:39 +08:00
feat: Add Create Workspace Form (#73)
Fixes #38 This adds a create-workspace form (with only 1 field, probably the simplest form ever 😄 )  It currently redirects to a path `/workspaces/<unique id>`, but that isn't implemented yet - but you can see the workspace show up on the projects page.
This commit is contained in:
+30
@@ -67,6 +67,11 @@ export namespace Project {
|
||||
}
|
||||
}
|
||||
|
||||
export interface CreateWorkspaceRequest {
|
||||
name: string
|
||||
project_id: string
|
||||
}
|
||||
|
||||
// Must be kept in sync with backend Workspace struct
|
||||
export interface Workspace {
|
||||
id: string
|
||||
@@ -77,6 +82,31 @@ export interface Workspace {
|
||||
name: string
|
||||
}
|
||||
|
||||
export namespace Workspace {
|
||||
export const create = async (request: CreateWorkspaceRequest): Promise<Workspace> => {
|
||||
const response = await fetch(`/api/v2/workspaces/me`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(request),
|
||||
})
|
||||
|
||||
const body = await response.json()
|
||||
if (!response.ok) {
|
||||
throw new Error(body.message)
|
||||
}
|
||||
|
||||
// Let SWR know that both the /api/v2/workspaces/* and /api/v2/projects/*
|
||||
// endpoints will need to fetch new data.
|
||||
const mutateWorkspacesPromise = mutate("/api/v2/workspaces")
|
||||
const mutateProjectsPromise = mutate("/api/v2/projects")
|
||||
await Promise.all([mutateWorkspacesPromise, mutateProjectsPromise])
|
||||
|
||||
return body
|
||||
}
|
||||
}
|
||||
|
||||
export const login = async (email: string, password: string): Promise<LoginResponse> => {
|
||||
const response = await fetch("/api/v2/login", {
|
||||
method: "POST",
|
||||
|
||||
Reference in New Issue
Block a user