refactor(workspaces): normalize workspace bootstrap and edit flows
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { authFetch } from "./client";
|
||||
|
||||
export interface Workspace {
|
||||
id: string;
|
||||
export interface Workspace {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
owner?: string;
|
||||
@@ -16,9 +16,9 @@ export interface PaginatedResponse<T> {
|
||||
results: T[];
|
||||
}
|
||||
|
||||
export interface WorkspaceMembership {
|
||||
id: string;
|
||||
workspace: string;
|
||||
export interface WorkspaceMembership {
|
||||
id: string;
|
||||
workspace: string;
|
||||
user: {
|
||||
id: string;
|
||||
email: string;
|
||||
@@ -29,14 +29,27 @@ export interface WorkspaceMembership {
|
||||
role: 'owner' | 'admin' | 'member' | 'guest';
|
||||
is_active: boolean;
|
||||
joined_at?: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
|
||||
export const fetchWorkspaces = async (params?: Record<string, string>): Promise<PaginatedResponse<Workspace>> => {
|
||||
const query = params ? new URLSearchParams(params).toString() : '';
|
||||
const url = `/api/workspaces/${query ? `?${query}` : ''}`;
|
||||
const response = await authFetch(url);
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
|
||||
type QueryValue = string | number | boolean | undefined | null;
|
||||
|
||||
const toQueryString = (params?: Record<string, QueryValue>) => {
|
||||
if (!params) return "";
|
||||
const query = new URLSearchParams();
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== "") {
|
||||
query.set(key, String(value));
|
||||
}
|
||||
});
|
||||
return query.toString();
|
||||
};
|
||||
|
||||
export const fetchWorkspaces = async (params?: Record<string, QueryValue>): Promise<PaginatedResponse<Workspace>> => {
|
||||
const query = toQueryString(params);
|
||||
const url = `/api/workspaces/${query ? `?${query}` : ''}`;
|
||||
const response = await authFetch(url);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch workspaces");
|
||||
@@ -98,9 +111,9 @@ export const deleteWorkspace = async (id: string): Promise<void> => {
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchWorkspaceMemberships = async (params?: Record<string, string>): Promise<PaginatedResponse<WorkspaceMembership>> => {
|
||||
const queryParams = new URLSearchParams((params || {}));
|
||||
const response = await authFetch(`/api/workspace-memberships/?${queryParams.toString()}`);
|
||||
export const fetchWorkspaceMemberships = async (params?: Record<string, QueryValue>): Promise<PaginatedResponse<WorkspaceMembership>> => {
|
||||
const queryParams = toQueryString(params);
|
||||
const response = await authFetch(`/api/workspace-memberships/?${queryParams.toString()}`);
|
||||
|
||||
if (!response.ok) throw new Error("Failed to fetch workspace memberships");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user