mirror of
https://github.com/coder/coder.git
synced 2026-10-24 01:26:25 +08:00
feat: Add create workspace page (#1589)
This commit is contained in:
+23
-29
@@ -1,5 +1,4 @@
|
||||
import axios, { AxiosRequestHeaders } from "axios"
|
||||
import { mutate } from "swr"
|
||||
import { WorkspaceBuildTransition } from "./types"
|
||||
import * as TypesGen from "./typesGenerated"
|
||||
|
||||
@@ -22,34 +21,6 @@ export const provisioners: TypesGen.ProvisionerDaemon[] = [
|
||||
},
|
||||
]
|
||||
|
||||
export namespace Workspace {
|
||||
export const create = async (
|
||||
organizationId: string,
|
||||
request: TypesGen.CreateWorkspaceRequest,
|
||||
): Promise<TypesGen.Workspace> => {
|
||||
const response = await fetch(`/api/v2/organizations/${organizationId}/workspaces`, {
|
||||
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/templates/*
|
||||
// endpoints will need to fetch new data.
|
||||
const mutateWorkspacesPromise = mutate("/api/v2/workspaces")
|
||||
const mutateTemplatesPromise = mutate("/api/v2/templates")
|
||||
await Promise.all([mutateWorkspacesPromise, mutateTemplatesPromise])
|
||||
|
||||
return body
|
||||
}
|
||||
}
|
||||
|
||||
export const login = async (email: string, password: string): Promise<TypesGen.LoginWithPasswordResponse> => {
|
||||
const payload = JSON.stringify({
|
||||
email,
|
||||
@@ -115,6 +86,21 @@ export const getTemplates = async (organizationId: string): Promise<TypesGen.Tem
|
||||
return response.data
|
||||
}
|
||||
|
||||
export const getTemplateByName = async (organizationId: string, name: string): Promise<TypesGen.Template> => {
|
||||
const response = await axios.get<TypesGen.Template>(`/api/v2/organizations/${organizationId}/templates/${name}`)
|
||||
return response.data
|
||||
}
|
||||
|
||||
export const getTemplateVersion = async (versionId: string): Promise<TypesGen.TemplateVersion> => {
|
||||
const response = await axios.get<TypesGen.TemplateVersion>(`/api/v2/templateversions/${versionId}`)
|
||||
return response.data
|
||||
}
|
||||
|
||||
export const getTemplateVersionSchema = async (versionId: string): Promise<TypesGen.ParameterSchema[]> => {
|
||||
const response = await axios.get<TypesGen.ParameterSchema[]>(`/api/v2/templateversions/${versionId}/schema`)
|
||||
return response.data
|
||||
}
|
||||
|
||||
export const getWorkspace = async (workspaceId: string): Promise<TypesGen.Workspace> => {
|
||||
const response = await axios.get<TypesGen.Workspace>(`/api/v2/workspaces/${workspaceId}`)
|
||||
return response.data
|
||||
@@ -180,6 +166,14 @@ export const createUser = async (user: TypesGen.CreateUserRequest): Promise<Type
|
||||
return response.data
|
||||
}
|
||||
|
||||
export const createWorkspace = async (
|
||||
organizationId: string,
|
||||
workspace: TypesGen.CreateWorkspaceRequest,
|
||||
): Promise<TypesGen.Workspace> => {
|
||||
const response = await axios.post<TypesGen.Workspace>(`/api/v2/organizations/${organizationId}/workspaces`, workspace)
|
||||
return response.data
|
||||
}
|
||||
|
||||
export const getBuildInfo = async (): Promise<TypesGen.BuildInfoResponse> => {
|
||||
const response = await axios.get("/api/v2/buildinfo")
|
||||
return response.data
|
||||
|
||||
Reference in New Issue
Block a user