add workspace navbar status + creation modal

This commit is contained in:
2026-03-12 09:20:25 +08:00
parent bc099512db
commit 94489a7769
11 changed files with 648 additions and 16 deletions

42
src/api/workspaces.ts Normal file
View File

@@ -0,0 +1,42 @@
import { authFetch } from "./client"
export interface Workspace {
id: string
name: string
[key: string]: any
}
export const fetchWorkspaces = async (): Promise<Workspace[]> => {
const response = await authFetch("/api/workspaces/")
if (!response.ok) {
throw new Error("Failed to fetch workspaces")
}
const data = await response.json()
// Handles paginated responses if the API returns { count, next, previous, results: [...] }
return data.results || data
}
export const createWorkspace = async (data: { name: string; description: string; members?: any[] }) => {
// 1. Only send name and description to the workspaces endpoint
const payload = {
name: data.name,
description: data.description,
};
const response = await authFetch('/api/workspaces/', {
method: 'POST',
headers: {
'Content-Type': 'application/json', // CRITICAL for DRF to parse the string correctly
},
body: JSON.stringify(payload),
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error || 'Failed to create workspace');
}
const newWorkspace = await response.json();
return newWorkspace;
};