feat(web): wire workspaces settings page to real API (MS21-UI-003) (#574)
All checks were successful
ci/woodpecker/push/web Pipeline was successful
All checks were successful
ci/woodpecker/push/web Pipeline was successful
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #574.
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
* User-scoped workspace discovery — does NOT require X-Workspace-Id header.
|
||||
*/
|
||||
|
||||
import { apiGet } from "./client";
|
||||
import type { WorkspaceMemberRole } from "@mosaic/shared";
|
||||
import { apiGet, apiPost } from "./client";
|
||||
|
||||
/**
|
||||
* A workspace entry from the user's membership list.
|
||||
@@ -13,10 +14,24 @@ export interface UserWorkspace {
|
||||
id: string;
|
||||
name: string;
|
||||
ownerId: string;
|
||||
role: string;
|
||||
role: WorkspaceMemberRole;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface CreateWorkspaceDto {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface CreatedWorkspace {
|
||||
id: string;
|
||||
name: string;
|
||||
ownerId: string;
|
||||
settings: Record<string, unknown>;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
memberCount: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all workspaces the authenticated user is a member of.
|
||||
* The API auto-provisions a default workspace if the user has none.
|
||||
@@ -24,3 +39,10 @@ export interface UserWorkspace {
|
||||
export async function fetchUserWorkspaces(): Promise<UserWorkspace[]> {
|
||||
return apiGet<UserWorkspace[]>("/api/workspaces");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a workspace through the admin endpoint.
|
||||
*/
|
||||
export async function createWorkspace(dto: CreateWorkspaceDto): Promise<CreatedWorkspace> {
|
||||
return apiPost<CreatedWorkspace>("/api/admin/workspaces", dto);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import { AuthProvider, useAuth } from "./auth-context";
|
||||
import type { AuthUser } from "@mosaic/shared";
|
||||
import { WorkspaceMemberRole } from "@mosaic/shared";
|
||||
|
||||
// Mock the API client
|
||||
vi.mock("../api/client", () => ({
|
||||
@@ -761,7 +762,7 @@ describe("AuthContext", (): void => {
|
||||
id: "ws-1",
|
||||
name: "My Workspace",
|
||||
ownerId: "user-1",
|
||||
role: "OWNER",
|
||||
role: WorkspaceMemberRole.OWNER,
|
||||
createdAt: "2026-01-01",
|
||||
},
|
||||
]);
|
||||
@@ -795,14 +796,14 @@ describe("AuthContext", (): void => {
|
||||
id: "ws-abc-123",
|
||||
name: "My Workspace",
|
||||
ownerId: "user-1",
|
||||
role: "OWNER",
|
||||
role: WorkspaceMemberRole.OWNER,
|
||||
createdAt: "2026-01-01",
|
||||
},
|
||||
{
|
||||
id: "ws-def-456",
|
||||
name: "Second Workspace",
|
||||
ownerId: "other",
|
||||
role: "MEMBER",
|
||||
role: WorkspaceMemberRole.MEMBER,
|
||||
createdAt: "2026-02-01",
|
||||
},
|
||||
]);
|
||||
@@ -892,7 +893,7 @@ describe("AuthContext", (): void => {
|
||||
id: "ws-1",
|
||||
name: "My Workspace",
|
||||
ownerId: "user-1",
|
||||
role: "OWNER",
|
||||
role: WorkspaceMemberRole.OWNER,
|
||||
createdAt: "2026-01-01",
|
||||
},
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user