feat(web): add admin users settings page (MS21-UI-001) (#573)
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 #573.
This commit is contained in:
98
apps/web/src/lib/api/admin.ts
Normal file
98
apps/web/src/lib/api/admin.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* Admin API Client
|
||||
* Handles admin user management requests
|
||||
*/
|
||||
|
||||
import type { WorkspaceMemberRole } from "@mosaic/shared";
|
||||
import { apiGet, apiPatch, apiPost, apiDelete } from "./client";
|
||||
|
||||
export interface AdminWorkspaceMembership {
|
||||
workspaceId: string;
|
||||
workspaceName: string;
|
||||
role: WorkspaceMemberRole;
|
||||
joinedAt: string;
|
||||
}
|
||||
|
||||
export interface AdminUser {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
emailVerified: boolean;
|
||||
image: string | null;
|
||||
createdAt: string;
|
||||
deactivatedAt: string | null;
|
||||
isLocalAuth: boolean;
|
||||
invitedAt: string | null;
|
||||
invitedBy: string | null;
|
||||
workspaceMemberships: AdminWorkspaceMembership[];
|
||||
}
|
||||
|
||||
export interface AdminUsersResponse {
|
||||
data: AdminUser[];
|
||||
meta: {
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
totalPages: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface InviteUserDto {
|
||||
email: string;
|
||||
name?: string;
|
||||
workspaceId?: string;
|
||||
role?: WorkspaceMemberRole;
|
||||
}
|
||||
|
||||
export interface InvitationResponse {
|
||||
userId: string;
|
||||
invitationToken: string;
|
||||
email: string;
|
||||
invitedAt: string;
|
||||
}
|
||||
|
||||
export interface UpdateUserDto {
|
||||
name?: string;
|
||||
deactivatedAt?: string | null;
|
||||
emailVerified?: boolean;
|
||||
preferences?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch paginated admin users
|
||||
*/
|
||||
export async function fetchAdminUsers(page?: number, limit?: number): Promise<AdminUsersResponse> {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (page !== undefined) {
|
||||
params.append("page", String(page));
|
||||
}
|
||||
|
||||
if (limit !== undefined) {
|
||||
params.append("limit", String(limit));
|
||||
}
|
||||
|
||||
const endpoint = `/api/admin/users${params.toString() ? `?${params.toString()}` : ""}`;
|
||||
return apiGet<AdminUsersResponse>(endpoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invite a user by email
|
||||
*/
|
||||
export async function inviteUser(dto: InviteUserDto): Promise<InvitationResponse> {
|
||||
return apiPost<InvitationResponse>("/api/admin/users/invite", dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update admin user fields
|
||||
*/
|
||||
export async function updateUser(id: string, dto: UpdateUserDto): Promise<AdminUser> {
|
||||
return apiPatch<AdminUser>(`/api/admin/users/${id}`, dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate a user account
|
||||
*/
|
||||
export async function deactivateUser(id: string): Promise<AdminUser> {
|
||||
return apiDelete<AdminUser>(`/api/admin/users/${id}`);
|
||||
}
|
||||
@@ -16,3 +16,4 @@ export * from "./telemetry";
|
||||
export * from "./dashboard";
|
||||
export * from "./projects";
|
||||
export * from "./workspaces";
|
||||
export * from "./admin";
|
||||
|
||||
Reference in New Issue
Block a user