feat: Add Create Workspace Form (#73)

Fixes #38 

This adds a create-workspace form (with only 1 field, probably the simplest form ever 😄 )

![image](https://user-images.githubusercontent.com/88213859/151108220-8a540c75-e55b-49af-8199-c69394508700.png)

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:
Bryan
2022-01-31 10:22:34 -08:00
committed by GitHub
parent b586a35c6d
commit 7cf686c996
4 changed files with 203 additions and 0 deletions
+30
View File
@@ -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",