feat(workspaces): add FilterBar component and search/ordering to Workspaces.tsx

This commit is contained in:
2026-03-12 21:47:19 +08:00
parent 5e4f4ec6e4
commit 228de3c180
5 changed files with 261 additions and 87 deletions

View File

@@ -1,3 +1,4 @@
// src/api/workspaces.ts
import { authFetch } from "./client";
export interface Workspace {
@@ -9,8 +10,10 @@ export interface Workspace {
[key: string]: any;
}
export const fetchWorkspaces = async (): Promise<Workspace[]> => {
const response = await authFetch("/api/workspaces/");
export const fetchWorkspaces = async (params?: Record<string, string>): Promise<Workspace[]> => {
const query = params ? new URLSearchParams(params).toString() : '';
const url = `/api/workspaces/${query ? `?${query}` : ''}`;
const response = await authFetch(url);
if (!response.ok) {
throw new Error("Failed to fetch workspaces");
@@ -22,37 +25,26 @@ export const fetchWorkspaces = async (): Promise<Workspace[]> => {
export const getWorkspace = async (id: string): Promise<Workspace> => {
const response = await authFetch(`/api/workspaces/${id}/`);
if (!response.ok) {
throw new Error("Failed to fetch workspace details");
}
if (!response.ok) throw new Error("Failed to fetch workspace details");
return await response.json();
};
export const createWorkspace = async (data: { name: string; description: string; members?: any[] }): Promise<Workspace> => {
const payload = {
name: data.name,
description: data.description,
members: data.members,
};
const response = await authFetch('/api/workspaces/', {
method: 'POST',
body: JSON.stringify(payload),
body: JSON.stringify(data),
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error || JSON.stringify(errorData) || 'Failed to create workspace');
}
return await response.json();
};
export const updateWorkspace = async (id: string, data: { name?: string; description?: string }): Promise<Workspace> => {
const response = await authFetch(`/api/workspaces/${id}/`, {
method: 'PATCH', // Using PATCH as defined in API docs for partial updates
method: 'PATCH',
body: JSON.stringify(data),
});
@@ -60,7 +52,6 @@ export const updateWorkspace = async (id: string, data: { name?: string; descrip
const errorData = await response.json();
throw new Error(errorData.error || JSON.stringify(errorData) || 'Failed to update workspace');
}
return await response.json();
};