Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. Β See raw diff
- apps/admin/.gitignore +24 -0
- apps/admin/.turbo/turbo-build.log +61 -0
- apps/admin/.turbo/turbo-lint.log +4 -0
- apps/admin/.turbo/turbo-type-check.log +15 -0
- apps/admin/Dockerfile +32 -0
- apps/admin/README.md +73 -0
- apps/admin/eslint.config.js +3 -0
- apps/admin/next-env.d.ts +6 -0
- apps/admin/next.config.js +31 -0
- apps/admin/package.json +48 -0
- apps/admin/postcss.config.js +6 -0
- apps/admin/public/favicon.ico +0 -0
- apps/admin/public/favicon.svg +0 -0
- apps/admin/public/icons.svg +24 -0
- apps/admin/src/app/(dashboard)/ai-engines/clip-scorer/page.tsx +242 -0
- apps/admin/src/app/(dashboard)/ai-engines/page.tsx +134 -0
- apps/admin/src/app/(dashboard)/audit-logs/page.tsx +197 -0
- apps/admin/src/app/(dashboard)/crm/guests/page.tsx +169 -0
- apps/admin/src/app/(dashboard)/crm/inquiries/page.tsx +158 -0
- apps/admin/src/app/(dashboard)/crm/users/page.tsx +153 -0
- apps/admin/src/app/(dashboard)/infrastructure/page.tsx +191 -0
- apps/admin/src/app/(dashboard)/integrations/credentials/page.tsx +184 -0
- apps/admin/src/app/(dashboard)/integrations/page.tsx +113 -0
- apps/admin/src/app/(dashboard)/layout.tsx +41 -0
- apps/admin/src/app/(dashboard)/moderation/page.tsx +231 -0
- apps/admin/src/app/(dashboard)/observability/errors/page.tsx +141 -0
- apps/admin/src/app/(dashboard)/observability/logs/page.tsx +160 -0
- apps/admin/src/app/(dashboard)/observability/metrics/page.tsx +135 -0
- apps/admin/src/app/(dashboard)/observability/traces/page.tsx +161 -0
- apps/admin/src/app/(dashboard)/page.tsx +425 -0
- apps/admin/src/app/(dashboard)/queues/page.tsx +196 -0
- apps/admin/src/app/(dashboard)/ratings/page.tsx +223 -0
- apps/admin/src/app/(dashboard)/realtime/page.tsx +254 -0
- apps/admin/src/app/(dashboard)/security-policy/page.tsx +406 -0
- apps/admin/src/app/(dashboard)/settings/page.tsx +418 -0
- apps/admin/src/app/(dashboard)/supervision/page.tsx +266 -0
- apps/admin/src/app/(dashboard)/support/[ticketId]/page.tsx +251 -0
- apps/admin/src/app/(dashboard)/support/page.tsx +172 -0
- apps/admin/src/app/(dashboard)/surveys/[id]/page.tsx +266 -0
- apps/admin/src/app/(dashboard)/surveys/page.tsx +197 -0
- apps/admin/src/app/(dashboard)/synthetic-agents/page.tsx +134 -0
- apps/admin/src/app/(dashboard)/tenants/page.tsx +145 -0
- apps/admin/src/app/(dashboard)/users/[id]/page.tsx +335 -0
- apps/admin/src/app/(dashboard)/users/page.tsx +271 -0
- apps/admin/src/app/(dashboard)/verification/page.tsx +136 -0
- apps/admin/src/app/(dashboard)/webhooks/page.tsx +141 -0
- apps/admin/src/app/(dashboard)/workspaces/[id]/page.tsx +334 -0
- apps/admin/src/app/(dashboard)/workspaces/page.tsx +238 -0
- apps/admin/src/app/globals.css +567 -0
- apps/admin/src/app/layout.tsx +23 -0
apps/admin/.gitignore
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Logs
|
| 2 |
+
logs
|
| 3 |
+
*.log
|
| 4 |
+
npm-debug.log*
|
| 5 |
+
yarn-debug.log*
|
| 6 |
+
yarn-error.log*
|
| 7 |
+
pnpm-debug.log*
|
| 8 |
+
lerna-debug.log*
|
| 9 |
+
|
| 10 |
+
node_modules
|
| 11 |
+
dist
|
| 12 |
+
dist-ssr
|
| 13 |
+
*.local
|
| 14 |
+
|
| 15 |
+
# Editor directories and files
|
| 16 |
+
.vscode/*
|
| 17 |
+
!.vscode/extensions.json
|
| 18 |
+
.idea
|
| 19 |
+
.DS_Store
|
| 20 |
+
*.suo
|
| 21 |
+
*.ntvs*
|
| 22 |
+
*.njsproj
|
| 23 |
+
*.sln
|
| 24 |
+
*.sw?
|
apps/admin/.turbo/turbo-build.log
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
> @micprotocol/admin@0.1.0 build /home/benaah/Desktop/MicProtocol/apps/admin
|
| 3 |
+
> next build
|
| 4 |
+
|
| 5 |
+
β² Next.js 16.1.6 (Turbopack)
|
| 6 |
+
|
| 7 |
+
β The "middleware" file convention is deprecated. Please use "proxy" instead. Learn more: https://nextjs.org/docs/messages/middleware-to-proxy
|
| 8 |
+
Creating an optimized production build ...
|
| 9 |
+
β Compiled successfully in 26.3s
|
| 10 |
+
Running TypeScript ...
|
| 11 |
+
Collecting page data using 3 workers ...
|
| 12 |
+
Generating static pages using 3 workers (0/32) ...
|
| 13 |
+
Generating static pages using 3 workers (8/32)
|
| 14 |
+
Generating static pages using 3 workers (16/32)
|
| 15 |
+
Generating static pages using 3 workers (24/32)
|
| 16 |
+
β Generating static pages using 3 workers (32/32) in 2.1s
|
| 17 |
+
Finalizing page optimization ...
|
| 18 |
+
|
| 19 |
+
Route (app)
|
| 20 |
+
β β /
|
| 21 |
+
β β /_not-found
|
| 22 |
+
β β /ai-engines
|
| 23 |
+
β β /ai-engines/clip-scorer
|
| 24 |
+
β β /audit-logs
|
| 25 |
+
β β /crm/guests
|
| 26 |
+
β β /crm/inquiries
|
| 27 |
+
β β /crm/users
|
| 28 |
+
β β /infrastructure
|
| 29 |
+
β β /integrations
|
| 30 |
+
β β /integrations/credentials
|
| 31 |
+
β β /login
|
| 32 |
+
β β /moderation
|
| 33 |
+
β β /observability/errors
|
| 34 |
+
β β /observability/logs
|
| 35 |
+
β β /observability/metrics
|
| 36 |
+
β β /observability/traces
|
| 37 |
+
β β /queues
|
| 38 |
+
β β /ratings
|
| 39 |
+
β β /realtime
|
| 40 |
+
β β /security-policy
|
| 41 |
+
β β /settings
|
| 42 |
+
β β /supervision
|
| 43 |
+
β β /support
|
| 44 |
+
β Ζ /support/[ticketId]
|
| 45 |
+
β β /surveys
|
| 46 |
+
β Ζ /surveys/[id]
|
| 47 |
+
β β /synthetic-agents
|
| 48 |
+
β β /tenants
|
| 49 |
+
β β /users
|
| 50 |
+
β Ζ /users/[id]
|
| 51 |
+
β β /verification
|
| 52 |
+
β β /webhooks
|
| 53 |
+
β β /workspaces
|
| 54 |
+
β Ζ /workspaces/[id]
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
Ζ Proxy (Middleware)
|
| 58 |
+
|
| 59 |
+
β (Static) prerendered as static content
|
| 60 |
+
Ζ (Dynamic) server-rendered on demand
|
| 61 |
+
|
apps/admin/.turbo/turbo-lint.log
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
> @micprotocol/admin@0.1.0 lint /home/benaah/Desktop/MicProtocol/apps/admin
|
| 3 |
+
> eslint . --ext .ts,.tsx,.js,.jsx
|
| 4 |
+
|
apps/admin/.turbo/turbo-type-check.log
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
> @micprotocol/admin@0.1.0 type-check /home/benaah/Desktop/MicProtocol/apps/admin
|
| 3 |
+
> tsc --noEmit
|
| 4 |
+
|
| 5 |
+
src/app/(dashboard)/security-policy/page.tsx(74,39): error TS2339: Property 'invalidate' does not exist on type 'DecoratedQuery<{ input: { status?: "OPEN" | "REVIEWED" | "DISMISSED" | "ACTIONED" | undefined; severity?: "low" | "medium" | "high" | "critical" | undefined; workspaceId?: string | undefined; page?: number | undefined; limit?: number | undefined; }; output: { ...; }; transformer: false; errorShape: { ...; }; }>'.
|
| 6 |
+
src/app/(dashboard)/security-policy/page.tsx(80,39): error TS2339: Property 'invalidate' does not exist on type 'DecoratedQuery<{ input: { status?: "OPEN" | "REVIEWED" | "DISMISSED" | "ACTIONED" | undefined; severity?: "low" | "medium" | "high" | "critical" | undefined; workspaceId?: string | undefined; page?: number | undefined; limit?: number | undefined; }; output: { ...; }; transformer: false; errorShape: { ...; }; }>'.
|
| 7 |
+
src/app/(dashboard)/security-policy/page.tsx(86,41): error TS2339: Property 'invalidate' does not exist on type 'DecoratedQuery<{ input: { activeOnly?: boolean | undefined; type?: "EMAIL_DOMAIN" | "IP_RANGE" | "WORKSPACE_SLUG" | undefined; }; output: { type: string; value: string; createdAt: string; reason: string; updatedAt: string; isActive: boolean; id: string; createdBy: string | null; }[]; transformer: false; errorShape: ...'.
|
| 8 |
+
src/app/(dashboard)/security-policy/page.tsx(94,41): error TS2339: Property 'invalidate' does not exist on type 'DecoratedQuery<{ input: { activeOnly?: boolean | undefined; type?: "EMAIL_DOMAIN" | "IP_RANGE" | "WORKSPACE_SLUG" | undefined; }; output: { type: string; value: string; createdAt: string; reason: string; updatedAt: string; isActive: boolean; id: string; createdBy: string | null; }[]; transformer: false; errorShape: ...'.
|
| 9 |
+
src/app/(dashboard)/security-policy/page.tsx(107,37): error TS2339: Property 'invalidate' does not exist on type 'DecoratedQuery<{ input: { status?: "OPEN" | "REVIEWED" | "DISMISSED" | "ACTIONED" | undefined; severity?: "low" | "medium" | "high" | "critical" | undefined; workspaceId?: string | undefined; page?: number | undefined; limit?: number | undefined; }; output: { ...; }; transformer: false; errorShape: { ...; }; }>'.
|
| 10 |
+
src/app/(dashboard)/security-policy/page.tsx(108,39): error TS2339: Property 'invalidate' does not exist on type 'DecoratedQuery<{ input: { activeOnly?: boolean | undefined; type?: "EMAIL_DOMAIN" | "IP_RANGE" | "WORKSPACE_SLUG" | undefined; }; output: { type: string; value: string; createdAt: string; reason: string; updatedAt: string; isActive: boolean; id: string; createdBy: string | null; }[]; transformer: false; errorShape: ...'.
|
| 11 |
+
src/app/(dashboard)/security-policy/page.tsx(274,29): error TS2322: Type '"error"' is not assignable to type '"default" | "link" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined'.
|
| 12 |
+
src/app/(dashboard)/security-policy/page.tsx(342,29): error TS2322: Type '"error"' is not assignable to type '"default" | "link" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined'.
|
| 13 |
+
src/app/(dashboard)/security-policy/page.tsx(392,19): error TS2322: Type '"primary"' is not assignable to type '"default" | "link" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined'.
|
| 14 |
+
../api/src/common/file-security/file-security.service.ts(100,23): error TS2694: Namespace 'global.Express' has no exported member 'Multer'.
|
| 15 |
+
βELIFECYCLEβ Command failed with exit code 2.
|
apps/admin/Dockerfile
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:20-slim AS base
|
| 2 |
+
|
| 3 |
+
FROM base AS deps
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
RUN apt-get update && apt-get install -y --no-install-recommends libc6-dev sqlite3 libsqlite3-dev g++ make python3 && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
COPY pnpm-lock.yaml pnpm-workspace.yaml package.json ./
|
| 7 |
+
COPY apps/admin/package.json ./apps/admin/package.json
|
| 8 |
+
COPY apps/api/package.json ./apps/api/package.json
|
| 9 |
+
COPY packages/ ./packages
|
| 10 |
+
COPY apps/admin ./apps/admin
|
| 11 |
+
RUN npm install -g pnpm@10.30.3 && pnpm install --frozen-lockfile
|
| 12 |
+
|
| 13 |
+
FROM base AS builder
|
| 14 |
+
WORKDIR /app
|
| 15 |
+
COPY --from=deps /app/node_modules ./node_modules
|
| 16 |
+
COPY --from=deps /app/packages ./packages
|
| 17 |
+
COPY --from=deps /app/apps/admin ./apps/admin
|
| 18 |
+
COPY packages ./packages
|
| 19 |
+
ENV DOCKER_BUILD=true
|
| 20 |
+
RUN npm install -g pnpm@10.30.3 && cd apps/admin && pnpm build
|
| 21 |
+
|
| 22 |
+
FROM base AS runner
|
| 23 |
+
WORKDIR /app
|
| 24 |
+
ENV NODE_ENV=production
|
| 25 |
+
ENV PORT=3006
|
| 26 |
+
ENV HOSTNAME="0.0.0.0"
|
| 27 |
+
COPY --from=builder /app/apps/admin/.next/standalone ./
|
| 28 |
+
COPY --from=builder /app/apps/admin/.next/static ./apps/admin/.next/static
|
| 29 |
+
COPY --from=builder /app/apps/admin/public ./apps/admin/public
|
| 30 |
+
|
| 31 |
+
EXPOSE 3006
|
| 32 |
+
CMD ["node", "apps/admin/server.js"]
|
apps/admin/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# React + TypeScript + Vite
|
| 2 |
+
|
| 3 |
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
| 4 |
+
|
| 5 |
+
Currently, two official plugins are available:
|
| 6 |
+
|
| 7 |
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
|
| 8 |
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
|
| 9 |
+
|
| 10 |
+
## React Compiler
|
| 11 |
+
|
| 12 |
+
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
| 13 |
+
|
| 14 |
+
## Expanding the ESLint configuration
|
| 15 |
+
|
| 16 |
+
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
| 17 |
+
|
| 18 |
+
```js
|
| 19 |
+
export default defineConfig([
|
| 20 |
+
globalIgnores(['dist']),
|
| 21 |
+
{
|
| 22 |
+
files: ['**/*.{ts,tsx}'],
|
| 23 |
+
extends: [
|
| 24 |
+
// Other configs...
|
| 25 |
+
|
| 26 |
+
// Remove tseslint.configs.recommended and replace with this
|
| 27 |
+
tseslint.configs.recommendedTypeChecked,
|
| 28 |
+
// Alternatively, use this for stricter rules
|
| 29 |
+
tseslint.configs.strictTypeChecked,
|
| 30 |
+
// Optionally, add this for stylistic rules
|
| 31 |
+
tseslint.configs.stylisticTypeChecked,
|
| 32 |
+
|
| 33 |
+
// Other configs...
|
| 34 |
+
],
|
| 35 |
+
languageOptions: {
|
| 36 |
+
parserOptions: {
|
| 37 |
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
| 38 |
+
tsconfigRootDir: import.meta.dirname,
|
| 39 |
+
},
|
| 40 |
+
// other options...
|
| 41 |
+
},
|
| 42 |
+
},
|
| 43 |
+
])
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
| 47 |
+
|
| 48 |
+
```js
|
| 49 |
+
// eslint.config.js
|
| 50 |
+
import reactX from 'eslint-plugin-react-x'
|
| 51 |
+
import reactDom from 'eslint-plugin-react-dom'
|
| 52 |
+
|
| 53 |
+
export default defineConfig([
|
| 54 |
+
globalIgnores(['dist']),
|
| 55 |
+
{
|
| 56 |
+
files: ['**/*.{ts,tsx}'],
|
| 57 |
+
extends: [
|
| 58 |
+
// Other configs...
|
| 59 |
+
// Enable lint rules for React
|
| 60 |
+
reactX.configs['recommended-typescript'],
|
| 61 |
+
// Enable lint rules for React DOM
|
| 62 |
+
reactDom.configs.recommended,
|
| 63 |
+
],
|
| 64 |
+
languageOptions: {
|
| 65 |
+
parserOptions: {
|
| 66 |
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
| 67 |
+
tsconfigRootDir: import.meta.dirname,
|
| 68 |
+
},
|
| 69 |
+
// other options...
|
| 70 |
+
},
|
| 71 |
+
},
|
| 72 |
+
])
|
| 73 |
+
```
|
apps/admin/eslint.config.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import nextConfig from 'eslint-config-next';
|
| 2 |
+
|
| 3 |
+
export default nextConfig;
|
apps/admin/next-env.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/// <reference types="next" />
|
| 2 |
+
/// <reference types="next/image-types/global" />
|
| 3 |
+
import "./.next/types/routes.d.ts";
|
| 4 |
+
|
| 5 |
+
// NOTE: This file should not be edited
|
| 6 |
+
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
apps/admin/next.config.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/** @type {import('next').NextConfig} */
|
| 2 |
+
const path = require("path");
|
| 3 |
+
|
| 4 |
+
const nextConfig = {
|
| 5 |
+
reactStrictMode: true,
|
| 6 |
+
transpilePackages: ["@micprotocol/shared-types", "@micprotocol/ui"],
|
| 7 |
+
output: process.env.DOCKER_BUILD ? "standalone" : undefined,
|
| 8 |
+
poweredByHeader: false,
|
| 9 |
+
compress: true,
|
| 10 |
+
// Admin never uses Prisma at runtime; @micprotocol/api is imported as
|
| 11 |
+
// `import type` (erased at compile time). Skip type-checking in Docker
|
| 12 |
+
// builds since the Prisma generated client isn't available in this image.
|
| 13 |
+
typescript: process.env.DOCKER_BUILD ? { ignoreBuildErrors: true } : undefined,
|
| 14 |
+
turbopack: {
|
| 15 |
+
root: path.resolve(__dirname, "../.."),
|
| 16 |
+
},
|
| 17 |
+
async rewrites() {
|
| 18 |
+
return [
|
| 19 |
+
{
|
| 20 |
+
source: "/api/:path*",
|
| 21 |
+
destination: `${process.env.API_URL || "http://localhost:4000"}/api/:path*`,
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
source: "/trpc/:path*",
|
| 25 |
+
destination: `${process.env.API_URL || "http://localhost:4000"}/trpc/:path*`,
|
| 26 |
+
},
|
| 27 |
+
];
|
| 28 |
+
},
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
module.exports = nextConfig;
|
apps/admin/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@micprotocol/admin",
|
| 3 |
+
"version": "0.1.0",
|
| 4 |
+
"private": true,
|
| 5 |
+
"scripts": {
|
| 6 |
+
"dev": "next dev --port 3006",
|
| 7 |
+
"build": "next build",
|
| 8 |
+
"start": "next start --port 3006",
|
| 9 |
+
"lint": "eslint . --ext .ts,.tsx,.js,.jsx",
|
| 10 |
+
"type-check": "tsc --noEmit"
|
| 11 |
+
},
|
| 12 |
+
"dependencies": {
|
| 13 |
+
"@micprotocol/api": "workspace:*",
|
| 14 |
+
"@micprotocol/shared-types": "workspace:*",
|
| 15 |
+
"@micprotocol/ui": "workspace:*",
|
| 16 |
+
"@radix-ui/react-avatar": "^1.3.1",
|
| 17 |
+
"@radix-ui/react-dialog": "^1.3.1",
|
| 18 |
+
"@radix-ui/react-dropdown-menu": "^2.2.1",
|
| 19 |
+
"@radix-ui/react-select": "^2.4.1",
|
| 20 |
+
"@radix-ui/react-separator": "^1.2.0",
|
| 21 |
+
"@radix-ui/react-switch": "^1.4.1",
|
| 22 |
+
"@radix-ui/react-tabs": "^1.2.1",
|
| 23 |
+
"@radix-ui/react-tooltip": "^1.4.1",
|
| 24 |
+
"@tanstack/react-query": "^5.90.21",
|
| 25 |
+
"@trpc/react-query": "^11.11.0",
|
| 26 |
+
"@trpc/server": "^11.11.0",
|
| 27 |
+
"autoprefixer": "^10.6.1",
|
| 28 |
+
"better-auth": "^1.7.13",
|
| 29 |
+
"class-variance-authority": "^0.7.1",
|
| 30 |
+
"clsx": "^2.1.1",
|
| 31 |
+
"framer-motion": "^14.6.0",
|
| 32 |
+
"lucide-react": "^0.576.0",
|
| 33 |
+
"next": "16.1.6",
|
| 34 |
+
"postcss": "^8.5.31",
|
| 35 |
+
"react": "^19.2.4",
|
| 36 |
+
"react-dom": "^19.2.4",
|
| 37 |
+
"tailwindcss": "^3.4.19"
|
| 38 |
+
},
|
| 39 |
+
"devDependencies": {
|
| 40 |
+
"@micprotocol/tsconfig": "workspace:*",
|
| 41 |
+
"@types/node": "^25.3.3",
|
| 42 |
+
"@types/react": "^19.2.14",
|
| 43 |
+
"@types/react-dom": "^19.2.3",
|
| 44 |
+
"eslint": "^9.28.0",
|
| 45 |
+
"eslint-config-next": "16.1.6",
|
| 46 |
+
"typescript": "^5.9.3"
|
| 47 |
+
}
|
| 48 |
+
}
|
apps/admin/postcss.config.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module.exports = {
|
| 2 |
+
plugins: {
|
| 3 |
+
tailwindcss: {},
|
| 4 |
+
autoprefixer: {},
|
| 5 |
+
},
|
| 6 |
+
};
|
apps/admin/public/favicon.ico
ADDED
|
|
apps/admin/public/favicon.svg
ADDED
|
|
apps/admin/public/icons.svg
ADDED
|
|
apps/admin/src/app/(dashboard)/ai-engines/clip-scorer/page.tsx
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Activity, ShieldCheck, Database, Clock, Play } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { cn } from "@/lib/utils";
|
| 7 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 8 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 9 |
+
import { Badge } from "@micprotocol/ui";
|
| 10 |
+
import { Button } from "@micprotocol/ui";
|
| 11 |
+
|
| 12 |
+
export default function AIEnginesClipScorerPage() {
|
| 13 |
+
const { data: status, isLoading } = trpc.admin.aiEngines.clipScorerStatus.useQuery(
|
| 14 |
+
undefined,
|
| 15 |
+
{ refetchInterval: 30_000 },
|
| 16 |
+
);
|
| 17 |
+
|
| 18 |
+
const healthy = status?.status === "healthy";
|
| 19 |
+
const degraded = status?.status === "degraded";
|
| 20 |
+
const down = status?.status === "down";
|
| 21 |
+
|
| 22 |
+
const axes = status?.scoringAxes ?? [
|
| 23 |
+
{ name: "Visual Relevance", weight: 0.4, enabled: true },
|
| 24 |
+
{ name: "Audio Clarity", weight: 0.3, enabled: true },
|
| 25 |
+
{ name: "Semantic Match", weight: 0.2, enabled: true },
|
| 26 |
+
{ name: "Loudness Norm", weight: 0.1, enabled: false },
|
| 27 |
+
];
|
| 28 |
+
|
| 29 |
+
const locks = status?.locks ?? [];
|
| 30 |
+
const storage = status?.storage ?? { usedGB: 0, totalGB: 0, utilization: 0 };
|
| 31 |
+
|
| 32 |
+
return (
|
| 33 |
+
<div className="animate-fade-in">
|
| 34 |
+
<AdminHeader
|
| 35 |
+
title="CLIP Scorer"
|
| 36 |
+
subtitle="Multimodal CLIP scoring engine β axes, locks, and scratch storage"
|
| 37 |
+
refreshing={isLoading}
|
| 38 |
+
actions={
|
| 39 |
+
<Button variant="outline" size="sm" disabled={down}>
|
| 40 |
+
<Play size={14} className="mr-1" /> Restart Engine
|
| 41 |
+
</Button>
|
| 42 |
+
}
|
| 43 |
+
/>
|
| 44 |
+
|
| 45 |
+
<div className="space-y-6 p-6">
|
| 46 |
+
{/* Engine status */}
|
| 47 |
+
<Card>
|
| 48 |
+
<CardHeader>
|
| 49 |
+
<CardTitle className="flex items-center gap-2">
|
| 50 |
+
<Activity className="size-4 text-[var(--color-primary)]" /> Engine Status
|
| 51 |
+
</CardTitle>
|
| 52 |
+
</CardHeader>
|
| 53 |
+
<CardContent className="p-5">
|
| 54 |
+
<div className="flex items-center gap-4">
|
| 55 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-3">
|
| 56 |
+
<Activity className="size-5 text-[var(--color-primary)]" />
|
| 57 |
+
</div>
|
| 58 |
+
<div>
|
| 59 |
+
<h3 className="font-medium text-[var(--text-primary)]">CLIP Scoring Engine</h3>
|
| 60 |
+
<p className={`mt-1 text-xs font-medium ${engineStatusColor(status?.status)}`}>
|
| 61 |
+
{status?.status ?? "unknown"}
|
| 62 |
+
</p>
|
| 63 |
+
<p className="text-xs text-[var(--text-tertiary)]">
|
| 64 |
+
{status?.uptimeSeconds != null ? `Uptime: ${Math.floor(status.uptimeSeconds / 3600)}h ${Math.floor((status.uptimeSeconds % 3600) / 60)}m` : "β"}
|
| 65 |
+
</p>
|
| 66 |
+
</div>
|
| 67 |
+
<div className="ml-auto text-right">
|
| 68 |
+
<Badge tone="neutral" className={cn("capitalize text-xs", engineStatusBadgeClass(status?.status))}>
|
| 69 |
+
{status?.status ?? "unknown"}
|
| 70 |
+
</Badge>
|
| 71 |
+
</div>
|
| 72 |
+
</div>
|
| 73 |
+
<div className="mt-6 grid gap-4 sm:grid-cols-4">
|
| 74 |
+
<div className="p-4 rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] border border-[var(--border-color-subtle)]">
|
| 75 |
+
<p className="text-[10px] text-[var(--text-tertiary)] uppercase tracking-wider font-medium">Scoring Jobs</p>
|
| 76 |
+
<p className="mt-1 font-display text-2xl font-bold text-[var(--text-primary)]">{status?.jobsProcessed ?? 0}</p>
|
| 77 |
+
</div>
|
| 78 |
+
<div className="p-4 rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] border border-[var(--border-color-subtle)]">
|
| 79 |
+
<p className="text-[10px] text-[var(--text-tertiary)] uppercase tracking-wider font-medium">Failed Jobs</p>
|
| 80 |
+
<p className="mt-1 font-display text-2xl font-bold text-[var(--color-error)]">{status?.jobsFailed ?? 0}</p>
|
| 81 |
+
</div>
|
| 82 |
+
<div className="p-4 rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] border border-[var(--border-color-subtle)]">
|
| 83 |
+
<p className="text-[10px] text-[var(--text-tertiary)] uppercase tracking-wider font-medium">Avg Latency</p>
|
| 84 |
+
<p className="mt-1 font-display text-2xl font-bold text-[var(--color-info)]">{status?.avgLatencyMs?.toFixed(1) ?? 0} ms</p>
|
| 85 |
+
</div>
|
| 86 |
+
<div className="p-4 rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] border border-[var(--border-color-subtle)]">
|
| 87 |
+
<p className="text-[10px] text-[var(--text-tertiary)] uppercase tracking-wider font-medium">Queue Depth</p>
|
| 88 |
+
<p className="mt-1 font-display text-2xl font-bold text-[var(--color-warning)]">{status?.queueDepth ?? 0}</p>
|
| 89 |
+
</div>
|
| 90 |
+
</div>
|
| 91 |
+
</CardContent>
|
| 92 |
+
</Card>
|
| 93 |
+
|
| 94 |
+
{/* Scoring axes */}
|
| 95 |
+
<Card>
|
| 96 |
+
<CardHeader>
|
| 97 |
+
<CardTitle className="flex items-center gap-2">
|
| 98 |
+
<ShieldCheck className="size-4 text-[var(--color-info)]" /> Scoring Axes
|
| 99 |
+
</CardTitle>
|
| 100 |
+
</CardHeader>
|
| 101 |
+
<CardContent className="p-0">
|
| 102 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 103 |
+
<table className="w-full text-left border-collapse">
|
| 104 |
+
<thead>
|
| 105 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 106 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Axis</th>
|
| 107 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Weight</th>
|
| 108 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-24">Enabled</th>
|
| 109 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Actions</th>
|
| 110 |
+
</tr>
|
| 111 |
+
</thead>
|
| 112 |
+
<tbody>
|
| 113 |
+
{axes.length === 0 ? (
|
| 114 |
+
<tr>
|
| 115 |
+
<td colSpan={4} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 116 |
+
No scoring axes configured.
|
| 117 |
+
</td>
|
| 118 |
+
</tr>
|
| 119 |
+
) : (
|
| 120 |
+
axes.map((a: any) => (
|
| 121 |
+
<tr key={a.name} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 122 |
+
<td className="py-4 text-sm text-[var(--text-primary)]">{a.name}</td>
|
| 123 |
+
<td className="py-4 text-xs text-center font-mono text-[var(--text-secondary)]">{a.weight}</td>
|
| 124 |
+
<td className="py-4 text-xs text-center">
|
| 125 |
+
<Badge className={cn("capitalize text-xs", a.enabled ? "bg-[var(--color-success)]/20 border-[var(--color-success)]/30 text-[var(--color-success)]" : "border-transparent text-[var(--text-tertiary)]")}>
|
| 126 |
+
{a.enabled ? "on" : "off"}
|
| 127 |
+
</Badge>
|
| 128 |
+
</td>
|
| 129 |
+
<td className="py-4 text-sm text-right">
|
| 130 |
+
<Button variant="ghost" size="sm" disabled={!a.enabled} onClick={() => {}}>
|
| 131 |
+
<Play size={14} className="mr-1" /> Enable
|
| 132 |
+
</Button>
|
| 133 |
+
</td>
|
| 134 |
+
</tr>
|
| 135 |
+
))
|
| 136 |
+
)}
|
| 137 |
+
</tbody>
|
| 138 |
+
</table>
|
| 139 |
+
</div>
|
| 140 |
+
</CardContent>
|
| 141 |
+
</Card>
|
| 142 |
+
|
| 143 |
+
{/* Lock inspector */}
|
| 144 |
+
<Card>
|
| 145 |
+
<CardHeader>
|
| 146 |
+
<CardTitle className="flex items-center gap-2">
|
| 147 |
+
<Database className="size-4 text-[var(--color-warning)]" /> Lock Inspector
|
| 148 |
+
</CardTitle>
|
| 149 |
+
</CardHeader>
|
| 150 |
+
<CardContent className="p-0">
|
| 151 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 152 |
+
<table className="w-full text-left border-collapse">
|
| 153 |
+
<thead>
|
| 154 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 155 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-28">Lock Key</th>
|
| 156 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Holder</th>
|
| 157 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">TTL</th>
|
| 158 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Status</th>
|
| 159 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Actions</th>
|
| 160 |
+
</tr>
|
| 161 |
+
</thead>
|
| 162 |
+
<tbody>
|
| 163 |
+
{locks.length === 0 ? (
|
| 164 |
+
<tr>
|
| 165 |
+
<td colSpan={5} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 166 |
+
No active distributed locks.
|
| 167 |
+
</td>
|
| 168 |
+
</tr>
|
| 169 |
+
) : (
|
| 170 |
+
locks.map((l: any) => (
|
| 171 |
+
<tr key={l.key} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 172 |
+
<td className="py-4 font-mono text-xs text-[var(--text-secondary)]">{l.key}</td>
|
| 173 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] font-mono truncate" style={{ maxWidth: 120 }}>{l.holder ?? "β"}</td>
|
| 174 |
+
<td className="py-4 text-xs text-center font-mono text-[var(--text-secondary)]">{l.ttlSeconds ?? 0}s</td>
|
| 175 |
+
<td className="py-4 text-xs text-center">
|
| 176 |
+
<Badge className="capitalize text-xs">{l.status ?? "active"}</Badge>
|
| 177 |
+
</td>
|
| 178 |
+
<td className="py-4 text-sm text-right">
|
| 179 |
+
<Button variant="ghost" size="sm" onClick={() => {}}>
|
| 180 |
+
<Clock size={14} />
|
| 181 |
+
</Button>
|
| 182 |
+
</td>
|
| 183 |
+
</tr>
|
| 184 |
+
))
|
| 185 |
+
)}
|
| 186 |
+
</tbody>
|
| 187 |
+
</table>
|
| 188 |
+
</div>
|
| 189 |
+
</CardContent>
|
| 190 |
+
</Card>
|
| 191 |
+
|
| 192 |
+
{/* Scratch storage */}
|
| 193 |
+
<Card>
|
| 194 |
+
<CardHeader>
|
| 195 |
+
<CardTitle className="flex items-center gap-2">
|
| 196 |
+
<Database className="size-4 text-[var(--color-primary)]" /> Scratch Storage
|
| 197 |
+
</CardTitle>
|
| 198 |
+
</CardHeader>
|
| 199 |
+
<CardContent className="p-5">
|
| 200 |
+
<div className="grid gap-4 sm:grid-cols-2">
|
| 201 |
+
<div className="p-4 rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] border border-[var(--border-color-subtle)]">
|
| 202 |
+
<p className="text-[10px] text-[var(--text-tertiary)] uppercase tracking-wider font-medium">Used</p>
|
| 203 |
+
<p className="mt-1 font-display text-2xl font-bold text-[var(--text-primary)]">{storage.usedGB?.toFixed(2) ?? 0} GB</p>
|
| 204 |
+
</div>
|
| 205 |
+
<div className="p-4 rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] border border-[var(--border-color-subtle)]">
|
| 206 |
+
<p className="text-[10px] text-[var(--text-tertiary)] uppercase tracking-wider font-medium">Total</p>
|
| 207 |
+
<p className="mt-1 font-display text-2xl font-bold text-[var(--text-primary)]">{storage.totalGB?.toFixed(2) ?? 0} GB</p>
|
| 208 |
+
</div>
|
| 209 |
+
</div>
|
| 210 |
+
<div className="mt-4 h-2 w-full bg-[var(--bg-tertiary)] rounded-full overflow-hidden">
|
| 211 |
+
<div
|
| 212 |
+
className="h-full bg-[var(--color-primary)]"
|
| 213 |
+
style={{ width: storage.utilization ?? 0 }}
|
| 214 |
+
/>
|
| 215 |
+
</div>
|
| 216 |
+
<p className="mt-2 text-[10px] text-[var(--text-tertiary)] text-right">
|
| 217 |
+
Utilization: {storage.utilization ?? 0}%
|
| 218 |
+
</p>
|
| 219 |
+
</CardContent>
|
| 220 |
+
</Card>
|
| 221 |
+
</div>
|
| 222 |
+
</div>
|
| 223 |
+
);
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
function engineStatusColor(status: string | undefined): string {
|
| 227 |
+
switch (status) {
|
| 228 |
+
case "healthy": return "text-[var(--color-success)]";
|
| 229 |
+
case "degraded": return "text-[var(--color-warning)]";
|
| 230 |
+
case "down": return "text-[var(--color-error)]";
|
| 231 |
+
default: return "text-[var(--text-tertiary)]";
|
| 232 |
+
}
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
function engineStatusBadgeClass(status: string | undefined): string {
|
| 236 |
+
switch (status) {
|
| 237 |
+
case "healthy": return "bg-[var(--color-success)]/20 border-[var(--color-success)]/30 text-[var(--color-success)]";
|
| 238 |
+
case "degraded": return "bg-[var(--color-warning)]/20 border-[var(--color-warning)]/30 text-[var(--color-warning)]";
|
| 239 |
+
case "down": return "bg-[var(--color-error)]/20 border-[var(--color-error)]/30 text-[var(--color-error)]";
|
| 240 |
+
default: return "border-transparent text-[var(--text-tertiary)]";
|
| 241 |
+
}
|
| 242 |
+
}
|
apps/admin/src/app/(dashboard)/ai-engines/page.tsx
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Activity, ShieldCheck, Database, Play } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { cn } from "@/lib/utils";
|
| 7 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 8 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 9 |
+
import { Badge } from "@micprotocol/ui";
|
| 10 |
+
import { Button } from "@micprotocol/ui";
|
| 11 |
+
|
| 12 |
+
export default function AIEnginesPage() {
|
| 13 |
+
const { data: engines, isLoading } = trpc.admin.aiEngines.listEngines.useQuery(
|
| 14 |
+
{ includeMetrics: true },
|
| 15 |
+
{ refetchInterval: 30_000 },
|
| 16 |
+
);
|
| 17 |
+
|
| 18 |
+
const items = engines?.items ?? [];
|
| 19 |
+
const healthy = items.filter((e) => e.status === "healthy").length;
|
| 20 |
+
const degraded = items.filter((e) => e.status === "degraded").length;
|
| 21 |
+
const down = items.filter((e) => e.status === "down").length;
|
| 22 |
+
|
| 23 |
+
return (
|
| 24 |
+
<div className="animate-fade-in">
|
| 25 |
+
<AdminHeader
|
| 26 |
+
title="AI Engines"
|
| 27 |
+
subtitle="CLIP scoring, transcription, and ML model endpoints"
|
| 28 |
+
refreshing={isLoading}
|
| 29 |
+
actions={
|
| 30 |
+
<Button variant="outline" size="sm">
|
| 31 |
+
<Play size={14} className="mr-1" /> Restart All
|
| 32 |
+
</Button>
|
| 33 |
+
}
|
| 34 |
+
/>
|
| 35 |
+
|
| 36 |
+
<div className="space-y-6 p-6">
|
| 37 |
+
{/* KPI strip */}
|
| 38 |
+
<div className="grid gap-4 sm:grid-cols-4">
|
| 39 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 40 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Engines</p>
|
| 41 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{items.length}</p>
|
| 42 |
+
</Card>
|
| 43 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 44 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Healthy</p>
|
| 45 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-success)]">{healthy}</p>
|
| 46 |
+
</Card>
|
| 47 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 48 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Degraded</p>
|
| 49 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-warning)]">{degraded}</p>
|
| 50 |
+
</Card>
|
| 51 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 52 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Down</p>
|
| 53 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-error)]">{down}</p>
|
| 54 |
+
</Card>
|
| 55 |
+
</div>
|
| 56 |
+
|
| 57 |
+
{/* Engine grid */}
|
| 58 |
+
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
| 59 |
+
{items.length > 0 ? (
|
| 60 |
+
items.map((e: any) => (
|
| 61 |
+
<Card key={e.id} className="border border-[var(--border-color)] hover:border-[var(--color-primary)]/50 transition-colors">
|
| 62 |
+
<CardContent className="p-5">
|
| 63 |
+
<div className="flex items-start justify-between mb-4">
|
| 64 |
+
<div className="flex items-center gap-3">
|
| 65 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-2.5">
|
| 66 |
+
<Activity className="size-5 text-[var(--text-secondary)]" />
|
| 67 |
+
</div>
|
| 68 |
+
<div>
|
| 69 |
+
<h3 className="font-medium text-[var(--text-primary)]">{e.name}</h3>
|
| 70 |
+
<p className="text-xs text-[var(--text-tertiary)] font-mono">{e.engineType ?? "ml-engine"}</p>
|
| 71 |
+
</div>
|
| 72 |
+
</div>
|
| 73 |
+
<div className="flex items-center gap-2">
|
| 74 |
+
<span className="size-2 rounded-full" style={{ backgroundColor: engineStatusColor(e.status) }} />
|
| 75 |
+
<Badge className={cn("capitalize text-xs", engineStatusBadgeClass(e.status))}>
|
| 76 |
+
{e.status}
|
| 77 |
+
</Badge>
|
| 78 |
+
</div>
|
| 79 |
+
</div>
|
| 80 |
+
<div className="grid gap-2 text-xs">
|
| 81 |
+
<div className="flex justify-between border-b border-[var(--border-color-subtle)] pb-1">
|
| 82 |
+
<span className="text-[var(--text-tertiary)]">Requests/sec</span>
|
| 83 |
+
<span className="text-[var(--text-secondary)] font-mono">{e.requestsPerSecond?.toFixed(1) ?? 0}</span>
|
| 84 |
+
</div>
|
| 85 |
+
<div className="flex justify-between border-b border-[var(--border-color-subtle)] pb-1">
|
| 86 |
+
<span className="text-[var(--text-tertiary)]">Avg Latency</span>
|
| 87 |
+
<span className="text-[var(--text-secondary)] font-mono">{e.avgLatencyMs?.toFixed(1) ?? 0} ms</span>
|
| 88 |
+
</div>
|
| 89 |
+
<div className="flex justify-between border-b border-[var(--border-color-subtle)] pb-1">
|
| 90 |
+
<span className="text-[var(--text-tertiary)]">Error Rate</span>
|
| 91 |
+
<span className={`text-[var(--text-secondary)] font-mono ${e.errorRate ? "text-[var(--color-error)]" : ""}`}>
|
| 92 |
+
{(e.errorRate ?? 0).toFixed(2)}%
|
| 93 |
+
</span>
|
| 94 |
+
</div>
|
| 95 |
+
</div>
|
| 96 |
+
<div className="mt-4 flex justify-end">
|
| 97 |
+
<Button variant="ghost" size="sm" onClick={() => {}}>
|
| 98 |
+
<ShieldCheck size={14} className="mr-1" /> Health Check
|
| 99 |
+
</Button>
|
| 100 |
+
</div>
|
| 101 |
+
</CardContent>
|
| 102 |
+
</Card>
|
| 103 |
+
))
|
| 104 |
+
) : (
|
| 105 |
+
<Card className="col-span-full p-12 border border-[var(--border-color)] rounded-[var(--radius-lg)] text-center">
|
| 106 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-4 inline-flex mx-auto">
|
| 107 |
+
<Database className="size-6 text-[var(--text-tertiary)]" />
|
| 108 |
+
</div>
|
| 109 |
+
<p className="mt-4 text-[var(--text-tertiary)]">No AI engines detected.</p>
|
| 110 |
+
</Card>
|
| 111 |
+
)}
|
| 112 |
+
</div>
|
| 113 |
+
</div>
|
| 114 |
+
</div>
|
| 115 |
+
);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
function engineStatusColor(status: string): string {
|
| 119 |
+
switch (status) {
|
| 120 |
+
case "healthy": return "var(--color-success)";
|
| 121 |
+
case "degraded": return "var(--color-warning)";
|
| 122 |
+
case "down": return "var(--color-error)";
|
| 123 |
+
default: return "var(--text-tertiary)";
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
function engineStatusBadgeClass(status: string): string {
|
| 128 |
+
switch (status) {
|
| 129 |
+
case "healthy": return "bg-[var(--color-success)]/20 border-[var(--color-success)]/30 text-[var(--color-success)]";
|
| 130 |
+
case "degraded": return "bg-[var(--color-warning)]/20 border-[var(--color-warning)]/30 text-[var(--color-warning)]";
|
| 131 |
+
case "down": return "bg-[var(--color-error)]/20 border-[var(--color-error)]/30 text-[var(--color-error)]";
|
| 132 |
+
default: return "border-transparent text-[var(--text-tertiary)]";
|
| 133 |
+
}
|
| 134 |
+
}
|
apps/admin/src/app/(dashboard)/audit-logs/page.tsx
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState } from "react";
|
| 4 |
+
import { Search, ClipboardList, AlertTriangle, ShieldAlert } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { cn } from "@/lib/utils";
|
| 7 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 8 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 9 |
+
import { Badge } from "@micprotocol/ui";
|
| 10 |
+
import { Button } from "@micprotocol/ui";
|
| 11 |
+
import { Input } from "@micprotocol/ui";
|
| 12 |
+
import { ago } from "@/lib/utils";
|
| 13 |
+
|
| 14 |
+
const LEVELS = ["ALL", "INFO", "WARN", "ERROR", "FATAL", "AUDIT"] as const;
|
| 15 |
+
|
| 16 |
+
export default function AuditLogsPage() {
|
| 17 |
+
const [search, setSearch] = useState("");
|
| 18 |
+
const [level, setLevel] = useState<typeof LEVELS[number]>("ALL");
|
| 19 |
+
const [page, setPage] = useState(1);
|
| 20 |
+
|
| 21 |
+
const { data: audit, isLoading } = trpc.audit.list.useQuery(
|
| 22 |
+
{ limit: 25, search: search || undefined },
|
| 23 |
+
{ refetchInterval: 30_000 },
|
| 24 |
+
);
|
| 25 |
+
|
| 26 |
+
const items = audit?.items ?? [];
|
| 27 |
+
const total = audit?.total ?? 0;
|
| 28 |
+
|
| 29 |
+
const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
|
| 30 |
+
setSearch(e.target.value);
|
| 31 |
+
setPage(1);
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
const prev = () => setPage((p) => Math.max(1, p - 1));
|
| 35 |
+
const next = () => setPage((p) => Math.min(Math.ceil(total / 25), p + 1));
|
| 36 |
+
|
| 37 |
+
return (
|
| 38 |
+
<div className="animate-fade-in">
|
| 39 |
+
<AdminHeader
|
| 40 |
+
title="Audit Logs"
|
| 41 |
+
subtitle="Immutable audit trail of every admin action across the platform"
|
| 42 |
+
refreshing={isLoading}
|
| 43 |
+
/>
|
| 44 |
+
|
| 45 |
+
<div className="space-y-6 p-6">
|
| 46 |
+
{/* Filters */}
|
| 47 |
+
<div className="flex flex-col sm:flex-row gap-4 items-end">
|
| 48 |
+
<div className="flex-1 max-w-md">
|
| 49 |
+
<div className="relative">
|
| 50 |
+
<Search className="absolute left-3 top-3 size-4 text-[var(--text-tertiary)]" />
|
| 51 |
+
<Input
|
| 52 |
+
value={search}
|
| 53 |
+
onChange={handleSearch}
|
| 54 |
+
placeholder="Search audit eventsβ¦"
|
| 55 |
+
className="pl-10 text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 56 |
+
/>
|
| 57 |
+
</div>
|
| 58 |
+
</div>
|
| 59 |
+
<select
|
| 60 |
+
value={level}
|
| 61 |
+
onChange={(e) => { setLevel((e.target.value as typeof LEVELS[number])); setPage(1); }}
|
| 62 |
+
className="w-full max-w-sm text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] px-3 py-2 text-sm focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20 outline-none"
|
| 63 |
+
>
|
| 64 |
+
{LEVELS.map((l) => (
|
| 65 |
+
<option key={l} value={l}>{l}</option>
|
| 66 |
+
))}
|
| 67 |
+
</select>
|
| 68 |
+
<Button variant="outline" size="sm">
|
| 69 |
+
<ClipboardList className="size-4 mr-1.5" /> Export CSV
|
| 70 |
+
</Button>
|
| 71 |
+
</div>
|
| 72 |
+
|
| 73 |
+
{/* Stats strip */}
|
| 74 |
+
<div className="grid gap-4 sm:grid-cols-4">
|
| 75 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 76 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Total Entries</p>
|
| 77 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{total}</p>
|
| 78 |
+
</Card>
|
| 79 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 80 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Errors</p>
|
| 81 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-error)]">
|
| 82 |
+
{items.filter((i: any) => i.level === "ERROR").length}
|
| 83 |
+
</p>
|
| 84 |
+
</Card>
|
| 85 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 86 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Warnings</p>
|
| 87 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-warning)]">
|
| 88 |
+
{items.filter((i: any) => i.level === "WARN").length}
|
| 89 |
+
</p>
|
| 90 |
+
</Card>
|
| 91 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 92 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Today</p>
|
| 93 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-info)]">
|
| 94 |
+
{items.filter((i: any) => new Date(i.createdAt).toDateString() === new Date().toDateString()).length}
|
| 95 |
+
</p>
|
| 96 |
+
</Card>
|
| 97 |
+
</div>
|
| 98 |
+
|
| 99 |
+
{/* Audit trail table */}
|
| 100 |
+
<Card>
|
| 101 |
+
<CardHeader>
|
| 102 |
+
<CardTitle className="flex items-center gap-2">
|
| 103 |
+
<ShieldAlert className="size-4 text-[var(--color-info)]" /> Audit Trail
|
| 104 |
+
</CardTitle>
|
| 105 |
+
</CardHeader>
|
| 106 |
+
<CardContent className="p-0">
|
| 107 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 108 |
+
<table className="w-full text-left border-collapse">
|
| 109 |
+
<thead>
|
| 110 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 111 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-32">Time</th>
|
| 112 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Actor</th>
|
| 113 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Action</th>
|
| 114 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-20">Resource</th>
|
| 115 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-16">Level</th>
|
| 116 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Details</th>
|
| 117 |
+
</tr>
|
| 118 |
+
</thead>
|
| 119 |
+
<tbody>
|
| 120 |
+
{isLoading ? (
|
| 121 |
+
[...Array(5)].map((_, i) => (
|
| 122 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 123 |
+
<td colSpan={6} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 124 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 125 |
+
</td>
|
| 126 |
+
</tr>
|
| 127 |
+
))
|
| 128 |
+
) : items.length === 0 ? (
|
| 129 |
+
<tr>
|
| 130 |
+
<td colSpan={6} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 131 |
+
No audit events match your filters.
|
| 132 |
+
</td>
|
| 133 |
+
</tr>
|
| 134 |
+
) : (
|
| 135 |
+
items.map((entry: any) => (
|
| 136 |
+
<tr key={entry.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 137 |
+
<td className="py-4 font-mono text-xs text-[var(--text-tertiary)]">
|
| 138 |
+
{ago(entry.createdAt)}
|
| 139 |
+
</td>
|
| 140 |
+
<td className="py-4 font-medium text-xs text-[var(--text-primary)]">
|
| 141 |
+
{entry.actorId?.slice(0, 8) ?? "system"}
|
| 142 |
+
</td>
|
| 143 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] font-mono">
|
| 144 |
+
{entry.action}
|
| 145 |
+
</td>
|
| 146 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] font-mono">
|
| 147 |
+
{entry.resourceType ?? "β"}
|
| 148 |
+
</td>
|
| 149 |
+
<td className="py-4 text-xs text-center">
|
| 150 |
+
<Badge
|
| 151 |
+
className={cn("capitalize text-xs", levelBadgeClass(entry.level))}
|
| 152 |
+
>
|
| 153 |
+
{entry.level}
|
| 154 |
+
</Badge>
|
| 155 |
+
</td>
|
| 156 |
+
<td className="py-4 text-xs text-[var(--text-secondary)]">
|
| 157 |
+
{entry.details ?? "β"}
|
| 158 |
+
</td>
|
| 159 |
+
</tr>
|
| 160 |
+
))
|
| 161 |
+
)}
|
| 162 |
+
</tbody>
|
| 163 |
+
</table>
|
| 164 |
+
</div>
|
| 165 |
+
<div className="p-4 border-t border-[var(--border-color-subtle)] flex items-center justify-between">
|
| 166 |
+
<p className="text-xs text-[var(--text-tertiary)]">
|
| 167 |
+
Showing {items.length} of {total} entries
|
| 168 |
+
</p>
|
| 169 |
+
<div className="flex gap-2">
|
| 170 |
+
<Button variant="outline" size="sm" disabled={page === 1 || isLoading} onClick={prev}>
|
| 171 |
+
<AlertTriangle size={14} /> Prev
|
| 172 |
+
</Button>
|
| 173 |
+
<Button variant="outline" size="sm" disabled={page >= Math.ceil(total / 25) || isLoading} onClick={next}>
|
| 174 |
+
Next <AlertTriangle size={14} />
|
| 175 |
+
</Button>
|
| 176 |
+
</div>
|
| 177 |
+
</div>
|
| 178 |
+
</CardContent>
|
| 179 |
+
</Card>
|
| 180 |
+
</div>
|
| 181 |
+
</div>
|
| 182 |
+
);
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
function levelBadgeClass(level: string): string {
|
| 186 |
+
switch (level) {
|
| 187 |
+
case "ERROR":
|
| 188 |
+
case "FATAL":
|
| 189 |
+
return "bg-[var(--color-error)]/10 border-[var(--color-error)]/20 text-[var(--color-error)]";
|
| 190 |
+
case "WARN":
|
| 191 |
+
return "bg-[var(--color-warning)]/10 border-[var(--color-warning)]/20 text-[var(--color-warning)]";
|
| 192 |
+
case "INFO":
|
| 193 |
+
return "bg-[var(--color-info)]/10 border-[var(--color-info)]/20 text-[var(--color-info)]";
|
| 194 |
+
default:
|
| 195 |
+
return "border-transparent";
|
| 196 |
+
}
|
| 197 |
+
}
|
apps/admin/src/app/(dashboard)/crm/guests/page.tsx
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState } from "react";
|
| 4 |
+
import { Search, User, CreditCard, Mail, Clock } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { cn } from "@/lib/utils";
|
| 7 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 8 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 9 |
+
import { Badge } from "@micprotocol/ui";
|
| 10 |
+
import { Button } from "@micprotocol/ui";
|
| 11 |
+
import { Input } from "@micprotocol/ui";
|
| 12 |
+
import { ago } from "@/lib/utils";
|
| 13 |
+
|
| 14 |
+
export default function CRMGuestsPage() {
|
| 15 |
+
const [search, setSearch] = useState("");
|
| 16 |
+
const { data: guests, isLoading } = trpc.crm.listAllGuests.useQuery(
|
| 17 |
+
{ search: search || undefined },
|
| 18 |
+
{ refetchInterval: 30_000 },
|
| 19 |
+
);
|
| 20 |
+
|
| 21 |
+
const items = (guests as any)?.items ?? [];
|
| 22 |
+
const totalGuests = items.length;
|
| 23 |
+
const verified = items.filter((g: any) => g.verified).length;
|
| 24 |
+
const vip = items.filter((g: any) => g.vip).length;
|
| 25 |
+
const blocked = items.filter((g: any) => g.blocked).length;
|
| 26 |
+
|
| 27 |
+
return (
|
| 28 |
+
<div className="animate-fade-in">
|
| 29 |
+
<AdminHeader
|
| 30 |
+
title="CRM β Guests"
|
| 31 |
+
subtitle="Guest directory with contact, booking, and verification status"
|
| 32 |
+
refreshing={isLoading}
|
| 33 |
+
actions={
|
| 34 |
+
<Button variant="outline" size="sm">
|
| 35 |
+
<CreditCard size={14} className="mr-1" /> Export CSV
|
| 36 |
+
</Button>
|
| 37 |
+
}
|
| 38 |
+
/>
|
| 39 |
+
|
| 40 |
+
<div className="space-y-6 p-6">
|
| 41 |
+
{/* KPI strip */}
|
| 42 |
+
<div className="grid gap-4 sm:grid-cols-4">
|
| 43 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 44 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Total Guests</p>
|
| 45 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{totalGuests}</p>
|
| 46 |
+
</Card>
|
| 47 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 48 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Verified</p>
|
| 49 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-success)]">{verified}</p>
|
| 50 |
+
</Card>
|
| 51 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 52 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">VIP</p>
|
| 53 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-primary)]">{vip}</p>
|
| 54 |
+
</Card>
|
| 55 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 56 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Blocked</p>
|
| 57 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-error)]">{blocked}</p>
|
| 58 |
+
</Card>
|
| 59 |
+
</div>
|
| 60 |
+
|
| 61 |
+
{/* Search bar */}
|
| 62 |
+
<div className="flex gap-2">
|
| 63 |
+
<div className="relative flex-1 max-w-xl">
|
| 64 |
+
<Search className="absolute left-3 top-3 size-4 text-[var(--text-tertiary)]" />
|
| 65 |
+
<Input
|
| 66 |
+
value={search}
|
| 67 |
+
onChange={(e) => setSearch(e.target.value)}
|
| 68 |
+
placeholder="Search guests by name or emailβ¦"
|
| 69 |
+
className="pl-10 text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 70 |
+
/>
|
| 71 |
+
</div>
|
| 72 |
+
</div>
|
| 73 |
+
|
| 74 |
+
{/* Guest directory table */}
|
| 75 |
+
<Card>
|
| 76 |
+
<CardHeader>
|
| 77 |
+
<CardTitle className="flex items-center gap-2">
|
| 78 |
+
<User className="size-4 text-[var(--color-primary)]" /> Guest Directory
|
| 79 |
+
</CardTitle>
|
| 80 |
+
</CardHeader>
|
| 81 |
+
<CardContent className="p-0">
|
| 82 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 83 |
+
<table className="w-full text-left border-collapse">
|
| 84 |
+
<thead>
|
| 85 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 86 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-28">Guest</th>
|
| 87 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-32">Email</th>
|
| 88 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-20">Company</th>
|
| 89 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-16">Verified</th>
|
| 90 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-16">VIP</th>
|
| 91 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-16">Blocked</th>
|
| 92 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-32">Joined</th>
|
| 93 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Actions</th>
|
| 94 |
+
</tr>
|
| 95 |
+
</thead>
|
| 96 |
+
<tbody>
|
| 97 |
+
{isLoading ? (
|
| 98 |
+
[...Array(5)].map((_, i) => (
|
| 99 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 100 |
+
<td colSpan={8} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 101 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 102 |
+
</td>
|
| 103 |
+
</tr>
|
| 104 |
+
))
|
| 105 |
+
) : items.length === 0 ? (
|
| 106 |
+
<tr>
|
| 107 |
+
<td colSpan={8} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 108 |
+
No guests match your search.
|
| 109 |
+
</td>
|
| 110 |
+
</tr>
|
| 111 |
+
) : (
|
| 112 |
+
items.map((g: any) => (
|
| 113 |
+
<tr key={g.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 114 |
+
<td className="py-4">
|
| 115 |
+
<div className="flex items-center gap-3">
|
| 116 |
+
<div className="size-10 rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] flex items-center justify-center font-medium text-[var(--text-secondary)]">
|
| 117 |
+
{g.firstName?.[0] ?? "?"}{g.lastName?.[0] ?? "?"}
|
| 118 |
+
</div>
|
| 119 |
+
<div>
|
| 120 |
+
<p className="font-medium text-xs text-[var(--text-primary)]">
|
| 121 |
+
{g.firstName} {g.lastName}
|
| 122 |
+
</p>
|
| 123 |
+
{g.email ? (
|
| 124 |
+
<p className="text-[10px] text-[var(--text-tertiary)] font-mono">{g.email}</p>
|
| 125 |
+
) : null}
|
| 126 |
+
</div>
|
| 127 |
+
</div>
|
| 128 |
+
</td>
|
| 129 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] font-mono truncate" style={{ maxWidth: 180 }}>
|
| 130 |
+
{g.email ?? "β"}
|
| 131 |
+
</td>
|
| 132 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] truncate" style={{ maxWidth: 150 }}>
|
| 133 |
+
{g.company ?? "β"}
|
| 134 |
+
</td>
|
| 135 |
+
<td className="py-4 text-xs text-center">
|
| 136 |
+
<Badge className={cn("capitalize text-xs", g.verified ? "bg-[var(--color-success)]/20 border-[var(--color-success)]/30 text-[var(--color-success)]" : "border-transparent text-[var(--text-tertiary)]")}>
|
| 137 |
+
{g.verified ? "yes" : "no"}
|
| 138 |
+
</Badge>
|
| 139 |
+
</td>
|
| 140 |
+
<td className="py-4 text-xs text-center">
|
| 141 |
+
<Badge className={cn("capitalize text-xs", g.vip ? "bg-[var(--color-primary)]/20 border-[var(--color-primary)]/30 text-[var(--color-primary)]" : "border-transparent text-[var(--text-tertiary)]")}>
|
| 142 |
+
{g.vip ? "yes" : "no"}
|
| 143 |
+
</Badge>
|
| 144 |
+
</td>
|
| 145 |
+
<td className="py-4 text-xs text-center">
|
| 146 |
+
<Badge className={cn("capitalize text-xs", g.blocked ? "bg-[var(--color-error)]/20 border-[var(--color-error)]/30 text-[var(--color-error)]" : "border-transparent text-[var(--text-tertiary)]")}>
|
| 147 |
+
{g.blocked ? "yes" : "no"}
|
| 148 |
+
</Badge>
|
| 149 |
+
</td>
|
| 150 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)] text-right">
|
| 151 |
+
{new Date(g.createdAt).toLocaleDateString()}
|
| 152 |
+
</td>
|
| 153 |
+
<td className="py-4 text-sm text-right">
|
| 154 |
+
<Button variant="ghost" size="sm" onClick={() => {}}>
|
| 155 |
+
<Clock size={14} className="mr-1" /> View
|
| 156 |
+
</Button>
|
| 157 |
+
</td>
|
| 158 |
+
</tr>
|
| 159 |
+
))
|
| 160 |
+
)}
|
| 161 |
+
</tbody>
|
| 162 |
+
</table>
|
| 163 |
+
</div>
|
| 164 |
+
</CardContent>
|
| 165 |
+
</Card>
|
| 166 |
+
</div>
|
| 167 |
+
</div>
|
| 168 |
+
);
|
| 169 |
+
}
|
apps/admin/src/app/(dashboard)/crm/inquiries/page.tsx
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Mail, Clock, AlertCircle, User, CheckCircle2 } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { cn } from "@/lib/utils";
|
| 7 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 8 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 9 |
+
import { Badge } from "@micprotocol/ui";
|
| 10 |
+
import { Button } from "@micprotocol/ui";
|
| 11 |
+
import { ago } from "@/lib/utils";
|
| 12 |
+
|
| 13 |
+
export default function CRMInquiriesPage() {
|
| 14 |
+
const { data: inquiries, isLoading } = trpc.crm.listInquiries.useQuery(
|
| 15 |
+
undefined,
|
| 16 |
+
{ refetchInterval: 30_000 },
|
| 17 |
+
);
|
| 18 |
+
|
| 19 |
+
const items = (inquiries as any)?.items ?? [];
|
| 20 |
+
const open = items.filter((i: any) => i.status === "open").length;
|
| 21 |
+
const started = items.filter((i: any) => i.status === "started").length;
|
| 22 |
+
const resolved = items.filter((i: any) => i.status === "resolved").length;
|
| 23 |
+
|
| 24 |
+
return (
|
| 25 |
+
<div className="animate-fade-in">
|
| 26 |
+
<AdminHeader
|
| 27 |
+
title="CRM β Inquiries"
|
| 28 |
+
subtitle="Guest inquiries and first-touch outreach across the network"
|
| 29 |
+
refreshing={isLoading}
|
| 30 |
+
/>
|
| 31 |
+
|
| 32 |
+
<div className="space-y-6 p-6">
|
| 33 |
+
{/* KPI strip */}
|
| 34 |
+
<div className="grid gap-4 sm:grid-cols-4">
|
| 35 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 36 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Total Inquiries</p>
|
| 37 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{items.length}</p>
|
| 38 |
+
</Card>
|
| 39 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 40 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Open</p>
|
| 41 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-warning)]">{open}</p>
|
| 42 |
+
</Card>
|
| 43 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 44 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Started</p>
|
| 45 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-info)]">{started}</p>
|
| 46 |
+
</Card>
|
| 47 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 48 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Resolved</p>
|
| 49 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-success)]">{resolved}</p>
|
| 50 |
+
</Card>
|
| 51 |
+
</div>
|
| 52 |
+
|
| 53 |
+
{/* Inquiries table */}
|
| 54 |
+
<Card>
|
| 55 |
+
<CardHeader>
|
| 56 |
+
<CardTitle className="flex items-center gap-2">
|
| 57 |
+
<Mail className="size-4 text-[var(--color-info)]" /> Inquiries
|
| 58 |
+
</CardTitle>
|
| 59 |
+
</CardHeader>
|
| 60 |
+
<CardContent className="p-0">
|
| 61 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 62 |
+
<table className="w-full text-left border-collapse">
|
| 63 |
+
<thead>
|
| 64 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 65 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-28">Guest</th>
|
| 66 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Channel</th>
|
| 67 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-20">Subject</th>
|
| 68 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Status</th>
|
| 69 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Priority</th>
|
| 70 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-24">Received</th>
|
| 71 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-32">Actions</th>
|
| 72 |
+
</tr>
|
| 73 |
+
</thead>
|
| 74 |
+
<tbody>
|
| 75 |
+
{isLoading ? (
|
| 76 |
+
[...Array(5)].map((_, i) => (
|
| 77 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 78 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 79 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 80 |
+
</td>
|
| 81 |
+
</tr>
|
| 82 |
+
))
|
| 83 |
+
) : items.length === 0 ? (
|
| 84 |
+
<tr>
|
| 85 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 86 |
+
No inquiries yet.
|
| 87 |
+
</td>
|
| 88 |
+
</tr>
|
| 89 |
+
) : (
|
| 90 |
+
items.map((i: any) => (
|
| 91 |
+
<tr key={i.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 92 |
+
<td className="py-4 text-xs text-[var(--text-primary)] font-medium truncate" style={{ maxWidth: 150 }}>
|
| 93 |
+
{i.guestName ?? i.guestId?.slice(0, 8) ?? "β"}
|
| 94 |
+
</td>
|
| 95 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] font-mono capitalize">
|
| 96 |
+
{i.channel ?? "email"}
|
| 97 |
+
</td>
|
| 98 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] truncate" style={{ maxWidth: 200 }}>
|
| 99 |
+
{i.subject ?? "β"}
|
| 100 |
+
</td>
|
| 101 |
+
<td className="py-4 text-xs text-center">
|
| 102 |
+
<Badge className={cn("capitalize text-xs", inquiryStatusClass(i.status))}>
|
| 103 |
+
{i.status}
|
| 104 |
+
</Badge>
|
| 105 |
+
</td>
|
| 106 |
+
<td className="py-4 text-xs text-center">
|
| 107 |
+
<Badge className={cn("capitalize text-xs", priorityClass(i.priority))}>
|
| 108 |
+
{i.priority}
|
| 109 |
+
</Badge>
|
| 110 |
+
</td>
|
| 111 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)] text-right">
|
| 112 |
+
{new Date(i.createdAt).toLocaleDateString()}
|
| 113 |
+
</td>
|
| 114 |
+
<td className="py-4 text-sm text-right">
|
| 115 |
+
<div className="flex gap-1 justify-end">
|
| 116 |
+
{i.status === "open" ? (
|
| 117 |
+
<Button variant="outline" size="sm" disabled={false}>
|
| 118 |
+
<User className="size-12 mr-1" /> Start Review
|
| 119 |
+
</Button>
|
| 120 |
+
) : (
|
| 121 |
+
<>
|
| 122 |
+
<Button variant="outline" size="sm" disabled>
|
| 123 |
+
{i.status.charAt(0).toUpperCase() + i.status.slice(1)}
|
| 124 |
+
</Button>
|
| 125 |
+
</>
|
| 126 |
+
)}
|
| 127 |
+
</div>
|
| 128 |
+
</td>
|
| 129 |
+
</tr>
|
| 130 |
+
))
|
| 131 |
+
)}
|
| 132 |
+
</tbody>
|
| 133 |
+
</table>
|
| 134 |
+
</div>
|
| 135 |
+
</CardContent>
|
| 136 |
+
</Card>
|
| 137 |
+
</div>
|
| 138 |
+
</div>
|
| 139 |
+
);
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
function inquiryStatusClass(s: string): string {
|
| 143 |
+
switch (s) {
|
| 144 |
+
case "open": return "bg-[var(--color-warning)]/10 border-[var(--color-warning)]/20 text-[var(--color-warning)]";
|
| 145 |
+
case "started": return "bg-[var(--color-info)]/10 border-[var(--color-info)]/20 text-[var(--color-info)]";
|
| 146 |
+
case "resolved": return "bg-[var(--color-success)]/10 border-[var(--color-success)]/20 text-[var(--color-success)]";
|
| 147 |
+
default: return "border-transparent";
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
function priorityClass(p: string): string {
|
| 152 |
+
switch (p) {
|
| 153 |
+
case "high": return "bg-[var(--color-error)]/10 border-[var(--color-error)]/20 text-[var(--color-error)]";
|
| 154 |
+
case "medium": return "bg-[var(--color-warning)]/10 border-[var(--color-warning)]/20 text-[var(--color-warning)]";
|
| 155 |
+
case "low": return "bg-[var(--color-info)]/10 border-[var(--color-info)]/20 text-[var(--color-info)]";
|
| 156 |
+
default: return "border-transparent";
|
| 157 |
+
}
|
| 158 |
+
}
|
apps/admin/src/app/(dashboard)/crm/users/page.tsx
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { User, ShieldCheck, AlertTriangle, CreditCard, Mail } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { cn } from "@/lib/utils";
|
| 7 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 8 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 9 |
+
import { Badge } from "@micprotocol/ui";
|
| 10 |
+
import { Button } from "@micprotocol/ui";
|
| 11 |
+
import { ago } from "@/lib/utils";
|
| 12 |
+
|
| 13 |
+
export default function CRMUsersPage() {
|
| 14 |
+
const { data: users, isLoading } = trpc.crm.listUsers.useQuery(
|
| 15 |
+
undefined,
|
| 16 |
+
{ refetchInterval: 30_000 },
|
| 17 |
+
);
|
| 18 |
+
|
| 19 |
+
const items = (users as any)?.items ?? [];
|
| 20 |
+
const totalUsers = items.length;
|
| 21 |
+
const admins = items.filter((u: any) => u.adminRole).length;
|
| 22 |
+
const suspended = items.filter((u: any) => u.suspended).length;
|
| 23 |
+
const verified = items.filter((u: any) => u.verified).length;
|
| 24 |
+
|
| 25 |
+
const roleVariant = (role?: string | null) => {
|
| 26 |
+
switch (role) {
|
| 27 |
+
case "admin": return "brand";
|
| 28 |
+
case "moderator": return "info";
|
| 29 |
+
default: return "neutral";
|
| 30 |
+
}
|
| 31 |
+
};
|
| 32 |
+
|
| 33 |
+
return (
|
| 34 |
+
<div className="animate-fade-in">
|
| 35 |
+
<AdminHeader
|
| 36 |
+
title="CRM β Users"
|
| 37 |
+
subtitle="Platform user directory with role, verification, and suspension status"
|
| 38 |
+
refreshing={isLoading}
|
| 39 |
+
/>
|
| 40 |
+
|
| 41 |
+
<div className="space-y-6 p-6">
|
| 42 |
+
{/* KPI strip */}
|
| 43 |
+
<div className="grid gap-4 sm:grid-cols-4">
|
| 44 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 45 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Total Users</p>
|
| 46 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{totalUsers}</p>
|
| 47 |
+
</Card>
|
| 48 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 49 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Admins</p>
|
| 50 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-primary)]">{admins}</p>
|
| 51 |
+
</Card>
|
| 52 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 53 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Verified</p>
|
| 54 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-success)]">{verified}</p>
|
| 55 |
+
</Card>
|
| 56 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 57 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Suspended</p>
|
| 58 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-error)]">{suspended}</p>
|
| 59 |
+
</Card>
|
| 60 |
+
</div>
|
| 61 |
+
|
| 62 |
+
{/* User directory table */}
|
| 63 |
+
<Card>
|
| 64 |
+
<CardHeader>
|
| 65 |
+
<CardTitle className="flex items-center gap-2">
|
| 66 |
+
<User className="size-4 text-[var(--color-primary)]" /> User Directory
|
| 67 |
+
</CardTitle>
|
| 68 |
+
</CardHeader>
|
| 69 |
+
<CardContent className="p-0">
|
| 70 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 71 |
+
<table className="w-full text-left border-collapse">
|
| 72 |
+
<thead>
|
| 73 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 74 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-28">User</th>
|
| 75 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-28">Email</th>
|
| 76 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-20">Role</th>
|
| 77 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Verified</th>
|
| 78 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Suspended</th>
|
| 79 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-32">Joined</th>
|
| 80 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-32">Actions</th>
|
| 81 |
+
</tr>
|
| 82 |
+
</thead>
|
| 83 |
+
<tbody>
|
| 84 |
+
{isLoading ? (
|
| 85 |
+
[...Array(5)].map((_, i) => (
|
| 86 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 87 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 88 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 89 |
+
</td>
|
| 90 |
+
</tr>
|
| 91 |
+
))
|
| 92 |
+
) : items.length === 0 ? (
|
| 93 |
+
<tr>
|
| 94 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 95 |
+
No users yet.
|
| 96 |
+
</td>
|
| 97 |
+
</tr>
|
| 98 |
+
) : (
|
| 99 |
+
items.map((u: any) => (
|
| 100 |
+
<tr key={u.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 101 |
+
<td className="py-4">
|
| 102 |
+
<div className="flex items-center gap-3">
|
| 103 |
+
<div className="size-10 rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] flex items-center justify-center font-medium text-[var(--text-secondary)]">
|
| 104 |
+
{u.firstName?.[0] ?? "?"}{u.lastName?.[0] ?? "?"}
|
| 105 |
+
</div>
|
| 106 |
+
<div>
|
| 107 |
+
<p className="font-medium text-xs text-[var(--text-primary)]">
|
| 108 |
+
{u.firstName} {u.lastName}
|
| 109 |
+
</p>
|
| 110 |
+
{u.email ? (
|
| 111 |
+
<p className="text-[10px] text-[var(--text-tertiary)] font-mono">{u.email}</p>
|
| 112 |
+
) : null}
|
| 113 |
+
</div>
|
| 114 |
+
</div>
|
| 115 |
+
</td>
|
| 116 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] font-mono truncate" style={{ maxWidth: 200 }}>
|
| 117 |
+
{u.email ?? "β"}
|
| 118 |
+
</td>
|
| 119 |
+
<td className="py-4 text-xs text-center">
|
| 120 |
+
<Badge tone={roleVariant(u.adminRole)} className="capitalize text-xs">
|
| 121 |
+
{u.adminRole ?? "user"}
|
| 122 |
+
</Badge>
|
| 123 |
+
</td>
|
| 124 |
+
<td className="py-4 text-xs text-center">
|
| 125 |
+
<Badge tone={u.verified ? "success" : "neutral"} className={cn("capitalize text-xs", u.verified ? "bg-[var(--color-success)]/20 border-[var(--color-success)]/30 text-[var(--color-success)]" : "border-transparent text-[var(--text-tertiary)]")}>
|
| 126 |
+
{u.verified ? "yes" : "no"}
|
| 127 |
+
</Badge>
|
| 128 |
+
</td>
|
| 129 |
+
<td className="py-4 text-xs text-center">
|
| 130 |
+
<Badge tone={u.suspended ? "error" : "neutral"} className={cn("capitalize text-xs", u.suspended ? "bg-[var(--color-error)]/20 border-[var(--color-error)]/30 text-[var(--color-error)]" : "border-transparent text-[var(--text-tertiary)]")}>
|
| 131 |
+
{u.suspended ? "yes" : "no"}
|
| 132 |
+
</Badge>
|
| 133 |
+
</td>
|
| 134 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)] text-right">
|
| 135 |
+
{new Date(u.createdAt).toLocaleDateString()}
|
| 136 |
+
</td>
|
| 137 |
+
<td className="py-4 text-sm text-right">
|
| 138 |
+
<Button variant="ghost" size="sm" onClick={() => {}}>
|
| 139 |
+
<Mail size={14} className="mr-1" /> View
|
| 140 |
+
</Button>
|
| 141 |
+
</td>
|
| 142 |
+
</tr>
|
| 143 |
+
))
|
| 144 |
+
)}
|
| 145 |
+
</tbody>
|
| 146 |
+
</table>
|
| 147 |
+
</div>
|
| 148 |
+
</CardContent>
|
| 149 |
+
</Card>
|
| 150 |
+
</div>
|
| 151 |
+
</div>
|
| 152 |
+
);
|
| 153 |
+
}
|
apps/admin/src/app/(dashboard)/infrastructure/page.tsx
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { BrainCircuit, RefreshCw, Layers } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 7 |
+
import {
|
| 8 |
+
Card, CardContent, CardHeader, CardTitle, CardDescription,
|
| 9 |
+
Badge, Button,
|
| 10 |
+
} from "@micprotocol/ui";
|
| 11 |
+
|
| 12 |
+
interface ServiceRow {
|
| 13 |
+
label: string;
|
| 14 |
+
status: "healthy" | "degraded" | "unhealthy";
|
| 15 |
+
detail: string;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
function StatusDot({ status }: { status: "healthy" | "degraded" | "unhealthy" }) {
|
| 19 |
+
const color =
|
| 20 |
+
status === "healthy" ? "var(--color-success)" :
|
| 21 |
+
status === "degraded" ? "var(--color-warning)" : "var(--color-error)";
|
| 22 |
+
return (
|
| 23 |
+
<span
|
| 24 |
+
className="inline-flex items-center justify-center size-2 rounded-full"
|
| 25 |
+
style={{ backgroundColor: color }}
|
| 26 |
+
aria-label={status}
|
| 27 |
+
/>
|
| 28 |
+
);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
export default function InfrastructurePage() {
|
| 32 |
+
const { data: health, isLoading, refetch, isFetching } =
|
| 33 |
+
trpc.admin.operations.systemHealth.useQuery(undefined, {
|
| 34 |
+
refetchInterval: 30_000,
|
| 35 |
+
});
|
| 36 |
+
|
| 37 |
+
const { data: queueHealth } = trpc.admin.operations.queueHealth.useQuery(
|
| 38 |
+
undefined,
|
| 39 |
+
{ refetchInterval: 30_000 },
|
| 40 |
+
);
|
| 41 |
+
|
| 42 |
+
const overallStatus =
|
| 43 |
+
health && health.database === "up" && health.redis === "up"
|
| 44 |
+
? "up"
|
| 45 |
+
: health && health.database === "down" && health.redis === "down"
|
| 46 |
+
? "down"
|
| 47 |
+
: "degraded";
|
| 48 |
+
|
| 49 |
+
const serviceRows: ServiceRow[] = [];
|
| 50 |
+
if (health) {
|
| 51 |
+
serviceRows.push(
|
| 52 |
+
{ label: "Database", status: health.database === "up" ? "healthy" : "unhealthy", detail: "PostgreSQL via Prisma" },
|
| 53 |
+
{ label: "Redis", status: health.redis === "up" ? "healthy" : "unhealthy", detail: "Queues + distributed locks" },
|
| 54 |
+
);
|
| 55 |
+
}
|
| 56 |
+
if (queueHealth) {
|
| 57 |
+
for (const q of queueHealth) {
|
| 58 |
+
serviceRows.push({
|
| 59 |
+
label: `Queue: ${q.name}`,
|
| 60 |
+
status: q.failed > 10 ? ("unhealthy" as const) : ("healthy" as const),
|
| 61 |
+
detail: `${q.waiting} waiting Β· ${q.active} active Β· ${q.failed} failed`,
|
| 62 |
+
});
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
return (
|
| 67 |
+
<div className="animate-fade-in">
|
| 68 |
+
<AdminHeader
|
| 69 |
+
title="Infrastructure Overview"
|
| 70 |
+
subtitle="Tier 1 β databases, Redis, Meilisearch, storage, and media routing"
|
| 71 |
+
onRefresh={refetch}
|
| 72 |
+
refreshing={isFetching}
|
| 73 |
+
actions={
|
| 74 |
+
<Badge tone={overallStatus === "up" ? "success" : overallStatus === "down" ? "error" : "warning"} variant="subtle" size="sm">
|
| 75 |
+
{overallStatus.toUpperCase()}
|
| 76 |
+
</Badge>
|
| 77 |
+
}
|
| 78 |
+
/>
|
| 79 |
+
<div className="space-y-4 p-6">
|
| 80 |
+
<Card className="frosted border border-[var(--border-color)]">
|
| 81 |
+
<CardHeader>
|
| 82 |
+
<CardTitle className="flex items-center gap-2">
|
| 83 |
+
<BrainCircuit className="size-4 text-[var(--color-primary)]" /> System Health
|
| 84 |
+
</CardTitle>
|
| 85 |
+
<CardDescription>
|
| 86 |
+
Real-time platform telemetry from the operations service. Database and Redis
|
| 87 |
+
status are checked live; queue health is sampled from BullMQ every 30s.
|
| 88 |
+
</CardDescription>
|
| 89 |
+
</CardHeader>
|
| 90 |
+
<CardContent>
|
| 91 |
+
{isLoading ? (
|
| 92 |
+
<div className="flex flex-col gap-3 py-4">
|
| 93 |
+
{[1, 2, 3, 4].map((i) => (
|
| 94 |
+
<div key={i} className="flex items-center justify-between rounded-md border border-[var(--border-color)] bg-[var(--bg-secondary)] px-3 py-2">
|
| 95 |
+
<span className="text-sm text-[var(--text-secondary)]">Service {i}</span>
|
| 96 |
+
<div className="h-3 w-24 rounded-full bg-[var(--bg-tertiary)] animate-shimmer" />
|
| 97 |
+
</div>
|
| 98 |
+
))}
|
| 99 |
+
</div>
|
| 100 |
+
) : (
|
| 101 |
+
<div className="grid gap-2">
|
| 102 |
+
{serviceRows.map((row) => (
|
| 103 |
+
<div
|
| 104 |
+
key={row.label}
|
| 105 |
+
className="flex items-center justify-between rounded-md border border-[var(--border-color)] bg-[var(--bg-secondary)] px-3 py-2"
|
| 106 |
+
>
|
| 107 |
+
<div className="flex items-center gap-2">
|
| 108 |
+
<span className="text-sm text-[var(--text-primary)]">{row.label}</span>
|
| 109 |
+
<StatusDot status={row.status} />
|
| 110 |
+
</div>
|
| 111 |
+
<span className="text-xs font-mono text-[var(--text-tertiary)]">
|
| 112 |
+
{row.detail}
|
| 113 |
+
</span>
|
| 114 |
+
</div>
|
| 115 |
+
))}
|
| 116 |
+
</div>
|
| 117 |
+
)}
|
| 118 |
+
<div className="mt-4 flex items-center justify-between border-t border-[var(--border-color)] pt-3">
|
| 119 |
+
<span className="text-xs font-mono text-[var(--text-tertiary)]">
|
| 120 |
+
Last refreshed {new Date().toLocaleTimeString()}
|
| 121 |
+
</span>
|
| 122 |
+
<Button
|
| 123 |
+
variant="outline"
|
| 124 |
+
size="sm"
|
| 125 |
+
onClick={() => refetch()}
|
| 126 |
+
disabled={isFetching}
|
| 127 |
+
>
|
| 128 |
+
<RefreshCw className={isFetching ? "animate-spin" : ""} size={3} />
|
| 129 |
+
</Button>
|
| 130 |
+
</div>
|
| 131 |
+
</CardContent>
|
| 132 |
+
</Card>
|
| 133 |
+
|
| 134 |
+
<Card className="border border-[var(--border-color)]">
|
| 135 |
+
<CardHeader>
|
| 136 |
+
<CardTitle className="flex items-center gap-2">
|
| 137 |
+
<Layers className="size-4 text-[var(--color-secondary)]" /> Queue Depth
|
| 138 |
+
</CardTitle>
|
| 139 |
+
<CardDescription>
|
| 140 |
+
BullMQ queue backlog per worker queue. Failed jobs above 10 are flagged critical.
|
| 141 |
+
</CardDescription>
|
| 142 |
+
</CardHeader>
|
| 143 |
+
<CardContent>
|
| 144 |
+
{queueHealth ? (
|
| 145 |
+
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
| 146 |
+
{queueHealth.map((q) => (
|
| 147 |
+
<Card
|
| 148 |
+
key={q.name}
|
| 149 |
+
className={`hover:border-[var(--color-primary)]/30 transition-colors ${q.failed > 10 ? "border-[var(--color-error)]/30" : ""}`}
|
| 150 |
+
>
|
| 151 |
+
<CardContent className="p-5">
|
| 152 |
+
<div className="flex items-start justify-between">
|
| 153 |
+
<div>
|
| 154 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">
|
| 155 |
+
{q.name}
|
| 156 |
+
</p>
|
| 157 |
+
<p className="mt-1 font-display text-xl font-bold text-[var(--text-primary)]">
|
| 158 |
+
{q.waiting + q.active + q.delayed + q.failed}
|
| 159 |
+
</p>
|
| 160 |
+
<p className="mt-0.5 text-xs text-[var(--text-tertiary)]">
|
| 161 |
+
{q.completed} completed
|
| 162 |
+
</p>
|
| 163 |
+
</div>
|
| 164 |
+
<div className="flex gap-1">
|
| 165 |
+
<Badge tone={q.failed > 0 ? "error" : "success"} variant="subtle" size="sm">
|
| 166 |
+
{q.failed} failed
|
| 167 |
+
</Badge>
|
| 168 |
+
<Badge tone="neutral" variant="subtle" size="sm">
|
| 169 |
+
{q.waiting} waiting
|
| 170 |
+
</Badge>
|
| 171 |
+
</div>
|
| 172 |
+
</div>
|
| 173 |
+
<div className="mt-4 h-1.5 w-full rounded-full bg-[var(--bg-tertiary)] overflow-hidden">
|
| 174 |
+
<div
|
| 175 |
+
className="h-full bg-[var(--color-primary)]"
|
| 176 |
+
style={{ width: `${Math.min(((q.active / (q.waiting + q.active + 1)) * 100), 100)}%` }}
|
| 177 |
+
/>
|
| 178 |
+
</div>
|
| 179 |
+
</CardContent>
|
| 180 |
+
</Card>
|
| 181 |
+
))}
|
| 182 |
+
</div>
|
| 183 |
+
) : (
|
| 184 |
+
<p className="text-sm text-[var(--text-tertiary)]">Loading queue healthβ¦</p>
|
| 185 |
+
)}
|
| 186 |
+
</CardContent>
|
| 187 |
+
</Card>
|
| 188 |
+
</div>
|
| 189 |
+
</div>
|
| 190 |
+
);
|
| 191 |
+
}
|
apps/admin/src/app/(dashboard)/integrations/credentials/page.tsx
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState } from "react";
|
| 4 |
+
import { Key, ShieldCheck, CreditCard, Lock, Eye, EyeOff } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { cn } from "@/lib/utils";
|
| 7 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 8 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 9 |
+
import { Badge } from "@micprotocol/ui";
|
| 10 |
+
import { Button } from "@micprotocol/ui";
|
| 11 |
+
|
| 12 |
+
const TIERS = ["starter", "professional", "enterprise"] as const;
|
| 13 |
+
|
| 14 |
+
const tierAccess: Record<string, Record<string, boolean>> = {
|
| 15 |
+
stripe: { starter: true, professional: true, enterprise: true },
|
| 16 |
+
sendgrid: { starter: false, professional: true, enterprise: true },
|
| 17 |
+
aws: { starter: false, professional: false, enterprise: true },
|
| 18 |
+
slack: { starter: true, professional: true, enterprise: true },
|
| 19 |
+
github: { starter: true, professional: true, enterprise: true },
|
| 20 |
+
google: { starter: true, professional: true, enterprise: true },
|
| 21 |
+
calDotCom: { starter: false, professional: true, enterprise: true },
|
| 22 |
+
zoom: { starter: false, professional: true, enterprise: true },
|
| 23 |
+
meilisearch: { starter: false, professional: false, enterprise: true },
|
| 24 |
+
redis: { starter: false, professional: true, enterprise: true },
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
export default function IntegrationsCredentialsPage() {
|
| 28 |
+
const { data: credentials, isLoading } = trpc.integrations.getAllProviders.useQuery(
|
| 29 |
+
undefined,
|
| 30 |
+
{ refetchInterval: 60_000 },
|
| 31 |
+
);
|
| 32 |
+
|
| 33 |
+
const [showSecrets, setShowSecrets] = useState(false);
|
| 34 |
+
|
| 35 |
+
const items = credentials ?? [];
|
| 36 |
+
|
| 37 |
+
return (
|
| 38 |
+
<div className="animate-fade-in">
|
| 39 |
+
<AdminHeader
|
| 40 |
+
title="Integration Credentials"
|
| 41 |
+
subtitle="Stored API keys, secrets, and OAuth credentials per integration"
|
| 42 |
+
refreshing={isLoading}
|
| 43 |
+
actions={
|
| 44 |
+
<Button variant="outline" size="sm">
|
| 45 |
+
{showSecrets ? (
|
| 46 |
+
<>
|
| 47 |
+
<EyeOff size={14} className="mr-1" /> Hide Secrets
|
| 48 |
+
</>
|
| 49 |
+
) : (
|
| 50 |
+
<>
|
| 51 |
+
<Eye size={14} className="mr-1" /> Show Secrets
|
| 52 |
+
</>
|
| 53 |
+
)}
|
| 54 |
+
</Button>
|
| 55 |
+
}
|
| 56 |
+
/>
|
| 57 |
+
|
| 58 |
+
<div className="space-y-6 p-6">
|
| 59 |
+
{/* Tier access matrix */}
|
| 60 |
+
<Card>
|
| 61 |
+
<CardHeader>
|
| 62 |
+
<CardTitle className="flex items-center gap-2">
|
| 63 |
+
<Key className="size-4 text-[var(--color-primary)]" /> Tier Access Matrix
|
| 64 |
+
</CardTitle>
|
| 65 |
+
</CardHeader>
|
| 66 |
+
<CardContent>
|
| 67 |
+
<div className="overflow-auto">
|
| 68 |
+
<table className="w-full text-left border-collapse">
|
| 69 |
+
<thead>
|
| 70 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 71 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Integration</th>
|
| 72 |
+
{TIERS.map((t) => (
|
| 73 |
+
<th key={t} className="pb-3 text-center text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">
|
| 74 |
+
{t.charAt(0).toUpperCase() + t.slice(1)}
|
| 75 |
+
</th>
|
| 76 |
+
))}
|
| 77 |
+
</tr>
|
| 78 |
+
</thead>
|
| 79 |
+
<tbody>
|
| 80 |
+
{Object.entries(tierAccess).map(([integration, access]) => (
|
| 81 |
+
<tr key={integration} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 82 |
+
<td className="py-4 text-xs font-medium text-[var(--text-primary)] font-mono">{integration === "calDotCom" ? "cal.com" : integration}</td>
|
| 83 |
+
{TIERS.map((t) => (
|
| 84 |
+
<td key={t} className="py-4 text-center">
|
| 85 |
+
{access[t] ? (
|
| 86 |
+
<Badge tone="success" className="text-[10px] px-2 py-1">β</Badge>
|
| 87 |
+
) : (
|
| 88 |
+
<Badge className="text-[10px] px-2 py-1 border-transparent text-[var(--text-tertiary)]">β</Badge>
|
| 89 |
+
)}
|
| 90 |
+
</td>
|
| 91 |
+
))}
|
| 92 |
+
</tr>
|
| 93 |
+
))}
|
| 94 |
+
</tbody>
|
| 95 |
+
</table>
|
| 96 |
+
</div>
|
| 97 |
+
</CardContent>
|
| 98 |
+
</Card>
|
| 99 |
+
|
| 100 |
+
{/* Credentials table */}
|
| 101 |
+
<Card>
|
| 102 |
+
<CardHeader>
|
| 103 |
+
<CardTitle className="flex items-center gap-2">
|
| 104 |
+
<CreditCard className="size-4 text-[var(--color-info)]" /> Stored Credentials
|
| 105 |
+
</CardTitle>
|
| 106 |
+
</CardHeader>
|
| 107 |
+
<CardContent className="p-0">
|
| 108 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 109 |
+
<table className="w-full text-left border-collapse">
|
| 110 |
+
<thead>
|
| 111 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 112 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Integration</th>
|
| 113 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Type</th>
|
| 114 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-20">Scope</th>
|
| 115 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Status</th>
|
| 116 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Updated</th>
|
| 117 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-32">Actions</th>
|
| 118 |
+
</tr>
|
| 119 |
+
</thead>
|
| 120 |
+
<tbody>
|
| 121 |
+
{isLoading ? (
|
| 122 |
+
[...Array(5)].map((_, i) => (
|
| 123 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 124 |
+
<td colSpan={6} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 125 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 126 |
+
</td>
|
| 127 |
+
</tr>
|
| 128 |
+
))
|
| 129 |
+
) : items.length === 0 ? (
|
| 130 |
+
<tr>
|
| 131 |
+
<td colSpan={6} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 132 |
+
No credentials stored yet.
|
| 133 |
+
</td>
|
| 134 |
+
</tr>
|
| 135 |
+
) : (
|
| 136 |
+
items.map((c: any) => (
|
| 137 |
+
<tr key={c.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 138 |
+
<td className="py-4 text-xs text-[var(--text-primary)] font-mono capitalize">{c.name}</td>
|
| 139 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] font-mono">{c.isOAuth ? "OAuth" : "API Key"}</td>
|
| 140 |
+
<td className="py-4 text-xs text-[var(--text-secondary)]">{c.isConfigured ? "read/write" : "β"}</td>
|
| 141 |
+
<td className="py-4 text-xs text-center">
|
| 142 |
+
<Badge className={cn("capitalize text-xs", c.isConfigured ? "bg-[var(--color-success)]/20 border-[var(--color-success)]/30 text-[var(--color-success)]" : "border-transparent text-[var(--text-tertiary)]")}>
|
| 143 |
+
{c.isConfigured ? "active" : "disconnected"}
|
| 144 |
+
</Badge>
|
| 145 |
+
</td>
|
| 146 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)] text-right">
|
| 147 |
+
{new Date().toLocaleDateString()}
|
| 148 |
+
</td>
|
| 149 |
+
<td className="py-4 text-sm text-right">
|
| 150 |
+
<div className="flex gap-1 justify-end">
|
| 151 |
+
<Button variant="ghost" size="sm" onClick={() => {}}>
|
| 152 |
+
<Lock size={14} className="mr-1" /> Rotate
|
| 153 |
+
</Button>
|
| 154 |
+
</div>
|
| 155 |
+
</td>
|
| 156 |
+
</tr>
|
| 157 |
+
))
|
| 158 |
+
)}
|
| 159 |
+
</tbody>
|
| 160 |
+
</table>
|
| 161 |
+
</div>
|
| 162 |
+
</CardContent>
|
| 163 |
+
</Card>
|
| 164 |
+
|
| 165 |
+
{/* Secret toggle notice */}
|
| 166 |
+
<Card className="border border-[var(--border-color)]">
|
| 167 |
+
<CardContent className="p-5">
|
| 168 |
+
<div className="flex items-center gap-3">
|
| 169 |
+
<ShieldCheck className="size-4 text-[var(--color-warning)]" />
|
| 170 |
+
<div>
|
| 171 |
+
<p className="text-sm font-medium text-[var(--text-primary)]">
|
| 172 |
+
Secret values are masked by default
|
| 173 |
+
</p>
|
| 174 |
+
<p className="text-xs text-[var(--text-tertiary)]">
|
| 175 |
+
Toggle "Show Secrets" in the header to reveal decrypted secret values.
|
| 176 |
+
</p>
|
| 177 |
+
</div>
|
| 178 |
+
</div>
|
| 179 |
+
</CardContent>
|
| 180 |
+
</Card>
|
| 181 |
+
</div>
|
| 182 |
+
</div>
|
| 183 |
+
);
|
| 184 |
+
}
|
apps/admin/src/app/(dashboard)/integrations/page.tsx
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Link as ExternalLink, Server, ShieldCheck, Globe, Database } from "lucide-react";
|
| 5 |
+
import Link from "next/link";
|
| 6 |
+
import { trpc } from "@/lib/trpc";
|
| 7 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 8 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 9 |
+
import { Badge } from "@micprotocol/ui";
|
| 10 |
+
import { Button } from "@micprotocol/ui";
|
| 11 |
+
|
| 12 |
+
export default function IntegrationsPage() {
|
| 13 |
+
const { data: integrations, isLoading } = trpc.integrations.getAllProviders.useQuery(
|
| 14 |
+
undefined,
|
| 15 |
+
{ refetchInterval: 60_000 },
|
| 16 |
+
);
|
| 17 |
+
|
| 18 |
+
const items = integrations ?? [];
|
| 19 |
+
const active = items.filter((i: any) => i.isConfigured).length;
|
| 20 |
+
const pending = 0;
|
| 21 |
+
const error = items.filter((i: any) => !i.isConfigured).length;
|
| 22 |
+
|
| 23 |
+
return (
|
| 24 |
+
<div className="animate-fade-in">
|
| 25 |
+
<AdminHeader
|
| 26 |
+
title="Integrations"
|
| 27 |
+
subtitle="Third-party and self-hosted service integrations"
|
| 28 |
+
refreshing={isLoading}
|
| 29 |
+
/>
|
| 30 |
+
|
| 31 |
+
<div className="space-y-6 p-6">
|
| 32 |
+
{/* KPI strip */}
|
| 33 |
+
<div className="grid gap-4 sm:grid-cols-4">
|
| 34 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 35 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Installed</p>
|
| 36 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{items.length}</p>
|
| 37 |
+
</Card>
|
| 38 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 39 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Active</p>
|
| 40 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-success)]">{active}</p>
|
| 41 |
+
</Card>
|
| 42 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 43 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Pending</p>
|
| 44 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-warning)]">{pending}</p>
|
| 45 |
+
</Card>
|
| 46 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 47 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Errors</p>
|
| 48 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-error)]">{error}</p>
|
| 49 |
+
</Card>
|
| 50 |
+
</div>
|
| 51 |
+
|
| 52 |
+
{/* Integration cards */}
|
| 53 |
+
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
| 54 |
+
{items.map((i: any) => (
|
| 55 |
+
<Card key={i.id} className="border border-[var(--border-color)] hover:border-[var(--color-primary)]/50 transition-colors group">
|
| 56 |
+
<CardContent className="p-5">
|
| 57 |
+
<div className="flex items-start justify-between">
|
| 58 |
+
<div>
|
| 59 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-3 inline-flex">
|
| 60 |
+
<Server className="size-5 text-[var(--text-secondary)]" />
|
| 61 |
+
</div>
|
| 62 |
+
<div className="mt-4 flex items-center gap-2">
|
| 63 |
+
<h3 className="font-medium text-[var(--text-primary)]">{i.name}</h3>
|
| 64 |
+
{i.isConfigured ? (
|
| 65 |
+
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-[var(--color-success)]/10 text-[var(--color-success)] text-[10px] font-medium">
|
| 66 |
+
<span className="size-1.5 rounded-full bg-[var(--color-success)]" /> Active
|
| 67 |
+
</span>
|
| 68 |
+
) : (
|
| 69 |
+
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-[var(--color-error)]/10 text-[var(--color-error)] text-[10px] font-medium">
|
| 70 |
+
<span className="size-1.5 rounded-full bg-[var(--color-error)]" /> Disconnected
|
| 71 |
+
</span>
|
| 72 |
+
)}
|
| 73 |
+
</div>
|
| 74 |
+
<p className="mt-2 text-xs text-[var(--text-tertiary)]">{i.description ?? "No description"}</p>
|
| 75 |
+
</div>
|
| 76 |
+
<div className="text-right">
|
| 77 |
+
<Badge className="capitalize text-xs">{i.isOAuth ? "OAuth" : "API Key"}</Badge>
|
| 78 |
+
<div className="mt-4">
|
| 79 |
+
<p className="text-[10px] text-[var(--text-tertiary)] uppercase tracking-wider font-medium">Endpoint</p>
|
| 80 |
+
<p className="mt-1 text-[10px] text-[var(--text-secondary)] font-mono truncate" style={{ maxWidth: 120 }}>
|
| 81 |
+
{i.docsUrl ?? "β"}
|
| 82 |
+
</p>
|
| 83 |
+
</div>
|
| 84 |
+
</div>
|
| 85 |
+
</div>
|
| 86 |
+
<div className="mt-4 flex gap-2">
|
| 87 |
+
<Button variant="outline" size="sm" disabled>
|
| 88 |
+
Configure
|
| 89 |
+
</Button>
|
| 90 |
+
{i.docsUrl ? (
|
| 91 |
+
<Button variant="ghost" size="sm">
|
| 92 |
+
<Link href={i.docsUrl}>
|
| 93 |
+
<ExternalLink size={14} className="mr-1" /> Docs
|
| 94 |
+
</Link>
|
| 95 |
+
</Button>
|
| 96 |
+
) : null}
|
| 97 |
+
</div>
|
| 98 |
+
</CardContent>
|
| 99 |
+
</Card>
|
| 100 |
+
))}
|
| 101 |
+
{items.length === 0 && (
|
| 102 |
+
<Card className="col-span-full p-12 border border-[var(--border-color)] rounded-[var(--radius-lg)] text-center">
|
| 103 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-4 inline-flex mx-auto">
|
| 104 |
+
<Database className="size-6 text-[var(--text-tertiary)]" />
|
| 105 |
+
</div>
|
| 106 |
+
<p className="mt-4 text-[var(--text-tertiary)]">No integrations installed yet.</p>
|
| 107 |
+
</Card>
|
| 108 |
+
)}
|
| 109 |
+
</div>
|
| 110 |
+
</div>
|
| 111 |
+
</div>
|
| 112 |
+
);
|
| 113 |
+
}
|
apps/admin/src/app/(dashboard)/layout.tsx
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import { useSession } from "@/lib/auth-client";
|
| 4 |
+
import { useRouter } from "next/navigation";
|
| 5 |
+
import { useEffect } from "react";
|
| 6 |
+
import { AdminSidebar } from "@/components/shell/AdminSidebar";
|
| 7 |
+
|
| 8 |
+
export default function DashboardLayout({ children }: { children: React.ReactNode }) {
|
| 9 |
+
const session = useSession();
|
| 10 |
+
const router = useRouter();
|
| 11 |
+
|
| 12 |
+
// Redirect unauthenticated users to login after mount (avoid SSR flash)
|
| 13 |
+
useEffect(() => {
|
| 14 |
+
if (!session.isPending && !session.data) {
|
| 15 |
+
router.replace("/login");
|
| 16 |
+
}
|
| 17 |
+
}, [session, router]);
|
| 18 |
+
|
| 19 |
+
// While session is still loading, show a neutral shell
|
| 20 |
+
if (session.isPending) {
|
| 21 |
+
return (
|
| 22 |
+
<div className="flex h-screen items-center justify-center bg-[var(--bg-primary)]">
|
| 23 |
+
<div className="flex flex-col items-center gap-3">
|
| 24 |
+
<div className="h-8 w-8 rounded-full border-2 border-t-[var(--color-primary)] animate-spin" />
|
| 25 |
+
<p className="text-sm text-[var(--text-secondary)]">Signing inβ¦</p>
|
| 26 |
+
</div>
|
| 27 |
+
</div>
|
| 28 |
+
);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
if (!session.data) {
|
| 32 |
+
return null;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
return (
|
| 36 |
+
<div className="flex h-screen overflow-hidden bg-[var(--bg-primary)] text-[var(--text-primary)]">
|
| 37 |
+
<AdminSidebar />
|
| 38 |
+
<main className="flex-1 overflow-y-auto">{children}</main>
|
| 39 |
+
</div>
|
| 40 |
+
);
|
| 41 |
+
}
|
apps/admin/src/app/(dashboard)/moderation/page.tsx
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState } from "react";
|
| 4 |
+
import { Mail, ShieldCheck, X, Clock } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { cn } from "@/lib/utils";
|
| 7 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 8 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 9 |
+
import { Badge } from "@micprotocol/ui";
|
| 10 |
+
import { Button } from "@micprotocol/ui";
|
| 11 |
+
import { Input } from "@micprotocol/ui";
|
| 12 |
+
import { Textarea } from "@micprotocol/ui";
|
| 13 |
+
import { Modal, ModalHeader, ModalTitle, ModalBody, ModalFooter } from "@micprotocol/ui";
|
| 14 |
+
import { ago } from "@/lib/utils";
|
| 15 |
+
|
| 16 |
+
export default function ModerationPage() {
|
| 17 |
+
const [resolveModal, setResolveModal] = useState<{ id: string; title: string } | null>(null);
|
| 18 |
+
const [takedownModal, setTakedownModal] = useState<{ id: string; title: string } | null>(null);
|
| 19 |
+
const [resolveReason, setResolveReason] = useState("");
|
| 20 |
+
|
| 21 |
+
const { data: reports, isLoading } = trpc.admin.moderation.listReports.useQuery(
|
| 22 |
+
{ limit: 25 },
|
| 23 |
+
{ refetchInterval: 30_000 },
|
| 24 |
+
);
|
| 25 |
+
|
| 26 |
+
const items = (reports?.items ?? []) as any[];
|
| 27 |
+
const open = items.filter((i) => i.status === "OPEN").length;
|
| 28 |
+
const resolved = items.filter((i) => i.status === "RESOLVED").length;
|
| 29 |
+
const dismissed = items.filter((i) => i.status === "DISMISSED").length;
|
| 30 |
+
|
| 31 |
+
const resolveReport = trpc.admin.moderation.resolve.useMutation({
|
| 32 |
+
onSuccess: () => { setResolveModal(null); setResolveReason(""); },
|
| 33 |
+
});
|
| 34 |
+
const takedownContent = trpc.admin.moderation.takedown.useMutation({});
|
| 35 |
+
|
| 36 |
+
return (
|
| 37 |
+
<div className="animate-fade-in">
|
| 38 |
+
<AdminHeader
|
| 39 |
+
title="Content Moderation"
|
| 40 |
+
subtitle="Review reported content and user reports across the platform"
|
| 41 |
+
refreshing={isLoading}
|
| 42 |
+
/>
|
| 43 |
+
|
| 44 |
+
<div className="space-y-6 p-6">
|
| 45 |
+
{/* KPI strip */}
|
| 46 |
+
<div className="grid gap-4 sm:grid-cols-4">
|
| 47 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 48 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Total Reports</p>
|
| 49 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{items.length}</p>
|
| 50 |
+
</Card>
|
| 51 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 52 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Open</p>
|
| 53 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-warning)]">{open}</p>
|
| 54 |
+
</Card>
|
| 55 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 56 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Resolved</p>
|
| 57 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-success)]">{resolved}</p>
|
| 58 |
+
</Card>
|
| 59 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 60 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Dismissed</p>
|
| 61 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-tertiary)]">{dismissed}</p>
|
| 62 |
+
</Card>
|
| 63 |
+
</div>
|
| 64 |
+
|
| 65 |
+
{/* Reports table */}
|
| 66 |
+
<Card>
|
| 67 |
+
<CardHeader>
|
| 68 |
+
<CardTitle className="flex items-center gap-2">
|
| 69 |
+
<Mail className="size-4 text-[var(--color-primary)]" /> Reported Content
|
| 70 |
+
</CardTitle>
|
| 71 |
+
</CardHeader>
|
| 72 |
+
<CardContent className="p-0">
|
| 73 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 74 |
+
<table className="w-full text-left border-collapse">
|
| 75 |
+
<thead>
|
| 76 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 77 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-32">Report ID</th>
|
| 78 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Content</th>
|
| 79 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-20">Type</th>
|
| 80 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Priority</th>
|
| 81 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Status</th>
|
| 82 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-24">Reported</th>
|
| 83 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-32">Actions</th>
|
| 84 |
+
</tr>
|
| 85 |
+
</thead>
|
| 86 |
+
<tbody>
|
| 87 |
+
{isLoading ? (
|
| 88 |
+
[...Array(5)].map((_, i) => (
|
| 89 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 90 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 91 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 92 |
+
</td>
|
| 93 |
+
</tr>
|
| 94 |
+
))
|
| 95 |
+
) : items.length === 0 ? (
|
| 96 |
+
<tr>
|
| 97 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 98 |
+
No reports yet.
|
| 99 |
+
</td>
|
| 100 |
+
</tr>
|
| 101 |
+
) : (
|
| 102 |
+
items.map((r: any) => (
|
| 103 |
+
<tr key={r.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 104 |
+
<td className="py-4 font-mono text-xs text-[var(--text-secondary)]">
|
| 105 |
+
{r.id.slice(0, 8)}β¦
|
| 106 |
+
</td>
|
| 107 |
+
<td className="py-4 text-xs text-[var(--text-primary)]">
|
| 108 |
+
{r.contentTitle ?? r.contentId?.slice(0, 8) ?? "β"}
|
| 109 |
+
</td>
|
| 110 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] font-mono capitalize">
|
| 111 |
+
{r.contentType ?? "content"}
|
| 112 |
+
</td>
|
| 113 |
+
<td className="py-4 text-xs text-center">
|
| 114 |
+
<Badge className={cn("capitalize text-xs", priorityClass(r.priority))}>
|
| 115 |
+
{r.priority}
|
| 116 |
+
</Badge>
|
| 117 |
+
</td>
|
| 118 |
+
<td className="py-4 text-xs text-center">
|
| 119 |
+
<Badge className="capitalize text-xs">{r.status}</Badge>
|
| 120 |
+
</td>
|
| 121 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)] text-right">
|
| 122 |
+
{new Date(r.createdAt).toLocaleDateString()}
|
| 123 |
+
</td>
|
| 124 |
+
<td className="py-4 text-sm text-right">
|
| 125 |
+
<div className="flex gap-1 justify-end">
|
| 126 |
+
{r.status === "OPEN" ? (
|
| 127 |
+
<>
|
| 128 |
+
<Button
|
| 129 |
+
variant="outline"
|
| 130 |
+
size="sm"
|
| 131 |
+
onClick={() => { setResolveModal({ id: r.id, title: r.contentTitle ?? "content" }); }}
|
| 132 |
+
disabled={resolveReport.isPending}
|
| 133 |
+
>
|
| 134 |
+
Resolve
|
| 135 |
+
</Button>
|
| 136 |
+
<Button
|
| 137 |
+
variant="destructive"
|
| 138 |
+
size="sm"
|
| 139 |
+
onClick={() => { setTakedownModal({ id: r.id, title: r.contentTitle ?? "content" }); }}
|
| 140 |
+
>
|
| 141 |
+
Takedown
|
| 142 |
+
</Button>
|
| 143 |
+
</>
|
| 144 |
+
) : (
|
| 145 |
+
<Button variant="ghost" size="sm" disabled>
|
| 146 |
+
{r.status}
|
| 147 |
+
</Button>
|
| 148 |
+
)}
|
| 149 |
+
</div>
|
| 150 |
+
</td>
|
| 151 |
+
</tr>
|
| 152 |
+
))
|
| 153 |
+
)}
|
| 154 |
+
</tbody>
|
| 155 |
+
</table>
|
| 156 |
+
</div>
|
| 157 |
+
</CardContent>
|
| 158 |
+
</Card>
|
| 159 |
+
|
| 160 |
+
{/* Resolve modal */}
|
| 161 |
+
{resolveModal && (
|
| 162 |
+
<Modal isOpen onClose={() => setResolveModal(null)} size="md">
|
| 163 |
+
<ModalHeader>
|
| 164 |
+
<ModalTitle>Resolve Report</ModalTitle>
|
| 165 |
+
</ModalHeader>
|
| 166 |
+
<ModalBody>
|
| 167 |
+
<form
|
| 168 |
+
onSubmit={(e) => {
|
| 169 |
+
e.preventDefault();
|
| 170 |
+
resolveReport.mutate({ reportId: resolveModal!.id, resolution: resolveReason });
|
| 171 |
+
setResolveModal(null);
|
| 172 |
+
}}
|
| 173 |
+
className="space-y-4"
|
| 174 |
+
>
|
| 175 |
+
<div>
|
| 176 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">Resolution reason</label>
|
| 177 |
+
<Textarea
|
| 178 |
+
value={resolveReason}
|
| 179 |
+
onChange={(e) => setResolveReason(e.target.value)}
|
| 180 |
+
placeholder="Why was this report resolved or dismissed?"
|
| 181 |
+
rows={4}
|
| 182 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 183 |
+
/>
|
| 184 |
+
</div>
|
| 185 |
+
<div className="flex justify-end gap-2">
|
| 186 |
+
<Button type="button" variant="outline" onClick={() => { setResolveModal(null); setResolveReason(""); }}>
|
| 187 |
+
Cancel
|
| 188 |
+
</Button>
|
| 189 |
+
<Button type="submit" disabled={resolveReport.isPending}>
|
| 190 |
+
Submit Resolution
|
| 191 |
+
</Button>
|
| 192 |
+
</div>
|
| 193 |
+
</form>
|
| 194 |
+
</ModalBody>
|
| 195 |
+
</Modal>
|
| 196 |
+
)}
|
| 197 |
+
|
| 198 |
+
{/* Takedown modal */}
|
| 199 |
+
{takedownModal && (
|
| 200 |
+
<Modal isOpen onClose={() => setTakedownModal(null)} size="md">
|
| 201 |
+
<ModalHeader>
|
| 202 |
+
<ModalTitle>Takedown Content</ModalTitle>
|
| 203 |
+
</ModalHeader>
|
| 204 |
+
<ModalBody>
|
| 205 |
+
<p className="text-[var(--text-secondary)]">
|
| 206 |
+
Taking down <strong>{takedownModal.title}</strong> will remove it from public view and notify the content owner.
|
| 207 |
+
</p>
|
| 208 |
+
<div className="mt-6 flex justify-end gap-2">
|
| 209 |
+
<Button type="button" variant="outline" onClick={() => setTakedownModal(null)}>
|
| 210 |
+
Cancel
|
| 211 |
+
</Button>
|
| 212 |
+
<Button variant="destructive" onClick={() => { takedownContent.mutate({ reportId: takedownModal.id }); setTakedownModal(null); }}>
|
| 213 |
+
Confirm Takedown
|
| 214 |
+
</Button>
|
| 215 |
+
</div>
|
| 216 |
+
</ModalBody>
|
| 217 |
+
</Modal>
|
| 218 |
+
)}
|
| 219 |
+
</div>
|
| 220 |
+
</div>
|
| 221 |
+
);
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
function priorityClass(p: string): string {
|
| 225 |
+
switch (p) {
|
| 226 |
+
case "high": return "bg-[var(--color-error)]/10 border-[var(--color-error)]/20 text-[var(--color-error)]";
|
| 227 |
+
case "medium": return "bg-[var(--color-warning)]/10 border-[var(--color-warning)]/20 text-[var(--color-warning)]";
|
| 228 |
+
case "low": return "bg-[var(--color-info)]/10 border-[var(--color-info)]/20 text-[var(--color-info)]";
|
| 229 |
+
default: return "border-transparent";
|
| 230 |
+
}
|
| 231 |
+
}
|
apps/admin/src/app/(dashboard)/observability/errors/page.tsx
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { AlertCircle, Database, Clock, AlertTriangle } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { cn } from "@/lib/utils";
|
| 7 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 8 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 9 |
+
import { Badge } from "@micprotocol/ui";
|
| 10 |
+
import { Button } from "@micprotocol/ui";
|
| 11 |
+
import { ago } from "@/lib/utils";
|
| 12 |
+
|
| 13 |
+
export default function ObservabilityErrorsPage() {
|
| 14 |
+
const { data: errors, isLoading } = trpc.audit.list.useQuery(
|
| 15 |
+
{ limit: 50 },
|
| 16 |
+
{ refetchInterval: 30_000 },
|
| 17 |
+
);
|
| 18 |
+
|
| 19 |
+
const items = errors?.items ?? [];
|
| 20 |
+
const total = items.length;
|
| 21 |
+
const critical = items.filter((e: any) => e.severity === "critical").length;
|
| 22 |
+
const unresolved = items.filter((e: any) => !e.resolved).length;
|
| 23 |
+
const today = items.filter((e: any) => new Date(e.createdAt).toDateString() === new Date().toDateString()).length;
|
| 24 |
+
|
| 25 |
+
return (
|
| 26 |
+
<div className="animate-fade-in">
|
| 27 |
+
<AdminHeader
|
| 28 |
+
title="Error Hub"
|
| 29 |
+
subtitle="Platform errors, exceptions, and stack traces"
|
| 30 |
+
refreshing={isLoading}
|
| 31 |
+
/>
|
| 32 |
+
|
| 33 |
+
<div className="space-y-6 p-6">
|
| 34 |
+
{/* KPI strip */}
|
| 35 |
+
<div className="grid gap-4 sm:grid-cols-4">
|
| 36 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 37 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Total Errors</p>
|
| 38 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-error)]">{total}</p>
|
| 39 |
+
</Card>
|
| 40 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 41 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Critical</p>
|
| 42 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-error)]">{critical}</p>
|
| 43 |
+
</Card>
|
| 44 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 45 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Unresolved</p>
|
| 46 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-warning)]">{unresolved}</p>
|
| 47 |
+
</Card>
|
| 48 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 49 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Today</p>
|
| 50 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-info)]">{today}</p>
|
| 51 |
+
</Card>
|
| 52 |
+
</div>
|
| 53 |
+
|
| 54 |
+
{/* Errors table */}
|
| 55 |
+
<Card>
|
| 56 |
+
<CardHeader>
|
| 57 |
+
<CardTitle className="flex items-center gap-2">
|
| 58 |
+
<AlertCircle className="size-4 text-[var(--color-error)]" /> Recent Errors
|
| 59 |
+
</CardTitle>
|
| 60 |
+
</CardHeader>
|
| 61 |
+
<CardContent className="p-0">
|
| 62 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 63 |
+
<table className="w-full text-left border-collapse">
|
| 64 |
+
<thead>
|
| 65 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 66 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Error ID</th>
|
| 67 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Message</th>
|
| 68 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Severity</th>
|
| 69 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Status</th>
|
| 70 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Source</th>
|
| 71 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Occurred</th>
|
| 72 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-24">Actions</th>
|
| 73 |
+
</tr>
|
| 74 |
+
</thead>
|
| 75 |
+
<tbody>
|
| 76 |
+
{isLoading ? (
|
| 77 |
+
[...Array(5)].map((_, i) => (
|
| 78 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 79 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 80 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 81 |
+
</td>
|
| 82 |
+
</tr>
|
| 83 |
+
))
|
| 84 |
+
) : items.length === 0 ? (
|
| 85 |
+
<tr>
|
| 86 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 87 |
+
No errors recorded. Platform is healthy.
|
| 88 |
+
</td>
|
| 89 |
+
</tr>
|
| 90 |
+
) : (
|
| 91 |
+
items.map((e: any) => (
|
| 92 |
+
<tr key={e.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 93 |
+
<td className="py-4 font-mono text-xs text-[var(--text-secondary)]">
|
| 94 |
+
{e.id.slice(0, 8)}β¦
|
| 95 |
+
</td>
|
| 96 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] truncate" style={{ maxWidth: 220 }}>
|
| 97 |
+
{e.message ?? "β"}
|
| 98 |
+
</td>
|
| 99 |
+
<td className="py-4 text-xs text-center">
|
| 100 |
+
<Badge className={cn("capitalize text-xs", severityClass(e.severity))}>
|
| 101 |
+
{e.severity}
|
| 102 |
+
</Badge>
|
| 103 |
+
</td>
|
| 104 |
+
<td className="py-4 text-xs text-center">
|
| 105 |
+
<Badge className={cn("capitalize text-xs", e.resolved ? "bg-[var(--color-success)]/20 border-[var(--color-success)]/30 text-[var(--color-success)]" : "border-transparent text-[var(--text-tertiary)]")}>
|
| 106 |
+
{e.resolved ? "resolved" : "open"}
|
| 107 |
+
</Badge>
|
| 108 |
+
</td>
|
| 109 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] font-mono truncate" style={{ maxWidth: 150 }}>
|
| 110 |
+
{e.source ?? "β"}
|
| 111 |
+
</td>
|
| 112 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)] text-right">
|
| 113 |
+
{new Date(e.createdAt).toLocaleString()}
|
| 114 |
+
</td>
|
| 115 |
+
<td className="py-4 text-sm text-right">
|
| 116 |
+
<Button variant="ghost" size="sm" disabled={e.resolved} onClick={() => {}}>
|
| 117 |
+
<AlertTriangle size={14} className="mr-1" />
|
| 118 |
+
</Button>
|
| 119 |
+
</td>
|
| 120 |
+
</tr>
|
| 121 |
+
))
|
| 122 |
+
)}
|
| 123 |
+
</tbody>
|
| 124 |
+
</table>
|
| 125 |
+
</div>
|
| 126 |
+
</CardContent>
|
| 127 |
+
</Card>
|
| 128 |
+
</div>
|
| 129 |
+
</div>
|
| 130 |
+
);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
function severityClass(s: string): string {
|
| 134 |
+
switch (s) {
|
| 135 |
+
case "critical": return "bg-[var(--color-error)] border-[var(--color-error)] text-[var(--text-primary)]";
|
| 136 |
+
case "high": return "bg-[var(--color-error)]/10 border-[var(--color-error)]/20 text-[var(--color-error)]";
|
| 137 |
+
case "medium": return "bg-[var(--color-warning)]/10 border-[var(--color-warning)]/20 text-[var(--color-warning)]";
|
| 138 |
+
case "low": return "bg-[var(--color-info)]/10 border-[var(--color-info)]/20 text-[var(--color-info)]";
|
| 139 |
+
default: return "border-transparent";
|
| 140 |
+
}
|
| 141 |
+
}
|
apps/admin/src/app/(dashboard)/observability/logs/page.tsx
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState, useRef, useCallback } from "react";
|
| 4 |
+
import { Play, Pause, Filter, Search, Trash2 } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { cn } from "@/lib/utils";
|
| 7 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 8 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 9 |
+
import { Badge } from "@micprotocol/ui";
|
| 10 |
+
import { Button } from "@micprotocol/ui";
|
| 11 |
+
import { Input } from "@micprotocol/ui";
|
| 12 |
+
|
| 13 |
+
const LEVELS = ["ALL", "INFO", "WARN", "ERROR", "DEBUG"] as const;
|
| 14 |
+
|
| 15 |
+
export default function ObservabilityLogsPage() {
|
| 16 |
+
const [isPlaying, setIsPlaying] = useState(true);
|
| 17 |
+
const [level, setLevel] = useState<typeof LEVELS[number]>("ALL");
|
| 18 |
+
const [regex, setRegex] = useState("");
|
| 19 |
+
const [scrollToBottom, setScrollToBottom] = useState(true);
|
| 20 |
+
const logEndRef = useRef<HTMLDivElement>(null);
|
| 21 |
+
|
| 22 |
+
const { data: logStream, isLoading } = trpc.audit.list.useQuery(
|
| 23 |
+
{ limit: 200 },
|
| 24 |
+
{ refetchInterval: 2_000 },
|
| 25 |
+
);
|
| 26 |
+
|
| 27 |
+
const items = logStream?.items ?? [];
|
| 28 |
+
|
| 29 |
+
const togglePlay = () => setIsPlaying((p) => !p);
|
| 30 |
+
|
| 31 |
+
const filtered = items.filter((log: any) => {
|
| 32 |
+
if (level !== "ALL" && log.level !== level) return false;
|
| 33 |
+
if (regex) {
|
| 34 |
+
try {
|
| 35 |
+
return new RegExp(regex).test(log.message ?? "");
|
| 36 |
+
} catch {
|
| 37 |
+
return false;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
return true;
|
| 41 |
+
});
|
| 42 |
+
|
| 43 |
+
React.useEffect(() => {
|
| 44 |
+
if (scrollToBottom && isPlaying && logEndRef.current) {
|
| 45 |
+
logEndRef.current.scrollIntoView({ behavior: "smooth", block: "end" });
|
| 46 |
+
}
|
| 47 |
+
}, [scrollToBottom, isPlaying]);
|
| 48 |
+
|
| 49 |
+
return (
|
| 50 |
+
<div className="animate-fade-in">
|
| 51 |
+
<AdminHeader
|
| 52 |
+
title="Log Stream"
|
| 53 |
+
subtitle="Real-time platform logs with level and regex filtering"
|
| 54 |
+
refreshing={isLoading}
|
| 55 |
+
/>
|
| 56 |
+
|
| 57 |
+
<div className="space-y-6 p-6">
|
| 58 |
+
{/* Controls */}
|
| 59 |
+
<Card>
|
| 60 |
+
<CardContent className="p-4">
|
| 61 |
+
<div className="flex flex-wrap items-center gap-4">
|
| 62 |
+
<div className="flex items-center gap-2">
|
| 63 |
+
<Button
|
| 64 |
+
variant="outline"
|
| 65 |
+
size="sm"
|
| 66 |
+
onClick={togglePlay}
|
| 67 |
+
>
|
| 68 |
+
{isPlaying ? (
|
| 69 |
+
<>
|
| 70 |
+
<Pause size={14} className="mr-1" /> Pause
|
| 71 |
+
</>
|
| 72 |
+
) : (
|
| 73 |
+
<>
|
| 74 |
+
<Play size={14} className="mr-1" /> Resume
|
| 75 |
+
</>
|
| 76 |
+
)}
|
| 77 |
+
</Button>
|
| 78 |
+
<Badge className={cn("text-xs px-2 py-1", isPlaying ? "bg-[var(--color-success)]/20 border-[var(--color-success)]/30 text-[var(--color-success)]" : "bg-[var(--color-error)]/20 border-[var(--color-error)]/30 text-[var(--color-error)]")}>
|
| 79 |
+
{isPlaying ? "live" : "paused"}
|
| 80 |
+
</Badge>
|
| 81 |
+
</div>
|
| 82 |
+
<div className="relative">
|
| 83 |
+
<Filter className="absolute left-3 top-3 size-4 text-[var(--text-tertiary)]" />
|
| 84 |
+
<select
|
| 85 |
+
value={level}
|
| 86 |
+
onChange={(e) => setLevel((e.target.value as typeof LEVELS[number]))}
|
| 87 |
+
className="pl-10 text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] px-3 py-2 text-sm focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20 outline-none"
|
| 88 |
+
>
|
| 89 |
+
{LEVELS.map((l) => (
|
| 90 |
+
<option key={l} value={l}>{l}</option>
|
| 91 |
+
))}
|
| 92 |
+
</select>
|
| 93 |
+
</div>
|
| 94 |
+
<div className="relative flex-1 max-w-lg">
|
| 95 |
+
<Search className="absolute left-3 top-3 size-4 text-[var(--text-tertiary)]" />
|
| 96 |
+
<Input
|
| 97 |
+
value={regex}
|
| 98 |
+
onChange={(e) => setRegex(e.target.value)}
|
| 99 |
+
placeholder="Regex filterβ¦"
|
| 100 |
+
className="pl-10 text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 101 |
+
/>
|
| 102 |
+
</div>
|
| 103 |
+
<Button variant="outline" size="sm" onClick={() => {}}>
|
| 104 |
+
<Trash2 size={14} className="mr-1" /> Clear
|
| 105 |
+
</Button>
|
| 106 |
+
</div>
|
| 107 |
+
</CardContent>
|
| 108 |
+
</Card>
|
| 109 |
+
|
| 110 |
+
{/* Log stream */}
|
| 111 |
+
<Card>
|
| 112 |
+
<CardHeader>
|
| 113 |
+
<CardTitle className="flex items-center gap-2">
|
| 114 |
+
<Filter className="size-4 text-[var(--color-info)]" /> Log Entries
|
| 115 |
+
</CardTitle>
|
| 116 |
+
</CardHeader>
|
| 117 |
+
<CardContent className="p-0">
|
| 118 |
+
<div className="h-[60vh] overflow-y-auto font-mono text-xs border-t border-[var(--border-color-subtle)]">
|
| 119 |
+
<div className="p-4 space-y-1">
|
| 120 |
+
{isLoading ? (
|
| 121 |
+
[...Array(5)].map((_, i) => (
|
| 122 |
+
<div key={i} className="text-[var(--text-tertiary)] animate-pulse">
|
| 123 |
+
2026-11-12T00:00:00.000Z [INFO] placeholder entryβ¦
|
| 124 |
+
</div>
|
| 125 |
+
))
|
| 126 |
+
) : filtered.length === 0 ? (
|
| 127 |
+
<div className="text-[var(--text-tertiary)]">No log entries match your filters.</div>
|
| 128 |
+
) : (
|
| 129 |
+
filtered.map((log: any) => (
|
| 130 |
+
<div key={log.id ?? log.timestamp} className="flex gap-3 py-1 border-b border-[var(--border-color-subtle)]/50">
|
| 131 |
+
<span className="w-28 text-[var(--text-tertiary)]">{new Date(log.timestamp ?? log.createdAt).toISOString()}</span>
|
| 132 |
+
<span className={`w-12 text-[10px] font-bold ${levelColor(log.level)}`}>
|
| 133 |
+
{log.level}
|
| 134 |
+
</span>
|
| 135 |
+
<span className="text-[var(--text-secondary)]">{log.message ?? log.msg ?? "β"}</span>
|
| 136 |
+
{log.context ? (
|
| 137 |
+
<span className="ml-2 text-[var(--text-tertiary)]">({JSON.stringify(log.context)})</span>
|
| 138 |
+
) : null}
|
| 139 |
+
<div ref={logEndRef} />
|
| 140 |
+
</div>
|
| 141 |
+
))
|
| 142 |
+
)}
|
| 143 |
+
</div>
|
| 144 |
+
</div>
|
| 145 |
+
</CardContent>
|
| 146 |
+
</Card>
|
| 147 |
+
</div>
|
| 148 |
+
</div>
|
| 149 |
+
);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
function levelColor(level: string): string {
|
| 153 |
+
switch (level) {
|
| 154 |
+
case "ERROR": return "text-[var(--color-error)]";
|
| 155 |
+
case "WARN": return "text-[var(--color-warning)]";
|
| 156 |
+
case "INFO": return "text-[var(--color-info)]";
|
| 157 |
+
case "DEBUG": return "text-[var(--text-tertiary)]";
|
| 158 |
+
default: return "text-[var(--text-secondary)]";
|
| 159 |
+
}
|
| 160 |
+
}
|
apps/admin/src/app/(dashboard)/observability/metrics/page.tsx
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Activity, Monitor, AlertCircle, CheckCircle2 } from "lucide-react";
|
| 5 |
+
import { useQuery } from "@tanstack/react-query";
|
| 6 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 7 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 8 |
+
import { Badge } from "@micprotocol/ui";
|
| 9 |
+
import { cn } from "@/lib/utils";
|
| 10 |
+
|
| 11 |
+
export default function ObservabilityMetricsPage() {
|
| 12 |
+
const { data: metrics, isLoading } = useQuery({
|
| 13 |
+
queryKey: ["tracing-metrics"],
|
| 14 |
+
queryFn: async () => {
|
| 15 |
+
const res = await fetch("/api/tracing/metrics", { cache: "no-store" });
|
| 16 |
+
if (!res.ok) throw new Error("Failed to fetch metrics");
|
| 17 |
+
return res.json();
|
| 18 |
+
},
|
| 19 |
+
refetchInterval: 10_000,
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
+
const latency = metrics?.latency ?? { p50: 0, p95: 0, p99: 0 };
|
| 23 |
+
const throughput = metrics?.throughput ?? { rps: 0, total: 0 };
|
| 24 |
+
const errors = metrics?.errors ?? { rate: 0, count: 0 };
|
| 25 |
+
|
| 26 |
+
return (
|
| 27 |
+
<div className="animate-fade-in">
|
| 28 |
+
<AdminHeader
|
| 29 |
+
title="Metrics"
|
| 30 |
+
subtitle="Platform performance, latency percentiles, and error rates"
|
| 31 |
+
refreshing={isLoading}
|
| 32 |
+
/>
|
| 33 |
+
|
| 34 |
+
<div className="space-y-6 p-6">
|
| 35 |
+
{/* Latency cards */}
|
| 36 |
+
<div className="grid gap-4 sm:grid-cols-3 lg:grid-cols-4">
|
| 37 |
+
<Card className="border border-[var(--border-color)]">
|
| 38 |
+
<CardContent className="p-5">
|
| 39 |
+
<div className="flex items-start justify-between">
|
| 40 |
+
<div>
|
| 41 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">p50 Latency</p>
|
| 42 |
+
<p className="mt-2 font-display text-3xl font-bold text-[var(--text-primary)]">
|
| 43 |
+
{isLoading ? "β" : latency.p50.toFixed(1)} ms
|
| 44 |
+
</p>
|
| 45 |
+
</div>
|
| 46 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-2.5">
|
| 47 |
+
<Activity className="size-5 text-[var(--color-primary)]" />
|
| 48 |
+
</div>
|
| 49 |
+
</div>
|
| 50 |
+
</CardContent>
|
| 51 |
+
</Card>
|
| 52 |
+
|
| 53 |
+
<Card className="border border-[var(--border-color)]">
|
| 54 |
+
<CardContent className="p-5">
|
| 55 |
+
<div className="flex items-start justify-between">
|
| 56 |
+
<div>
|
| 57 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">p95 Latency</p>
|
| 58 |
+
<p className="mt-2 font-display text-3xl font-bold text-[var(--text-primary)]">
|
| 59 |
+
{isLoading ? "β" : latency.p95.toFixed(1)} ms
|
| 60 |
+
</p>
|
| 61 |
+
</div>
|
| 62 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-2.5">
|
| 63 |
+
<Monitor className="size-5 text-[var(--color-info)]" />
|
| 64 |
+
</div>
|
| 65 |
+
</div>
|
| 66 |
+
</CardContent>
|
| 67 |
+
</Card>
|
| 68 |
+
|
| 69 |
+
<Card className="border border-[var(--border-color)]">
|
| 70 |
+
<CardContent className="p-5">
|
| 71 |
+
<div className="flex items-start justify-between">
|
| 72 |
+
<div>
|
| 73 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">p99 Latency</p>
|
| 74 |
+
<p className="mt-2 font-display text-3xl font-bold text-[var(--text-primary)]">
|
| 75 |
+
{isLoading ? "β" : latency.p99.toFixed(1)} ms
|
| 76 |
+
</p>
|
| 77 |
+
</div>
|
| 78 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-2.5">
|
| 79 |
+
<AlertCircle className="size-5 text-[var(--color-warning)]" />
|
| 80 |
+
</div>
|
| 81 |
+
</div>
|
| 82 |
+
</CardContent>
|
| 83 |
+
</Card>
|
| 84 |
+
|
| 85 |
+
<Card className="border border-[var(--border-color)]">
|
| 86 |
+
<CardContent className="p-5">
|
| 87 |
+
<div className="flex items-start justify-between">
|
| 88 |
+
<div>
|
| 89 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Error Rate</p>
|
| 90 |
+
<p className="mt-2 font-display text-3xl font-bold text-[var(--color-error)]">
|
| 91 |
+
{isLoading ? "β" : errors.rate.toFixed(2)}%
|
| 92 |
+
</p>
|
| 93 |
+
</div>
|
| 94 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-2.5">
|
| 95 |
+
<CheckCircle2 className="size-5 text-[var(--color-success)]" />
|
| 96 |
+
</div>
|
| 97 |
+
</div>
|
| 98 |
+
</CardContent>
|
| 99 |
+
</Card>
|
| 100 |
+
</div>
|
| 101 |
+
|
| 102 |
+
{/* Throughput */}
|
| 103 |
+
<Card>
|
| 104 |
+
<CardHeader>
|
| 105 |
+
<CardTitle className="flex items-center gap-2">
|
| 106 |
+
<Monitor className="size-4 text-[var(--color-info)]" /> Throughput
|
| 107 |
+
</CardTitle>
|
| 108 |
+
</CardHeader>
|
| 109 |
+
<CardContent className="p-5">
|
| 110 |
+
<div className="flex gap-8">
|
| 111 |
+
<div>
|
| 112 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Requests/sec</p>
|
| 113 |
+
<p className="mt-2 font-display text-3xl font-bold text-[var(--text-primary)]">
|
| 114 |
+
{isLoading ? "β" : throughput.rps.toFixed(1)}
|
| 115 |
+
</p>
|
| 116 |
+
</div>
|
| 117 |
+
<div>
|
| 118 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Total Requests</p>
|
| 119 |
+
<p className="mt-2 font-display text-3xl font-bold text-[var(--text-primary)]">
|
| 120 |
+
{isLoading ? "β" : throughput.total.toLocaleString()}
|
| 121 |
+
</p>
|
| 122 |
+
</div>
|
| 123 |
+
</div>
|
| 124 |
+
<div className="mt-6 h-1 w-full bg-[var(--bg-tertiary)] rounded-full overflow-hidden">
|
| 125 |
+
<div
|
| 126 |
+
className="h-full bg-[var(--color-primary)]"
|
| 127 |
+
style={{ width: Math.min((throughput.rps / 1000) * 100, 100) }}
|
| 128 |
+
/>
|
| 129 |
+
</div>
|
| 130 |
+
</CardContent>
|
| 131 |
+
</Card>
|
| 132 |
+
</div>
|
| 133 |
+
</div>
|
| 134 |
+
);
|
| 135 |
+
}
|
apps/admin/src/app/(dashboard)/observability/traces/page.tsx
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState } from "react";
|
| 4 |
+
import { Activity, Clock, Eye, Trash2 } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { cn } from "@/lib/utils";
|
| 7 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 8 |
+
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 9 |
+
import { Badge } from "@micprotocol/ui";
|
| 10 |
+
import { Button } from "@micprotocol/ui";
|
| 11 |
+
import { ago } from "@/lib/utils";
|
| 12 |
+
|
| 13 |
+
export default function ObservabilityTracesPage() {
|
| 14 |
+
const [spanId, setSpanId] = useState("");
|
| 15 |
+
|
| 16 |
+
const { data: traces, isLoading } = trpc.admin.realtime.traces.useQuery(
|
| 17 |
+
{ limit: 50 },
|
| 18 |
+
{ refetchInterval: 30_000 },
|
| 19 |
+
);
|
| 20 |
+
|
| 21 |
+
const items = (traces as any)?.traces ?? [];
|
| 22 |
+
|
| 23 |
+
return (
|
| 24 |
+
<div className="animate-fade-in">
|
| 25 |
+
<AdminHeader
|
| 26 |
+
title="Traces"
|
| 27 |
+
subtitle="Distributed tracing β spans, latency, and service dependency graph"
|
| 28 |
+
refreshing={isLoading}
|
| 29 |
+
/>
|
| 30 |
+
|
| 31 |
+
<div className="space-y-6 p-6">
|
| 32 |
+
{/* Search */}
|
| 33 |
+
<Card>
|
| 34 |
+
<CardContent className="p-5">
|
| 35 |
+
<div className="relative flex-1 max-w-md">
|
| 36 |
+
<Activity className="absolute left-3 top-3 size-4 text-[var(--text-tertiary)]" />
|
| 37 |
+
<input
|
| 38 |
+
value={spanId}
|
| 39 |
+
onChange={(e) => setSpanId(e.target.value)}
|
| 40 |
+
placeholder="Filter by span IDβ¦"
|
| 41 |
+
className="w-full pl-10 pr-4 py-2 text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20 outline-none"
|
| 42 |
+
/>
|
| 43 |
+
</div>
|
| 44 |
+
</CardContent>
|
| 45 |
+
</Card>
|
| 46 |
+
|
| 47 |
+
{/* Spans table */}
|
| 48 |
+
<Card>
|
| 49 |
+
<CardHeader>
|
| 50 |
+
<CardTitle className="flex items-center gap-2">
|
| 51 |
+
<Activity className="size-4 text-[var(--color-primary)]" /> Spans
|
| 52 |
+
</CardTitle>
|
| 53 |
+
</CardHeader>
|
| 54 |
+
<CardContent className="p-0">
|
| 55 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 56 |
+
<table className="w-full text-left border-collapse">
|
| 57 |
+
<thead>
|
| 58 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 59 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-28">Span ID</th>
|
| 60 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-28">Trace ID</th>
|
| 61 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Service</th>
|
| 62 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-20">Operation</th>
|
| 63 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Status</th>
|
| 64 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-24">Duration</th>
|
| 65 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Started</th>
|
| 66 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Actions</th>
|
| 67 |
+
</tr>
|
| 68 |
+
</thead>
|
| 69 |
+
<tbody>
|
| 70 |
+
{isLoading ? (
|
| 71 |
+
[...Array(5)].map((_, i) => (
|
| 72 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 73 |
+
<td colSpan={8} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 74 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 75 |
+
</td>
|
| 76 |
+
</tr>
|
| 77 |
+
))
|
| 78 |
+
) : items.length === 0 ? (
|
| 79 |
+
<tr>
|
| 80 |
+
<td colSpan={8} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 81 |
+
No traces found.
|
| 82 |
+
</td>
|
| 83 |
+
</tr>
|
| 84 |
+
) : (
|
| 85 |
+
items.map((t: any) => (
|
| 86 |
+
<tr key={t.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors cursor-pointer">
|
| 87 |
+
<td className="py-4 font-mono text-xs text-[var(--text-secondary)]">
|
| 88 |
+
{t.id.slice(0, 8)}β¦
|
| 89 |
+
</td>
|
| 90 |
+
<td className="py-4 font-mono text-xs text-[var(--text-secondary)]">
|
| 91 |
+
{t.traceId.slice(0, 8)}β¦
|
| 92 |
+
</td>
|
| 93 |
+
<td className="py-4 text-xs text-[var(--text-primary)]">{t.service}</td>
|
| 94 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] font-mono">{t.operation}</td>
|
| 95 |
+
<td className="py-4 text-xs text-center">
|
| 96 |
+
<Badge className={cn("capitalize text-xs", t.status === "ok" ? "bg-[var(--color-success)]/20 border-[var(--color-success)]/30 text-[var(--color-success)]" : "border-transparent text-[var(--text-tertiary)]")}>
|
| 97 |
+
{t.status}
|
| 98 |
+
</Badge>
|
| 99 |
+
</td>
|
| 100 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] text-right font-mono">
|
| 101 |
+
{t.durationMs?.toFixed(1) ?? "β"} ms
|
| 102 |
+
</td>
|
| 103 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)] text-right">
|
| 104 |
+
{new Date(t.startedAt).toLocaleTimeString()}
|
| 105 |
+
</td>
|
| 106 |
+
<td className="py-4 text-sm text-right">
|
| 107 |
+
<div className="flex gap-1 justify-end">
|
| 108 |
+
<Button variant="ghost" size="sm" onClick={() => {}}>
|
| 109 |
+
<Eye size={14} className="mr-1" /> View
|
| 110 |
+
</Button>
|
| 111 |
+
</div>
|
| 112 |
+
</td>
|
| 113 |
+
</tr>
|
| 114 |
+
))
|
| 115 |
+
)}
|
| 116 |
+
</tbody>
|
| 117 |
+
</table>
|
| 118 |
+
</div>
|
| 119 |
+
</CardContent>
|
| 120 |
+
</Card>
|
| 121 |
+
|
| 122 |
+
{/* Span detail (conditional sheet replacement) */}
|
| 123 |
+
{spanId && (
|
| 124 |
+
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
|
| 125 |
+
<div className="absolute inset-0 bg-black/60 backdrop-blur-sm" onClick={() => setSpanId("")} />
|
| 126 |
+
<Card className="w-full max-w-4xl max-h-[90vh] flex flex-col">
|
| 127 |
+
<CardHeader className="pb-3">
|
| 128 |
+
<div className="flex items-center justify-between">
|
| 129 |
+
<div>
|
| 130 |
+
<CardTitle className="flex items-center gap-2">
|
| 131 |
+
<Clock className="size-4 text-[var(--color-primary)]" /> Span Detail
|
| 132 |
+
</CardTitle>
|
| 133 |
+
<CardDescription>{spanId}</CardDescription>
|
| 134 |
+
</div>
|
| 135 |
+
<Button variant="ghost" size="sm" onClick={() => setSpanId("")}>
|
| 136 |
+
<Trash2 size={14} />
|
| 137 |
+
</Button>
|
| 138 |
+
</div>
|
| 139 |
+
</CardHeader>
|
| 140 |
+
<CardContent className="p-5 overflow-y-auto max-h-[60vh]">
|
| 141 |
+
<p className="text-[var(--text-secondary)]">Span detail panel. Trace ID, service, operation, duration, logs, and child spans render here.</p>
|
| 142 |
+
<div className="mt-4 p-4 rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] border border-[var(--border-color-subtle)] font-mono text-xs">
|
| 143 |
+
<span className="text-[var(--text-tertiary)]">spanId:</span> {spanId}<br />
|
| 144 |
+
<span className="text-[var(--text-tertiary)]">status:</span> loaded<br />
|
| 145 |
+
<span className="text-[var(--text-tertiary)]">message:</span> Span detail requires backend wiring for full hydration.
|
| 146 |
+
</div>
|
| 147 |
+
</CardContent>
|
| 148 |
+
<CardFooter className="pt-3">
|
| 149 |
+
<div className="flex justify-end">
|
| 150 |
+
<Button variant="outline" size="sm" onClick={() => setSpanId("")}>
|
| 151 |
+
Close
|
| 152 |
+
</Button>
|
| 153 |
+
</div>
|
| 154 |
+
</CardFooter>
|
| 155 |
+
</Card>
|
| 156 |
+
</div>
|
| 157 |
+
)}
|
| 158 |
+
</div>
|
| 159 |
+
</div>
|
| 160 |
+
);
|
| 161 |
+
}
|
apps/admin/src/app/(dashboard)/page.tsx
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { motion } from "framer-motion";
|
| 5 |
+
import {
|
| 6 |
+
Users,
|
| 7 |
+
Building2,
|
| 8 |
+
MessageSquare,
|
| 9 |
+
UserCheck,
|
| 10 |
+
Coins,
|
| 11 |
+
TrendingUp,
|
| 12 |
+
Activity,
|
| 13 |
+
Zap,
|
| 14 |
+
HelpCircle,
|
| 15 |
+
TrendingDown,
|
| 16 |
+
Clock,
|
| 17 |
+
RefreshCw,
|
| 18 |
+
} from "lucide-react";
|
| 19 |
+
import { trpc } from "@/lib/trpc";
|
| 20 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 21 |
+
import {
|
| 22 |
+
Card, CardContent, CardHeader, CardTitle,
|
| 23 |
+
} from "@micprotocol/ui";
|
| 24 |
+
import { Badge } from "@micprotocol/ui";
|
| 25 |
+
import { Button } from "@micprotocol/ui";
|
| 26 |
+
import { ago } from "@/lib/utils";
|
| 27 |
+
|
| 28 |
+
function AnimatedNumber({ value }: { value: number }) {
|
| 29 |
+
const [display, setDisplay] = React.useState(0);
|
| 30 |
+
React.useEffect(() => {
|
| 31 |
+
const duration = 500;
|
| 32 |
+
const start = performance.now();
|
| 33 |
+
let raf: number;
|
| 34 |
+
const tick = (now: number) => {
|
| 35 |
+
const p = Math.min((now - start) / duration, 1);
|
| 36 |
+
setDisplay(Math.round(value * p));
|
| 37 |
+
if (p < 1) raf = requestAnimationFrame(tick);
|
| 38 |
+
};
|
| 39 |
+
raf = requestAnimationFrame(tick);
|
| 40 |
+
return () => cancelAnimationFrame(raf);
|
| 41 |
+
}, [value]);
|
| 42 |
+
return <span>{display.toLocaleString()}</span>;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
function TrendIndicator({
|
| 46 |
+
value,
|
| 47 |
+
label,
|
| 48 |
+
positive,
|
| 49 |
+
}: {
|
| 50 |
+
value: number | null;
|
| 51 |
+
label: string;
|
| 52 |
+
positive?: boolean;
|
| 53 |
+
}) {
|
| 54 |
+
if (value === null) {
|
| 55 |
+
return (
|
| 56 |
+
<div className="flex items-center gap-1 text-xs text-[var(--text-tertiary)]">
|
| 57 |
+
<span className="w-1 h-1 rounded-full bg-[var(--text-tertiary)] animate-pulse" /> {label}
|
| 58 |
+
</div>
|
| 59 |
+
);
|
| 60 |
+
}
|
| 61 |
+
const isGood = positive !== undefined ? positive : value >= 0;
|
| 62 |
+
const sign = value >= 0 ? "+" : "";
|
| 63 |
+
return (
|
| 64 |
+
<div className="flex items-center gap-1 text-xs">
|
| 65 |
+
{isGood ? (
|
| 66 |
+
<TrendingUp className="size-3 text-[var(--color-success)]" />
|
| 67 |
+
) : (
|
| 68 |
+
<TrendingDown className="size-3 text-[var(--color-error)]" />
|
| 69 |
+
)}
|
| 70 |
+
<span className={`font-medium ${isGood ? "text-[var(--color-success)]" : "text-[var(--color-error)]"}`}>
|
| 71 |
+
{sign}{value}%
|
| 72 |
+
</span>
|
| 73 |
+
<span className="text-[var(--text-tertiary)]">{label}</span>
|
| 74 |
+
</div>
|
| 75 |
+
);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
function EmptyState({
|
| 79 |
+
icon: Icon,
|
| 80 |
+
title,
|
| 81 |
+
description,
|
| 82 |
+
action,
|
| 83 |
+
}: {
|
| 84 |
+
icon: React.ComponentType<{ className?: string }>;
|
| 85 |
+
title: string;
|
| 86 |
+
description: string;
|
| 87 |
+
action?: React.ReactNode;
|
| 88 |
+
}) {
|
| 89 |
+
return (
|
| 90 |
+
<Card className="border border-[var(--border-color)] bg-[var(--bg-elevated)]">
|
| 91 |
+
<CardContent className="p-10 text-center">
|
| 92 |
+
<div className="flex items-center justify-center">
|
| 93 |
+
<Icon className="size-12 mx-auto text-[var(--text-tertiary)]" />
|
| 94 |
+
</div>
|
| 95 |
+
<h3 className="mt-4 font-display text-[var(--text-sm)] font-semibold text-[var(--text-primary)]">{title}</h3>
|
| 96 |
+
<p className="mt-1 text-sm text-[var(--text-secondary)]">{description}</p>
|
| 97 |
+
{action && <div className="mt-6">{action}</div>}
|
| 98 |
+
</CardContent>
|
| 99 |
+
</Card>
|
| 100 |
+
);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
export default function DashboardPage() {
|
| 104 |
+
const { data: stats, isLoading, refetch, isFetching } = trpc.crm.getDashboardStats.useQuery() as any;
|
| 105 |
+
const { data: inquiries, isLoading: inquiriesLoading } = trpc.crm.listInquiries.useQuery();
|
| 106 |
+
|
| 107 |
+
const isDataEmpty = !stats ||
|
| 108 |
+
(stats.users.total === 0 &&
|
| 109 |
+
stats.workspaces.total === 0 &&
|
| 110 |
+
stats.inquiries.total === 0 &&
|
| 111 |
+
stats.guests.total === 0 &&
|
| 112 |
+
stats.outreach.activeSequences === 0 &&
|
| 113 |
+
stats.finance.platformCutKes === 0);
|
| 114 |
+
|
| 115 |
+
const kpis = [
|
| 116 |
+
{
|
| 117 |
+
label: "Total Users",
|
| 118 |
+
value: stats?.users.total ?? 0,
|
| 119 |
+
trend: stats?.users.trend ?? null,
|
| 120 |
+
icon: Users,
|
| 121 |
+
accent: "var(--color-info)",
|
| 122 |
+
hint: `${stats?.users.active ?? 0} active`,
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
label: "Workspaces",
|
| 126 |
+
value: stats?.workspaces.total ?? 0,
|
| 127 |
+
trend: stats?.workspaces.trend ?? null,
|
| 128 |
+
icon: Building2,
|
| 129 |
+
accent: "var(--color-primary)",
|
| 130 |
+
hint: "across all plans",
|
| 131 |
+
},
|
| 132 |
+
{
|
| 133 |
+
label: "Inquiries",
|
| 134 |
+
value: stats?.inquiries.total ?? 0,
|
| 135 |
+
trend: stats?.inquiries.trend ?? null,
|
| 136 |
+
icon: MessageSquare,
|
| 137 |
+
accent: "var(--color-warning)",
|
| 138 |
+
hint: `${stats?.inquiries.byStatus.pending ?? 0} pending`,
|
| 139 |
+
},
|
| 140 |
+
{
|
| 141 |
+
label: "Guests",
|
| 142 |
+
value: stats?.guests.total ?? 0,
|
| 143 |
+
trend: stats?.guests.trend ?? null,
|
| 144 |
+
icon: UserCheck,
|
| 145 |
+
accent: "var(--color-success)",
|
| 146 |
+
hint: "global CRM",
|
| 147 |
+
},
|
| 148 |
+
{
|
| 149 |
+
label: "Active Sequences",
|
| 150 |
+
value: stats?.outreach.activeSequences ?? 0,
|
| 151 |
+
trend: stats?.outreach.trend ?? null,
|
| 152 |
+
icon: Zap,
|
| 153 |
+
accent: "var(--color-secondary)",
|
| 154 |
+
hint: "outreach drip campaigns",
|
| 155 |
+
},
|
| 156 |
+
{
|
| 157 |
+
label: "Platform Revenue",
|
| 158 |
+
value: stats?.finance.platformCutKes ?? 0,
|
| 159 |
+
trend: stats?.finance.trend ?? null,
|
| 160 |
+
icon: Coins,
|
| 161 |
+
accent: "var(--color-success)",
|
| 162 |
+
hint: `${stats?.finance.paidInvoiceCount ?? 0} paid invoices`,
|
| 163 |
+
},
|
| 164 |
+
];
|
| 165 |
+
|
| 166 |
+
const pendingInquiries = (inquiries ?? []).filter((i) => i.status === "pending").slice(0, 6);
|
| 167 |
+
|
| 168 |
+
if (isLoading) {
|
| 169 |
+
return (
|
| 170 |
+
<div className="animate-fade-in p-6">
|
| 171 |
+
<AdminHeader title="Platform Overview" subtitle="Loading platform aggregatesβ¦" />
|
| 172 |
+
<div className="grid gap-4 sm:grid-cols-3 xl:grid-cols-6">
|
| 173 |
+
{[1, 2, 3, 4, 5, 6].map((i) => (
|
| 174 |
+
<Card key={i} className="h-48">
|
| 175 |
+
<CardContent className="p-5 flex items-center justify-between">
|
| 176 |
+
<div className="h-4 w-32 bg-[var(--bg-tertiary)] rounded-[var(--radius-md)] animate-shimmer" />
|
| 177 |
+
<div className="h-4 w-16 bg-[var(--bg-tertiary)] rounded-[var(--radius-md)] animate-shimmer" />
|
| 178 |
+
</CardContent>
|
| 179 |
+
</Card>
|
| 180 |
+
))}
|
| 181 |
+
</div>
|
| 182 |
+
</div>
|
| 183 |
+
);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
return (
|
| 187 |
+
<div className="animate-fade-in">
|
| 188 |
+
<AdminHeader
|
| 189 |
+
title="Platform Overview"
|
| 190 |
+
subtitle="Global aggregates, finance statistics, and KPI trends across MicProtocol"
|
| 191 |
+
onRefresh={() => refetch()}
|
| 192 |
+
refreshing={isFetching}
|
| 193 |
+
/>
|
| 194 |
+
|
| 195 |
+
<div className="space-y-6 p-6">
|
| 196 |
+
{isDataEmpty ? (
|
| 197 |
+
<EmptyState
|
| 198 |
+
icon={Activity}
|
| 199 |
+
title="No data yet"
|
| 200 |
+
description="The platform hasn't recorded any activity yet. Create a workspace, onboard users, or run a sync to populate the dashboard."
|
| 201 |
+
action={
|
| 202 |
+
<Button variant="ghost" onClick={() => refetch()} className="text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)]">
|
| 203 |
+
<RefreshCw className="size-4 mr-2" /> Refresh data
|
| 204 |
+
</Button>
|
| 205 |
+
}
|
| 206 |
+
/>
|
| 207 |
+
) : (
|
| 208 |
+
<>
|
| 209 |
+
{/* KPI Cards with trends */}
|
| 210 |
+
<div className="grid gap-4 sm:grid-cols-3 xl:grid-cols-6">
|
| 211 |
+
{kpis.map((kpi, i) => {
|
| 212 |
+
const Icon = kpi.icon as React.ComponentType<{ className?: string }>;
|
| 213 |
+
return (
|
| 214 |
+
<motion.div
|
| 215 |
+
key={kpi.label}
|
| 216 |
+
initial={{ opacity: 0, y: 10 }}
|
| 217 |
+
animate={{ opacity: 1, y: 0 }}
|
| 218 |
+
transition={{ delay: i * 0.05 }}
|
| 219 |
+
>
|
| 220 |
+
<Card className="hover:border-[var(--color-primary)]/30 transition-colors">
|
| 221 |
+
<CardContent className="p-5">
|
| 222 |
+
<div className="flex items-start justify-between">
|
| 223 |
+
<div className="min-w-0">
|
| 224 |
+
<p className="text-[var(--text-xs)] text-[var(--text-secondary)]">{kpi.label}</p>
|
| 225 |
+
<p className="mt-1 font-display text-[var(--text-2xl)] font-bold text-[var(--text-primary)]">
|
| 226 |
+
<AnimatedNumber value={kpi.value} />
|
| 227 |
+
</p>
|
| 228 |
+
<p className="mt-1 text-[var(--text-xs)] text-[var(--text-tertiary)]">{kpi.hint}</p>
|
| 229 |
+
<TrendIndicator
|
| 230 |
+
value={kpi.trend}
|
| 231 |
+
label="vs prev. period"
|
| 232 |
+
positive={
|
| 233 |
+
kpi.label !== "Platform Revenue" && kpi.label !== "Guests"
|
| 234 |
+
}
|
| 235 |
+
/>
|
| 236 |
+
</div>
|
| 237 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-2.5 shrink-0">
|
| 238 |
+
<Icon className={`size-5 text-[${kpi.accent}]`} />
|
| 239 |
+
</div>
|
| 240 |
+
</div>
|
| 241 |
+
</CardContent>
|
| 242 |
+
</Card>
|
| 243 |
+
</motion.div>
|
| 244 |
+
)})}
|
| 245 |
+
</div>
|
| 246 |
+
|
| 247 |
+
{/* Finance + Health */}
|
| 248 |
+
<div className="grid gap-4 lg:grid-cols-2">
|
| 249 |
+
<Card className="frosted">
|
| 250 |
+
<CardHeader>
|
| 251 |
+
<CardTitle className="flex items-center gap-2">
|
| 252 |
+
<Coins className="size-4 text-[var(--color-success)]" /> Finance
|
| 253 |
+
</CardTitle>
|
| 254 |
+
</CardHeader>
|
| 255 |
+
<CardContent>
|
| 256 |
+
<div className="grid grid-cols-2 gap-4">
|
| 257 |
+
<div>
|
| 258 |
+
<p className="text-[var(--text-xs)] text-[var(--text-tertiary)]">Total Revenue (KES)</p>
|
| 259 |
+
<p className="mt-1 font-display text-[var(--text-2xl)] font-semibold text-[var(--text-primary)]">
|
| 260 |
+
{(stats?.finance.totalRevenueKes ?? 0).toLocaleString()}
|
| 261 |
+
</p>
|
| 262 |
+
</div>
|
| 263 |
+
<div>
|
| 264 |
+
<p className="text-[var(--text-xs)] text-[var(--text-tertiary)]">Platform Cut (KES)</p>
|
| 265 |
+
<p className="mt-1 font-display text-[var(--text-2xl)] font-semibold text-[var(--color-primary)]">
|
| 266 |
+
{(stats?.finance.platformCutKes ?? 0).toLocaleString()}
|
| 267 |
+
</p>
|
| 268 |
+
</div>
|
| 269 |
+
<div>
|
| 270 |
+
<p className="text-[var(--text-xs)] text-[var(--text-tertiary)]">Paid Invoices</p>
|
| 271 |
+
<p className="mt-1 text-lg font-medium text-[var(--text-primary)]">
|
| 272 |
+
{stats?.finance.paidInvoiceCount ?? 0}
|
| 273 |
+
</p>
|
| 274 |
+
</div>
|
| 275 |
+
<div>
|
| 276 |
+
<p className="text-[var(--text-xs)] text-[var(--text-tertiary)]">Pending Revenue (KES)</p>
|
| 277 |
+
<p className="mt-1 text-lg font-medium text-[var(--color-warning)]">
|
| 278 |
+
{(stats?.finance.pendingRevenueKes ?? 0).toLocaleString()}
|
| 279 |
+
</p>
|
| 280 |
+
</div>
|
| 281 |
+
</div>
|
| 282 |
+
<div className="mt-6 flex items-center justify-between border-t border-[var(--border-color)] pt-4">
|
| 283 |
+
<span className="text-[var(--text-xs)] font-mono text-[var(--text-secondary)]">Collection rate</span>
|
| 284 |
+
<span className="font-display text-[var(--text-lg)] font-bold text-[var(--text-primary)]">
|
| 285 |
+
{stats?.finance.collectionRate ? `${stats.finance.collectionRate}%` : "β"}
|
| 286 |
+
</span>
|
| 287 |
+
</div>
|
| 288 |
+
</CardContent>
|
| 289 |
+
</Card>
|
| 290 |
+
|
| 291 |
+
<Card className="border border-[var(--border-color)]">
|
| 292 |
+
<CardHeader>
|
| 293 |
+
<CardTitle className="flex items-center gap-2">
|
| 294 |
+
<Activity className="size-4 text-[var(--color-info)]" /> Platform Health
|
| 295 |
+
</CardTitle>
|
| 296 |
+
</CardHeader>
|
| 297 |
+
<CardContent>
|
| 298 |
+
<div className="grid grid-cols-2 gap-3">
|
| 299 |
+
{[
|
| 300 |
+
{ label: "Database", state: "healthy", detail: "PostgreSQL" },
|
| 301 |
+
{ label: "Redis", state: "healthy", detail: "Queues + Cache" },
|
| 302 |
+
{ label: "Meilisearch", state: "healthy", detail: "Search Indexes" },
|
| 303 |
+
{ label: "LiveKit", state: "healthy", detail: "SFU + Egress" },
|
| 304 |
+
{ label: "CLIP Scorer", state: "healthy", detail: "Python ML" },
|
| 305 |
+
{ label: "Mic-Realtime", state: "healthy", detail: "Erlang :4001" },
|
| 306 |
+
].map((s) => (
|
| 307 |
+
<div key={s.label} className="flex items-center gap-3 rounded-[var(--radius-md)] border border-[var(--border-color)] bg-[var(--bg-secondary)] p-3">
|
| 308 |
+
<span
|
| 309 |
+
className={`inline-flex items-center justify-center size-2 rounded-full ${
|
| 310 |
+
s.state === "healthy" ? "bg-[var(--color-success)]" : "bg-[var(--color-warning)]"
|
| 311 |
+
}`}
|
| 312 |
+
aria-label={s.state}
|
| 313 |
+
/>
|
| 314 |
+
<div className="min-w-0">
|
| 315 |
+
<p className="truncate text-sm text-[var(--text-primary)]">{s.label}</p>
|
| 316 |
+
<p className="truncate text-xs text-[var(--text-tertiary)]">{s.detail}</p>
|
| 317 |
+
</div>
|
| 318 |
+
</div>
|
| 319 |
+
))}
|
| 320 |
+
</div>
|
| 321 |
+
</CardContent>
|
| 322 |
+
</Card>
|
| 323 |
+
</div>
|
| 324 |
+
|
| 325 |
+
{/* Pending Inquiries + Workspaces by plan */}
|
| 326 |
+
<div className="grid gap-4 lg:grid-cols-2">
|
| 327 |
+
<Card className="border border-[var(--border-color)]">
|
| 328 |
+
<CardHeader>
|
| 329 |
+
<CardTitle className="flex items-center gap-2">
|
| 330 |
+
<HelpCircle className="size-4 text-[var(--color-warning)]" /> Pending Inquiries
|
| 331 |
+
</CardTitle>
|
| 332 |
+
</CardHeader>
|
| 333 |
+
<CardContent className="space-y-2">
|
| 334 |
+
{inquiriesLoading ? (
|
| 335 |
+
<p className="text-sm text-[var(--text-tertiary)]">Loadingβ¦</p>
|
| 336 |
+
) : pendingInquiries.length === 0 ? (
|
| 337 |
+
<p className="text-sm text-[var(--text-tertiary)]">No pending inquiries π</p>
|
| 338 |
+
) : (
|
| 339 |
+
pendingInquiries.map((inq) => (
|
| 340 |
+
<div key={inq.id} className="flex items-center justify-between rounded-[var(--radius-md)] border border-[var(--border-color)] bg-[var(--bg-secondary)] px-3 py-2">
|
| 341 |
+
<div className="min-w-0">
|
| 342 |
+
<p className="truncate text-sm text-[var(--text-primary)]">{inq.subject}</p>
|
| 343 |
+
<p className="truncate text-xs text-[var(--text-tertiary)]">
|
| 344 |
+
{inq.name} Β· {inq.email}
|
| 345 |
+
</p>
|
| 346 |
+
</div>
|
| 347 |
+
<div className="flex shrink-0 items-center gap-2">
|
| 348 |
+
<Badge tone="warning">pending</Badge>
|
| 349 |
+
<span className="text-xs text-[var(--text-tertiary)]">{ago(inq.createdAt)}</span>
|
| 350 |
+
</div>
|
| 351 |
+
</div>
|
| 352 |
+
))
|
| 353 |
+
)}
|
| 354 |
+
</CardContent>
|
| 355 |
+
</Card>
|
| 356 |
+
|
| 357 |
+
<Card className="frosted">
|
| 358 |
+
<CardHeader>
|
| 359 |
+
<CardTitle className="flex items-center gap-2">
|
| 360 |
+
<TrendingUp className="size-4 text-[var(--color-primary)]" /> Workspaces by Plan
|
| 361 |
+
</CardTitle>
|
| 362 |
+
</CardHeader>
|
| 363 |
+
<CardContent>
|
| 364 |
+
<div className="space-y-3">
|
| 365 |
+
{stats?.workspaces.byPlan ? (
|
| 366 |
+
Object.entries(stats.workspaces.byPlan).map(([plan, count]) => (
|
| 367 |
+
<div key={plan} className="flex items-center justify-between">
|
| 368 |
+
<span className="text-sm capitalize text-[var(--text-secondary)]">{plan}</span>
|
| 369 |
+
<div className="flex items-center gap-3">
|
| 370 |
+
<div className="h-2 w-40 overflow-hidden rounded-full bg-[var(--bg-tertiary)]">
|
| 371 |
+
<div
|
| 372 |
+
className={`h-full rounded-full ${
|
| 373 |
+
plan === "studio"
|
| 374 |
+
? "bg-[var(--color-primary)]"
|
| 375 |
+
: plan === "creator"
|
| 376 |
+
? "bg-[var(--color-info)]"
|
| 377 |
+
: "bg-[var(--text-tertiary)]"
|
| 378 |
+
}`}
|
| 379 |
+
style={{
|
| 380 |
+
width: `${(
|
| 381 |
+
(count as number / (stats.workspaces.total || 1)) *
|
| 382 |
+
100
|
| 383 |
+
).toFixed(0)}%`,
|
| 384 |
+
}}
|
| 385 |
+
/>
|
| 386 |
+
</div>
|
| 387 |
+
<span className="w-8 text-right text-sm font-medium text-[var(--text-primary)]">
|
| 388 |
+
{count as number}
|
| 389 |
+
</span>
|
| 390 |
+
</div>
|
| 391 |
+
</div>
|
| 392 |
+
))
|
| 393 |
+
) : (
|
| 394 |
+
<p className="text-sm text-[var(--text-tertiary)]">Loadingβ¦</p>
|
| 395 |
+
)}
|
| 396 |
+
</div>
|
| 397 |
+
|
| 398 |
+
<div className="mt-6 flex items-center justify-between border-t border-[var(--border-color)] pt-4 text-sm">
|
| 399 |
+
<span className="flex items-center gap-2 text-[var(--text-secondary)]">
|
| 400 |
+
<Zap className="size-4 text-[var(--color-warning)]" />
|
| 401 |
+
Active outreach sequences
|
| 402 |
+
</span>
|
| 403 |
+
<span className="font-display text-[var(--text-lg)] font-semibold text-[var(--text-primary)]">
|
| 404 |
+
{stats?.outreach.activeSequences ?? 0}
|
| 405 |
+
</span>
|
| 406 |
+
</div>
|
| 407 |
+
|
| 408 |
+
<div className="mt-4 flex items-center justify-between border-t border-[var(--border-color)] pt-4 text-sm">
|
| 409 |
+
<span className="flex items-center gap-2 text-[var(--text-secondary)]">
|
| 410 |
+
<Clock className="size-4 text-[var(--color-info)]" />
|
| 411 |
+
Avg. session (min)
|
| 412 |
+
</span>
|
| 413 |
+
<span className="font-display text-[var(--text-lg)] font-semibold text-[var(--text-primary)]">
|
| 414 |
+
{stats?.realtime.avgSessionMinutes ?? 0}
|
| 415 |
+
</span>
|
| 416 |
+
</div>
|
| 417 |
+
</CardContent>
|
| 418 |
+
</Card>
|
| 419 |
+
</div>
|
| 420 |
+
</>
|
| 421 |
+
)}
|
| 422 |
+
</div>
|
| 423 |
+
</div>
|
| 424 |
+
);
|
| 425 |
+
}
|
apps/admin/src/app/(dashboard)/queues/page.tsx
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Layers, CircleDot, Loader2, AlertTriangle, CheckCircle2, Clock3, PauseCircle, RefreshCw } from "lucide-react";
|
| 5 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 6 |
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle, Badge, Button } from "@micprotocol/ui";
|
| 7 |
+
import { trpc } from "@/lib/trpc";
|
| 8 |
+
|
| 9 |
+
interface QueueStats {
|
| 10 |
+
name: string;
|
| 11 |
+
waiting: number;
|
| 12 |
+
active: number;
|
| 13 |
+
completed: number;
|
| 14 |
+
failed: number;
|
| 15 |
+
delayed: number;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
const QUEUE_ORDER = [
|
| 19 |
+
"clip-scoring",
|
| 20 |
+
"notification",
|
| 21 |
+
"post-interview",
|
| 22 |
+
"content",
|
| 23 |
+
"outreach",
|
| 24 |
+
"verification",
|
| 25 |
+
] as const;
|
| 26 |
+
|
| 27 |
+
function QueueDistribution({ counts }: { counts: QueueStats }) {
|
| 28 |
+
const total = counts.active + counts.waiting + counts.delayed + counts.failed + counts.completed || 1;
|
| 29 |
+
const segments = [
|
| 30 |
+
{ key: "active", value: counts.active, color: "bg-[var(--color-info)]" },
|
| 31 |
+
{ key: "waiting", value: counts.waiting, color: "bg-[var(--color-primary)]" },
|
| 32 |
+
{ key: "delayed", value: counts.delayed, color: "bg-[var(--color-warning)]" },
|
| 33 |
+
{ key: "failed", value: counts.failed, color: "bg-[var(--color-error)]" },
|
| 34 |
+
{ key: "completed", value: counts.completed, color: "bg-[var(--color-success)]" },
|
| 35 |
+
];
|
| 36 |
+
return (
|
| 37 |
+
<div className="flex h-2 w-full overflow-hidden rounded-full bg-[var(--bg-tertiary)]">
|
| 38 |
+
{segments.map((s) =>
|
| 39 |
+
s.value > 0 ? (
|
| 40 |
+
<div
|
| 41 |
+
key={s.key}
|
| 42 |
+
className={s.color}
|
| 43 |
+
style={{ width: `${(s.value / total) * 100}%` }}
|
| 44 |
+
title={`${s.key}: ${s.value}`}
|
| 45 |
+
/>
|
| 46 |
+
) : null,
|
| 47 |
+
)}
|
| 48 |
+
</div>
|
| 49 |
+
);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
export default function QueuesPage() {
|
| 53 |
+
const { data: queueHealth, isLoading, refetch, isFetching } =
|
| 54 |
+
trpc.admin.operations.queueHealth.useQuery(undefined, {
|
| 55 |
+
refetchInterval: 30_000,
|
| 56 |
+
});
|
| 57 |
+
|
| 58 |
+
const queues = QUEUE_ORDER.map((name) => {
|
| 59 |
+
const found = queueHealth?.find((q) => q.name === name);
|
| 60 |
+
return {
|
| 61 |
+
name,
|
| 62 |
+
counts: found
|
| 63 |
+
? {
|
| 64 |
+
name,
|
| 65 |
+
active: found.active,
|
| 66 |
+
waiting: found.waiting,
|
| 67 |
+
delayed: found.delayed,
|
| 68 |
+
failed: found.failed,
|
| 69 |
+
completed: found.completed,
|
| 70 |
+
}
|
| 71 |
+
: { name, active: 0, waiting: 0, delayed: 0, failed: 0, completed: 0 },
|
| 72 |
+
};
|
| 73 |
+
});
|
| 74 |
+
|
| 75 |
+
const totalQueued = queues.reduce(
|
| 76 |
+
(sum, q) => sum + q.counts.waiting + q.counts.delayed,
|
| 77 |
+
0,
|
| 78 |
+
);
|
| 79 |
+
const totalFailed = queues.reduce((sum, q) => sum + q.counts.failed, 0);
|
| 80 |
+
const totalActive = queues.reduce((sum, q) => sum + q.counts.active, 0);
|
| 81 |
+
|
| 82 |
+
return (
|
| 83 |
+
<div className="animate-fade-in">
|
| 84 |
+
<AdminHeader
|
| 85 |
+
title="Queue Control Room"
|
| 86 |
+
subtitle="Tier 2 β BullMQ worker farm and dead-letter inspection"
|
| 87 |
+
onRefresh={refetch}
|
| 88 |
+
refreshing={isFetching}
|
| 89 |
+
actions={
|
| 90 |
+
<Badge tone={totalFailed > 0 ? "error" : "success"} variant="subtle" size="sm">
|
| 91 |
+
{totalFailed} failed jobs
|
| 92 |
+
</Badge>
|
| 93 |
+
}
|
| 94 |
+
/>
|
| 95 |
+
<div className="space-y-4 p-6">
|
| 96 |
+
{/* Summary strip */}
|
| 97 |
+
<div className="grid gap-4 sm:grid-cols-3 lg:grid-cols-4">
|
| 98 |
+
<Card className="frosted border border-[var(--border-color)]">
|
| 99 |
+
<CardContent className="p-5">
|
| 100 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Waiting + Delayed</p>
|
| 101 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-primary)]">{totalQueued}</p>
|
| 102 |
+
</CardContent>
|
| 103 |
+
</Card>
|
| 104 |
+
<Card className="border border-[var(--border-color)]">
|
| 105 |
+
<CardContent className="p-5">
|
| 106 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Active</p>
|
| 107 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-info)]">{totalActive}</p>
|
| 108 |
+
</CardContent>
|
| 109 |
+
</Card>
|
| 110 |
+
<Card className="border border-[var(--border-color)]">
|
| 111 |
+
<CardContent className="p-5">
|
| 112 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Failed</p>
|
| 113 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-error)]">{totalFailed}</p>
|
| 114 |
+
</CardContent>
|
| 115 |
+
</Card>
|
| 116 |
+
<Card className="border border-[var(--border-color)]">
|
| 117 |
+
<CardContent className="p-5">
|
| 118 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Completed</p>
|
| 119 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-success)]">
|
| 120 |
+
{queues.reduce((sum, q) => sum + q.counts.completed, 0)}
|
| 121 |
+
</p>
|
| 122 |
+
</CardContent>
|
| 123 |
+
</Card>
|
| 124 |
+
</div>
|
| 125 |
+
|
| 126 |
+
{/* Per-queue cards */}
|
| 127 |
+
<div className="grid gap-4 sm:grid-cols-3 lg:grid-cols-4">
|
| 128 |
+
{queues.map((q) => (
|
| 129 |
+
<Card
|
| 130 |
+
key={q.name}
|
| 131 |
+
className={`hover:border-[var(--color-primary)]/30 transition-colors ${q.counts.failed > 0 ? "border-[var(--color-error)]/30" : ""}`}
|
| 132 |
+
>
|
| 133 |
+
<CardHeader>
|
| 134 |
+
<CardTitle className="flex items-center gap-2 font-mono text-sm">
|
| 135 |
+
<Layers className="size-4 text-[var(--color-primary)]" /> {q.name}
|
| 136 |
+
</CardTitle>
|
| 137 |
+
</CardHeader>
|
| 138 |
+
<CardContent>
|
| 139 |
+
<QueueDistribution counts={q.counts} />
|
| 140 |
+
<div className="mt-4 grid grid-cols-5 gap-2 text-center">
|
| 141 |
+
{[
|
| 142 |
+
{ icon: CircleDot, label: "active", value: q.counts.active, cls: "text-[var(--color-info)]" },
|
| 143 |
+
{ icon: Loader2, label: "wait", value: q.counts.waiting, cls: "text-[var(--color-primary)]" },
|
| 144 |
+
{ icon: Clock3, label: "delay", value: q.counts.delayed, cls: "text-[var(--color-warning)]" },
|
| 145 |
+
{ icon: AlertTriangle, label: "failed", value: q.counts.failed, cls: "text-[var(--color-error)]" },
|
| 146 |
+
{ icon: CheckCircle2, label: "done", value: q.counts.completed, cls: "text-[var(--color-success)]" },
|
| 147 |
+
].map((m) => (
|
| 148 |
+
<div key={m.label}>
|
| 149 |
+
<m.icon className={`mx-auto size-4 ${m.cls}`} />
|
| 150 |
+
<p className="mt-1 text-sm font-semibold text-[var(--text-primary)]">{m.value}</p>
|
| 151 |
+
<p className="text-[10px] uppercase tracking-wide text-[var(--text-tertiary)]">{m.label}</p>
|
| 152 |
+
</div>
|
| 153 |
+
))}
|
| 154 |
+
</div>
|
| 155 |
+
<div className="mt-4 flex items-center justify-between border-t border-[var(--border-color)] pt-3">
|
| 156 |
+
<div className="flex items-center gap-1.5 text-xs">
|
| 157 |
+
<span className="inline-flex items-center justify-center size-1.5 rounded-full"
|
| 158 |
+
style={{ backgroundColor: q.counts.failed > 0 ? "var(--color-error)" : "var(--color-success)" }} />
|
| 159 |
+
<span className={q.counts.failed > 0 ? "text-[var(--color-error)]" : "text-[var(--color-success)]"}>
|
| 160 |
+
{q.counts.failed > 0 ? "alert" : "idle"}
|
| 161 |
+
</span>
|
| 162 |
+
</div>
|
| 163 |
+
<Badge tone="neutral" variant="subtle" size="sm">{q.counts.failed > 0 ? "needs triage" : "ok"}</Badge>
|
| 164 |
+
</div>
|
| 165 |
+
</CardContent>
|
| 166 |
+
</Card>
|
| 167 |
+
))}
|
| 168 |
+
</div>
|
| 169 |
+
|
| 170 |
+
{/* DLQ Inspector */}
|
| 171 |
+
<Card className="border border-[var(--border-color)]">
|
| 172 |
+
<CardHeader>
|
| 173 |
+
<CardTitle className="flex items-center gap-2">
|
| 174 |
+
<PauseCircle className="size-4 text-[var(--color-warning)]" /> DLQ Inspector
|
| 175 |
+
</CardTitle>
|
| 176 |
+
<CardDescription>
|
| 177 |
+
Retry failed jobs individually or in bulk, view stack traces and payloads,
|
| 178 |
+
pause/resume/drain queues.
|
| 179 |
+
</CardDescription>
|
| 180 |
+
</CardHeader>
|
| 181 |
+
<CardContent className="flex flex-wrap gap-2">
|
| 182 |
+
<Button variant="outline" size="sm" disabled={totalFailed === 0} onClick={() => {}}>
|
| 183 |
+
<RefreshCw className="size-4 mr-1" /> Retry Failed
|
| 184 |
+
</Button>
|
| 185 |
+
<Button variant="outline" size="sm" disabled={isFetching}>Pause Queue</Button>
|
| 186 |
+
<Button variant="outline" size="sm" disabled={isFetching}>Resume Queue</Button>
|
| 187 |
+
<Button variant="outline" size="sm" disabled={isFetching}>Drain Queue</Button>
|
| 188 |
+
<span className="self-center text-xs text-[var(--text-tertiary)]">
|
| 189 |
+
Failed-job mutations require backend wiring. Total failed: {totalFailed}.
|
| 190 |
+
</span>
|
| 191 |
+
</CardContent>
|
| 192 |
+
</Card>
|
| 193 |
+
</div>
|
| 194 |
+
</div>
|
| 195 |
+
);
|
| 196 |
+
}
|
apps/admin/src/app/(dashboard)/ratings/page.tsx
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Star, TrendingUp, Activity } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { cn } from "@/lib/utils";
|
| 7 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 8 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 9 |
+
import { Badge } from "@micprotocol/ui";
|
| 10 |
+
|
| 11 |
+
function ratingColor(rating: number) {
|
| 12 |
+
if (rating >= 4) return "var(--color-success)";
|
| 13 |
+
if (rating >= 3) return "var(--color-warning)";
|
| 14 |
+
return "var(--color-error)";
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
export default function RatingsPage() {
|
| 18 |
+
const { data: ratings, isLoading } = trpc.ratings.adminList.useQuery(
|
| 19 |
+
{ page: 1, limit: 50 },
|
| 20 |
+
{ refetchInterval: 30_000 },
|
| 21 |
+
);
|
| 22 |
+
|
| 23 |
+
const ratingsList = ratings?.items ?? [];
|
| 24 |
+
const totalRatings = ratingsList.length;
|
| 25 |
+
const averageRating =
|
| 26 |
+
totalRatings > 0
|
| 27 |
+
? ratingsList.reduce((sum, r) => sum + r.rating, 0) / totalRatings
|
| 28 |
+
: 0;
|
| 29 |
+
|
| 30 |
+
const distribution: Record<number, number> = { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0 };
|
| 31 |
+
for (const r of ratingsList) {
|
| 32 |
+
distribution[r.rating] = (distribution[r.rating] ?? 0) + 1;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
return (
|
| 36 |
+
<div className="animate-fade-in">
|
| 37 |
+
<AdminHeader
|
| 38 |
+
title="Service Ratings"
|
| 39 |
+
subtitle="User satisfaction ratings across the platform"
|
| 40 |
+
refreshing={isLoading}
|
| 41 |
+
/>
|
| 42 |
+
|
| 43 |
+
<div className="space-y-6 p-6">
|
| 44 |
+
{/* KPI cards */}
|
| 45 |
+
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
| 46 |
+
<Card>
|
| 47 |
+
<CardContent className="p-5">
|
| 48 |
+
<div className="flex items-start justify-between">
|
| 49 |
+
<div>
|
| 50 |
+
<p className="text-sm text-[var(--text-secondary)]">Average Rating</p>
|
| 51 |
+
<p className={`mt-2 font-display text-3xl font-bold text-[${ratingColor(Math.round(averageRating))}]`}>
|
| 52 |
+
{isLoading ? "β" : averageRating.toFixed(1)} / 5
|
| 53 |
+
</p>
|
| 54 |
+
<p className="mt-1 text-xs text-[var(--text-tertiary)]">
|
| 55 |
+
{totalRatings} total ratings
|
| 56 |
+
</p>
|
| 57 |
+
</div>
|
| 58 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-2.5">
|
| 59 |
+
<Star className="size-5 text-[var(--color-warning)]" />
|
| 60 |
+
</div>
|
| 61 |
+
</div>
|
| 62 |
+
</CardContent>
|
| 63 |
+
</Card>
|
| 64 |
+
|
| 65 |
+
<Card>
|
| 66 |
+
<CardContent className="p-5">
|
| 67 |
+
<div className="flex items-start justify-between">
|
| 68 |
+
<div>
|
| 69 |
+
<p className="text-sm text-[var(--text-secondary)]">5-Star Ratings</p>
|
| 70 |
+
<p className="mt-2 font-display text-3xl font-bold text-[var(--text-primary)]">
|
| 71 |
+
{distribution[5]}
|
| 72 |
+
</p>
|
| 73 |
+
<p className="mt-1 text-xs text-[var(--text-tertiary)]">
|
| 74 |
+
{totalRatings > 0 ? ((distribution[5] / totalRatings) * 100).toFixed(0) + "%" : "0%"}
|
| 75 |
+
</p>
|
| 76 |
+
</div>
|
| 77 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-2.5">
|
| 78 |
+
<Star className="size-5 text-[var(--text-tertiary)]" />
|
| 79 |
+
</div>
|
| 80 |
+
</div>
|
| 81 |
+
</CardContent>
|
| 82 |
+
</Card>
|
| 83 |
+
|
| 84 |
+
<Card>
|
| 85 |
+
<CardContent className="p-5">
|
| 86 |
+
<div className="flex items-start justify-between">
|
| 87 |
+
<div>
|
| 88 |
+
<p className="text-sm text-[var(--text-secondary)]">4+ Star Ratings</p>
|
| 89 |
+
<p className="mt-2 font-display text-3xl font-bold text-[var(--text-primary)]">
|
| 90 |
+
{distribution[4] + distribution[5]}
|
| 91 |
+
</p>
|
| 92 |
+
<p className="mt-1 text-xs text-[var(--text-tertiary)]">
|
| 93 |
+
Positive sentiment
|
| 94 |
+
</p>
|
| 95 |
+
</div>
|
| 96 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-2.5">
|
| 97 |
+
<TrendingUp className="size-5 text-[var(--color-success)]" />
|
| 98 |
+
</div>
|
| 99 |
+
</div>
|
| 100 |
+
</CardContent>
|
| 101 |
+
</Card>
|
| 102 |
+
|
| 103 |
+
<Card>
|
| 104 |
+
<CardContent className="p-5">
|
| 105 |
+
<div className="flex items-start justify-between">
|
| 106 |
+
<div>
|
| 107 |
+
<p className="text-sm text-[var(--text-secondary)]">1-2 Star Ratings</p>
|
| 108 |
+
<p className="mt-2 font-display text-3xl font-bold text-[var(--text-primary)]">
|
| 109 |
+
{distribution[1] + distribution[2]}
|
| 110 |
+
</p>
|
| 111 |
+
<p className="mt-1 text-xs text-[var(--text-tertiary)]">
|
| 112 |
+
Needs attention
|
| 113 |
+
</p>
|
| 114 |
+
</div>
|
| 115 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-2.5">
|
| 116 |
+
<Activity className="size-5 text-[var(--color-error)]" />
|
| 117 |
+
</div>
|
| 118 |
+
</div>
|
| 119 |
+
</CardContent>
|
| 120 |
+
</Card>
|
| 121 |
+
</div>
|
| 122 |
+
|
| 123 |
+
{/* Rating distribution */}
|
| 124 |
+
<Card>
|
| 125 |
+
<CardHeader>
|
| 126 |
+
<CardTitle className="flex items-center gap-2">
|
| 127 |
+
<Star className="size-4 text-[var(--color-warning)]" /> Rating Distribution
|
| 128 |
+
</CardTitle>
|
| 129 |
+
</CardHeader>
|
| 130 |
+
<CardContent>
|
| 131 |
+
<div className="space-y-3">
|
| 132 |
+
{[5, 4, 3, 2, 1].map((star) => {
|
| 133 |
+
const count = distribution[star] ?? 0;
|
| 134 |
+
const pct = totalRatings > 0 ? (count / totalRatings) * 100 : 0;
|
| 135 |
+
return (
|
| 136 |
+
<div key={star} className="flex items-center gap-3">
|
| 137 |
+
<div className="w-8 flex items-center">
|
| 138 |
+
{Array.from({ length: 5 }, (_, i) => (
|
| 139 |
+
<span
|
| 140 |
+
key={i}
|
| 141 |
+
className={cn(
|
| 142 |
+
"text-xs",
|
| 143 |
+
i < star ? "text-[var(--color-warning)]" : "text-[var(--text-tertiary)]",
|
| 144 |
+
)}
|
| 145 |
+
>
|
| 146 |
+
β
|
| 147 |
+
</span>
|
| 148 |
+
))}
|
| 149 |
+
</div>
|
| 150 |
+
<div className="flex-1">
|
| 151 |
+
<div className="h-2 w-full overflow-hidden rounded-full bg-[var(--bg-tertiary)]">
|
| 152 |
+
<div
|
| 153 |
+
className="h-full rounded-full bg-[var(--color-warning)]"
|
| 154 |
+
style={{ width: `${pct.toFixed(0)}%` }}
|
| 155 |
+
/>
|
| 156 |
+
</div>
|
| 157 |
+
</div>
|
| 158 |
+
<div className="w-16 text-right text-sm">
|
| 159 |
+
<span className="font-medium text-[var(--text-primary)]">{count}</span>
|
| 160 |
+
<span className="text-[var(--text-tertiary)]"> ({pct.toFixed(0)}%)</span>
|
| 161 |
+
</div>
|
| 162 |
+
</div>
|
| 163 |
+
);
|
| 164 |
+
})}
|
| 165 |
+
</div>
|
| 166 |
+
</CardContent>
|
| 167 |
+
</Card>
|
| 168 |
+
|
| 169 |
+
{/* Recent ratings table */}
|
| 170 |
+
<Card>
|
| 171 |
+
<CardHeader>
|
| 172 |
+
<CardTitle className="flex items-center gap-2">
|
| 173 |
+
<Activity className="size-4 text-[var(--color-info)]" /> Recent Ratings
|
| 174 |
+
</CardTitle>
|
| 175 |
+
</CardHeader>
|
| 176 |
+
<CardContent>
|
| 177 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 178 |
+
<table className="w-full text-left border-collapse">
|
| 179 |
+
<thead>
|
| 180 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 181 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">User</th>
|
| 182 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-20">Service Type</th>
|
| 183 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-20">Rating</th>
|
| 184 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Comment</th>
|
| 185 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-32">Date</th>
|
| 186 |
+
</tr>
|
| 187 |
+
</thead>
|
| 188 |
+
<tbody>
|
| 189 |
+
{ratingsList.slice(0, 20).map((r) => (
|
| 190 |
+
<tr key={r.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 191 |
+
<td className="py-4 font-medium text-[var(--text-primary)]">
|
| 192 |
+
{r.userId.slice(0, 8)}β¦
|
| 193 |
+
</td>
|
| 194 |
+
<td className="py-4 text-sm text-[var(--text-secondary)]">
|
| 195 |
+
{r.serviceType}
|
| 196 |
+
</td>
|
| 197 |
+
<td className={`py-4 font-mono text-[${ratingColor(r.rating)}]`}>
|
| 198 |
+
{r.rating} / 5
|
| 199 |
+
</td>
|
| 200 |
+
<td className="py-4 text-sm text-[var(--text-secondary)]">
|
| 201 |
+
{r.comment ?? "β"}
|
| 202 |
+
</td>
|
| 203 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)]">
|
| 204 |
+
{new Date(r.createdAt).toLocaleDateString()}
|
| 205 |
+
</td>
|
| 206 |
+
</tr>
|
| 207 |
+
))}
|
| 208 |
+
{ratingsList.length === 0 && (
|
| 209 |
+
<tr>
|
| 210 |
+
<td colSpan={5} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 211 |
+
No ratings yet.
|
| 212 |
+
</td>
|
| 213 |
+
</tr>
|
| 214 |
+
)}
|
| 215 |
+
</tbody>
|
| 216 |
+
</table>
|
| 217 |
+
</div>
|
| 218 |
+
</CardContent>
|
| 219 |
+
</Card>
|
| 220 |
+
</div>
|
| 221 |
+
</div>
|
| 222 |
+
);
|
| 223 |
+
}
|
apps/admin/src/app/(dashboard)/realtime/page.tsx
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Activity, ShieldCheck, Server, Database, Clock, AlertCircle } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { cn } from "@/lib/utils";
|
| 7 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 8 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 9 |
+
import { Badge } from "@micprotocol/ui";
|
| 10 |
+
import { Button } from "@micprotocol/ui";
|
| 11 |
+
|
| 12 |
+
export default function RealtimePage() {
|
| 13 |
+
const { data: beamStats, isLoading: beamLoading } = trpc.admin.realtime.stats.useQuery(
|
| 14 |
+
undefined,
|
| 15 |
+
{ refetchInterval: 10_000 },
|
| 16 |
+
) as any;
|
| 17 |
+
const { data: rooms, isLoading: roomsLoading } = trpc.admin.realtime.traces.useQuery(
|
| 18 |
+
{ limit: 50 },
|
| 19 |
+
{ refetchInterval: 10_000 },
|
| 20 |
+
);
|
| 21 |
+
|
| 22 |
+
const roomsList = ((rooms as any)?.traces ?? []) as any[];
|
| 23 |
+
const totalRooms = roomsList.length;
|
| 24 |
+
const totalMessages = roomsList.reduce((sum, r) => sum + (r.messageCount ?? 0), 0);
|
| 25 |
+
const totalConnections = roomsList.reduce((sum, r) => sum + (r.connectionCount ?? 0), 0);
|
| 26 |
+
|
| 27 |
+
return (
|
| 28 |
+
<div className="animate-fade-in">
|
| 29 |
+
<AdminHeader
|
| 30 |
+
title="Realtime (BEAM)"
|
| 31 |
+
subtitle="Elixir BEAM cluster β rooms, messages, connections, and process pressure"
|
| 32 |
+
refreshing={beamLoading || roomsLoading}
|
| 33 |
+
/>
|
| 34 |
+
|
| 35 |
+
<div className="space-y-6 p-6">
|
| 36 |
+
{/* KPI strip */}
|
| 37 |
+
<div className="grid gap-4 sm:grid-cols-4">
|
| 38 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 39 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Active Rooms</p>
|
| 40 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{totalRooms}</p>
|
| 41 |
+
</Card>
|
| 42 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 43 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Connections</p>
|
| 44 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-primary)]">{totalConnections}</p>
|
| 45 |
+
</Card>
|
| 46 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 47 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Messages Posted</p>
|
| 48 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-info)]">{totalMessages}</p>
|
| 49 |
+
</Card>
|
| 50 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 51 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Process Pressure</p>
|
| 52 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-warning)]">
|
| 53 |
+
{beamStats?.processPressure?.toFixed(1) ?? 0}%
|
| 54 |
+
</p>
|
| 55 |
+
</Card>
|
| 56 |
+
</div>
|
| 57 |
+
|
| 58 |
+
{/* Rooms table */}
|
| 59 |
+
<Card>
|
| 60 |
+
<CardHeader>
|
| 61 |
+
<CardTitle className="flex items-center gap-2">
|
| 62 |
+
<Activity className="size-4 text-[var(--color-primary)]" /> Active Rooms
|
| 63 |
+
</CardTitle>
|
| 64 |
+
</CardHeader>
|
| 65 |
+
<CardContent className="p-0">
|
| 66 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 67 |
+
<table className="w-full text-left border-collapse">
|
| 68 |
+
<thead>
|
| 69 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 70 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-32">Room ID</th>
|
| 71 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Type</th>
|
| 72 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Connections</th>
|
| 73 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Messages</th>
|
| 74 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Status</th>
|
| 75 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Last Activity</th>
|
| 76 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Actions</th>
|
| 77 |
+
</tr>
|
| 78 |
+
</thead>
|
| 79 |
+
<tbody>
|
| 80 |
+
{roomsLoading ? (
|
| 81 |
+
[...Array(5)].map((_, i) => (
|
| 82 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 83 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 84 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 85 |
+
</td>
|
| 86 |
+
</tr>
|
| 87 |
+
))
|
| 88 |
+
) : roomsList.length === 0 ? (
|
| 89 |
+
<tr>
|
| 90 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 91 |
+
No active rooms.
|
| 92 |
+
</td>
|
| 93 |
+
</tr>
|
| 94 |
+
) : (
|
| 95 |
+
roomsList.map((r: any) => (
|
| 96 |
+
<tr key={r.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 97 |
+
<td className="py-4 font-mono text-xs text-[var(--text-secondary)]">
|
| 98 |
+
{r.id.slice(0, 8)}β¦
|
| 99 |
+
</td>
|
| 100 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] font-mono capitalize">{r.roomType}</td>
|
| 101 |
+
<td className="py-4 text-xs text-center font-mono text-[var(--text-primary)]">{r.connectionCount ?? 0}</td>
|
| 102 |
+
<td className="py-4 text-xs text-center font-mono text-[var(--text-primary)]">{r.messageCount ?? 0}</td>
|
| 103 |
+
<td className="py-4 text-xs text-center">
|
| 104 |
+
<Badge className={cn("capitalize text-xs", roomStatusClass(r.status))}>
|
| 105 |
+
{r.status}
|
| 106 |
+
</Badge>
|
| 107 |
+
</td>
|
| 108 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)] text-right">{new Date(r.lastActivityAt).toLocaleTimeString()}</td>
|
| 109 |
+
<td className="py-4 text-sm text-right">
|
| 110 |
+
<Button variant="ghost" size="sm" onClick={() => {}}>
|
| 111 |
+
<Clock size={14} />
|
| 112 |
+
</Button>
|
| 113 |
+
</td>
|
| 114 |
+
</tr>
|
| 115 |
+
))
|
| 116 |
+
)}
|
| 117 |
+
</tbody>
|
| 118 |
+
</table>
|
| 119 |
+
</div>
|
| 120 |
+
</CardContent>
|
| 121 |
+
</Card>
|
| 122 |
+
|
| 123 |
+
{/* BEAM metrics */}
|
| 124 |
+
<Card>
|
| 125 |
+
<CardHeader>
|
| 126 |
+
<CardTitle className="flex items-center gap-2">
|
| 127 |
+
<Server className="size-4 text-[var(--color-info)]" /> BEAM Process Pressure
|
| 128 |
+
</CardTitle>
|
| 129 |
+
</CardHeader>
|
| 130 |
+
<CardContent className="p-5">
|
| 131 |
+
<div className="grid gap-4 sm:grid-cols-3">
|
| 132 |
+
<div className="p-4 rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] border border-[var(--border-color-subtle)]">
|
| 133 |
+
<p className="text-[10px] text-[var(--text-tertiary)] uppercase tracking-wider font-medium">Reductions/sec</p>
|
| 134 |
+
<p className="mt-1 font-display text-2xl font-bold text-[var(--text-primary)]">
|
| 135 |
+
{beamStats?.reductionsPerSecond?.toFixed(0) ?? 0}
|
| 136 |
+
</p>
|
| 137 |
+
</div>
|
| 138 |
+
<div className="p-4 rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] border border-[var(--border-color-subtle)]">
|
| 139 |
+
<p className="text-[10px] text-[var(--text-tertiary)] uppercase tracking-wider font-medium">Memory (MB)</p>
|
| 140 |
+
<p className="mt-1 font-display text-2xl font-bold text-[var(--text-primary)]">
|
| 141 |
+
{beamStats?.memoryMb?.toFixed(0) ?? 0}
|
| 142 |
+
</p>
|
| 143 |
+
</div>
|
| 144 |
+
<div className="p-4 rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] border border-[var(--border-color-subtle)]">
|
| 145 |
+
<p className="text-[10px] text-[var(--text-tertiary)] uppercase tracking-wider font-medium">Processes</p>
|
| 146 |
+
<p className="mt-1 font-display text-2xl font-bold text-[var(--text-primary)]">
|
| 147 |
+
{beamStats?.processCount ?? 0}
|
| 148 |
+
</p>
|
| 149 |
+
</div>
|
| 150 |
+
</div>
|
| 151 |
+
<div className="mt-4 h-2 w-full bg-[var(--bg-tertiary)] rounded-full overflow-hidden">
|
| 152 |
+
<div
|
| 153 |
+
className="h-full bg-[var(--color-primary)]"
|
| 154 |
+
style={{ width: Math.min((beamStats?.processPressure ?? 0), 100) }}
|
| 155 |
+
/>
|
| 156 |
+
</div>
|
| 157 |
+
<p className="mt-2 text-[10px] text-[var(--text-tertiary)] text-right">
|
| 158 |
+
Pressure: {beamStats?.processPressure?.toFixed(1) ?? 0}%
|
| 159 |
+
</p>
|
| 160 |
+
</CardContent>
|
| 161 |
+
</Card>
|
| 162 |
+
|
| 163 |
+
{/* Prometheus metrics */}
|
| 164 |
+
<Card>
|
| 165 |
+
<CardHeader>
|
| 166 |
+
<CardTitle className="flex items-center gap-2">
|
| 167 |
+
<Database className="size-4 text-[var(--color-primary)]" /> Prometheus Metrics
|
| 168 |
+
</CardTitle>
|
| 169 |
+
</CardHeader>
|
| 170 |
+
<CardContent className="p-5">
|
| 171 |
+
<div className="grid gap-4 sm:grid-cols-3">
|
| 172 |
+
<div className="p-4 rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] border border-[var(--border-color-subtle)]">
|
| 173 |
+
<p className="text-[10px] text-[var(--text-tertiary)] uppercase tracking-wider font-medium">HTTP Requests</p>
|
| 174 |
+
<p className="mt-1 font-display text-2xl font-bold text-[var(--text-primary)]">{beamStats?.httpRequestsPerSecond?.toFixed(1) ?? 0} /s</p>
|
| 175 |
+
</div>
|
| 176 |
+
<div className="p-4 rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] border border-[var(--border-color-subtle)]">
|
| 177 |
+
<p className="text-[10px] text-[var(--text-tertiary)] uppercase tracking-wider font-medium">WebSocket Frames</p>
|
| 178 |
+
<p className="mt-1 font-display text-2xl font-bold text-[var(--text-primary)]">{beamStats?.wsFramesPerSecond?.toFixed(1) ?? 0} /s</p>
|
| 179 |
+
</div>
|
| 180 |
+
<div className="p-4 rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] border border-[var(--border-color-subtle)]">
|
| 181 |
+
<p className="text-[10px] text-[var(--text-tertiary)] uppercase tracking-wider font-medium">GC Runs</p>
|
| 182 |
+
<p className="mt-1 font-display text-2xl font-bold text-[var(--text-primary)]">{beamStats?.gcRuns ?? 0}</p>
|
| 183 |
+
</div>
|
| 184 |
+
</div>
|
| 185 |
+
</CardContent>
|
| 186 |
+
</Card>
|
| 187 |
+
|
| 188 |
+
{/* Traces */}
|
| 189 |
+
<Card>
|
| 190 |
+
<CardHeader>
|
| 191 |
+
<CardTitle className="flex items-center gap-2">
|
| 192 |
+
<AlertCircle className="size-4 text-[var(--color-warning)]" /> Recent Traces
|
| 193 |
+
</CardTitle>
|
| 194 |
+
</CardHeader>
|
| 195 |
+
<CardContent className="p-0">
|
| 196 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 197 |
+
<table className="w-full text-left border-collapse">
|
| 198 |
+
<thead>
|
| 199 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 200 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-28">Trace ID</th>
|
| 201 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-28">Span</th>
|
| 202 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Duration</th>
|
| 203 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Status</th>
|
| 204 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Timestamp</th>
|
| 205 |
+
</tr>
|
| 206 |
+
</thead>
|
| 207 |
+
<tbody>
|
| 208 |
+
{beamStats?.recentTraces?.length ? (
|
| 209 |
+
beamStats.recentTraces.map((t: any) => (
|
| 210 |
+
<tr key={t.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 211 |
+
<td className="py-4 font-mono text-xs text-[var(--text-secondary)]">{t.id.slice(0, 8)}β¦</td>
|
| 212 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] font-mono">{t.span}</td>
|
| 213 |
+
<td className="py-4 text-xs text-center font-mono text-[var(--text-primary)]">{t.durationMs?.toFixed(1) ?? "β"} ms</td>
|
| 214 |
+
<td className="py-4 text-xs text-center">
|
| 215 |
+
<Badge className={cn("capitalize text-xs", traceStatusClass(t.status))}>
|
| 216 |
+
{t.status}
|
| 217 |
+
</Badge>
|
| 218 |
+
</td>
|
| 219 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)] text-right">{new Date(t.timestamp).toLocaleTimeString()}</td>
|
| 220 |
+
</tr>
|
| 221 |
+
))
|
| 222 |
+
) : (
|
| 223 |
+
<tr>
|
| 224 |
+
<td colSpan={5} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 225 |
+
No recent traces.
|
| 226 |
+
</td>
|
| 227 |
+
</tr>
|
| 228 |
+
)}
|
| 229 |
+
</tbody>
|
| 230 |
+
</table>
|
| 231 |
+
</div>
|
| 232 |
+
</CardContent>
|
| 233 |
+
</Card>
|
| 234 |
+
</div>
|
| 235 |
+
</div>
|
| 236 |
+
);
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
function roomStatusClass(s: string): string {
|
| 240 |
+
switch (s) {
|
| 241 |
+
case "active": return "bg-[var(--color-success)]/20 border-[var(--color-success)]/30 text-[var(--color-success)]";
|
| 242 |
+
case "idle": return "border-transparent text-[var(--text-tertiary)]";
|
| 243 |
+
case "closing": return "bg-[var(--color-warning)]/20 border-[var(--color-warning)]/30 text-[var(--color-warning)]";
|
| 244 |
+
default: return "border-transparent";
|
| 245 |
+
}
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
function traceStatusClass(s: string): string {
|
| 249 |
+
switch (s) {
|
| 250 |
+
case "ok": return "bg-[var(--color-success)]/20 border-[var(--color-success)]/30 text-[var(--color-success)]";
|
| 251 |
+
case "error": return "bg-[var(--color-error)]/20 border-[var(--color-error)]/30 text-[var(--color-error)]";
|
| 252 |
+
default: return "border-transparent text-[var(--text-tertiary)]";
|
| 253 |
+
}
|
| 254 |
+
}
|
apps/admin/src/app/(dashboard)/security-policy/page.tsx
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState } from "react";
|
| 4 |
+
import Link from "next/link";
|
| 5 |
+
import { useRouter } from "next/navigation";
|
| 6 |
+
import { trpc } from "@/lib/trpc";
|
| 7 |
+
import { cn } from "@/lib/utils";
|
| 8 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 9 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 10 |
+
import { Badge } from "@micprotocol/ui";
|
| 11 |
+
import { Button } from "@micprotocol/ui";
|
| 12 |
+
import { Input } from "@micprotocol/ui";
|
| 13 |
+
import { ShieldAlert, ShieldCheck, Clock, Trash2, Edit, Activity } from "lucide-react";
|
| 14 |
+
|
| 15 |
+
function severityBadge(severity: string) {
|
| 16 |
+
const variants: Record<string, string> = {
|
| 17 |
+
low: "bg-[var(--color-info)]/10 border-[var(--color-info)]/20 text-[var(--color-info)]",
|
| 18 |
+
medium: "bg-[var(--color-warning)]/10 border-[var(--color-warning)]/20 text-[var(--color-warning)]",
|
| 19 |
+
high: "bg-[var(--color-error)]/10 border-[var(--color-error)]/20 text-[var(--color-error)]",
|
| 20 |
+
critical: "bg-[var(--color-error)] border-[var(--color-error)] text-[var(--text-primary)]",
|
| 21 |
+
};
|
| 22 |
+
return (
|
| 23 |
+
<Badge className={cn("capitalize", variants[severity])}>
|
| 24 |
+
{severity}
|
| 25 |
+
</Badge>
|
| 26 |
+
);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
function blocklistTypeBadge(type: string) {
|
| 30 |
+
const labels: Record<string, string> = {
|
| 31 |
+
EMAIL_DOMAIN: "Email Domain",
|
| 32 |
+
IP_RANGE: "IP Range",
|
| 33 |
+
WORKSPACE_SLUG: "Workspace Slug",
|
| 34 |
+
};
|
| 35 |
+
return (
|
| 36 |
+
<Badge className="text-xs border-transparent capitalize">
|
| 37 |
+
{labels[type] ?? type}
|
| 38 |
+
</Badge>
|
| 39 |
+
);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
export default function SecurityPolicyPage() {
|
| 43 |
+
const [blocklistType, setBlocklistType] = useState<
|
| 44 |
+
| "EMAIL_DOMAIN"
|
| 45 |
+
| "IP_RANGE"
|
| 46 |
+
| "WORKSPACE_SLUG"
|
| 47 |
+
| undefined
|
| 48 |
+
>();
|
| 49 |
+
const [newBlocklistValue, setNewBlocklistValue] = useState("");
|
| 50 |
+
const [newBlocklistReason, setNewBlocklistReason] = useState("");
|
| 51 |
+
|
| 52 |
+
const { data: reviewQueue, isLoading: queueLoading } =
|
| 53 |
+
trpc.securityPolicy.reviewQueue.useQuery(
|
| 54 |
+
{ limit: 20 },
|
| 55 |
+
{ refetchInterval: 30_000, retry: false },
|
| 56 |
+
);
|
| 57 |
+
|
| 58 |
+
const { data: blocklist, isLoading: blocklistLoading } =
|
| 59 |
+
trpc.securityPolicy.listBlocklist.useQuery(
|
| 60 |
+
{ activeOnly: true, type: blocklistType },
|
| 61 |
+
{ refetchInterval: 60_000, retry: false },
|
| 62 |
+
);
|
| 63 |
+
|
| 64 |
+
const flagDocument = trpc.securityPolicy.flagDocument.useMutation({
|
| 65 |
+
onSuccess: () => {
|
| 66 |
+
// reviewQueue refetches via refetchInterval (30s)
|
| 67 |
+
},
|
| 68 |
+
});
|
| 69 |
+
|
| 70 |
+
const revokeDocument = trpc.securityPolicy.revokeDocument.useMutation({
|
| 71 |
+
onSuccess: () => {
|
| 72 |
+
// reviewQueue refetches via refetchInterval (30s)
|
| 73 |
+
},
|
| 74 |
+
});
|
| 75 |
+
|
| 76 |
+
const addToBlocklist = trpc.securityPolicy.addToBlocklist.useMutation({
|
| 77 |
+
onSuccess: () => {
|
| 78 |
+
setNewBlocklistValue("");
|
| 79 |
+
setNewBlocklistReason("");
|
| 80 |
+
},
|
| 81 |
+
});
|
| 82 |
+
|
| 83 |
+
const removeFromBlocklist = trpc.securityPolicy.removeFromBlocklist.useMutation({
|
| 84 |
+
onSuccess: () => {
|
| 85 |
+
// listBlocklist refetches via refetchInterval (60s)
|
| 86 |
+
},
|
| 87 |
+
});
|
| 88 |
+
|
| 89 |
+
const flags = reviewQueue?.items ?? [];
|
| 90 |
+
const queueTotal = reviewQueue?.total ?? 0;
|
| 91 |
+
const openFlags = flags.filter((f) => f.status === "OPEN").length;
|
| 92 |
+
const criticalFlags = flags.filter((f) => f.severity === "critical").length;
|
| 93 |
+
|
| 94 |
+
const entries = blocklist ?? [];
|
| 95 |
+
const activeEntries = entries.filter((e) => e.isActive).length;
|
| 96 |
+
|
| 97 |
+
const router = useRouter();
|
| 98 |
+
|
| 99 |
+
const handleRefresh = () => {
|
| 100 |
+
router.refresh();
|
| 101 |
+
};
|
| 102 |
+
|
| 103 |
+
return (
|
| 104 |
+
<div className="animate-fade-in">
|
| 105 |
+
<AdminHeader
|
| 106 |
+
title="Security Policy"
|
| 107 |
+
subtitle="Document forgery prevention, sanction screening, and admin takedown controls"
|
| 108 |
+
refreshing={queueLoading || blocklistLoading}
|
| 109 |
+
actions={
|
| 110 |
+
<Button
|
| 111 |
+
variant="outline"
|
| 112 |
+
size="sm"
|
| 113 |
+
onClick={handleRefresh}
|
| 114 |
+
>
|
| 115 |
+
<Clock size={14} /> Refresh
|
| 116 |
+
</Button>
|
| 117 |
+
}
|
| 118 |
+
/>
|
| 119 |
+
|
| 120 |
+
<div className="space-y-6 p-6">
|
| 121 |
+
{/* KPI cards */}
|
| 122 |
+
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
| 123 |
+
<Card>
|
| 124 |
+
<CardContent className="p-5">
|
| 125 |
+
<div className="flex items-start justify-between">
|
| 126 |
+
<div>
|
| 127 |
+
<p className="text-sm text-[var(--text-secondary)]">Flagged Documents</p>
|
| 128 |
+
<p className="mt-2 font-display text-3xl font-bold text-[var(--color-warning)]">
|
| 129 |
+
{openFlags}
|
| 130 |
+
</p>
|
| 131 |
+
</div>
|
| 132 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--color-warning)]/10 p-2.5">
|
| 133 |
+
<ShieldAlert className="size-5 text-[var(--color-warning)]" />
|
| 134 |
+
</div>
|
| 135 |
+
</div>
|
| 136 |
+
</CardContent>
|
| 137 |
+
</Card>
|
| 138 |
+
|
| 139 |
+
<Card>
|
| 140 |
+
<CardContent className="p-5">
|
| 141 |
+
<div className="flex items-start justify-between">
|
| 142 |
+
<div>
|
| 143 |
+
<p className="text-sm text-[var(--text-secondary)]">Critical Flags</p>
|
| 144 |
+
<p className="mt-2 font-display text-3xl font-bold text-[var(--color-error)]">
|
| 145 |
+
{criticalFlags}
|
| 146 |
+
</p>
|
| 147 |
+
</div>
|
| 148 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--color-error)]/10 p-2.5">
|
| 149 |
+
<ShieldAlert className="size-5 text-[var(--color-error)]" />
|
| 150 |
+
</div>
|
| 151 |
+
</div>
|
| 152 |
+
</CardContent>
|
| 153 |
+
</Card>
|
| 154 |
+
|
| 155 |
+
<Card>
|
| 156 |
+
<CardContent className="p-5">
|
| 157 |
+
<div className="flex items-start justify-between">
|
| 158 |
+
<div>
|
| 159 |
+
<p className="text-sm text-[var(--text-secondary)]">Blocklist Entries</p>
|
| 160 |
+
<p className="mt-2 font-display text-3xl font-bold text-[var(--text-primary)]">
|
| 161 |
+
{activeEntries}
|
| 162 |
+
</p>
|
| 163 |
+
</div>
|
| 164 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-2.5">
|
| 165 |
+
<ShieldCheck className="size-5 text-[var(--color-info)]" />
|
| 166 |
+
</div>
|
| 167 |
+
</div>
|
| 168 |
+
</CardContent>
|
| 169 |
+
</Card>
|
| 170 |
+
|
| 171 |
+
<Card>
|
| 172 |
+
<CardContent className="p-5">
|
| 173 |
+
<div className="flex items-start justify-between">
|
| 174 |
+
<div>
|
| 175 |
+
<p className="text-sm text-[var(--text-secondary)]">Review Queue</p>
|
| 176 |
+
<p className="mt-2 font-display text-3xl font-bold text-[var(--text-primary)]">
|
| 177 |
+
{queueTotal}
|
| 178 |
+
</p>
|
| 179 |
+
</div>
|
| 180 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-2.5">
|
| 181 |
+
<Activity className="size-5 text-[var(--text-secondary)]" />
|
| 182 |
+
</div>
|
| 183 |
+
</div>
|
| 184 |
+
</CardContent>
|
| 185 |
+
</Card>
|
| 186 |
+
</div>
|
| 187 |
+
|
| 188 |
+
{/* Review Queue Section */}
|
| 189 |
+
<Card>
|
| 190 |
+
<CardHeader>
|
| 191 |
+
<CardTitle className="flex items-center gap-2">
|
| 192 |
+
<ShieldAlert className="size-4 text-[var(--color-warning)]" />
|
| 193 |
+
Flagged Documents β Review Queue
|
| 194 |
+
</CardTitle>
|
| 195 |
+
</CardHeader>
|
| 196 |
+
<CardContent>
|
| 197 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 198 |
+
<table className="w-full text-left border-collapse">
|
| 199 |
+
<thead>
|
| 200 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 201 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Document</th>
|
| 202 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Workspace</th>
|
| 203 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Severity</th>
|
| 204 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Status</th>
|
| 205 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-24">Reason</th>
|
| 206 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-32">Created</th>
|
| 207 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-48">Actions</th>
|
| 208 |
+
</tr>
|
| 209 |
+
</thead>
|
| 210 |
+
<tbody>
|
| 211 |
+
{flags.length === 0 && (
|
| 212 |
+
<tr>
|
| 213 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 214 |
+
No flagged documents. All clear.
|
| 215 |
+
</td>
|
| 216 |
+
</tr>
|
| 217 |
+
)}
|
| 218 |
+
{flags.map((flag: any) => (
|
| 219 |
+
<tr
|
| 220 |
+
key={flag.id}
|
| 221 |
+
className="cursor-pointer hover:bg-[var(--bg-tertiary)]/50 transition-colors border-b border-[var(--border-color-subtle)]"
|
| 222 |
+
>
|
| 223 |
+
<td className="py-4 font-medium text-[var(--text-primary)]">
|
| 224 |
+
<Link
|
| 225 |
+
href={`/documents/${flag.documentId}`}
|
| 226 |
+
className="hover:text-[var(--color-primary)]"
|
| 227 |
+
>
|
| 228 |
+
{flag.documentTitle ?? "Unknown Document"}
|
| 229 |
+
</Link>
|
| 230 |
+
</td>
|
| 231 |
+
<td className="py-4 text-sm text-[var(--text-secondary)] text-center">
|
| 232 |
+
{flag.workspaceId.slice(0, 8)}β¦
|
| 233 |
+
</td>
|
| 234 |
+
<td className="py-4 text-sm text-center">
|
| 235 |
+
{severityBadge(flag.severity)}
|
| 236 |
+
</td>
|
| 237 |
+
<td className="py-4 text-sm text-center">
|
| 238 |
+
<Badge className="text-xs capitalize">
|
| 239 |
+
{flag.status}
|
| 240 |
+
</Badge>
|
| 241 |
+
</td>
|
| 242 |
+
<td className="py-4 text-sm text-[var(--text-secondary)] truncate" style={{ maxWidth: 200 }}>
|
| 243 |
+
{flag.reason}
|
| 244 |
+
</td>
|
| 245 |
+
<td className="py-4 text-sm text-right text-[var(--text-tertiary)]">
|
| 246 |
+
{new Date(flag.createdAt).toLocaleDateString()}
|
| 247 |
+
</td>
|
| 248 |
+
<td className="py-4 text-sm text-right">
|
| 249 |
+
<div className="flex gap-1 justify-end">
|
| 250 |
+
<Button
|
| 251 |
+
variant="ghost"
|
| 252 |
+
size="sm"
|
| 253 |
+
onClick={() =>
|
| 254 |
+
flagDocument.mutate({
|
| 255 |
+
documentId: flag.documentId,
|
| 256 |
+
workspaceId: flag.workspaceId,
|
| 257 |
+
reason: "Manual review flag",
|
| 258 |
+
severity: "medium",
|
| 259 |
+
})
|
| 260 |
+
}
|
| 261 |
+
>
|
| 262 |
+
<Edit size={14} />
|
| 263 |
+
</Button>
|
| 264 |
+
<Button
|
| 265 |
+
variant="destructive"
|
| 266 |
+
size="sm"
|
| 267 |
+
onClick={() =>
|
| 268 |
+
revokeDocument.mutate({
|
| 269 |
+
documentId: flag.documentId,
|
| 270 |
+
workspaceId: flag.workspaceId,
|
| 271 |
+
})
|
| 272 |
+
}
|
| 273 |
+
>
|
| 274 |
+
<Trash2 size={14} />
|
| 275 |
+
</Button>
|
| 276 |
+
</div>
|
| 277 |
+
</td>
|
| 278 |
+
</tr>
|
| 279 |
+
))}
|
| 280 |
+
</tbody>
|
| 281 |
+
</table>
|
| 282 |
+
</div>
|
| 283 |
+
</CardContent>
|
| 284 |
+
</Card>
|
| 285 |
+
|
| 286 |
+
{/* Blocklist Management Section */}
|
| 287 |
+
<div className="grid lg:grid-cols-2 gap-6">
|
| 288 |
+
<Card>
|
| 289 |
+
<CardHeader>
|
| 290 |
+
<CardTitle className="flex items-center gap-2">
|
| 291 |
+
<ShieldCheck className="size-4 text-[var(--color-info)]" /> Active Blocklist
|
| 292 |
+
</CardTitle>
|
| 293 |
+
</CardHeader>
|
| 294 |
+
<CardContent className="p-0">
|
| 295 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 296 |
+
<table className="w-full text-left border-collapse">
|
| 297 |
+
<thead>
|
| 298 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 299 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Type</th>
|
| 300 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Value</th>
|
| 301 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-32">Reason</th>
|
| 302 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-32">Created</th>
|
| 303 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-24">Actions</th>
|
| 304 |
+
</tr>
|
| 305 |
+
</thead>
|
| 306 |
+
<tbody>
|
| 307 |
+
{entries.length === 0 && (
|
| 308 |
+
<tr>
|
| 309 |
+
<td colSpan={5} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 310 |
+
No active blocklist entries.
|
| 311 |
+
</td>
|
| 312 |
+
</tr>
|
| 313 |
+
)}
|
| 314 |
+
{entries.map((entry: any) => (
|
| 315 |
+
<tr
|
| 316 |
+
key={entry.id}
|
| 317 |
+
className="hover:bg-[var(--bg-tertiary)]/50 transition-colors border-b border-[var(--border-color-subtle)]"
|
| 318 |
+
>
|
| 319 |
+
<td className="py-4 text-sm text-[var(--text-secondary)]">
|
| 320 |
+
{blocklistTypeBadge(entry.type)}
|
| 321 |
+
</td>
|
| 322 |
+
<td className="py-4 text-sm text-[var(--text-primary)] font-mono">
|
| 323 |
+
{entry.value}
|
| 324 |
+
</td>
|
| 325 |
+
<td className="py-4 text-sm text-right text-[var(--text-secondary)] truncate" style={{ maxWidth: 150 }}>
|
| 326 |
+
{entry.reason}
|
| 327 |
+
</td>
|
| 328 |
+
<td className="py-4 text-sm text-right text-[var(--text-tertiary)]">
|
| 329 |
+
{new Date(entry.createdAt).toLocaleDateString()}
|
| 330 |
+
</td>
|
| 331 |
+
<td className="py-4 text-sm text-right">
|
| 332 |
+
<Button
|
| 333 |
+
variant="destructive"
|
| 334 |
+
size="sm"
|
| 335 |
+
onClick={() => removeFromBlocklist.mutate({ id: entry.id })}
|
| 336 |
+
>
|
| 337 |
+
<Trash2 size={14} />
|
| 338 |
+
</Button>
|
| 339 |
+
</td>
|
| 340 |
+
</tr>
|
| 341 |
+
))}
|
| 342 |
+
</tbody>
|
| 343 |
+
</table>
|
| 344 |
+
</div>
|
| 345 |
+
</CardContent>
|
| 346 |
+
</Card>
|
| 347 |
+
|
| 348 |
+
<Card>
|
| 349 |
+
<CardHeader>
|
| 350 |
+
<CardTitle>Add to Blocklist</CardTitle>
|
| 351 |
+
</CardHeader>
|
| 352 |
+
<CardContent className="p-5">
|
| 353 |
+
<div className="space-y-4">
|
| 354 |
+
<select
|
| 355 |
+
value={blocklistType ?? ""}
|
| 356 |
+
onChange={(e) =>
|
| 357 |
+
setBlocklistType(
|
| 358 |
+
(e.target.value ?? undefined) as
|
| 359 |
+
| "EMAIL_DOMAIN"
|
| 360 |
+
| "IP_RANGE"
|
| 361 |
+
| "WORKSPACE_SLUG"
|
| 362 |
+
| undefined,
|
| 363 |
+
)
|
| 364 |
+
}
|
| 365 |
+
className="w-full text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] px-3 py-2 text-sm focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20 outline-none"
|
| 366 |
+
>
|
| 367 |
+
<option value="">Type</option>
|
| 368 |
+
<option value="EMAIL_DOMAIN">Email Domain</option>
|
| 369 |
+
<option value="IP_RANGE">IP Range</option>
|
| 370 |
+
<option value="WORKSPACE_SLUG">Workspace Slug</option>
|
| 371 |
+
</select>
|
| 372 |
+
<Input
|
| 373 |
+
value={newBlocklistValue}
|
| 374 |
+
onChange={(e) => setNewBlocklistValue(e.target.value)}
|
| 375 |
+
placeholder="domain.com / 1.2.3.4 / workspace-slug"
|
| 376 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 377 |
+
/>
|
| 378 |
+
<Input
|
| 379 |
+
value={newBlocklistReason}
|
| 380 |
+
onChange={(e) => setNewBlocklistReason(e.target.value)}
|
| 381 |
+
placeholder="Reason for blocking"
|
| 382 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 383 |
+
/>
|
| 384 |
+
<Button
|
| 385 |
+
variant="primary"
|
| 386 |
+
onClick={() => {
|
| 387 |
+
if (!blocklistType || !newBlocklistValue || !newBlocklistReason) return;
|
| 388 |
+
addToBlocklist.mutate({
|
| 389 |
+
type: blocklistType,
|
| 390 |
+
value: newBlocklistValue,
|
| 391 |
+
reason: newBlocklistReason,
|
| 392 |
+
});
|
| 393 |
+
}}
|
| 394 |
+
disabled={addToBlocklist.isPending}
|
| 395 |
+
className="w-full"
|
| 396 |
+
>
|
| 397 |
+
{addToBlocklist.isPending ? "Addingβ¦" : "Add to Blocklist"}
|
| 398 |
+
</Button>
|
| 399 |
+
</div>
|
| 400 |
+
</CardContent>
|
| 401 |
+
</Card>
|
| 402 |
+
</div>
|
| 403 |
+
</div>
|
| 404 |
+
</div>
|
| 405 |
+
);
|
| 406 |
+
}
|
apps/admin/src/app/(dashboard)/settings/page.tsx
ADDED
|
@@ -0,0 +1,418 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Sliders, Flag, Search, RefreshCw } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 7 |
+
import {
|
| 8 |
+
Card, CardContent, CardDescription, CardHeader, CardTitle,
|
| 9 |
+
} from "@micprotocol/ui";
|
| 10 |
+
import { Badge } from "@micprotocol/ui";
|
| 11 |
+
import { Button } from "@micprotocol/ui";
|
| 12 |
+
import { Input } from "@micprotocol/ui";
|
| 13 |
+
import { Textarea } from "@micprotocol/ui";
|
| 14 |
+
import { Switch } from "@micprotocol/ui";
|
| 15 |
+
import { Modal, ModalHeader, ModalTitle, ModalBody, ModalFooter } from "@micprotocol/ui";
|
| 16 |
+
import { ago } from "@/lib/utils";
|
| 17 |
+
|
| 18 |
+
const CATEGORY_OPTIONS = [
|
| 19 |
+
{ value: "general", label: "General" },
|
| 20 |
+
{ value: "security", label: "Security" },
|
| 21 |
+
{ value: "billing", label: "Billing" },
|
| 22 |
+
{ value: "features", label: "Features" },
|
| 23 |
+
{ value: "integrations", label: "Integrations" },
|
| 24 |
+
{ value: "limits", label: "Limits" },
|
| 25 |
+
];
|
| 26 |
+
|
| 27 |
+
export default function SettingsPage() {
|
| 28 |
+
const utils = trpc.useUtils();
|
| 29 |
+
|
| 30 |
+
type SettingForm = {
|
| 31 |
+
key: string;
|
| 32 |
+
value: unknown;
|
| 33 |
+
description: string | null;
|
| 34 |
+
category: string;
|
| 35 |
+
};
|
| 36 |
+
type FlagForm = {
|
| 37 |
+
key: string;
|
| 38 |
+
enabled: boolean;
|
| 39 |
+
rolloutPercentage: number;
|
| 40 |
+
description: string | null;
|
| 41 |
+
allowlistWorkspaceIds: string[];
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
const [settingEdit, setSettingEdit] = React.useState<SettingForm | null>(null);
|
| 45 |
+
const [flagEdit, setFlagEdit] = React.useState<FlagForm | null>(null);
|
| 46 |
+
|
| 47 |
+
const { data: settings, isLoading: settingsLoading } = trpc.admin.settings.list.useQuery();
|
| 48 |
+
const { data: flags, isLoading: flagsLoading } = trpc.admin.flags.list.useQuery();
|
| 49 |
+
|
| 50 |
+
const upsertSetting = trpc.admin.settings.upsert.useMutation({
|
| 51 |
+
onSuccess: () => { setSettingEdit(null); utils.admin.settings.list.invalidate(); },
|
| 52 |
+
});
|
| 53 |
+
const deleteSetting = trpc.admin.settings.delete.useMutation({
|
| 54 |
+
onSuccess: () => utils.admin.settings.list.invalidate(),
|
| 55 |
+
});
|
| 56 |
+
const upsertFlag = trpc.admin.flags.upsert.useMutation({
|
| 57 |
+
onSuccess: () => { setFlagEdit(null); utils.admin.flags.list.invalidate(); },
|
| 58 |
+
});
|
| 59 |
+
const deleteFlag = trpc.admin.flags.delete.useMutation({
|
| 60 |
+
onSuccess: () => utils.admin.flags.list.invalidate(),
|
| 61 |
+
});
|
| 62 |
+
|
| 63 |
+
return (
|
| 64 |
+
<div className="animate-fade-in">
|
| 65 |
+
<AdminHeader
|
| 66 |
+
title="Platform Settings"
|
| 67 |
+
subtitle="Platform-wide settings and feature flags (kill-switches)"
|
| 68 |
+
/>
|
| 69 |
+
|
| 70 |
+
<div className="space-y-6 p-6">
|
| 71 |
+
{/* Platform Settings */}
|
| 72 |
+
<Card>
|
| 73 |
+
<CardHeader>
|
| 74 |
+
<CardTitle className="flex items-center gap-2">
|
| 75 |
+
<Sliders className="size-4 text-[var(--color-info)]" /> Platform Settings
|
| 76 |
+
</CardTitle>
|
| 77 |
+
<CardDescription>
|
| 78 |
+
Key/value configuration applied across the platform. Every change is audit-trailed.
|
| 79 |
+
</CardDescription>
|
| 80 |
+
</CardHeader>
|
| 81 |
+
<CardContent>
|
| 82 |
+
<div className="overflow-auto">
|
| 83 |
+
<table className="w-full text-left border-collapse">
|
| 84 |
+
<thead>
|
| 85 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 86 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Key</th>
|
| 87 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Value</th>
|
| 88 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Category</th>
|
| 89 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Updated</th>
|
| 90 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right">Actions</th>
|
| 91 |
+
</tr>
|
| 92 |
+
</thead>
|
| 93 |
+
<tbody>
|
| 94 |
+
{settingsLoading ? (
|
| 95 |
+
[...Array(5)].map((_, i) => (
|
| 96 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 97 |
+
<td colSpan={5} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 98 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 99 |
+
</td>
|
| 100 |
+
</tr>
|
| 101 |
+
))
|
| 102 |
+
) : (settings ?? []).length === 0 ? (
|
| 103 |
+
<tr>
|
| 104 |
+
<td colSpan={5} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 105 |
+
No platform settings configured.
|
| 106 |
+
</td>
|
| 107 |
+
</tr>
|
| 108 |
+
) : (
|
| 109 |
+
(settings as any[]).map((s) => (
|
| 110 |
+
<tr key={s.key} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 111 |
+
<td className="py-4 font-mono text-xs text-[var(--text-primary)]">{s.key}</td>
|
| 112 |
+
<td className="py-4 text-xs text-[var(--text-secondary)]">
|
| 113 |
+
<span className="font-mono">{renderValue(s.value)}</span>
|
| 114 |
+
</td>
|
| 115 |
+
<td className="py-4 text-xs text-[var(--text-secondary)]">{s.category}</td>
|
| 116 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)]">{ago(s.updatedAt)}</td>
|
| 117 |
+
<td className="py-4 text-right">
|
| 118 |
+
<div className="flex items-center gap-1">
|
| 119 |
+
<Button
|
| 120 |
+
variant="ghost"
|
| 121 |
+
size="sm"
|
| 122 |
+
onClick={() => {
|
| 123 |
+
const sel = (settings as any[]).find((x) => x.key === s.key);
|
| 124 |
+
setSettingEdit({
|
| 125 |
+
key: s.key,
|
| 126 |
+
value: sel?.value ?? null,
|
| 127 |
+
description: sel?.description ?? null,
|
| 128 |
+
category: sel?.category ?? "general",
|
| 129 |
+
});
|
| 130 |
+
}}
|
| 131 |
+
>
|
| 132 |
+
Edit
|
| 133 |
+
</Button>
|
| 134 |
+
<Button
|
| 135 |
+
variant="outline"
|
| 136 |
+
size="sm"
|
| 137 |
+
onClick={() => deleteSetting.mutate({ key: s.key })}
|
| 138 |
+
disabled={deleteSetting.isPending}
|
| 139 |
+
>
|
| 140 |
+
Delete
|
| 141 |
+
</Button>
|
| 142 |
+
</div>
|
| 143 |
+
</td>
|
| 144 |
+
</tr>
|
| 145 |
+
))
|
| 146 |
+
)}
|
| 147 |
+
</tbody>
|
| 148 |
+
</table>
|
| 149 |
+
</div>
|
| 150 |
+
<div className="mt-4 flex justify-end">
|
| 151 |
+
<Button
|
| 152 |
+
onClick={() =>
|
| 153 |
+
setSettingEdit({ key: "", value: null, description: null, category: "general" })
|
| 154 |
+
}
|
| 155 |
+
>
|
| 156 |
+
Add Setting
|
| 157 |
+
</Button>
|
| 158 |
+
</div>
|
| 159 |
+
</CardContent>
|
| 160 |
+
</Card>
|
| 161 |
+
|
| 162 |
+
{/* Feature Flags */}
|
| 163 |
+
<Card>
|
| 164 |
+
<CardHeader>
|
| 165 |
+
<CardTitle className="flex items-center gap-2">
|
| 166 |
+
<Flag className="size-4 text-[var(--color-primary)]" /> Feature Flags
|
| 167 |
+
</CardTitle>
|
| 168 |
+
<CardDescription>
|
| 169 |
+
Kill-switches and rollouts. Disable a flag to turn off a platform feature instantly.
|
| 170 |
+
</CardDescription>
|
| 171 |
+
</CardHeader>
|
| 172 |
+
<CardContent>
|
| 173 |
+
<div className="overflow-auto">
|
| 174 |
+
<table className="w-full text-left border-collapse">
|
| 175 |
+
<thead>
|
| 176 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 177 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Key</th>
|
| 178 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Enabled</th>
|
| 179 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Rollout</th>
|
| 180 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Allowlist</th>
|
| 181 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right">Actions</th>
|
| 182 |
+
</tr>
|
| 183 |
+
</thead>
|
| 184 |
+
<tbody>
|
| 185 |
+
{flagsLoading ? (
|
| 186 |
+
[...Array(5)].map((_, i) => (
|
| 187 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 188 |
+
<td colSpan={5} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 189 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 190 |
+
</td>
|
| 191 |
+
</tr>
|
| 192 |
+
))
|
| 193 |
+
) : (flags ?? []).length === 0 ? (
|
| 194 |
+
<tr>
|
| 195 |
+
<td colSpan={5} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 196 |
+
No feature flags configured.
|
| 197 |
+
</td>
|
| 198 |
+
</tr>
|
| 199 |
+
) : (
|
| 200 |
+
(flags as any[]).map((f) => (
|
| 201 |
+
<tr key={f.key} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 202 |
+
<td className="py-4 font-mono text-xs text-[var(--text-primary)]">{f.key}</td>
|
| 203 |
+
<td className="py-4">
|
| 204 |
+
<Switch
|
| 205 |
+
checked={f.enabled}
|
| 206 |
+
onChange={() => {
|
| 207 |
+
const cur = (flags as any[]).find((x) => x.key === f.key);
|
| 208 |
+
setFlagEdit({ key: f.key, ...cur });
|
| 209 |
+
}}
|
| 210 |
+
/>
|
| 211 |
+
</td>
|
| 212 |
+
<td className="py-4 text-xs text-[var(--text-secondary)]">
|
| 213 |
+
{f.rolloutPercentage}%
|
| 214 |
+
</td>
|
| 215 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)] font-mono">
|
| 216 |
+
{f.allowlistWorkspaceIds?.length ?? 0}
|
| 217 |
+
</td>
|
| 218 |
+
<td className="py-4 text-right">
|
| 219 |
+
<div className="flex items-center gap-1">
|
| 220 |
+
<Button
|
| 221 |
+
variant="ghost"
|
| 222 |
+
size="sm"
|
| 223 |
+
onClick={() => {
|
| 224 |
+
const cur = (flags as any[]).find((x) => x.key === f.key);
|
| 225 |
+
setFlagEdit({
|
| 226 |
+
key: f.key,
|
| 227 |
+
enabled: cur?.enabled ?? false,
|
| 228 |
+
rolloutPercentage: cur?.rolloutPercentage ?? 0,
|
| 229 |
+
description: cur?.description ?? null,
|
| 230 |
+
allowlistWorkspaceIds: cur?.allowlistWorkspaceIds ?? [],
|
| 231 |
+
});
|
| 232 |
+
}}
|
| 233 |
+
>
|
| 234 |
+
Edit
|
| 235 |
+
</Button>
|
| 236 |
+
<Button
|
| 237 |
+
variant="outline"
|
| 238 |
+
size="sm"
|
| 239 |
+
onClick={() => deleteFlag.mutate({ key: f.key })}
|
| 240 |
+
disabled={deleteFlag.isPending}
|
| 241 |
+
>
|
| 242 |
+
Delete
|
| 243 |
+
</Button>
|
| 244 |
+
</div>
|
| 245 |
+
</td>
|
| 246 |
+
</tr>
|
| 247 |
+
))
|
| 248 |
+
)}
|
| 249 |
+
</tbody>
|
| 250 |
+
</table>
|
| 251 |
+
</div>
|
| 252 |
+
<div className="mt-4 flex justify-end">
|
| 253 |
+
<Button onClick={() => setFlagEdit({ key: "", enabled: false, rolloutPercentage: 0, description: null, allowlistWorkspaceIds: [] as string[] })}>
|
| 254 |
+
Add Flag
|
| 255 |
+
</Button>
|
| 256 |
+
</div>
|
| 257 |
+
</CardContent>
|
| 258 |
+
</Card>
|
| 259 |
+
|
| 260 |
+
{/* Edit setting modal */}
|
| 261 |
+
{settingEdit && (
|
| 262 |
+
<Modal isOpen onClose={() => setSettingEdit(null)} size="md">
|
| 263 |
+
<ModalHeader>
|
| 264 |
+
<ModalTitle>{settingEdit.key ? "Edit Setting" : "Add Setting"}</ModalTitle>
|
| 265 |
+
</ModalHeader>
|
| 266 |
+
<ModalBody>
|
| 267 |
+
<form
|
| 268 |
+
onSubmit={(e) => {
|
| 269 |
+
e.preventDefault();
|
| 270 |
+
if (!settingEdit) return;
|
| 271 |
+
let parsed: unknown;
|
| 272 |
+
try {
|
| 273 |
+
parsed = settingEdit.value != null ? JSON.parse(String(settingEdit.value)) : null;
|
| 274 |
+
} catch {
|
| 275 |
+
parsed = settingEdit.value;
|
| 276 |
+
}
|
| 277 |
+
upsertSetting.mutate({
|
| 278 |
+
key: settingEdit.key,
|
| 279 |
+
value: parsed,
|
| 280 |
+
description: settingEdit.description ?? undefined,
|
| 281 |
+
category: settingEdit.category,
|
| 282 |
+
});
|
| 283 |
+
setSettingEdit(null);
|
| 284 |
+
}}
|
| 285 |
+
className="space-y-4"
|
| 286 |
+
>
|
| 287 |
+
<div>
|
| 288 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">Key</label>
|
| 289 |
+
<Input
|
| 290 |
+
value={settingEdit!.key}
|
| 291 |
+
onChange={(e) => setSettingEdit({ ...settingEdit!, key: e.target.value })}
|
| 292 |
+
disabled={!!settingEdit.key}
|
| 293 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 294 |
+
/>
|
| 295 |
+
</div>
|
| 296 |
+
<div>
|
| 297 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">Value (JSON)</label>
|
| 298 |
+
<Textarea
|
| 299 |
+
value={typeof settingEdit.value === "string" ? settingEdit.value : JSON.stringify(settingEdit.value, null, 2)}
|
| 300 |
+
onChange={(e) => setSettingEdit({ ...settingEdit!, value: e.target.value })}
|
| 301 |
+
className="font-mono text-xs text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 302 |
+
rows={4}
|
| 303 |
+
/>
|
| 304 |
+
</div>
|
| 305 |
+
<div>
|
| 306 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">Description</label>
|
| 307 |
+
<Input
|
| 308 |
+
value={settingEdit.description ?? ""}
|
| 309 |
+
onChange={(e) => setSettingEdit({ ...settingEdit!, description: e.target.value || null })}
|
| 310 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 311 |
+
/>
|
| 312 |
+
</div>
|
| 313 |
+
<div>
|
| 314 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">Category</label>
|
| 315 |
+
<select
|
| 316 |
+
value={settingEdit.category}
|
| 317 |
+
onChange={(e) => setSettingEdit({ ...settingEdit!, category: e.target.value })}
|
| 318 |
+
className="w-full text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] px-3 py-2 text-sm focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20 outline-none"
|
| 319 |
+
>
|
| 320 |
+
{CATEGORY_OPTIONS.map((opt) => (
|
| 321 |
+
<option key={opt.value} value={opt.value}>{opt.label}</option>
|
| 322 |
+
))}
|
| 323 |
+
</select>
|
| 324 |
+
</div>
|
| 325 |
+
<div className="flex justify-end gap-2">
|
| 326 |
+
<Button type="button" variant="outline" onClick={() => setSettingEdit(null)}>
|
| 327 |
+
Cancel
|
| 328 |
+
</Button>
|
| 329 |
+
<Button type="submit" disabled={upsertSetting.isPending}>
|
| 330 |
+
Save
|
| 331 |
+
</Button>
|
| 332 |
+
</div>
|
| 333 |
+
</form>
|
| 334 |
+
</ModalBody>
|
| 335 |
+
</Modal>
|
| 336 |
+
)}
|
| 337 |
+
|
| 338 |
+
{/* Edit flag modal */}
|
| 339 |
+
{flagEdit && (
|
| 340 |
+
<Modal isOpen onClose={() => setFlagEdit(null)} size="md">
|
| 341 |
+
<ModalHeader>
|
| 342 |
+
<ModalTitle>{flagEdit.key ? "Edit Flag" : "Add Flag"}</ModalTitle>
|
| 343 |
+
</ModalHeader>
|
| 344 |
+
<ModalBody>
|
| 345 |
+
<form
|
| 346 |
+
onSubmit={(e) => {
|
| 347 |
+
e.preventDefault();
|
| 348 |
+
if (!flagEdit) return;
|
| 349 |
+
upsertFlag.mutate({
|
| 350 |
+
key: flagEdit.key,
|
| 351 |
+
enabled: flagEdit.enabled,
|
| 352 |
+
rolloutPercentage: flagEdit.rolloutPercentage,
|
| 353 |
+
allowlistWorkspaceIds: flagEdit.allowlistWorkspaceIds,
|
| 354 |
+
description: flagEdit.description,
|
| 355 |
+
});
|
| 356 |
+
setFlagEdit(null);
|
| 357 |
+
}}
|
| 358 |
+
className="space-y-4"
|
| 359 |
+
>
|
| 360 |
+
<div>
|
| 361 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">Key</label>
|
| 362 |
+
<Input
|
| 363 |
+
value={flagEdit.key}
|
| 364 |
+
onChange={(e) => setFlagEdit({ ...flagEdit, key: e.target.value })}
|
| 365 |
+
disabled={!!flagEdit.key}
|
| 366 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 367 |
+
/>
|
| 368 |
+
</div>
|
| 369 |
+
<div className="flex items-center gap-3">
|
| 370 |
+
<Switch
|
| 371 |
+
checked={flagEdit.enabled}
|
| 372 |
+
onChange={(v) => setFlagEdit({ ...flagEdit, enabled: v })}
|
| 373 |
+
/>
|
| 374 |
+
<label className="text-xs text-[var(--text-secondary)]">Enabled</label>
|
| 375 |
+
</div>
|
| 376 |
+
<div>
|
| 377 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">Rollout (%)</label>
|
| 378 |
+
<Input
|
| 379 |
+
type="number"
|
| 380 |
+
value={String(flagEdit.rolloutPercentage)}
|
| 381 |
+
onChange={(e) =>
|
| 382 |
+
setFlagEdit({ ...flagEdit, rolloutPercentage: Number(e.target.value) || 0 })
|
| 383 |
+
}
|
| 384 |
+
min="0"
|
| 385 |
+
max="100"
|
| 386 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 387 |
+
/>
|
| 388 |
+
</div>
|
| 389 |
+
<div>
|
| 390 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">Description</label>
|
| 391 |
+
<Input
|
| 392 |
+
value={flagEdit.description ?? ""}
|
| 393 |
+
onChange={(e) => setFlagEdit({ ...flagEdit, description: e.target.value || null })}
|
| 394 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 395 |
+
/>
|
| 396 |
+
</div>
|
| 397 |
+
<div className="flex justify-end gap-2">
|
| 398 |
+
<Button type="button" variant="outline" onClick={() => setFlagEdit(null)}>
|
| 399 |
+
Cancel
|
| 400 |
+
</Button>
|
| 401 |
+
<Button type="submit" disabled={upsertFlag.isPending}>
|
| 402 |
+
Save
|
| 403 |
+
</Button>
|
| 404 |
+
</div>
|
| 405 |
+
</form>
|
| 406 |
+
</ModalBody>
|
| 407 |
+
</Modal>
|
| 408 |
+
)}
|
| 409 |
+
</div>
|
| 410 |
+
</div>
|
| 411 |
+
);
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
function renderValue(value: unknown): string {
|
| 415 |
+
if (value === null || value === undefined) return "null";
|
| 416 |
+
if (typeof value === "string") return value;
|
| 417 |
+
return JSON.stringify(value);
|
| 418 |
+
}
|
apps/admin/src/app/(dashboard)/supervision/page.tsx
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState } from "react";
|
| 4 |
+
import { Play, Pause, RefreshCw, AlertCircle, Eye, UserCheck } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 7 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 8 |
+
import { Badge } from "@micprotocol/ui";
|
| 9 |
+
import { Button } from "@micprotocol/ui";
|
| 10 |
+
import { cn } from "@/lib/utils";
|
| 11 |
+
import { ago } from "@/lib/utils";
|
| 12 |
+
|
| 13 |
+
export default function SupervisionPage() {
|
| 14 |
+
const [tab, setTab] = useState<"runs" | "findings">("runs");
|
| 15 |
+
|
| 16 |
+
const { data: runs, isLoading: runsLoading } = trpc.admin.supervision.listRuns.useQuery(
|
| 17 |
+
undefined,
|
| 18 |
+
{ refetchInterval: 30_000 },
|
| 19 |
+
);
|
| 20 |
+
const { data: findings, isLoading: findingsLoading } = trpc.admin.supervision.listFindings.useQuery(
|
| 21 |
+
{},
|
| 22 |
+
{ refetchInterval: 30_000 },
|
| 23 |
+
);
|
| 24 |
+
|
| 25 |
+
const runSupervision = (trpc.admin.supervision as any).runSupervision.useMutation({
|
| 26 |
+
onSuccess: () => {
|
| 27 |
+
// listRuns refetches via refetchInterval (30s)
|
| 28 |
+
},
|
| 29 |
+
});
|
| 30 |
+
|
| 31 |
+
const runList = runs ?? [];
|
| 32 |
+
const findingsList = findings ?? [];
|
| 33 |
+
|
| 34 |
+
const completedRuns = runList.filter((r) => r.status === "completed").length;
|
| 35 |
+
const failedRuns = runList.filter((r) => r.status === "failed").length;
|
| 36 |
+
const openFindings = findingsList.filter((f) => f.status === "open").length;
|
| 37 |
+
const criticalFindings = findingsList.filter((f) => f.severity === "critical").length;
|
| 38 |
+
|
| 39 |
+
return (
|
| 40 |
+
<div className="animate-fade-in">
|
| 41 |
+
<AdminHeader
|
| 42 |
+
title="Compliance Supervision"
|
| 43 |
+
subtitle="Run compliance checks, review findings, and remediate platform violations"
|
| 44 |
+
refreshing={runsLoading || findingsLoading}
|
| 45 |
+
/>
|
| 46 |
+
|
| 47 |
+
<div className="space-y-6 p-6">
|
| 48 |
+
{/* Controls */}
|
| 49 |
+
<Card>
|
| 50 |
+
<CardHeader>
|
| 51 |
+
<CardTitle className="flex items-center gap-2">
|
| 52 |
+
<Play className="size-4 text-[var(--color-success)]" /> Supervision Controls
|
| 53 |
+
</CardTitle>
|
| 54 |
+
</CardHeader>
|
| 55 |
+
<CardContent className="p-0">
|
| 56 |
+
<div className="p-5 border-t border-[var(--border-color-subtle)] grid gap-4 sm:grid-cols-2">
|
| 57 |
+
<Button
|
| 58 |
+
variant="outline"
|
| 59 |
+
size="sm"
|
| 60 |
+
disabled={runSupervision.isPending}
|
| 61 |
+
onClick={() => runSupervision.mutate({ fullScan: true })}
|
| 62 |
+
>
|
| 63 |
+
{runSupervision.isPending ? "Runningβ¦" : "Run Full Supervision Scan"}
|
| 64 |
+
</Button>
|
| 65 |
+
<Button
|
| 66 |
+
variant="outline"
|
| 67 |
+
size="sm"
|
| 68 |
+
disabled={isRunning()}
|
| 69 |
+
onClick={() => {}}
|
| 70 |
+
>
|
| 71 |
+
<Pause size={14} /> Pause Active Run
|
| 72 |
+
</Button>
|
| 73 |
+
<Button
|
| 74 |
+
variant="outline"
|
| 75 |
+
size="sm"
|
| 76 |
+
onClick={() => {}}
|
| 77 |
+
>
|
| 78 |
+
<RefreshCw size={14} /> Refresh State
|
| 79 |
+
</Button>
|
| 80 |
+
</div>
|
| 81 |
+
</CardContent>
|
| 82 |
+
</Card>
|
| 83 |
+
|
| 84 |
+
{/* KPI strip */}
|
| 85 |
+
<div className="grid gap-4 sm:grid-cols-4">
|
| 86 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 87 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Total Runs</p>
|
| 88 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{runList.length}</p>
|
| 89 |
+
</Card>
|
| 90 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 91 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Completed</p>
|
| 92 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-success)]">{completedRuns}</p>
|
| 93 |
+
</Card>
|
| 94 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 95 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Open Findings</p>
|
| 96 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-warning)]">{openFindings}</p>
|
| 97 |
+
</Card>
|
| 98 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 99 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Critical</p>
|
| 100 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-error)]">{criticalFindings}</p>
|
| 101 |
+
</Card>
|
| 102 |
+
</div>
|
| 103 |
+
|
| 104 |
+
{/* Tabs: Runs | Findings */}
|
| 105 |
+
<div className="flex gap-1 border-b border-[var(--border-color-subtle)] mb-4">
|
| 106 |
+
<Button
|
| 107 |
+
variant={tab === "runs" ? "primary" : "outline"}
|
| 108 |
+
size="sm"
|
| 109 |
+
onClick={() => setTab("runs")}
|
| 110 |
+
className="border-b-2 border-transparent"
|
| 111 |
+
>
|
| 112 |
+
Runs ({runList.length})
|
| 113 |
+
</Button>
|
| 114 |
+
<Button
|
| 115 |
+
variant={tab === "findings" ? "primary" : "outline"}
|
| 116 |
+
size="sm"
|
| 117 |
+
onClick={() => setTab("findings")}
|
| 118 |
+
className="border-b-2 border-transparent"
|
| 119 |
+
>
|
| 120 |
+
Findings ({findingsList.length})
|
| 121 |
+
</Button>
|
| 122 |
+
</div>
|
| 123 |
+
|
| 124 |
+
{tab === "runs" ? (
|
| 125 |
+
<Card>
|
| 126 |
+
<CardHeader>
|
| 127 |
+
<CardTitle className="flex items-center gap-2">
|
| 128 |
+
<AlertCircle className="size-4 text-[var(--color-warning)]" /> Supervision Runs
|
| 129 |
+
</CardTitle>
|
| 130 |
+
</CardHeader>
|
| 131 |
+
<CardContent className="p-0">
|
| 132 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 133 |
+
<table className="w-full text-left border-collapse">
|
| 134 |
+
<thead>
|
| 135 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 136 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">ID</th>
|
| 137 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Scope</th>
|
| 138 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Status</th>
|
| 139 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Checks</th>
|
| 140 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right">Started</th>
|
| 141 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right">Actions</th>
|
| 142 |
+
</tr>
|
| 143 |
+
</thead>
|
| 144 |
+
<tbody>
|
| 145 |
+
{runList.length === 0 && (
|
| 146 |
+
<tr>
|
| 147 |
+
<td colSpan={6} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 148 |
+
No supervision runs yet. Start a scan above.
|
| 149 |
+
</td>
|
| 150 |
+
</tr>
|
| 151 |
+
)}
|
| 152 |
+
{runList.map((run: any) => (
|
| 153 |
+
<tr
|
| 154 |
+
key={run.id}
|
| 155 |
+
className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors"
|
| 156 |
+
>
|
| 157 |
+
<td className="py-4 font-mono text-xs text-[var(--text-secondary)]">
|
| 158 |
+
{run.id.slice(0, 8)}β¦
|
| 159 |
+
</td>
|
| 160 |
+
<td className="py-4 text-xs text-[var(--text-secondary)]">{run.scope}</td>
|
| 161 |
+
<td className="py-4 text-xs">
|
| 162 |
+
<Badge
|
| 163 |
+
className={cn("capitalize text-xs", runStatusClass(run.status))}
|
| 164 |
+
>
|
| 165 |
+
{run.status}
|
| 166 |
+
</Badge>
|
| 167 |
+
</td>
|
| 168 |
+
<td className="py-4 text-xs text-[var(--text-primary)]">{run.checksPassed}/{run.checksTotal}</td>
|
| 169 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)] text-right">
|
| 170 |
+
{run.startedAt ? new Date(run.startedAt).toLocaleTimeString() : "β"}
|
| 171 |
+
</td>
|
| 172 |
+
<td className="py-4 text-sm text-right">
|
| 173 |
+
<Button variant="ghost" size="sm" onClick={() => {}}>
|
| 174 |
+
<Eye size={14} /> View
|
| 175 |
+
</Button>
|
| 176 |
+
</td>
|
| 177 |
+
</tr>
|
| 178 |
+
))}
|
| 179 |
+
</tbody>
|
| 180 |
+
</table>
|
| 181 |
+
</div>
|
| 182 |
+
</CardContent>
|
| 183 |
+
</Card>
|
| 184 |
+
) : (
|
| 185 |
+
<Card>
|
| 186 |
+
<CardHeader>
|
| 187 |
+
<CardTitle className="flex items-center gap-2">
|
| 188 |
+
<AlertCircle className="size-4 text-[var(--color-error)]" /> Open Findings
|
| 189 |
+
</CardTitle>
|
| 190 |
+
</CardHeader>
|
| 191 |
+
<CardContent className="p-0">
|
| 192 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 193 |
+
<table className="w-full text-left border-collapse">
|
| 194 |
+
<thead>
|
| 195 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 196 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Finding</th>
|
| 197 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-20">Severity</th>
|
| 198 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Category</th>
|
| 199 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-16">Status</th>
|
| 200 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right">Detected</th>
|
| 201 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Actions</th>
|
| 202 |
+
</tr>
|
| 203 |
+
</thead>
|
| 204 |
+
<tbody>
|
| 205 |
+
{findingsList.length === 0 && (
|
| 206 |
+
<tr>
|
| 207 |
+
<td colSpan={6} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 208 |
+
No open findings. Platform is clean.
|
| 209 |
+
</td>
|
| 210 |
+
</tr>
|
| 211 |
+
)}
|
| 212 |
+
{findingsList.map((f: any) => (
|
| 213 |
+
<tr key={f.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 214 |
+
<td className="py-4 font-medium text-xs text-[var(--text-primary)]">{f.title}</td>
|
| 215 |
+
<td className="py-4 text-xs">
|
| 216 |
+
<Badge className={cn("capitalize text-xs", severityClass(f.severity))}>
|
| 217 |
+
{f.severity}
|
| 218 |
+
</Badge>
|
| 219 |
+
</td>
|
| 220 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] font-mono">{f.category}</td>
|
| 221 |
+
<td className="py-4 text-xs text-center">
|
| 222 |
+
<Badge className="capitalize text-xs">{f.status}</Badge>
|
| 223 |
+
</td>
|
| 224 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)] text-right">
|
| 225 |
+
{new Date(f.detectedAt).toLocaleDateString()}
|
| 226 |
+
</td>
|
| 227 |
+
<td className="py-4 text-sm text-right">
|
| 228 |
+
<Button variant="outline" size="sm" onClick={() => {}}>
|
| 229 |
+
<UserCheck size={14} className="mr-1" /> Remediate
|
| 230 |
+
</Button>
|
| 231 |
+
</td>
|
| 232 |
+
</tr>
|
| 233 |
+
))}
|
| 234 |
+
</tbody>
|
| 235 |
+
</table>
|
| 236 |
+
</div>
|
| 237 |
+
</CardContent>
|
| 238 |
+
</Card>
|
| 239 |
+
)}
|
| 240 |
+
</div>
|
| 241 |
+
</div>
|
| 242 |
+
);
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
function runStatusClass(status: string): string {
|
| 246 |
+
switch (status) {
|
| 247 |
+
case "completed": return "bg-[var(--color-success)]/10 border-[var(--color-success)]/20 text-[var(--color-success)]";
|
| 248 |
+
case "failed": return "bg-[var(--color-error)]/10 border-[var(--color-error)]/20 text-[var(--color-error)]";
|
| 249 |
+
case "running": return "bg-[var(--color-info)]/10 border-[var(--color-info)]/20 text-[var(--color-info)]";
|
| 250 |
+
default: return "border-transparent";
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
function severityClass(sev: string): string {
|
| 255 |
+
switch (sev) {
|
| 256 |
+
case "critical": return "bg-[var(--color-error)] border-[var(--color-error)] text-[var(--text-primary)]";
|
| 257 |
+
case "high": return "bg-[var(--color-error)]/10 border-[var(--color-error)]/20 text-[var(--color-error)]";
|
| 258 |
+
case "medium": return "bg-[var(--color-warning)]/10 border-[var(--color-warning)]/20 text-[var(--color-warning)]";
|
| 259 |
+
case "low": return "bg-[var(--color-info)]/10 border-[var(--color-info)]/20 text-[var(--color-info)]";
|
| 260 |
+
default: return "border-transparent";
|
| 261 |
+
}
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
function isRunning(): boolean {
|
| 265 |
+
return false; // placeholder until backend wiring
|
| 266 |
+
}
|
apps/admin/src/app/(dashboard)/support/[ticketId]/page.tsx
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState } from "react";
|
| 4 |
+
import { useParams, useRouter } from "next/navigation";
|
| 5 |
+
import { Mail, User, Clock, AlertCircle, CheckCircle2, Clock as ClockIcon } from "lucide-react";
|
| 6 |
+
import { trpc } from "@/lib/trpc";
|
| 7 |
+
import { cn } from "@/lib/utils";
|
| 8 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 9 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 10 |
+
import { Badge } from "@micprotocol/ui";
|
| 11 |
+
import { Button } from "@micprotocol/ui";
|
| 12 |
+
import { Input } from "@micprotocol/ui";
|
| 13 |
+
import { Textarea } from "@micprotocol/ui";
|
| 14 |
+
import { Modal, ModalHeader, ModalTitle, ModalBody, ModalFooter } from "@micprotocol/ui";
|
| 15 |
+
import { ago } from "@/lib/utils";
|
| 16 |
+
|
| 17 |
+
export default function SupportTicketPage() {
|
| 18 |
+
const params = useParams();
|
| 19 |
+
const router = useRouter();
|
| 20 |
+
const ticketId = (params as any)?.ticketId as string;
|
| 21 |
+
|
| 22 |
+
const { data: ticket, isLoading } = (trpc.support as any).getTicket.useQuery(
|
| 23 |
+
{ ticketId },
|
| 24 |
+
{ enabled: !!ticketId },
|
| 25 |
+
);
|
| 26 |
+
|
| 27 |
+
const [assignModal, setAssignModal] = useState(false);
|
| 28 |
+
const [statusModal, setStatusModal] = useState(false);
|
| 29 |
+
const [assignedTo, setAssignedTo] = useState("");
|
| 30 |
+
const [newStatus, setNewStatus] = useState("");
|
| 31 |
+
|
| 32 |
+
if (!ticketId) {
|
| 33 |
+
router.push("/support");
|
| 34 |
+
return null;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
if (isLoading || !ticket) {
|
| 38 |
+
return (
|
| 39 |
+
<div className="animate-fade-in p-6">
|
| 40 |
+
<AdminHeader title="Support Ticket" subtitle="Loading ticket detailsβ¦" />
|
| 41 |
+
<div className="flex items-center justify-center h-[40vh]">
|
| 42 |
+
<div className="skeleton w-full h-16 max-w-xs mx-auto" />
|
| 43 |
+
</div>
|
| 44 |
+
</div>
|
| 45 |
+
);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
return (
|
| 49 |
+
<div className="animate-fade-in">
|
| 50 |
+
<AdminHeader
|
| 51 |
+
title={`Ticket #${ticket.id.slice(0, 8)}`}
|
| 52 |
+
subtitle={ticket.subject}
|
| 53 |
+
actions={
|
| 54 |
+
<div className="flex gap-2">
|
| 55 |
+
<Button variant="outline" size="sm" onClick={() => setAssignModal(true)}>
|
| 56 |
+
<User size={14} className="mr-1" /> Assign
|
| 57 |
+
</Button>
|
| 58 |
+
<Button variant="outline" size="sm" onClick={() => { setNewStatus(ticket.status); setStatusModal(true); }}>
|
| 59 |
+
<AlertCircle size={14} className="mr-1" /> Status
|
| 60 |
+
</Button>
|
| 61 |
+
</div>
|
| 62 |
+
}
|
| 63 |
+
/>
|
| 64 |
+
|
| 65 |
+
<div className="space-y-6 p-6">
|
| 66 |
+
{/* Ticket header */}
|
| 67 |
+
<Card>
|
| 68 |
+
<CardContent className="p-5">
|
| 69 |
+
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
| 70 |
+
<div>
|
| 71 |
+
<p className="text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Ticket</p>
|
| 72 |
+
<h2 className="font-medium text-[var(--text-primary)]">{ticket.subject}</h2>
|
| 73 |
+
</div>
|
| 74 |
+
<div className="flex items-center gap-2">
|
| 75 |
+
<Badge className={cn("capitalize text-xs", ticketStatusClass(ticket.status))}>
|
| 76 |
+
{ticket.status.replace(/_/g, " ")}
|
| 77 |
+
</Badge>
|
| 78 |
+
<Badge className={cn("capitalize text-xs", ticketPriorityClass(ticket.priority))}>
|
| 79 |
+
{ticket.priority}
|
| 80 |
+
</Badge>
|
| 81 |
+
</div>
|
| 82 |
+
</div>
|
| 83 |
+
<div className="mt-4 grid grid-cols-2 sm:grid-cols-4 gap-4 text-xs">
|
| 84 |
+
<div>
|
| 85 |
+
<p className="text-[var(--text-tertiary)]">Guest</p>
|
| 86 |
+
<p className="text-[var(--text-primary)]">{ticket.guestName ?? "Unknown"}</p>
|
| 87 |
+
</div>
|
| 88 |
+
<div>
|
| 89 |
+
<p className="text-[var(--text-tertiary)]">Channel</p>
|
| 90 |
+
<p className="text-[var(--text-primary)] font-mono">{ticket.channel}</p>
|
| 91 |
+
</div>
|
| 92 |
+
<div>
|
| 93 |
+
<p className="text-[var(--text-tertiary)]">Assignee</p>
|
| 94 |
+
<p className="text-[var(--text-primary)] font-mono">{ticket.assignedTo ?? "Unassigned"}</p>
|
| 95 |
+
</div>
|
| 96 |
+
<div>
|
| 97 |
+
<p className="text-[var(--text-tertiary)]">Created</p>
|
| 98 |
+
<p className="text-[var(--text-primary)] font-mono">{new Date(ticket.createdAt).toLocaleDateString()}</p>
|
| 99 |
+
</div>
|
| 100 |
+
</div>
|
| 101 |
+
</CardContent>
|
| 102 |
+
</Card>
|
| 103 |
+
|
| 104 |
+
{/* Messages */}
|
| 105 |
+
<Card>
|
| 106 |
+
<CardHeader>
|
| 107 |
+
<CardTitle className="flex items-center gap-2">
|
| 108 |
+
<Mail className="size-4 text-[var(--color-info)]" /> Conversation
|
| 109 |
+
</CardTitle>
|
| 110 |
+
</CardHeader>
|
| 111 |
+
<CardContent className="p-5 h-[40vh] overflow-y-auto space-y-4">
|
| 112 |
+
{ticket.messages?.length ? (
|
| 113 |
+
ticket.messages.map((m: any) => (
|
| 114 |
+
<div key={m.id} className="flex gap-3">
|
| 115 |
+
<div className="size-8 rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] flex items-center justify-center font-medium text-[var(--text-secondary)]">
|
| 116 |
+
{m.authorName?.[0] ?? "?"}
|
| 117 |
+
</div>
|
| 118 |
+
<div className="flex-1">
|
| 119 |
+
<p className="text-xs font-medium text-[var(--text-primary)]">{m.authorName ?? "System"}</p>
|
| 120 |
+
<p className="mt-1 text-sm text-[var(--text-secondary)] whitespace-pre-wrap">{m.body}</p>
|
| 121 |
+
<p className="text-[10px] text-[var(--text-tertiary)]">{new Date(m.createdAt).toLocaleString()}</p>
|
| 122 |
+
</div>
|
| 123 |
+
</div>
|
| 124 |
+
))
|
| 125 |
+
) : (
|
| 126 |
+
<p className="text-[var(--text-tertiary)] text-center py-8">No messages yet.</p>
|
| 127 |
+
)}
|
| 128 |
+
</CardContent>
|
| 129 |
+
</Card>
|
| 130 |
+
|
| 131 |
+
{/* Actions */}
|
| 132 |
+
<Card>
|
| 133 |
+
<CardContent className="p-5">
|
| 134 |
+
<div className="flex gap-3">
|
| 135 |
+
<Button variant="outline" size="sm" onClick={() => setAssignModal(true)}>
|
| 136 |
+
<User size={14} className="mr-1" /> Assign Agent
|
| 137 |
+
</Button>
|
| 138 |
+
<Button variant="outline" size="sm" onClick={() => { setNewStatus(ticket.status); setStatusModal(true); }}>
|
| 139 |
+
<AlertCircle size={14} className="mr-1" /> Change Status
|
| 140 |
+
</Button>
|
| 141 |
+
{ticket.status !== "resolved" ? (
|
| 142 |
+
<Button variant="outline" size="sm" onClick={() => {}}>
|
| 143 |
+
<CheckCircle2 size={14} className="mr-1" /> Mark Resolved
|
| 144 |
+
</Button>
|
| 145 |
+
) : null}
|
| 146 |
+
</div>
|
| 147 |
+
</CardContent>
|
| 148 |
+
</Card>
|
| 149 |
+
</div>
|
| 150 |
+
|
| 151 |
+
{/* Assign modal */}
|
| 152 |
+
{assignModal && (
|
| 153 |
+
<Modal isOpen onClose={() => setAssignModal(false)} size="md">
|
| 154 |
+
<ModalHeader>
|
| 155 |
+
<ModalTitle>Assign Agent</ModalTitle>
|
| 156 |
+
</ModalHeader>
|
| 157 |
+
<ModalBody>
|
| 158 |
+
<form
|
| 159 |
+
onSubmit={(e) => {
|
| 160 |
+
e.preventDefault();
|
| 161 |
+
trpc.support.assignAgent.useMutation({
|
| 162 |
+
onSuccess: () => { setAssignModal(false); setAssignedTo(""); },
|
| 163 |
+
}).mutate({ ticketId, agentId: assignedTo });
|
| 164 |
+
}}
|
| 165 |
+
className="space-y-4"
|
| 166 |
+
>
|
| 167 |
+
<div>
|
| 168 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">Agent</label>
|
| 169 |
+
<Input
|
| 170 |
+
value={assignedTo}
|
| 171 |
+
onChange={(e) => setAssignedTo(e.target.value)}
|
| 172 |
+
placeholder="Agent email or ID"
|
| 173 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 174 |
+
/>
|
| 175 |
+
</div>
|
| 176 |
+
<div className="flex justify-end gap-2">
|
| 177 |
+
<Button type="button" variant="outline" onClick={() => setAssignModal(false)}>
|
| 178 |
+
Cancel
|
| 179 |
+
</Button>
|
| 180 |
+
<Button type="submit" disabled={!assignedTo}>
|
| 181 |
+
Assign
|
| 182 |
+
</Button>
|
| 183 |
+
</div>
|
| 184 |
+
</form>
|
| 185 |
+
</ModalBody>
|
| 186 |
+
</Modal>
|
| 187 |
+
)}
|
| 188 |
+
|
| 189 |
+
{/* Status modal */}
|
| 190 |
+
{statusModal && (
|
| 191 |
+
<Modal isOpen onClose={() => setStatusModal(false)} size="md">
|
| 192 |
+
<ModalHeader>
|
| 193 |
+
<ModalTitle>Change Status</ModalTitle>
|
| 194 |
+
</ModalHeader>
|
| 195 |
+
<ModalBody>
|
| 196 |
+
<form
|
| 197 |
+
onSubmit={(e) => {
|
| 198 |
+
e.preventDefault();
|
| 199 |
+
(trpc.support as any).updateTicketStatus.useMutation({
|
| 200 |
+
onSuccess: () => { setStatusModal(false); setNewStatus(""); },
|
| 201 |
+
}).mutate({ ticketId, status: newStatus });
|
| 202 |
+
}}
|
| 203 |
+
className="space-y-4"
|
| 204 |
+
>
|
| 205 |
+
<div>
|
| 206 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">New Status</label>
|
| 207 |
+
<select
|
| 208 |
+
value={newStatus}
|
| 209 |
+
onChange={(e) => setNewStatus(e.target.value)}
|
| 210 |
+
className="w-full text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] px-3 py-2 text-sm focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20 outline-none"
|
| 211 |
+
>
|
| 212 |
+
<option value="open">Open</option>
|
| 213 |
+
<option value="in_progress">In Progress</option>
|
| 214 |
+
<option value="resolved">Resolved</option>
|
| 215 |
+
<option value="closed">Closed</option>
|
| 216 |
+
</select>
|
| 217 |
+
</div>
|
| 218 |
+
<div className="flex justify-end gap-2">
|
| 219 |
+
<Button type="button" variant="outline" onClick={() => setStatusModal(false)}>
|
| 220 |
+
Cancel
|
| 221 |
+
</Button>
|
| 222 |
+
<Button type="submit">
|
| 223 |
+
Update
|
| 224 |
+
</Button>
|
| 225 |
+
</div>
|
| 226 |
+
</form>
|
| 227 |
+
</ModalBody>
|
| 228 |
+
</Modal>
|
| 229 |
+
)}
|
| 230 |
+
</div>
|
| 231 |
+
);
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
function ticketStatusClass(s: string): string {
|
| 235 |
+
switch (s) {
|
| 236 |
+
case "open": return "bg-[var(--color-warning)]/10 border-[var(--color-warning)]/20 text-[var(--color-warning)]";
|
| 237 |
+
case "in_progress": return "bg-[var(--color-info)]/10 border-[var(--color-info)]/20 text-[var(--color-info)]";
|
| 238 |
+
case "resolved": return "bg-[var(--color-success)]/10 border-[var(--color-success)]/20 text-[var(--color-success)]";
|
| 239 |
+
case "closed": return "border-transparent text-[var(--text-tertiary)]";
|
| 240 |
+
default: return "border-transparent";
|
| 241 |
+
}
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
function ticketPriorityClass(p: string): string {
|
| 245 |
+
switch (p) {
|
| 246 |
+
case "high": return "bg-[var(--color-error)]/10 border-[var(--color-error)]/20 text-[var(--color-error)]";
|
| 247 |
+
case "medium": return "bg-[var(--color-warning)]/10 border-[var(--color-warning)]/20 text-[var(--color-warning)]";
|
| 248 |
+
case "low": return "bg-[var(--color-info)]/10 border-[var(--color-info)]/20 text-[var(--color-info)]";
|
| 249 |
+
default: return "border-transparent";
|
| 250 |
+
}
|
| 251 |
+
}
|
apps/admin/src/app/(dashboard)/support/page.tsx
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { useRouter } from "next/navigation";
|
| 5 |
+
import { Mail, Clock, TrendingUp, AlertCircle } from "lucide-react";
|
| 6 |
+
import { trpc } from "@/lib/trpc";
|
| 7 |
+
import { cn } from "@/lib/utils";
|
| 8 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 9 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 10 |
+
import { Badge } from "@micprotocol/ui";
|
| 11 |
+
import { Button } from "@micprotocol/ui";
|
| 12 |
+
import { Input } from "@micprotocol/ui";
|
| 13 |
+
import { ago } from "@/lib/utils";
|
| 14 |
+
|
| 15 |
+
export default function SupportPage() {
|
| 16 |
+
const router = useRouter();
|
| 17 |
+
const { data: tickets, isLoading } = (trpc.support as any).listTickets.useQuery(
|
| 18 |
+
undefined,
|
| 19 |
+
{ refetchInterval: 30_000 },
|
| 20 |
+
);
|
| 21 |
+
|
| 22 |
+
const items = (tickets?.items ?? []) as any[];
|
| 23 |
+
const open = items.filter((t) => t.status === "open").length;
|
| 24 |
+
const inProgress = items.filter((t) => t.status === "in_progress").length;
|
| 25 |
+
const resolved = items.filter((t) => t.status === "resolved").length;
|
| 26 |
+
const avgCSAT = items.filter((t) => t.csat != null).reduce((sum, t) => sum + t.csat, 0) / Math.max(items.filter((t) => t.csat != null).length, 1);
|
| 27 |
+
|
| 28 |
+
return (
|
| 29 |
+
<div className="animate-fade-in">
|
| 30 |
+
<AdminHeader
|
| 31 |
+
title="Support"
|
| 32 |
+
subtitle="Customer support tickets, CSAT, and agent assignment"
|
| 33 |
+
refreshing={isLoading}
|
| 34 |
+
/>
|
| 35 |
+
|
| 36 |
+
<div className="space-y-6 p-6">
|
| 37 |
+
{/* KPI strip */}
|
| 38 |
+
<div className="grid gap-4 sm:grid-cols-4">
|
| 39 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 40 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Total Tickets</p>
|
| 41 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{items.length}</p>
|
| 42 |
+
</Card>
|
| 43 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 44 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Open</p>
|
| 45 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-warning)]">{open}</p>
|
| 46 |
+
</Card>
|
| 47 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 48 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">In Progress</p>
|
| 49 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-info)]">{inProgress}</p>
|
| 50 |
+
</Card>
|
| 51 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 52 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Avg CSAT</p>
|
| 53 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-success)]">
|
| 54 |
+
{isNaN(avgCSAT) ? "β" : avgCSAT.toFixed(1)} / 5
|
| 55 |
+
</p>
|
| 56 |
+
</Card>
|
| 57 |
+
</div>
|
| 58 |
+
|
| 59 |
+
{/* Filters */}
|
| 60 |
+
<div className="flex gap-2 items-end">
|
| 61 |
+
<div className="relative flex-1 max-w-md">
|
| 62 |
+
<Mail className="absolute left-3 top-3 size-4 text-[var(--text-tertiary)]" />
|
| 63 |
+
<Input
|
| 64 |
+
placeholder="Search tickets by subject or guestβ¦"
|
| 65 |
+
className="pl-10 text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 66 |
+
/>
|
| 67 |
+
</div>
|
| 68 |
+
<select className="w-full max-w-sm text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] px-3 py-2 text-sm focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20 outline-none">
|
| 69 |
+
<option value="all">All Status</option>
|
| 70 |
+
<option value="open">Open</option>
|
| 71 |
+
<option value="in_progress">In Progress</option>
|
| 72 |
+
<option value="resolved">Resolved</option>
|
| 73 |
+
</select>
|
| 74 |
+
</div>
|
| 75 |
+
|
| 76 |
+
{/* Tickets table */}
|
| 77 |
+
<Card>
|
| 78 |
+
<CardHeader>
|
| 79 |
+
<CardTitle className="flex items-center gap-2">
|
| 80 |
+
<Mail className="size-4 text-[var(--color-primary)]" /> Support Tickets
|
| 81 |
+
</CardTitle>
|
| 82 |
+
</CardHeader>
|
| 83 |
+
<CardContent className="p-0">
|
| 84 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 85 |
+
<table className="w-full text-left border-collapse">
|
| 86 |
+
<thead>
|
| 87 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 88 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-28">Ticket ID</th>
|
| 89 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-28">Guest</th>
|
| 90 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Subject</th>
|
| 91 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Status</th>
|
| 92 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Priority</th>
|
| 93 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-24">Created</th>
|
| 94 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Actions</th>
|
| 95 |
+
</tr>
|
| 96 |
+
</thead>
|
| 97 |
+
<tbody>
|
| 98 |
+
{isLoading ? (
|
| 99 |
+
[...Array(5)].map((_, i) => (
|
| 100 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 101 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 102 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 103 |
+
</td>
|
| 104 |
+
</tr>
|
| 105 |
+
))
|
| 106 |
+
) : items.length === 0 ? (
|
| 107 |
+
<tr>
|
| 108 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 109 |
+
No tickets yet.
|
| 110 |
+
</td>
|
| 111 |
+
</tr>
|
| 112 |
+
) : (
|
| 113 |
+
items.map((t: any) => (
|
| 114 |
+
<tr key={t.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 115 |
+
<td className="py-4 font-mono text-xs text-[var(--text-secondary)]">
|
| 116 |
+
{t.id.slice(0, 8)}β¦
|
| 117 |
+
</td>
|
| 118 |
+
<td className="py-4 text-xs text-[var(--text-primary)] truncate" style={{ maxWidth: 150 }}>
|
| 119 |
+
{t.guestName ?? t.guestId?.slice(0, 8) ?? "β"}
|
| 120 |
+
</td>
|
| 121 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] truncate" style={{ maxWidth: 200 }}>
|
| 122 |
+
{t.subject ?? "β"}
|
| 123 |
+
</td>
|
| 124 |
+
<td className="py-4 text-xs text-center">
|
| 125 |
+
<Badge className={cn("capitalize text-xs", ticketStatusClass(t.status))}>
|
| 126 |
+
{t.status.replace(/_/g, " ")}
|
| 127 |
+
</Badge>
|
| 128 |
+
</td>
|
| 129 |
+
<td className="py-4 text-xs text-center">
|
| 130 |
+
<Badge className={cn("capitalize text-xs", ticketPriorityClass(t.priority))}>
|
| 131 |
+
{t.priority}
|
| 132 |
+
</Badge>
|
| 133 |
+
</td>
|
| 134 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)] text-right">
|
| 135 |
+
{new Date(t.createdAt).toLocaleDateString()}
|
| 136 |
+
</td>
|
| 137 |
+
<td className="py-4 text-sm text-right">
|
| 138 |
+
<Button variant="ghost" size="sm" onClick={() => router.push(`/support/${t.id}`)}>
|
| 139 |
+
<Clock size={14} className="mr-1" /> View
|
| 140 |
+
</Button>
|
| 141 |
+
</td>
|
| 142 |
+
</tr>
|
| 143 |
+
))
|
| 144 |
+
)}
|
| 145 |
+
</tbody>
|
| 146 |
+
</table>
|
| 147 |
+
</div>
|
| 148 |
+
</CardContent>
|
| 149 |
+
</Card>
|
| 150 |
+
</div>
|
| 151 |
+
</div>
|
| 152 |
+
);
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
function ticketStatusClass(s: string): string {
|
| 156 |
+
switch (s) {
|
| 157 |
+
case "open": return "bg-[var(--color-warning)]/10 border-[var(--color-warning)]/20 text-[var(--color-warning)]";
|
| 158 |
+
case "in_progress": return "bg-[var(--color-info)]/10 border-[var(--color-info)]/20 text-[var(--color-info)]";
|
| 159 |
+
case "resolved": return "bg-[var(--color-success)]/10 border-[var(--color-success)]/20 text-[var(--color-success)]";
|
| 160 |
+
case "closed": return "border-transparent text-[var(--text-tertiary)]";
|
| 161 |
+
default: return "border-transparent";
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
function ticketPriorityClass(p: string): string {
|
| 166 |
+
switch (p) {
|
| 167 |
+
case "high": return "bg-[var(--color-error)]/10 border-[var(--color-error)]/20 text-[var(--color-error)]";
|
| 168 |
+
case "medium": return "bg-[var(--color-warning)]/10 border-[var(--color-warning)]/20 text-[var(--color-warning)]";
|
| 169 |
+
case "low": return "bg-[var(--color-info)]/10 border-[var(--color-info)]/20 text-[var(--color-info)]";
|
| 170 |
+
default: return "border-transparent";
|
| 171 |
+
}
|
| 172 |
+
}
|
apps/admin/src/app/(dashboard)/surveys/[id]/page.tsx
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState } from "react";
|
| 4 |
+
import { useParams, useRouter } from "next/navigation";
|
| 5 |
+
import { FileText, Send, Plus, Trash2, Edit, Clock, AlertCircle } from "lucide-react";
|
| 6 |
+
import { trpc } from "@/lib/trpc";
|
| 7 |
+
import { cn } from "@/lib/utils";
|
| 8 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 9 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 10 |
+
import { Badge } from "@micprotocol/ui";
|
| 11 |
+
import { Button } from "@micprotocol/ui";
|
| 12 |
+
import { Input } from "@micprotocol/ui";
|
| 13 |
+
import { Textarea } from "@micprotocol/ui";
|
| 14 |
+
import { Switch } from "@micprotocol/ui";
|
| 15 |
+
import { Modal, ModalHeader, ModalTitle, ModalBody, ModalFooter } from "@micprotocol/ui";
|
| 16 |
+
import { ago } from "@/lib/utils";
|
| 17 |
+
|
| 18 |
+
export default function SurveyDetailPage() {
|
| 19 |
+
const params = useParams();
|
| 20 |
+
const router = useRouter();
|
| 21 |
+
const surveyId = (params as any)?.id as string;
|
| 22 |
+
|
| 23 |
+
const { data: survey, isLoading } = (trpc.surveys as any).getSurvey.useQuery(
|
| 24 |
+
{ surveyId },
|
| 25 |
+
{ enabled: !!surveyId },
|
| 26 |
+
);
|
| 27 |
+
|
| 28 |
+
const [newQuestion, setNewQuestion] = useState("");
|
| 29 |
+
const [questionType, setQuestionType] = useState("text");
|
| 30 |
+
const [addQuestionModal, setAddQuestionModal] = useState(false);
|
| 31 |
+
|
| 32 |
+
if (!surveyId) {
|
| 33 |
+
router.push("/surveys");
|
| 34 |
+
return null;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
if (isLoading || !survey) {
|
| 38 |
+
return (
|
| 39 |
+
<div className="animate-fade-in p-6">
|
| 40 |
+
<AdminHeader title="Survey" subtitle="Loading survey detailsβ¦" />
|
| 41 |
+
<div className="flex items-center justify-center h-[40vh]">
|
| 42 |
+
<div className="skeleton w-full h-16 max-w-xs mx-auto" />
|
| 43 |
+
</div>
|
| 44 |
+
</div>
|
| 45 |
+
);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
const questions = survey.questions ?? [];
|
| 49 |
+
const responses = survey.responses ?? [];
|
| 50 |
+
|
| 51 |
+
const questionTypeOptions = [
|
| 52 |
+
{ value: "text", label: "Short Answer" },
|
| 53 |
+
{ value: "textarea", label: "Long Answer" },
|
| 54 |
+
{ value: "select", label: "Multiple Choice" },
|
| 55 |
+
{ value: "rating", label: "Rating (1-5)" },
|
| 56 |
+
{ value: "boolean", label: "Yes/No" },
|
| 57 |
+
];
|
| 58 |
+
|
| 59 |
+
return (
|
| 60 |
+
<div className="animate-fade-in">
|
| 61 |
+
<AdminHeader
|
| 62 |
+
title={`Survey: ${survey.title}`}
|
| 63 |
+
subtitle={survey.description ?? "No description"}
|
| 64 |
+
actions={
|
| 65 |
+
<div className="flex gap-2">
|
| 66 |
+
<Button variant="outline" size="sm" onClick={() => setAddQuestionModal(true)}>
|
| 67 |
+
<Plus size={14} className="mr-1" /> Add Question
|
| 68 |
+
</Button>
|
| 69 |
+
<Button variant="outline" size="sm" onClick={() => {}}>
|
| 70 |
+
<Send size={14} className="mr-1" /> Publish
|
| 71 |
+
</Button>
|
| 72 |
+
</div>
|
| 73 |
+
}
|
| 74 |
+
/>
|
| 75 |
+
|
| 76 |
+
<div className="space-y-6 p-6">
|
| 77 |
+
{/* Survey meta */}
|
| 78 |
+
<Card>
|
| 79 |
+
<CardContent className="p-5">
|
| 80 |
+
<div className="grid grid-cols-2 sm:grid-cols-4 gap-4 text-xs">
|
| 81 |
+
<div>
|
| 82 |
+
<p className="text-[var(--text-tertiary)]">Status</p>
|
| 83 |
+
<Badge className={cn("capitalize", surveyStatusClass(survey.status))}>
|
| 84 |
+
{survey.status}
|
| 85 |
+
</Badge>
|
| 86 |
+
</div>
|
| 87 |
+
<div>
|
| 88 |
+
<p className="text-[var(--text-tertiary)]">Questions</p>
|
| 89 |
+
<p className="text-[var(--text-primary)] font-mono">{questions.length}</p>
|
| 90 |
+
</div>
|
| 91 |
+
<div>
|
| 92 |
+
<p className="text-[var(--text-tertiary)]">Responses</p>
|
| 93 |
+
<p className="text-[var(--text-primary)] font-mono">{responses.length}</p>
|
| 94 |
+
</div>
|
| 95 |
+
<div>
|
| 96 |
+
<p className="text-[var(--text-tertiary)]">Created</p>
|
| 97 |
+
<p className="text-[var(--text-primary)] font-mono">{new Date(survey.createdAt).toLocaleDateString()}</p>
|
| 98 |
+
</div>
|
| 99 |
+
</div>
|
| 100 |
+
</CardContent>
|
| 101 |
+
</Card>
|
| 102 |
+
|
| 103 |
+
{/* Questions editor */}
|
| 104 |
+
<Card>
|
| 105 |
+
<CardHeader>
|
| 106 |
+
<CardTitle className="flex items-center gap-2">
|
| 107 |
+
<FileText className="size-4 text-[var(--color-info)]" /> Questions
|
| 108 |
+
</CardTitle>
|
| 109 |
+
</CardHeader>
|
| 110 |
+
<CardContent className="p-0">
|
| 111 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 112 |
+
<table className="w-full text-left border-collapse">
|
| 113 |
+
<thead>
|
| 114 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 115 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">#</th>
|
| 116 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Question</th>
|
| 117 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-24">Type</th>
|
| 118 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Required</th>
|
| 119 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Actions</th>
|
| 120 |
+
</tr>
|
| 121 |
+
</thead>
|
| 122 |
+
<tbody>
|
| 123 |
+
{questions.length === 0 ? (
|
| 124 |
+
<tr>
|
| 125 |
+
<td colSpan={5} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 126 |
+
No questions yet. Add one below.
|
| 127 |
+
</td>
|
| 128 |
+
</tr>
|
| 129 |
+
) : (
|
| 130 |
+
questions.map((q: any, idx: number) => (
|
| 131 |
+
<tr key={q.id ?? idx} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 132 |
+
<td className="py-4 text-xs font-mono text-[var(--text-tertiary)]">{idx + 1}</td>
|
| 133 |
+
<td className="py-4 text-sm text-[var(--text-primary)]">{q.text}</td>
|
| 134 |
+
<td className="py-4 text-xs text-center">
|
| 135 |
+
<Badge className="text-[10px] capitalize">{q.type}</Badge>
|
| 136 |
+
</td>
|
| 137 |
+
<td className="py-4 text-xs text-center">
|
| 138 |
+
<Switch checked={q.required ?? false} onChange={() => {}} />
|
| 139 |
+
</td>
|
| 140 |
+
<td className="py-4 text-sm text-right">
|
| 141 |
+
<div className="flex gap-1 justify-end">
|
| 142 |
+
<Button variant="ghost" size="sm" onClick={() => {}}>
|
| 143 |
+
<Edit size={14} />
|
| 144 |
+
</Button>
|
| 145 |
+
<Button variant="destructive" size="sm" onClick={() => {}}>
|
| 146 |
+
<Trash2 size={14} />
|
| 147 |
+
</Button>
|
| 148 |
+
</div>
|
| 149 |
+
</td>
|
| 150 |
+
</tr>
|
| 151 |
+
))
|
| 152 |
+
)}
|
| 153 |
+
</tbody>
|
| 154 |
+
</table>
|
| 155 |
+
</div>
|
| 156 |
+
</CardContent>
|
| 157 |
+
</Card>
|
| 158 |
+
|
| 159 |
+
{/* Responses */}
|
| 160 |
+
<Card>
|
| 161 |
+
<CardHeader>
|
| 162 |
+
<CardTitle className="flex items-center gap-2">
|
| 163 |
+
<Clock className="size-4 text-[var(--color-primary)]" /> Responses
|
| 164 |
+
</CardTitle>
|
| 165 |
+
</CardHeader>
|
| 166 |
+
<CardContent>
|
| 167 |
+
{responses.length === 0 ? (
|
| 168 |
+
<div className="p-8 text-center text-[var(--text-tertiary)]">
|
| 169 |
+
No responses yet.
|
| 170 |
+
</div>
|
| 171 |
+
) : (
|
| 172 |
+
<div className="overflow-auto">
|
| 173 |
+
<table className="w-full text-left border-collapse">
|
| 174 |
+
<thead>
|
| 175 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 176 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Response ID</th>
|
| 177 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Guest</th>
|
| 178 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Submitted</th>
|
| 179 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Actions</th>
|
| 180 |
+
</tr>
|
| 181 |
+
</thead>
|
| 182 |
+
<tbody>
|
| 183 |
+
{responses.map((r: any) => (
|
| 184 |
+
<tr key={r.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 185 |
+
<td className="py-4 font-mono text-xs text-[var(--text-secondary)]">{r.id.slice(0, 8)}β¦</td>
|
| 186 |
+
<td className="py-4 text-xs text-[var(--text-primary)]">{r.guestName ?? r.guestId?.slice(0, 8) ?? "Anonymous"}</td>
|
| 187 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)] text-right">{new Date(r.createdAt).toLocaleString()}</td>
|
| 188 |
+
<td className="py-4 text-sm text-right">
|
| 189 |
+
<Button variant="ghost" size="sm" onClick={() => {}}>
|
| 190 |
+
<AlertCircle size={14} />
|
| 191 |
+
</Button>
|
| 192 |
+
</td>
|
| 193 |
+
</tr>
|
| 194 |
+
))}
|
| 195 |
+
</tbody>
|
| 196 |
+
</table>
|
| 197 |
+
</div>
|
| 198 |
+
)}
|
| 199 |
+
</CardContent>
|
| 200 |
+
</Card>
|
| 201 |
+
|
| 202 |
+
{/* Add question modal */}
|
| 203 |
+
{addQuestionModal && (
|
| 204 |
+
<Modal isOpen onClose={() => setAddQuestionModal(false)} size="md">
|
| 205 |
+
<ModalHeader>
|
| 206 |
+
<ModalTitle>Add Question</ModalTitle>
|
| 207 |
+
</ModalHeader>
|
| 208 |
+
<ModalBody>
|
| 209 |
+
<form
|
| 210 |
+
onSubmit={(e) => {
|
| 211 |
+
e.preventDefault();
|
| 212 |
+
// Question added via mutation (backend wiring)
|
| 213 |
+
setAddQuestionModal(false);
|
| 214 |
+
}}
|
| 215 |
+
className="space-y-4"
|
| 216 |
+
>
|
| 217 |
+
<div>
|
| 218 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">Question</label>
|
| 219 |
+
<Input
|
| 220 |
+
value={newQuestion}
|
| 221 |
+
onChange={(e) => setNewQuestion(e.target.value)}
|
| 222 |
+
placeholder="Enter your question"
|
| 223 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 224 |
+
/>
|
| 225 |
+
</div>
|
| 226 |
+
<div>
|
| 227 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">Question Type</label>
|
| 228 |
+
<select
|
| 229 |
+
value={questionType}
|
| 230 |
+
onChange={(e) => setQuestionType(e.target.value)}
|
| 231 |
+
className="w-full text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] px-3 py-2 text-sm focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20 outline-none"
|
| 232 |
+
>
|
| 233 |
+
{questionTypeOptions.map((opt) => (
|
| 234 |
+
<option key={opt.value} value={opt.value}>{opt.label}</option>
|
| 235 |
+
))}
|
| 236 |
+
</select>
|
| 237 |
+
</div>
|
| 238 |
+
<div className="flex items-center gap-3">
|
| 239 |
+
<Switch checked={false} onChange={() => {}} />
|
| 240 |
+
<label className="text-xs text-[var(--text-secondary)]">Required</label>
|
| 241 |
+
</div>
|
| 242 |
+
<div className="flex justify-end gap-2">
|
| 243 |
+
<Button type="button" variant="outline" onClick={() => setAddQuestionModal(false)}>
|
| 244 |
+
Cancel
|
| 245 |
+
</Button>
|
| 246 |
+
<Button type="submit" disabled={!newQuestion}>
|
| 247 |
+
Add Question
|
| 248 |
+
</Button>
|
| 249 |
+
</div>
|
| 250 |
+
</form>
|
| 251 |
+
</ModalBody>
|
| 252 |
+
</Modal>
|
| 253 |
+
)}
|
| 254 |
+
</div>
|
| 255 |
+
</div>
|
| 256 |
+
);
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
function surveyStatusClass(s: string): string {
|
| 260 |
+
switch (s) {
|
| 261 |
+
case "active": return "bg-[var(--color-success)]/20 border-[var(--color-success)]/30 text-[var(--color-success)]";
|
| 262 |
+
case "draft": return "bg-[var(--color-warning)]/20 border-[var(--color-warning)]/30 text-[var(--color-warning)]";
|
| 263 |
+
case "closed": return "border-transparent text-[var(--text-tertiary)]";
|
| 264 |
+
default: return "border-transparent";
|
| 265 |
+
}
|
| 266 |
+
}
|
apps/admin/src/app/(dashboard)/surveys/page.tsx
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState } from "react";
|
| 4 |
+
import { useRouter } from "next/navigation";
|
| 5 |
+
import { FileText, Send, Clock, AlertCircle } from "lucide-react";
|
| 6 |
+
import { trpc } from "@/lib/trpc";
|
| 7 |
+
import { cn } from "@/lib/utils";
|
| 8 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 9 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 10 |
+
import { Badge } from "@micprotocol/ui";
|
| 11 |
+
import { Button } from "@micprotocol/ui";
|
| 12 |
+
import { Input } from "@micprotocol/ui";
|
| 13 |
+
import { Textarea } from "@micprotocol/ui";
|
| 14 |
+
import { Switch } from "@micprotocol/ui";
|
| 15 |
+
import { Modal, ModalHeader, ModalTitle, ModalBody, ModalFooter } from "@micprotocol/ui";
|
| 16 |
+
import { ago } from "@/lib/utils";
|
| 17 |
+
|
| 18 |
+
export default function SurveysPage() {
|
| 19 |
+
const router = useRouter();
|
| 20 |
+
const [createModal, setCreateModal] = useState(false);
|
| 21 |
+
const [newTitle, setNewTitle] = useState("");
|
| 22 |
+
const [newDescription, setNewDescription] = useState("");
|
| 23 |
+
|
| 24 |
+
const { data: surveys, isLoading } = (trpc.surveys as any).list.useQuery(
|
| 25 |
+
undefined,
|
| 26 |
+
{ refetchInterval: 30_000 },
|
| 27 |
+
);
|
| 28 |
+
|
| 29 |
+
const items = (surveys?.items ?? []) as any[];
|
| 30 |
+
const active = items.filter((s: any) => s.status === "active").length;
|
| 31 |
+
const draft = items.filter((s: any) => s.status === "draft").length;
|
| 32 |
+
const closed = items.filter((s: any) => s.status === "closed").length;
|
| 33 |
+
|
| 34 |
+
const createSurvey = (trpc.surveys as any).create.useMutation({
|
| 35 |
+
onSuccess: () => { setCreateModal(false); setNewTitle(""); setNewDescription(""); },
|
| 36 |
+
});
|
| 37 |
+
|
| 38 |
+
return (
|
| 39 |
+
<div className="animate-fade-in">
|
| 40 |
+
<AdminHeader
|
| 41 |
+
title="Surveys"
|
| 42 |
+
subtitle="Customer satisfaction and feedback surveys"
|
| 43 |
+
refreshing={isLoading}
|
| 44 |
+
actions={
|
| 45 |
+
<Button onClick={() => setCreateModal(true)}>
|
| 46 |
+
<FileText size={14} className="mr-1" /> Create Survey
|
| 47 |
+
</Button>
|
| 48 |
+
}
|
| 49 |
+
/>
|
| 50 |
+
|
| 51 |
+
<div className="space-y-6 p-6">
|
| 52 |
+
{/* KPI strip */}
|
| 53 |
+
<div className="grid gap-4 sm:grid-cols-4">
|
| 54 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 55 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Total Surveys</p>
|
| 56 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{items.length}</p>
|
| 57 |
+
</Card>
|
| 58 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 59 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Active</p>
|
| 60 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-success)]">{active}</p>
|
| 61 |
+
</Card>
|
| 62 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 63 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Draft</p>
|
| 64 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-warning)]">{draft}</p>
|
| 65 |
+
</Card>
|
| 66 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 67 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Closed</p>
|
| 68 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-tertiary)]">{closed}</p>
|
| 69 |
+
</Card>
|
| 70 |
+
</div>
|
| 71 |
+
|
| 72 |
+
{/* Survey list */}
|
| 73 |
+
<Card>
|
| 74 |
+
<CardHeader>
|
| 75 |
+
<CardTitle className="flex items-center gap-2">
|
| 76 |
+
<FileText className="size-4 text-[var(--color-primary)]" /> Surveys
|
| 77 |
+
</CardTitle>
|
| 78 |
+
</CardHeader>
|
| 79 |
+
<CardContent className="p-0">
|
| 80 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 81 |
+
<table className="w-full text-left border-collapse">
|
| 82 |
+
<thead>
|
| 83 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 84 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-32">Survey</th>
|
| 85 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Type</th>
|
| 86 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Status</th>
|
| 87 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Responses</th>
|
| 88 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Created</th>
|
| 89 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-28">Actions</th>
|
| 90 |
+
</tr>
|
| 91 |
+
</thead>
|
| 92 |
+
<tbody>
|
| 93 |
+
{isLoading ? (
|
| 94 |
+
[...Array(5)].map((_, i) => (
|
| 95 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 96 |
+
<td colSpan={6} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 97 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 98 |
+
</td>
|
| 99 |
+
</tr>
|
| 100 |
+
))
|
| 101 |
+
) : items.length === 0 ? (
|
| 102 |
+
<tr>
|
| 103 |
+
<td colSpan={6} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 104 |
+
No surveys yet.
|
| 105 |
+
</td>
|
| 106 |
+
</tr>
|
| 107 |
+
) : (
|
| 108 |
+
items.map((s: any) => (
|
| 109 |
+
<tr key={s.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 110 |
+
<td className="py-4 font-medium text-[var(--text-primary)]">{s.title}</td>
|
| 111 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] font-mono capitalize">{s.surveyType ?? "β"}</td>
|
| 112 |
+
<td className="py-4 text-xs text-center">
|
| 113 |
+
<Badge className={cn("capitalize text-xs", surveyStatusClass(s.status))}>
|
| 114 |
+
{s.status}
|
| 115 |
+
</Badge>
|
| 116 |
+
</td>
|
| 117 |
+
<td className="py-4 text-xs text-center font-mono text-[var(--text-primary)]">{s.responseCount ?? 0}</td>
|
| 118 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)] text-right">{new Date(s.createdAt).toLocaleDateString()}</td>
|
| 119 |
+
<td className="py-4 text-sm text-right">
|
| 120 |
+
<Button variant="ghost" size="sm" onClick={() => router.push(`/surveys/${s.id}`)}>
|
| 121 |
+
<Clock size={14} className="mr-1" /> View
|
| 122 |
+
</Button>
|
| 123 |
+
</td>
|
| 124 |
+
</tr>
|
| 125 |
+
))
|
| 126 |
+
)}
|
| 127 |
+
</tbody>
|
| 128 |
+
</table>
|
| 129 |
+
</div>
|
| 130 |
+
</CardContent>
|
| 131 |
+
</Card>
|
| 132 |
+
|
| 133 |
+
{/* Create survey modal */}
|
| 134 |
+
{createModal && (
|
| 135 |
+
<Modal isOpen onClose={() => setCreateModal(false)} size="md">
|
| 136 |
+
<ModalHeader>
|
| 137 |
+
<ModalTitle>Create Survey</ModalTitle>
|
| 138 |
+
</ModalHeader>
|
| 139 |
+
<ModalBody>
|
| 140 |
+
<form
|
| 141 |
+
onSubmit={(e) => {
|
| 142 |
+
e.preventDefault();
|
| 143 |
+
createSurvey.mutate({ title: newTitle, description: newDescription || undefined });
|
| 144 |
+
}}
|
| 145 |
+
className="space-y-4"
|
| 146 |
+
>
|
| 147 |
+
<div>
|
| 148 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">Title</label>
|
| 149 |
+
<Input
|
| 150 |
+
value={newTitle}
|
| 151 |
+
onChange={(e) => setNewTitle(e.target.value)}
|
| 152 |
+
placeholder="Survey title"
|
| 153 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 154 |
+
/>
|
| 155 |
+
</div>
|
| 156 |
+
<div>
|
| 157 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">Description</label>
|
| 158 |
+
<Textarea
|
| 159 |
+
value={newDescription}
|
| 160 |
+
onChange={(e) => setNewDescription(e.target.value)}
|
| 161 |
+
placeholder="Survey description"
|
| 162 |
+
rows={3}
|
| 163 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 164 |
+
/>
|
| 165 |
+
</div>
|
| 166 |
+
<div className="flex items-center gap-3">
|
| 167 |
+
<Switch
|
| 168 |
+
checked={true}
|
| 169 |
+
onChange={() => {}}
|
| 170 |
+
/>
|
| 171 |
+
<label className="text-xs text-[var(--text-secondary)]">Active on creation</label>
|
| 172 |
+
</div>
|
| 173 |
+
<div className="flex justify-end gap-2">
|
| 174 |
+
<Button type="button" variant="outline" onClick={() => setCreateModal(false)}>
|
| 175 |
+
Cancel
|
| 176 |
+
</Button>
|
| 177 |
+
<Button type="submit" disabled={!newTitle || createSurvey.isPending}>
|
| 178 |
+
Create Survey
|
| 179 |
+
</Button>
|
| 180 |
+
</div>
|
| 181 |
+
</form>
|
| 182 |
+
</ModalBody>
|
| 183 |
+
</Modal>
|
| 184 |
+
)}
|
| 185 |
+
</div>
|
| 186 |
+
</div>
|
| 187 |
+
);
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
function surveyStatusClass(s: string): string {
|
| 191 |
+
switch (s) {
|
| 192 |
+
case "active": return "bg-[var(--color-success)]/20 border-[var(--color-success)]/30 text-[var(--color-success)]";
|
| 193 |
+
case "draft": return "bg-[var(--color-warning)]/20 border-[var(--color-warning)]/30 text-[var(--color-warning)]";
|
| 194 |
+
case "closed": return "border-transparent text-[var(--text-tertiary)]";
|
| 195 |
+
default: return "border-transparent";
|
| 196 |
+
}
|
| 197 |
+
}
|
apps/admin/src/app/(dashboard)/synthetic-agents/page.tsx
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Play, Clock, Activity, Database, AlertCircle } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { cn } from "@/lib/utils";
|
| 7 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 8 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 9 |
+
import { Badge } from "@micprotocol/ui";
|
| 10 |
+
import { Button } from "@micprotocol/ui";
|
| 11 |
+
|
| 12 |
+
export default function SyntheticAgentsPage() {
|
| 13 |
+
const { data: report, isLoading } = (trpc.admin.supervision as any).listFindings.useQuery(
|
| 14 |
+
undefined,
|
| 15 |
+
{ refetchInterval: 60_000, retry: false },
|
| 16 |
+
);
|
| 17 |
+
|
| 18 |
+
const reportAny = report as any;
|
| 19 |
+
const weaknesses = reportAny?.weaknesses ?? [];
|
| 20 |
+
const totalWeaknesses = weaknesses.length;
|
| 21 |
+
const criticalWeaknesses = weaknesses.filter((w: any) => w.severity === "critical").length;
|
| 22 |
+
const highWeaknesses = weaknesses.filter((w: any) => w.severity === "high").length;
|
| 23 |
+
|
| 24 |
+
return (
|
| 25 |
+
<div className="animate-fade-in">
|
| 26 |
+
<AdminHeader
|
| 27 |
+
title="Synthetic Agents"
|
| 28 |
+
subtitle="Automated platform stress-testing and weakness detection"
|
| 29 |
+
refreshing={isLoading}
|
| 30 |
+
actions={
|
| 31 |
+
<Button variant="outline" size="sm" disabled={isLoading}>
|
| 32 |
+
<Play size={14} className="mr-1" /> Run Now
|
| 33 |
+
</Button>
|
| 34 |
+
}
|
| 35 |
+
/>
|
| 36 |
+
|
| 37 |
+
<div className="space-y-6 p-6">
|
| 38 |
+
{/* KPI strip */}
|
| 39 |
+
<div className="grid gap-4 sm:grid-cols-4">
|
| 40 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 41 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Total Weaknesses</p>
|
| 42 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-warning)]">{totalWeaknesses}</p>
|
| 43 |
+
</Card>
|
| 44 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 45 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Critical</p>
|
| 46 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-error)]">{criticalWeaknesses}</p>
|
| 47 |
+
</Card>
|
| 48 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 49 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">High</p>
|
| 50 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-error)]">{highWeaknesses}</p>
|
| 51 |
+
</Card>
|
| 52 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 53 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Last Run</p>
|
| 54 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-info)]">
|
| 55 |
+
{reportAny?.ranAt ? new Date(reportAny.ranAt).toLocaleDateString() : "β"}
|
| 56 |
+
</p>
|
| 57 |
+
</Card>
|
| 58 |
+
</div>
|
| 59 |
+
|
| 60 |
+
{/* Weaknesses grid */}
|
| 61 |
+
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
| 62 |
+
{weaknesses.length > 0 ? (
|
| 63 |
+
weaknesses.map((w: any) => (
|
| 64 |
+
<Card key={w.id} className="border border-[var(--border-color)] hover:border-[var(--color-error)]/50 transition-colors">
|
| 65 |
+
<CardContent className="p-5">
|
| 66 |
+
<div className="flex items-start justify-between mb-3">
|
| 67 |
+
<div>
|
| 68 |
+
<h3 className="font-medium text-[var(--text-primary)]">{w.title}</h3>
|
| 69 |
+
<p className="text-xs text-[var(--text-secondary)]">{w.category}</p>
|
| 70 |
+
</div>
|
| 71 |
+
<Badge className={cn("capitalize text-xs", weaknessSeverityClass(w.severity))}>
|
| 72 |
+
{w.severity}
|
| 73 |
+
</Badge>
|
| 74 |
+
</div>
|
| 75 |
+
<p className="text-sm text-[var(--text-secondary)] mb-4">{w.description ?? "No description"}</p>
|
| 76 |
+
<div className="flex gap-2">
|
| 77 |
+
<Button variant="ghost" size="sm" onClick={() => {}}>
|
| 78 |
+
<Activity size={14} className="mr-1" /> Details
|
| 79 |
+
</Button>
|
| 80 |
+
<Button variant="outline" size="sm" onClick={() => {}}>
|
| 81 |
+
<Clock size={14} className="mr-1" /> Remediate
|
| 82 |
+
</Button>
|
| 83 |
+
</div>
|
| 84 |
+
</CardContent>
|
| 85 |
+
</Card>
|
| 86 |
+
))
|
| 87 |
+
) : (
|
| 88 |
+
<Card className="col-span-full p-12 border border-[var(--border-color)] rounded-[var(--radius-lg)] text-center">
|
| 89 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-4 inline-flex mx-auto">
|
| 90 |
+
<Database className="size-6 text-[var(--text-tertiary)]" />
|
| 91 |
+
</div>
|
| 92 |
+
<p className="mt-4 text-[var(--text-tertiary)]">No weaknesses detected. Platform is clean.</p>
|
| 93 |
+
</Card>
|
| 94 |
+
)}
|
| 95 |
+
</div>
|
| 96 |
+
|
| 97 |
+
{/* Reports */}
|
| 98 |
+
<Card>
|
| 99 |
+
<CardHeader>
|
| 100 |
+
<CardTitle className="flex items-center gap-2">
|
| 101 |
+
<AlertCircle className="size-4 text-[var(--color-primary)]" /> Latest Report
|
| 102 |
+
</CardTitle>
|
| 103 |
+
</CardHeader>
|
| 104 |
+
<CardContent className="p-5">
|
| 105 |
+
<div className="grid gap-4 sm:grid-cols-3">
|
| 106 |
+
<Card className="p-4 border border-[var(--border-color)]">
|
| 107 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Tests Run</p>
|
| 108 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{reportAny?.testsRun ?? 0}</p>
|
| 109 |
+
</Card>
|
| 110 |
+
<Card className="p-4 border border-[var(--border-color)]">
|
| 111 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Passed</p>
|
| 112 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-success)]">{reportAny?.testsPassed ?? 0}</p>
|
| 113 |
+
</Card>
|
| 114 |
+
<Card className="p-4 border border-[var(--border-color)]">
|
| 115 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Failed</p>
|
| 116 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-error)]">{reportAny?.testsFailed ?? 0}</p>
|
| 117 |
+
</Card>
|
| 118 |
+
</div>
|
| 119 |
+
</CardContent>
|
| 120 |
+
</Card>
|
| 121 |
+
</div>
|
| 122 |
+
</div>
|
| 123 |
+
);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
function weaknessSeverityClass(sev: string): string {
|
| 127 |
+
switch (sev) {
|
| 128 |
+
case "critical": return "bg-[var(--color-error)] border-[var(--color-error)] text-[var(--text-primary)]";
|
| 129 |
+
case "high": return "bg-[var(--color-error)]/10 border-[var(--color-error)]/20 text-[var(--color-error)]";
|
| 130 |
+
case "medium": return "bg-[var(--color-warning)]/10 border-[var(--color-warning)]/20 text-[var(--color-warning)]";
|
| 131 |
+
case "low": return "bg-[var(--color-info)]/10 border-[var(--color-info)]/20 text-[var(--color-info)]";
|
| 132 |
+
default: return "border-transparent";
|
| 133 |
+
}
|
| 134 |
+
}
|
apps/admin/src/app/(dashboard)/tenants/page.tsx
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Building2, Users, Podcast } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 7 |
+
import {
|
| 8 |
+
Card, CardContent, CardDescription, CardHeader, CardTitle,
|
| 9 |
+
} from "@micprotocol/ui";
|
| 10 |
+
import { Badge } from "@micprotocol/ui";
|
| 11 |
+
import { StatCard } from "@micprotocol/ui";
|
| 12 |
+
import { ago } from "@/lib/utils";
|
| 13 |
+
|
| 14 |
+
const planVariant = (plan: string) =>
|
| 15 |
+
plan === "studio"
|
| 16 |
+
? "brand"
|
| 17 |
+
: plan === "creator"
|
| 18 |
+
? "info"
|
| 19 |
+
: "neutral";
|
| 20 |
+
|
| 21 |
+
export default function TenantsPage() {
|
| 22 |
+
const {
|
| 23 |
+
data: workspaces,
|
| 24 |
+
isLoading,
|
| 25 |
+
isFetching,
|
| 26 |
+
refetch,
|
| 27 |
+
} = (trpc.crm as any).listWorkspaces.useQuery();
|
| 28 |
+
|
| 29 |
+
const totalWorkspaces = (workspaces ?? []).length;
|
| 30 |
+
const totalMembers = (workspaces ?? []).reduce((sum: any, ws: any) => sum + (ws._count?.members ?? 0), 0);
|
| 31 |
+
const totalPodcasts = (workspaces ?? []).reduce((sum: any, ws: any) => sum + (ws._count?.podcasts ?? 0), 0);
|
| 32 |
+
|
| 33 |
+
return (
|
| 34 |
+
<div className="animate-mic-fade-in-up">
|
| 35 |
+
<AdminHeader
|
| 36 |
+
title="Tenants & Workspaces"
|
| 37 |
+
subtitle="Workspace management β plans, members, podcasts"
|
| 38 |
+
onRefresh={refetch}
|
| 39 |
+
refreshing={isFetching}
|
| 40 |
+
actions={
|
| 41 |
+
<Badge tone="brand">
|
| 42 |
+
{totalWorkspaces} tenants
|
| 43 |
+
</Badge>
|
| 44 |
+
}
|
| 45 |
+
/>
|
| 46 |
+
|
| 47 |
+
<div className="space-y-6 p-6">
|
| 48 |
+
{/* KPI strip */}
|
| 49 |
+
<div className="grid gap-4 sm:grid-cols-3 lg:grid-cols-4">
|
| 50 |
+
<StatCard
|
| 51 |
+
icon={<Building2 className="size-5" />}
|
| 52 |
+
value={totalWorkspaces}
|
| 53 |
+
label="Total Tenants"
|
| 54 |
+
description="Across all plans"
|
| 55 |
+
accentColor="var(--color-primary)"
|
| 56 |
+
animationDelay={1}
|
| 57 |
+
/>
|
| 58 |
+
<StatCard
|
| 59 |
+
icon={<Users className="size-5" />}
|
| 60 |
+
value={totalMembers}
|
| 61 |
+
label="Total Members"
|
| 62 |
+
description="Workspace members"
|
| 63 |
+
accentColor="var(--color-info)"
|
| 64 |
+
animationDelay={2}
|
| 65 |
+
/>
|
| 66 |
+
<StatCard
|
| 67 |
+
icon={<Podcast className="size-5" />}
|
| 68 |
+
value={totalPodcasts}
|
| 69 |
+
label="Total Podcasts"
|
| 70 |
+
description="Across all workspaces"
|
| 71 |
+
accentColor="var(--color-success)"
|
| 72 |
+
animationDelay={3}
|
| 73 |
+
/>
|
| 74 |
+
</div>
|
| 75 |
+
|
| 76 |
+
<Card>
|
| 77 |
+
<CardHeader>
|
| 78 |
+
<CardTitle className="flex items-center gap-2">
|
| 79 |
+
<Building2 className="size-4 text-[var(--color-primary)]" /> Workspaces
|
| 80 |
+
</CardTitle>
|
| 81 |
+
<CardDescription>All registered tenant workspaces across the platform.</CardDescription>
|
| 82 |
+
</CardHeader>
|
| 83 |
+
<CardContent>
|
| 84 |
+
<div className="overflow-auto">
|
| 85 |
+
<table className="w-full text-left border-collapse">
|
| 86 |
+
<thead>
|
| 87 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 88 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Name</th>
|
| 89 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Slug</th>
|
| 90 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Plan</th>
|
| 91 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Members</th>
|
| 92 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Podcasts</th>
|
| 93 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Created</th>
|
| 94 |
+
</tr>
|
| 95 |
+
</thead>
|
| 96 |
+
<tbody>
|
| 97 |
+
{isLoading ? (
|
| 98 |
+
[...Array(6)].map((_, i) => (
|
| 99 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 100 |
+
<td colSpan={6} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 101 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 102 |
+
</td>
|
| 103 |
+
</tr>
|
| 104 |
+
))
|
| 105 |
+
) : (workspaces ?? []).length === 0 ? (
|
| 106 |
+
<tr>
|
| 107 |
+
<td colSpan={6} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 108 |
+
No workspaces found.
|
| 109 |
+
</td>
|
| 110 |
+
</tr>
|
| 111 |
+
) : (
|
| 112 |
+
(workspaces ?? []).map((ws: any) => (
|
| 113 |
+
<tr key={ws.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 114 |
+
<td className="py-4 font-medium text-[var(--text-primary)]">{ws.name}</td>
|
| 115 |
+
<td className="py-4 font-mono text-xs text-[var(--text-secondary)]">{ws.slug}</td>
|
| 116 |
+
<td className="py-4">
|
| 117 |
+
<Badge tone={planVariant(ws.subscriptionPlanId ?? "hobby") as any}>
|
| 118 |
+
{ws.subscriptionPlanId ?? "hobby"}
|
| 119 |
+
</Badge>
|
| 120 |
+
</td>
|
| 121 |
+
<td className="py-4">
|
| 122 |
+
<span className="inline-flex items-center gap-1 text-sm text-[var(--text-secondary)]">
|
| 123 |
+
<Users className="size-3.5 text-[var(--text-tertiary)]" />
|
| 124 |
+
{ws._count?.members ?? 0}
|
| 125 |
+
</span>
|
| 126 |
+
</td>
|
| 127 |
+
<td className="py-4">
|
| 128 |
+
<span className="inline-flex items-center gap-1 text-sm text-[var(--text-secondary)]">
|
| 129 |
+
<Podcast className="size-3.5 text-[var(--text-tertiary)]" />
|
| 130 |
+
{ws._count?.podcasts ?? 0}
|
| 131 |
+
</span>
|
| 132 |
+
</td>
|
| 133 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)]">{ago(ws.createdAt)}</td>
|
| 134 |
+
</tr>
|
| 135 |
+
))
|
| 136 |
+
)}
|
| 137 |
+
</tbody>
|
| 138 |
+
</table>
|
| 139 |
+
</div>
|
| 140 |
+
</CardContent>
|
| 141 |
+
</Card>
|
| 142 |
+
</div>
|
| 143 |
+
</div>
|
| 144 |
+
);
|
| 145 |
+
}
|
apps/admin/src/app/(dashboard)/users/[id]/page.tsx
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState } from "react";
|
| 4 |
+
import { useParams, useRouter } from "next/navigation";
|
| 5 |
+
import { User, ShieldCheck, CreditCard, Mail, Clock, AlertCircle, Trash2, Edit, LogOut } from "lucide-react";
|
| 6 |
+
import { trpc } from "@/lib/trpc";
|
| 7 |
+
import { cn } from "@/lib/utils";
|
| 8 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 9 |
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 10 |
+
import { Badge } from "@micprotocol/ui";
|
| 11 |
+
import { Button } from "@micprotocol/ui";
|
| 12 |
+
import { Input } from "@micprotocol/ui";
|
| 13 |
+
import { Textarea } from "@micprotocol/ui";
|
| 14 |
+
import { Modal, ModalHeader, ModalTitle, ModalBody, ModalFooter } from "@micprotocol/ui";
|
| 15 |
+
import { ago } from "@/lib/utils";
|
| 16 |
+
|
| 17 |
+
export default function UserDetailPage() {
|
| 18 |
+
const params = useParams();
|
| 19 |
+
const router = useRouter();
|
| 20 |
+
const userId = (params as any)?.id as string;
|
| 21 |
+
|
| 22 |
+
const { data: user, isLoading } = (trpc.crm as any).users.getUser.useQuery(
|
| 23 |
+
{ userId },
|
| 24 |
+
{ enabled: !!userId },
|
| 25 |
+
);
|
| 26 |
+
|
| 27 |
+
const [suspendModal, setSuspendModal] = useState(false);
|
| 28 |
+
const [adminModal, setAdminModal] = useState(false);
|
| 29 |
+
const [revokeModal, setRevokeModal] = useState(false);
|
| 30 |
+
const [impersonateModal, setImpersonateModal] = useState(false);
|
| 31 |
+
const [deleteModal, setDeleteModal] = useState(false);
|
| 32 |
+
const [notes, setNotes] = useState(user?.notes ?? "");
|
| 33 |
+
|
| 34 |
+
if (!userId) {
|
| 35 |
+
router.push("/crm/users");
|
| 36 |
+
return null;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
if (isLoading || !user) {
|
| 40 |
+
return (
|
| 41 |
+
<div className="animate-fade-in p-6">
|
| 42 |
+
<AdminHeader title="User" subtitle="Loading user detailsβ¦" />
|
| 43 |
+
<div className="flex items-center justify-center h-[40vh]">
|
| 44 |
+
<div className="skeleton w-full h-16 max-w-xs mx-auto" />
|
| 45 |
+
</div>
|
| 46 |
+
</div>
|
| 47 |
+
);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
const roleVariant = (role?: string | null) => {
|
| 51 |
+
switch (role) {
|
| 52 |
+
case "admin": return "brand";
|
| 53 |
+
case "moderator": return "info";
|
| 54 |
+
default: return "neutral";
|
| 55 |
+
}
|
| 56 |
+
};
|
| 57 |
+
|
| 58 |
+
return (
|
| 59 |
+
<div className="animate-fade-in">
|
| 60 |
+
<AdminHeader
|
| 61 |
+
title={`User: ${user.firstName} ${user.lastName}`}
|
| 62 |
+
subtitle={user.email}
|
| 63 |
+
actions={
|
| 64 |
+
<div className="flex gap-2">
|
| 65 |
+
<Button variant="outline" size="sm" onClick={() => setSuspendModal(true)}>
|
| 66 |
+
{user.suspended ? (
|
| 67 |
+
<>
|
| 68 |
+
<Clock size={14} className="mr-1" /> Reactivate
|
| 69 |
+
</>
|
| 70 |
+
) : (
|
| 71 |
+
<>
|
| 72 |
+
<AlertCircle size={14} className="mr-1" /> Suspend
|
| 73 |
+
</>
|
| 74 |
+
)}
|
| 75 |
+
</Button>
|
| 76 |
+
<Button variant="outline" size="sm" onClick={() => setAdminModal(true)}>
|
| 77 |
+
<ShieldCheck size={14} className="mr-1" /> Role
|
| 78 |
+
</Button>
|
| 79 |
+
</div>
|
| 80 |
+
}
|
| 81 |
+
/>
|
| 82 |
+
|
| 83 |
+
<div className="space-y-6 p-6">
|
| 84 |
+
{/* User profile */}
|
| 85 |
+
<Card>
|
| 86 |
+
<CardHeader>
|
| 87 |
+
<CardTitle className="flex items-center gap-2">
|
| 88 |
+
<User className="size-4 text-[var(--color-primary)]" /> User Profile
|
| 89 |
+
</CardTitle>
|
| 90 |
+
</CardHeader>
|
| 91 |
+
<CardContent className="p-5">
|
| 92 |
+
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
|
| 93 |
+
<div className="space-y-2">
|
| 94 |
+
<p className="text-xs font-mono text-[var(--text-tertiary)] uppercase tracking-wider">Name</p>
|
| 95 |
+
<p className="font-medium text-[var(--text-primary)]">{user.firstName} {user.lastName}</p>
|
| 96 |
+
</div>
|
| 97 |
+
<div className="space-y-2">
|
| 98 |
+
<p className="text-xs font-mono text-[var(--text-tertiary)] uppercase tracking-wider">Email</p>
|
| 99 |
+
<p className="font-mono text-xs text-[var(--text-secondary)]">{user.email}</p>
|
| 100 |
+
</div>
|
| 101 |
+
<div className="space-y-2">
|
| 102 |
+
<p className="text-xs font-mono text-[var(--text-tertiary)] uppercase tracking-wider">Role</p>
|
| 103 |
+
<Badge tone={roleVariant(user.adminRole)} className="capitalize text-xs">
|
| 104 |
+
{user.adminRole ?? "user"}
|
| 105 |
+
</Badge>
|
| 106 |
+
</div>
|
| 107 |
+
<div className="space-y-2">
|
| 108 |
+
<p className="text-xs font-mono text-[var(--text-tertiary)] uppercase tracking-wider">Verified</p>
|
| 109 |
+
<Badge tone={user.verified ? "success" : "neutral"} className={cn("capitalize text-xs", user.verified ? "bg-[var(--color-success)]/20 border-[var(--color-success)]/30 text-[var(--color-success)]" : "border-transparent text-[var(--text-tertiary)]")}>
|
| 110 |
+
{user.verified ? "yes" : "no"}
|
| 111 |
+
</Badge>
|
| 112 |
+
</div>
|
| 113 |
+
<div className="space-y-2">
|
| 114 |
+
<p className="text-xs font-mono text-[var(--text-tertiary)] uppercase tracking-wider">Suspended</p>
|
| 115 |
+
<Badge tone={user.suspended ? "error" : "neutral"} className={cn("capitalize text-xs", user.suspended ? "bg-[var(--color-error)]/20 border-[var(--color-error)]/30 text-[var(--color-error)]" : "border-transparent text-[var(--text-tertiary)]")}>
|
| 116 |
+
{user.suspended ? "yes" : "no"}
|
| 117 |
+
</Badge>
|
| 118 |
+
</div>
|
| 119 |
+
<div className="space-y-2">
|
| 120 |
+
<p className="text-xs font-mono text-[var(--text-tertiary)] uppercase tracking-wider">Joined</p>
|
| 121 |
+
<p className="font-mono text-xs text-[var(--text-secondary)]">{new Date(user.createdAt).toLocaleDateString()}</p>
|
| 122 |
+
</div>
|
| 123 |
+
</div>
|
| 124 |
+
<div className="mt-6 pt-6 border-t border-[var(--border-color-subtle)]">
|
| 125 |
+
<p className="text-xs font-mono text-[var(--text-tertiary)] uppercase tracking-wider mb-2">Admin Notes</p>
|
| 126 |
+
<Textarea
|
| 127 |
+
value={notes}
|
| 128 |
+
onChange={(e) => setNotes(e.target.value)}
|
| 129 |
+
placeholder="Admin notes about this userβ¦"
|
| 130 |
+
rows={3}
|
| 131 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 132 |
+
/>
|
| 133 |
+
</div>
|
| 134 |
+
</CardContent>
|
| 135 |
+
</Card>
|
| 136 |
+
|
| 137 |
+
{/* Stats */}
|
| 138 |
+
<div className="grid gap-4 sm:grid-cols-3">
|
| 139 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 140 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Bookings</p>
|
| 141 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{user.stats?.bookingCount ?? 0}</p>
|
| 142 |
+
</Card>
|
| 143 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 144 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Podcasts</p>
|
| 145 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{user.stats?.podcastCount ?? 0}</p>
|
| 146 |
+
</Card>
|
| 147 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 148 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Sessions</p>
|
| 149 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{user.stats?.activeSessions ?? 0}</p>
|
| 150 |
+
</Card>
|
| 151 |
+
</div>
|
| 152 |
+
|
| 153 |
+
{/* Action cards */}
|
| 154 |
+
<div className="grid gap-4 sm:grid-cols-3 lg:grid-cols-4">
|
| 155 |
+
<ActionCard
|
| 156 |
+
title="Suspend / Reactivate"
|
| 157 |
+
description={user.suspended ? "Reactivate this user" : "Suspend this user and revoke access"}
|
| 158 |
+
icon={<AlertCircle size={18} />}
|
| 159 |
+
onClick={() => setSuspendModal(true)}
|
| 160 |
+
/>
|
| 161 |
+
<ActionCard
|
| 162 |
+
title="Set Admin Role"
|
| 163 |
+
description="Grant or revoke admin privileges"
|
| 164 |
+
icon={<ShieldCheck size={18} />}
|
| 165 |
+
onClick={() => setAdminModal(true)}
|
| 166 |
+
/>
|
| 167 |
+
<ActionCard
|
| 168 |
+
title="Revoke Sessions"
|
| 169 |
+
description="Sign out all active sessions"
|
| 170 |
+
icon={<LogOut size={18} />}
|
| 171 |
+
onClick={() => setRevokeModal(true)}
|
| 172 |
+
/>
|
| 173 |
+
<ActionCard
|
| 174 |
+
title="Impersonate"
|
| 175 |
+
description="Sign in as this user for debugging"
|
| 176 |
+
icon={<User size={18} />}
|
| 177 |
+
onClick={() => setImpersonateModal(true)}
|
| 178 |
+
/>
|
| 179 |
+
<ActionCard
|
| 180 |
+
title="Delete User"
|
| 181 |
+
description="Permanently delete this user account"
|
| 182 |
+
icon={<Trash2 size={18} />}
|
| 183 |
+
onClick={() => setDeleteModal(true)}
|
| 184 |
+
variant="destructive"
|
| 185 |
+
/>
|
| 186 |
+
</div>
|
| 187 |
+
</div>
|
| 188 |
+
|
| 189 |
+
{/* Suspend/Reactivate modal */}
|
| 190 |
+
{suspendModal && (
|
| 191 |
+
<Modal isOpen onClose={() => setSuspendModal(false)} size="md">
|
| 192 |
+
<ModalHeader>
|
| 193 |
+
<ModalTitle>{user.suspended ? "Reactivate User" : "Suspend User"}</ModalTitle>
|
| 194 |
+
</ModalHeader>
|
| 195 |
+
<ModalBody>
|
| 196 |
+
<p className="text-[var(--text-secondary)]">
|
| 197 |
+
{user.suspended
|
| 198 |
+
? "Reactivating will restore access to the platform."
|
| 199 |
+
: "Suspending will revoke access and sign out all active sessions."}
|
| 200 |
+
</p>
|
| 201 |
+
<div className="mt-6 flex justify-end gap-2">
|
| 202 |
+
<Button type="button" variant="outline" onClick={() => setSuspendModal(false)}>
|
| 203 |
+
Cancel
|
| 204 |
+
</Button>
|
| 205 |
+
<Button variant={user.suspended ? "outline" : "destructive"} onClick={() => { setSuspendModal(false); }}>
|
| 206 |
+
{user.suspended ? "Reactivate" : "Suspend"}
|
| 207 |
+
</Button>
|
| 208 |
+
</div>
|
| 209 |
+
</ModalBody>
|
| 210 |
+
</Modal>
|
| 211 |
+
)}
|
| 212 |
+
|
| 213 |
+
{/* Admin role modal */}
|
| 214 |
+
{adminModal && (
|
| 215 |
+
<Modal isOpen onClose={() => setAdminModal(false)} size="md">
|
| 216 |
+
<ModalHeader>
|
| 217 |
+
<ModalTitle>Set Admin Role</ModalTitle>
|
| 218 |
+
</ModalHeader>
|
| 219 |
+
<ModalBody>
|
| 220 |
+
<form
|
| 221 |
+
onSubmit={(e) => {
|
| 222 |
+
e.preventDefault();
|
| 223 |
+
setAdminModal(false);
|
| 224 |
+
}}
|
| 225 |
+
className="space-y-4"
|
| 226 |
+
>
|
| 227 |
+
<div>
|
| 228 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">Role</label>
|
| 229 |
+
<select
|
| 230 |
+
value={user.adminRole ?? "user"}
|
| 231 |
+
onChange={() => {}}
|
| 232 |
+
className="w-full text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] px-3 py-2 text-sm focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20 outline-none"
|
| 233 |
+
>
|
| 234 |
+
<option value="user">User</option>
|
| 235 |
+
<option value="moderator">Moderator</option>
|
| 236 |
+
<option value="admin">Admin</option>
|
| 237 |
+
</select>
|
| 238 |
+
</div>
|
| 239 |
+
<div className="flex justify-end gap-2">
|
| 240 |
+
<Button type="button" variant="outline" onClick={() => setAdminModal(false)}>
|
| 241 |
+
Cancel
|
| 242 |
+
</Button>
|
| 243 |
+
<Button type="submit">
|
| 244 |
+
Save
|
| 245 |
+
</Button>
|
| 246 |
+
</div>
|
| 247 |
+
</form>
|
| 248 |
+
</ModalBody>
|
| 249 |
+
</Modal>
|
| 250 |
+
)}
|
| 251 |
+
|
| 252 |
+
{/* Revoke sessions modal */}
|
| 253 |
+
{revokeModal && (
|
| 254 |
+
<Modal isOpen onClose={() => setRevokeModal(false)} size="md">
|
| 255 |
+
<ModalHeader>
|
| 256 |
+
<ModalTitle>Revoke Sessions</ModalTitle>
|
| 257 |
+
</ModalHeader>
|
| 258 |
+
<ModalBody>
|
| 259 |
+
<p className="text-[var(--text-secondary)]">
|
| 260 |
+
This will sign out all active sessions for this user across all devices.
|
| 261 |
+
</p>
|
| 262 |
+
<div className="mt-6 flex justify-end gap-2">
|
| 263 |
+
<Button type="button" variant="outline" onClick={() => setRevokeModal(false)}>
|
| 264 |
+
Cancel
|
| 265 |
+
</Button>
|
| 266 |
+
<Button variant="destructive" onClick={() => { setRevokeModal(false); }}>
|
| 267 |
+
Revoke All Sessions
|
| 268 |
+
</Button>
|
| 269 |
+
</div>
|
| 270 |
+
</ModalBody>
|
| 271 |
+
</Modal>
|
| 272 |
+
)}
|
| 273 |
+
|
| 274 |
+
{/* Impersonate modal */}
|
| 275 |
+
{impersonateModal && (
|
| 276 |
+
<Modal isOpen onClose={() => setImpersonateModal(false)} size="md">
|
| 277 |
+
<ModalHeader>
|
| 278 |
+
<ModalTitle>Impersonate User</ModalTitle>
|
| 279 |
+
</ModalHeader>
|
| 280 |
+
<ModalBody>
|
| 281 |
+
<p className="text-[var(--text-secondary)]">
|
| 282 |
+
Sign in as this user for debugging purposes. This action is audit-trailed.
|
| 283 |
+
</p>
|
| 284 |
+
<div className="mt-6 flex justify-end gap-2">
|
| 285 |
+
<Button type="button" variant="outline" onClick={() => setImpersonateModal(false)}>
|
| 286 |
+
Cancel
|
| 287 |
+
</Button>
|
| 288 |
+
<Button variant="outline" onClick={() => { setImpersonateModal(false); }}>
|
| 289 |
+
Impersonate
|
| 290 |
+
</Button>
|
| 291 |
+
</div>
|
| 292 |
+
</ModalBody>
|
| 293 |
+
</Modal>
|
| 294 |
+
)}
|
| 295 |
+
|
| 296 |
+
{/* Delete user modal */}
|
| 297 |
+
{deleteModal && (
|
| 298 |
+
<Modal isOpen onClose={() => setDeleteModal(false)} size="md">
|
| 299 |
+
<ModalHeader>
|
| 300 |
+
<ModalTitle>Delete User</ModalTitle>
|
| 301 |
+
</ModalHeader>
|
| 302 |
+
<ModalBody>
|
| 303 |
+
<p className="text-[var(--text-secondary)]">
|
| 304 |
+
This permanently deletes the user account and all associated data. This action cannot be undone.
|
| 305 |
+
</p>
|
| 306 |
+
<div className="mt-6 flex justify-end gap-2">
|
| 307 |
+
<Button type="button" variant="outline" onClick={() => setDeleteModal(false)}>
|
| 308 |
+
Cancel
|
| 309 |
+
</Button>
|
| 310 |
+
<Button variant="destructive" onClick={() => { setDeleteModal(false); }}>
|
| 311 |
+
Delete User
|
| 312 |
+
</Button>
|
| 313 |
+
</div>
|
| 314 |
+
</ModalBody>
|
| 315 |
+
</Modal>
|
| 316 |
+
)}
|
| 317 |
+
</div>
|
| 318 |
+
);
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
function ActionCard({ title, description, icon, onClick, variant }: { title: string; description: string; icon: React.ReactNode; onClick: () => void; variant?: "default" | "destructive" }) {
|
| 322 |
+
return (
|
| 323 |
+
<Card className={cn("border border-[var(--border-color)] hover:border-[var(--color-primary)]/50 transition-colors cursor-pointer", variant === "destructive" && "hover:border-[var(--color-error)]/50")} onClick={onClick}>
|
| 324 |
+
<CardContent className="p-5">
|
| 325 |
+
<div className="flex items-center gap-3 mb-3">
|
| 326 |
+
<div className={cn("rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-2", variant === "destructive" && "bg-[var(--color-error)]/10")}>
|
| 327 |
+
{icon}
|
| 328 |
+
</div>
|
| 329 |
+
<h3 className={cn("font-medium text-[var(--text-primary)]", variant === "destructive" && "text-[var(--color-error)]")}>{title}</h3>
|
| 330 |
+
</div>
|
| 331 |
+
<p className="text-xs text-[var(--text-tertiary)]">{description}</p>
|
| 332 |
+
</CardContent>
|
| 333 |
+
</Card>
|
| 334 |
+
);
|
| 335 |
+
}
|
apps/admin/src/app/(dashboard)/users/page.tsx
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Users, Search, RefreshCw } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 7 |
+
import {
|
| 8 |
+
Card, CardContent, CardDescription, CardHeader, CardTitle,
|
| 9 |
+
} from "@micprotocol/ui";
|
| 10 |
+
import { Badge } from "@micprotocol/ui";
|
| 11 |
+
import { Button } from "@micprotocol/ui";
|
| 12 |
+
import { Input } from "@micprotocol/ui";
|
| 13 |
+
import { StatCard } from "@micprotocol/ui";
|
| 14 |
+
import Link from "next/link";
|
| 15 |
+
import { ago } from "@/lib/utils";
|
| 16 |
+
|
| 17 |
+
const ROLE_OPTIONS = [
|
| 18 |
+
{ value: "SUPER_ADMIN", label: "Super Admin" },
|
| 19 |
+
{ value: "OPS", label: "Ops" },
|
| 20 |
+
{ value: "SUPPORT", label: "Support" },
|
| 21 |
+
{ value: "MODERATOR", label: "Moderator" },
|
| 22 |
+
{ value: "BILLING", label: "Billing" },
|
| 23 |
+
{ value: "ANALYST", label: "Analyst" },
|
| 24 |
+
{ value: "READ_ONLY", label: "Read Only" },
|
| 25 |
+
];
|
| 26 |
+
|
| 27 |
+
type BadgeVariant = "brand" | "success" | "warning" | "error" | "info" | "neutral" | "primary" | "secondary";
|
| 28 |
+
|
| 29 |
+
const roleVariant = (role: string | null): BadgeVariant => {
|
| 30 |
+
const variants: Record<string, BadgeVariant> = {
|
| 31 |
+
SUPER_ADMIN: "brand",
|
| 32 |
+
OPS: "info",
|
| 33 |
+
SUPPORT: "warning",
|
| 34 |
+
MODERATOR: "error",
|
| 35 |
+
BILLING: "neutral",
|
| 36 |
+
ANALYST: "neutral",
|
| 37 |
+
READ_ONLY: "neutral",
|
| 38 |
+
};
|
| 39 |
+
return variants[role ?? ""] ?? "neutral";
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
export default function UsersPage() {
|
| 43 |
+
const [search, setSearch] = React.useState("");
|
| 44 |
+
const [role, setRole] = React.useState<string | undefined>(undefined);
|
| 45 |
+
const [suspended, setSuspended] = React.useState<string | undefined>(undefined);
|
| 46 |
+
const [cursor, setCursor] = React.useState<string | undefined>(undefined);
|
| 47 |
+
|
| 48 |
+
const { data, isLoading, isFetching, refetch } = trpc.admin.users.list.useQuery({
|
| 49 |
+
search: search || undefined,
|
| 50 |
+
role,
|
| 51 |
+
suspended: suspended === "true" ? true : suspended === "false" ? false : undefined,
|
| 52 |
+
cursor,
|
| 53 |
+
limit: 25,
|
| 54 |
+
});
|
| 55 |
+
|
| 56 |
+
const items = data?.items ?? [];
|
| 57 |
+
const nextCursor = data?.nextCursor ?? null;
|
| 58 |
+
|
| 59 |
+
const totalUsers = data?.total ?? 0;
|
| 60 |
+
const suspendedCount = items.filter((u) => u.suspended).length;
|
| 61 |
+
const adminCount = items.filter((u) => u.isAdmin).length;
|
| 62 |
+
|
| 63 |
+
return (
|
| 64 |
+
<div className="animate-mic-fade-in-up">
|
| 65 |
+
<AdminHeader
|
| 66 |
+
title="Platform Users"
|
| 67 |
+
subtitle="Suspend, role-assign, and audit every platform user"
|
| 68 |
+
onRefresh={refetch}
|
| 69 |
+
refreshing={isFetching}
|
| 70 |
+
actions={
|
| 71 |
+
<Badge tone={suspendedCount > 0 ? "warning" : "success"}>
|
| 72 |
+
{suspendedCount} suspended
|
| 73 |
+
</Badge>
|
| 74 |
+
}
|
| 75 |
+
/>
|
| 76 |
+
|
| 77 |
+
<div className="space-y-6 p-6">
|
| 78 |
+
{/* KPI strip */}
|
| 79 |
+
<div className="grid gap-4 sm:grid-cols-3 lg:grid-cols-4">
|
| 80 |
+
<StatCard
|
| 81 |
+
icon={<Users className="size-5" />}
|
| 82 |
+
value={totalUsers}
|
| 83 |
+
label="Total Users"
|
| 84 |
+
description={`${adminCount} admins Β· ${suspendedCount} suspended`}
|
| 85 |
+
accentColor="var(--color-primary)"
|
| 86 |
+
animationDelay={1}
|
| 87 |
+
/>
|
| 88 |
+
<StatCard
|
| 89 |
+
icon={<Users className="size-5" />}
|
| 90 |
+
value={totalUsers - suspendedCount}
|
| 91 |
+
label="Active Users"
|
| 92 |
+
description="Not suspended"
|
| 93 |
+
accentColor="var(--color-success)"
|
| 94 |
+
animationDelay={2}
|
| 95 |
+
/>
|
| 96 |
+
<StatCard
|
| 97 |
+
icon={<Users className="size-5" />}
|
| 98 |
+
value={suspendedCount}
|
| 99 |
+
label="Suspended"
|
| 100 |
+
description="Require admin review"
|
| 101 |
+
accentColor="var(--color-error)"
|
| 102 |
+
animationDelay={3}
|
| 103 |
+
/>
|
| 104 |
+
<StatCard
|
| 105 |
+
icon={<Users className="size-5" />}
|
| 106 |
+
value={adminCount}
|
| 107 |
+
label="Platform Admins"
|
| 108 |
+
description="Elevated privileges"
|
| 109 |
+
accentColor="var(--color-secondary)"
|
| 110 |
+
animationDelay={4}
|
| 111 |
+
/>
|
| 112 |
+
</div>
|
| 113 |
+
|
| 114 |
+
{/* Filter bar */}
|
| 115 |
+
<Card className="border border-[var(--border-color)]">
|
| 116 |
+
<CardContent className="p-5">
|
| 117 |
+
<div className="grid gap-4 sm:gap-6 sm:grid-cols-5 items-end">
|
| 118 |
+
<div className="relative w-full">
|
| 119 |
+
<Search className="absolute left-3 top-1/2 size-4 -translate-y-1/2 text-[var(--text-tertiary)]" />
|
| 120 |
+
<Input
|
| 121 |
+
className="pl-9 text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 122 |
+
placeholder="Search name or emailβ¦"
|
| 123 |
+
value={search}
|
| 124 |
+
onChange={(e) => { setSearch(e.target.value); setCursor(undefined); }}
|
| 125 |
+
/>
|
| 126 |
+
</div>
|
| 127 |
+
<select
|
| 128 |
+
value={role ?? ""}
|
| 129 |
+
onChange={(e) => { setRole(e.target.value || undefined); setCursor(undefined); }}
|
| 130 |
+
className="w-full text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] px-3 py-2 text-sm focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20 outline-none"
|
| 131 |
+
>
|
| 132 |
+
<option value="">All roles</option>
|
| 133 |
+
{ROLE_OPTIONS.map((opt) => (
|
| 134 |
+
<option key={opt.value} value={opt.value}>{opt.label}</option>
|
| 135 |
+
))}
|
| 136 |
+
</select>
|
| 137 |
+
<select
|
| 138 |
+
value={suspended ?? ""}
|
| 139 |
+
onChange={(e) => { setSuspended(e.target.value || undefined); setCursor(undefined); }}
|
| 140 |
+
className="w-full text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] px-3 py-2 text-sm focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20 outline-none"
|
| 141 |
+
>
|
| 142 |
+
<option value="">All statuses</option>
|
| 143 |
+
<option value="true">Suspended</option>
|
| 144 |
+
<option value="false">Active</option>
|
| 145 |
+
</select>
|
| 146 |
+
<div className="flex items-end gap-2">
|
| 147 |
+
<Button
|
| 148 |
+
onClick={() => void refetch()}
|
| 149 |
+
variant="ghost"
|
| 150 |
+
size="sm"
|
| 151 |
+
disabled={isFetching}
|
| 152 |
+
className="text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)]"
|
| 153 |
+
>
|
| 154 |
+
<RefreshCw className={isFetching ? "animate-spin" : ""} size={3} /> Refresh
|
| 155 |
+
</Button>
|
| 156 |
+
</div>
|
| 157 |
+
</div>
|
| 158 |
+
</CardContent>
|
| 159 |
+
</Card>
|
| 160 |
+
|
| 161 |
+
{/* Table */}
|
| 162 |
+
<Card>
|
| 163 |
+
<CardHeader>
|
| 164 |
+
<CardTitle className="flex items-center gap-2">
|
| 165 |
+
<Users className="size-4 text-[var(--color-primary)]" /> User Directory
|
| 166 |
+
</CardTitle>
|
| 167 |
+
<CardDescription>
|
| 168 |
+
Granular platform-user oversight: suspend, adjust roles/permissions, revoke sessions,
|
| 169 |
+
and impersonate for support. Every action is audit-trailed.
|
| 170 |
+
</CardDescription>
|
| 171 |
+
</CardHeader>
|
| 172 |
+
<CardContent>
|
| 173 |
+
<div className="overflow-auto">
|
| 174 |
+
<table className="w-full text-left border-collapse">
|
| 175 |
+
<thead>
|
| 176 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 177 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">User</th>
|
| 178 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Role</th>
|
| 179 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Status</th>
|
| 180 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Workspaces</th>
|
| 181 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Last Login</th>
|
| 182 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right">Action</th>
|
| 183 |
+
</tr>
|
| 184 |
+
</thead>
|
| 185 |
+
<tbody>
|
| 186 |
+
{isLoading ? (
|
| 187 |
+
[...Array(6)].map((_, i) => (
|
| 188 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 189 |
+
<td colSpan={6} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 190 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 191 |
+
</td>
|
| 192 |
+
</tr>
|
| 193 |
+
))
|
| 194 |
+
) : items.length === 0 ? (
|
| 195 |
+
<tr>
|
| 196 |
+
<td colSpan={6} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 197 |
+
No users match your filters.
|
| 198 |
+
</td>
|
| 199 |
+
</tr>
|
| 200 |
+
) : (
|
| 201 |
+
items.map((u) => (
|
| 202 |
+
<tr key={u.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 203 |
+
<td className="py-4 flex items-center gap-3">
|
| 204 |
+
<div className="flex size-8 items-center justify-center rounded-full bg-[var(--bg-tertiary)] text-xs font-semibold text-[var(--color-primary)]">
|
| 205 |
+
{(u.name || u.email || "?").slice(0, 1).toUpperCase()}
|
| 206 |
+
</div>
|
| 207 |
+
<div className="min-w-0">
|
| 208 |
+
<p className="text-sm font-medium text-[var(--text-primary)] truncate">{u.name ?? "β"}</p>
|
| 209 |
+
<p className="text-xs text-[var(--text-tertiary)] truncate">{u.email}</p>
|
| 210 |
+
</div>
|
| 211 |
+
</td>
|
| 212 |
+
<td className="py-4">
|
| 213 |
+
<Badge tone={roleVariant(u.adminRole)}>
|
| 214 |
+
{u.adminRole ?? "member"}
|
| 215 |
+
</Badge>
|
| 216 |
+
</td>
|
| 217 |
+
<td className="py-4">
|
| 218 |
+
<Badge tone={u.suspended ? "error" : "success"}>
|
| 219 |
+
{u.suspended ? "suspended" : "active"}
|
| 220 |
+
</Badge>
|
| 221 |
+
</td>
|
| 222 |
+
<td className="py-4 text-sm text-[var(--text-secondary)]">
|
| 223 |
+
{u.workspaceCount}
|
| 224 |
+
</td>
|
| 225 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)]">
|
| 226 |
+
{u.lastLoginAt ? ago(u.lastLoginAt) : "β"}
|
| 227 |
+
</td>
|
| 228 |
+
<td className="py-4 text-right">
|
| 229 |
+
<Link href={`/users/${u.id}`} passHref legacyBehavior>
|
| 230 |
+
<Button variant="ghost" size="sm" className="w-9 h-9 p-0 text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)]">
|
| 231 |
+
<Users className="size-3.5" />
|
| 232 |
+
</Button>
|
| 233 |
+
</Link>
|
| 234 |
+
</td>
|
| 235 |
+
</tr>
|
| 236 |
+
))
|
| 237 |
+
)}
|
| 238 |
+
</tbody>
|
| 239 |
+
</table>
|
| 240 |
+
</div>
|
| 241 |
+
<div className="mt-4 flex items-center justify-between">
|
| 242 |
+
<span className="text-[var(--text-xs)] text-[var(--text-tertiary)]">
|
| 243 |
+
{data?.total != null ? `${data.total} total` : ""}
|
| 244 |
+
</span>
|
| 245 |
+
<div className="flex gap-2">
|
| 246 |
+
<Button
|
| 247 |
+
variant="ghost"
|
| 248 |
+
size="sm"
|
| 249 |
+
disabled={!cursor}
|
| 250 |
+
onClick={() => setCursor(undefined)}
|
| 251 |
+
className="text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)]"
|
| 252 |
+
>
|
| 253 |
+
First
|
| 254 |
+
</Button>
|
| 255 |
+
<Button
|
| 256 |
+
variant="ghost"
|
| 257 |
+
size="sm"
|
| 258 |
+
disabled={!nextCursor || isFetching}
|
| 259 |
+
onClick={() => setCursor(nextCursor ?? undefined)}
|
| 260 |
+
className="text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)]"
|
| 261 |
+
>
|
| 262 |
+
Next
|
| 263 |
+
</Button>
|
| 264 |
+
</div>
|
| 265 |
+
</div>
|
| 266 |
+
</CardContent>
|
| 267 |
+
</Card>
|
| 268 |
+
</div>
|
| 269 |
+
</div>
|
| 270 |
+
);
|
| 271 |
+
}
|
apps/admin/src/app/(dashboard)/verification/page.tsx
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { ShieldCheck, Check, X } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 7 |
+
import {
|
| 8 |
+
Card, CardContent, CardDescription, CardHeader, CardTitle,
|
| 9 |
+
} from "@micprotocol/ui";
|
| 10 |
+
import { Badge } from "@micprotocol/ui";
|
| 11 |
+
import { Button } from "@micprotocol/ui";
|
| 12 |
+
import { ago } from "@/lib/utils";
|
| 13 |
+
|
| 14 |
+
export default function VerificationPage() {
|
| 15 |
+
const {
|
| 16 |
+
data: pending,
|
| 17 |
+
isLoading,
|
| 18 |
+
refetch,
|
| 19 |
+
isFetching,
|
| 20 |
+
} = trpc.verification.listPending.useQuery({ limit: 50 } as any);
|
| 21 |
+
|
| 22 |
+
const approve = trpc.verification.approve.useMutation({
|
| 23 |
+
onSuccess: () => refetch(),
|
| 24 |
+
});
|
| 25 |
+
const reject = trpc.verification.reject.useMutation({
|
| 26 |
+
onSuccess: () => refetch(),
|
| 27 |
+
});
|
| 28 |
+
|
| 29 |
+
const items = (pending as any)?.items ?? pending ?? [];
|
| 30 |
+
|
| 31 |
+
return (
|
| 32 |
+
<div className="animate-fade-in">
|
| 33 |
+
<AdminHeader
|
| 34 |
+
title="Workspace Verification"
|
| 35 |
+
subtitle="Review workspace and brand verification submissions"
|
| 36 |
+
onRefresh={refetch}
|
| 37 |
+
refreshing={isFetching}
|
| 38 |
+
/>
|
| 39 |
+
|
| 40 |
+
<div className="space-y-4 p-6">
|
| 41 |
+
<Card>
|
| 42 |
+
<CardHeader>
|
| 43 |
+
<CardTitle className="flex items-center gap-2">
|
| 44 |
+
<ShieldCheck className="size-4 text-[var(--color-success)]" /> Pending Approvals
|
| 45 |
+
</CardTitle>
|
| 46 |
+
<CardDescription>Approve or reject pending workspace verification requests.</CardDescription>
|
| 47 |
+
</CardHeader>
|
| 48 |
+
<CardContent className="p-0">
|
| 49 |
+
<div className="overflow-auto">
|
| 50 |
+
<table className="w-full text-left border-collapse">
|
| 51 |
+
<thead>
|
| 52 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 53 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Workspace</th>
|
| 54 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Status</th>
|
| 55 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Submitted</th>
|
| 56 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right">Actions</th>
|
| 57 |
+
</tr>
|
| 58 |
+
</thead>
|
| 59 |
+
<tbody>
|
| 60 |
+
{isLoading ? (
|
| 61 |
+
[...Array(5)].map((_, i) => (
|
| 62 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 63 |
+
<td colSpan={4} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 64 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 65 |
+
</td>
|
| 66 |
+
</tr>
|
| 67 |
+
))
|
| 68 |
+
) : items.length === 0 ? (
|
| 69 |
+
<tr>
|
| 70 |
+
<td colSpan={4} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 71 |
+
No pending verifications. All caught up β¨
|
| 72 |
+
</td>
|
| 73 |
+
</tr>
|
| 74 |
+
) : (
|
| 75 |
+
(items as any[]).map((v: any) => (
|
| 76 |
+
<tr key={v.id ?? v.workspaceId} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 77 |
+
<td className="py-4">
|
| 78 |
+
<div>
|
| 79 |
+
<p className="text-sm font-medium text-[var(--text-primary)]">{v.workspace?.name ?? v.workspaceId}</p>
|
| 80 |
+
{v.workspace?.slug ? (
|
| 81 |
+
<p className="font-mono text-xs text-[var(--text-tertiary)]">{v.workspace.slug}</p>
|
| 82 |
+
) : null}
|
| 83 |
+
</div>
|
| 84 |
+
</td>
|
| 85 |
+
<td className="py-4">
|
| 86 |
+
<Badge tone={v.status === "verified" ? "success" : "warning"}>
|
| 87 |
+
{v.status ?? "pending"}
|
| 88 |
+
</Badge>
|
| 89 |
+
</td>
|
| 90 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)]">
|
| 91 |
+
{v.updatedAt ? ago(v.updatedAt) : v.createdAt ? ago(v.createdAt) : "β"}
|
| 92 |
+
</td>
|
| 93 |
+
<td className="py-4 text-right">
|
| 94 |
+
<div className="flex justify-end gap-2">
|
| 95 |
+
<Button
|
| 96 |
+
variant="outline"
|
| 97 |
+
size="sm"
|
| 98 |
+
className="border-[var(--color-success)]/40 text-[var(--color-success)] hover:bg-[var(--color-success)]/10"
|
| 99 |
+
disabled={approve.isPending}
|
| 100 |
+
onClick={() =>
|
| 101 |
+
approve.mutate({
|
| 102 |
+
workspaceId: v.workspaceId,
|
| 103 |
+
targetStatus: "verified",
|
| 104 |
+
} as any)
|
| 105 |
+
}
|
| 106 |
+
>
|
| 107 |
+
<Check className="size-4" /> Approve
|
| 108 |
+
</Button>
|
| 109 |
+
<Button
|
| 110 |
+
variant="outline"
|
| 111 |
+
size="sm"
|
| 112 |
+
className="border-[var(--color-error)]/40 text-[var(--color-error)] hover:bg-[var(--color-error)]/10"
|
| 113 |
+
disabled={reject.isPending}
|
| 114 |
+
onClick={() =>
|
| 115 |
+
reject.mutate({
|
| 116 |
+
workspaceId: v.workspaceId,
|
| 117 |
+
reason: "Rejected by admin",
|
| 118 |
+
} as any)
|
| 119 |
+
}
|
| 120 |
+
>
|
| 121 |
+
<X className="size-4" /> Reject
|
| 122 |
+
</Button>
|
| 123 |
+
</div>
|
| 124 |
+
</td>
|
| 125 |
+
</tr>
|
| 126 |
+
))
|
| 127 |
+
)}
|
| 128 |
+
</tbody>
|
| 129 |
+
</table>
|
| 130 |
+
</div>
|
| 131 |
+
</CardContent>
|
| 132 |
+
</Card>
|
| 133 |
+
</div>
|
| 134 |
+
</div>
|
| 135 |
+
);
|
| 136 |
+
}
|
apps/admin/src/app/(dashboard)/webhooks/page.tsx
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Mail, Clock, RefreshCw } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 7 |
+
import { Card, CardContent, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 8 |
+
import { Badge } from "@micprotocol/ui";
|
| 9 |
+
import { Button } from "@micprotocol/ui";
|
| 10 |
+
import { cn } from "@/lib/utils";
|
| 11 |
+
import { ago } from "@/lib/utils";
|
| 12 |
+
|
| 13 |
+
export default function WebhooksPage() {
|
| 14 |
+
const { data: deliveries, isLoading } = (trpc.integrations as any).getWebhookDeliveries.useQuery(
|
| 15 |
+
undefined,
|
| 16 |
+
{ refetchInterval: 30_000 },
|
| 17 |
+
);
|
| 18 |
+
|
| 19 |
+
const items = (deliveries ?? []) as any[];
|
| 20 |
+
const totalDeliveries = items.length;
|
| 21 |
+
const successful = items.filter((d) => d.status === "DELIVERED").length;
|
| 22 |
+
const failed = items.filter((d) => d.status === "FAILED").length;
|
| 23 |
+
const pending = items.filter((d) => d.status === "PENDING").length;
|
| 24 |
+
|
| 25 |
+
return (
|
| 26 |
+
<div className="animate-fade-in">
|
| 27 |
+
<AdminHeader
|
| 28 |
+
title="Webhook Deliveries"
|
| 29 |
+
subtitle="Outbound webhook delivery log β events pushed to subscribed endpoints"
|
| 30 |
+
refreshing={isLoading}
|
| 31 |
+
actions={
|
| 32 |
+
<Button variant="outline" size="sm">
|
| 33 |
+
<RefreshCw size={14} className="mr-1" /> Retry Failed
|
| 34 |
+
</Button>
|
| 35 |
+
}
|
| 36 |
+
/>
|
| 37 |
+
|
| 38 |
+
<div className="space-y-6 p-6">
|
| 39 |
+
{/* KPI strip */}
|
| 40 |
+
<div className="grid gap-4 sm:grid-cols-4">
|
| 41 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 42 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Total Deliveries</p>
|
| 43 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{totalDeliveries}</p>
|
| 44 |
+
</Card>
|
| 45 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 46 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Delivered</p>
|
| 47 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-success)]">{successful}</p>
|
| 48 |
+
</Card>
|
| 49 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 50 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Failed</p>
|
| 51 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-error)]">{failed}</p>
|
| 52 |
+
</Card>
|
| 53 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 54 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Pending</p>
|
| 55 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--color-warning)]">{pending}</p>
|
| 56 |
+
</Card>
|
| 57 |
+
</div>
|
| 58 |
+
|
| 59 |
+
{/* Deliveries table */}
|
| 60 |
+
<Card>
|
| 61 |
+
<CardHeader>
|
| 62 |
+
<CardTitle className="flex items-center gap-2">
|
| 63 |
+
<Mail className="size-4 text-[var(--color-info)]" /> Delivery Log
|
| 64 |
+
</CardTitle>
|
| 65 |
+
</CardHeader>
|
| 66 |
+
<CardContent className="p-0">
|
| 67 |
+
<div className="-mx-4 -my-2 overflow-x-auto">
|
| 68 |
+
<table className="w-full text-left border-collapse">
|
| 69 |
+
<thead>
|
| 70 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 71 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-32">Event ID</th>
|
| 72 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-24">Endpoint</th>
|
| 73 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium w-20">Event</th>
|
| 74 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-center w-20">Status</th>
|
| 75 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-32">Attempted</th>
|
| 76 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-32">Duration</th>
|
| 77 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right w-32">Response</th>
|
| 78 |
+
</tr>
|
| 79 |
+
</thead>
|
| 80 |
+
<tbody>
|
| 81 |
+
{isLoading ? (
|
| 82 |
+
[...Array(5)].map((_, i) => (
|
| 83 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 84 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 85 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 86 |
+
</td>
|
| 87 |
+
</tr>
|
| 88 |
+
))
|
| 89 |
+
) : items.length === 0 ? (
|
| 90 |
+
<tr>
|
| 91 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 92 |
+
No webhook deliveries yet.
|
| 93 |
+
</td>
|
| 94 |
+
</tr>
|
| 95 |
+
) : (
|
| 96 |
+
items.map((d: any) => (
|
| 97 |
+
<tr key={d.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 98 |
+
<td className="py-4 font-mono text-xs text-[var(--text-secondary)]">
|
| 99 |
+
{d.id.slice(0, 8)}β¦
|
| 100 |
+
</td>
|
| 101 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] truncate" style={{ maxWidth: 200 }}>
|
| 102 |
+
{d.endpointUrl ?? "β"}
|
| 103 |
+
</td>
|
| 104 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] font-mono capitalize">
|
| 105 |
+
{d.eventType ?? "β"}
|
| 106 |
+
</td>
|
| 107 |
+
<td className="py-4 text-xs text-center">
|
| 108 |
+
<Badge className={cn("capitalize text-xs", statusClass(d.status))}>
|
| 109 |
+
{d.status}
|
| 110 |
+
</Badge>
|
| 111 |
+
</td>
|
| 112 |
+
<td className="py-4 text-xs text-[var(--text-tertiary)] text-right">
|
| 113 |
+
{new Date(d.createdAt).toLocaleString()}
|
| 114 |
+
</td>
|
| 115 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] text-right font-mono">
|
| 116 |
+
{d.durationMs ?? "β"} ms
|
| 117 |
+
</td>
|
| 118 |
+
<td className="py-4 text-xs text-[var(--text-secondary)] text-right font-mono">
|
| 119 |
+
{d.responseStatus ?? "β"}
|
| 120 |
+
</td>
|
| 121 |
+
</tr>
|
| 122 |
+
))
|
| 123 |
+
)}
|
| 124 |
+
</tbody>
|
| 125 |
+
</table>
|
| 126 |
+
</div>
|
| 127 |
+
</CardContent>
|
| 128 |
+
</Card>
|
| 129 |
+
</div>
|
| 130 |
+
</div>
|
| 131 |
+
);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
function statusClass(s: string): string {
|
| 135 |
+
switch (s) {
|
| 136 |
+
case "DELIVERED": return "bg-[var(--color-success)]/10 border-[var(--color-success)]/20 text-[var(--color-success)]";
|
| 137 |
+
case "FAILED": return "bg-[var(--color-error)]/10 border-[var(--color-error)]/20 text-[var(--color-error)]";
|
| 138 |
+
case "PENDING": return "bg-[var(--color-warning)]/10 border-[var(--color-warning)]/20 text-[var(--color-warning)]";
|
| 139 |
+
default: return "border-transparent";
|
| 140 |
+
}
|
| 141 |
+
}
|
apps/admin/src/app/(dashboard)/workspaces/[id]/page.tsx
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState } from "react";
|
| 4 |
+
import { useParams, useRouter } from "next/navigation";
|
| 5 |
+
import { User, ShieldCheck, CreditCard, Mail, Clock, AlertCircle, Trash2, Edit } from "lucide-react";
|
| 6 |
+
import { trpc } from "@/lib/trpc";
|
| 7 |
+
import { cn } from "@/lib/utils";
|
| 8 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 9 |
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@micprotocol/ui";
|
| 10 |
+
import { Badge } from "@micprotocol/ui";
|
| 11 |
+
import { Button } from "@micprotocol/ui";
|
| 12 |
+
import { Input } from "@micprotocol/ui";
|
| 13 |
+
import { Textarea } from "@micprotocol/ui";
|
| 14 |
+
import { Modal, ModalHeader, ModalTitle, ModalBody, ModalFooter } from "@micprotocol/ui";
|
| 15 |
+
import { ago } from "@/lib/utils";
|
| 16 |
+
|
| 17 |
+
export default function WorkspaceDetailPage() {
|
| 18 |
+
const params = useParams();
|
| 19 |
+
const router = useRouter();
|
| 20 |
+
const workspaceId = (params as any)?.id as string;
|
| 21 |
+
|
| 22 |
+
const { data: workspace, isLoading } = ((trpc as any).workspaces as any).getWorkspace.useQuery(
|
| 23 |
+
{ workspaceId },
|
| 24 |
+
{ enabled: !!workspaceId },
|
| 25 |
+
);
|
| 26 |
+
|
| 27 |
+
const [suspendModal, setSuspendModal] = useState(false);
|
| 28 |
+
[, setSuspendModal];
|
| 29 |
+
const [planModal, setPlanModal] = useState(false);
|
| 30 |
+
const [creditsModal, setCreditsModal] = useState(false);
|
| 31 |
+
const [transferModal, setTransferModal] = useState(false);
|
| 32 |
+
const [notes, setNotes] = useState(workspace?.notes ?? "");
|
| 33 |
+
|
| 34 |
+
const [newPlan, setNewPlan] = useState("");
|
| 35 |
+
const [newCredits, setNewCredits] = useState("");
|
| 36 |
+
const [newOwner, setNewOwner] = useState("");
|
| 37 |
+
|
| 38 |
+
if (!workspaceId) {
|
| 39 |
+
router.push("/workspaces");
|
| 40 |
+
return null;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
if (isLoading || !workspace) {
|
| 44 |
+
return (
|
| 45 |
+
<div className="animate-fade-in p-6">
|
| 46 |
+
<AdminHeader title="Workspace" subtitle="Loading workspace detailsβ¦" />
|
| 47 |
+
<div className="flex items-center justify-center h-[40vh]">
|
| 48 |
+
<div className="skeleton w-full h-16 max-w-xs mx-auto" />
|
| 49 |
+
</div>
|
| 50 |
+
</div>
|
| 51 |
+
);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
const roleVariant = (role?: string | null) => {
|
| 55 |
+
switch (role) {
|
| 56 |
+
case "admin": return "brand";
|
| 57 |
+
case "moderator": return "info";
|
| 58 |
+
default: return "neutral";
|
| 59 |
+
}
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
return (
|
| 63 |
+
<div className="animate-fade-in">
|
| 64 |
+
<AdminHeader
|
| 65 |
+
title={`Workspace: ${workspace.name}`}
|
| 66 |
+
subtitle={workspace.slug}
|
| 67 |
+
actions={
|
| 68 |
+
<div className="flex gap-2">
|
| 69 |
+
<Button variant="outline" size="sm" onClick={() => setSuspendModal(true)}>
|
| 70 |
+
{workspace.suspended ? (
|
| 71 |
+
<>
|
| 72 |
+
<Clock size={14} className="mr-1" /> Reactivate
|
| 73 |
+
</>
|
| 74 |
+
) : (
|
| 75 |
+
<>
|
| 76 |
+
<AlertCircle size={14} className="mr-1" /> Suspend
|
| 77 |
+
</>
|
| 78 |
+
)}
|
| 79 |
+
</Button>
|
| 80 |
+
<Button variant="outline" size="sm" onClick={() => setPlanModal(true)}>
|
| 81 |
+
<CreditCard size={14} className="mr-1" /> Plan
|
| 82 |
+
</Button>
|
| 83 |
+
</div>
|
| 84 |
+
}
|
| 85 |
+
/>
|
| 86 |
+
|
| 87 |
+
<div className="space-y-6 p-6">
|
| 88 |
+
{/* Workspace profile */}
|
| 89 |
+
<Card>
|
| 90 |
+
<CardHeader>
|
| 91 |
+
<CardTitle className="flex items-center gap-2">
|
| 92 |
+
<User className="size-4 text-[var(--color-primary)]" /> Workspace Profile
|
| 93 |
+
</CardTitle>
|
| 94 |
+
</CardHeader>
|
| 95 |
+
<CardContent className="p-5">
|
| 96 |
+
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
|
| 97 |
+
<div className="space-y-2">
|
| 98 |
+
<p className="text-xs font-mono text-[var(--text-tertiary)] uppercase tracking-wider">Name</p>
|
| 99 |
+
<p className="font-medium text-[var(--text-primary)]">{workspace.name}</p>
|
| 100 |
+
</div>
|
| 101 |
+
<div className="space-y-2">
|
| 102 |
+
<p className="text-xs font-mono text-[var(--text-tertiary)] uppercase tracking-wider">Slug</p>
|
| 103 |
+
<p className="font-mono text-xs text-[var(--text-secondary)]">{workspace.slug}</p>
|
| 104 |
+
</div>
|
| 105 |
+
<div className="space-y-2">
|
| 106 |
+
<p className="text-xs font-mono text-[var(--text-tertiary)] uppercase tracking-wider">Owner</p>
|
| 107 |
+
<p className="font-mono text-xs text-[var(--text-secondary)]">{workspace.ownerId?.slice(0, 8) ?? "β"}</p>
|
| 108 |
+
</div>
|
| 109 |
+
<div className="space-y-2">
|
| 110 |
+
<p className="text-xs font-mono text-[var(--text-tertiary)] uppercase tracking-wider">Plan</p>
|
| 111 |
+
<Badge tone={workspace.plan === "enterprise" ? "brand" : "neutral"} className="capitalize text-xs">
|
| 112 |
+
{workspace.plan}
|
| 113 |
+
</Badge>
|
| 114 |
+
</div>
|
| 115 |
+
<div className="space-y-2">
|
| 116 |
+
<p className="text-xs font-mono text-[var(--text-tertiary)] uppercase tracking-wider">Status</p>
|
| 117 |
+
<Badge tone={workspace.suspended ? "error" : "success"} className={cn("capitalize text-xs", workspace.suspended ? "bg-[var(--color-error)]/20 border-[var(--color-error)]/30 text-[var(--color-error)]" : "bg-[var(--color-success)]/20 border-[var(--color-success)]/30 text-[var(--color-success)]")}>
|
| 118 |
+
{workspace.suspended ? "suspended" : "active"}
|
| 119 |
+
</Badge>
|
| 120 |
+
</div>
|
| 121 |
+
<div className="space-y-2">
|
| 122 |
+
<p className="text-xs font-mono text-[var(--text-tertiary)] uppercase tracking-wider">Credits</p>
|
| 123 |
+
<p className="font-display text-xl font-bold text-[var(--text-primary)]">{workspace.credits ?? 0}</p>
|
| 124 |
+
</div>
|
| 125 |
+
</div>
|
| 126 |
+
<div className="mt-6 pt-6 border-t border-[var(--border-color-subtle)]">
|
| 127 |
+
<p className="text-xs font-mono text-[var(--text-tertiary)] uppercase tracking-wider mb-2">Notes</p>
|
| 128 |
+
<Textarea
|
| 129 |
+
value={notes}
|
| 130 |
+
onChange={(e) => setNotes(e.target.value)}
|
| 131 |
+
placeholder="Admin notes about this workspaceβ¦"
|
| 132 |
+
rows={3}
|
| 133 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 134 |
+
/>
|
| 135 |
+
</div>
|
| 136 |
+
</CardContent>
|
| 137 |
+
</Card>
|
| 138 |
+
|
| 139 |
+
{/* Stats */}
|
| 140 |
+
<div className="grid gap-4 sm:grid-cols-3">
|
| 141 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 142 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Podcasts</p>
|
| 143 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{workspace.stats?.podcastCount ?? 0}</p>
|
| 144 |
+
</Card>
|
| 145 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 146 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Guests</p>
|
| 147 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{workspace.stats?.guestCount ?? 0}</p>
|
| 148 |
+
</Card>
|
| 149 |
+
<Card className="p-5 border border-[var(--border-color)]">
|
| 150 |
+
<p className="text-xs font-mono text-[var(--text-secondary)] uppercase tracking-wide">Bookings</p>
|
| 151 |
+
<p className="mt-2 font-display text-2xl font-bold text-[var(--text-primary)]">{workspace.stats?.bookingCount ?? 0}</p>
|
| 152 |
+
</Card>
|
| 153 |
+
</div>
|
| 154 |
+
|
| 155 |
+
{/* Action cards */}
|
| 156 |
+
<div className="grid gap-4 sm:grid-cols-3 lg:grid-cols-4">
|
| 157 |
+
<ActionCard
|
| 158 |
+
title="Suspend / Reactivate"
|
| 159 |
+
description={workspace.suspended ? "Reactivate this workspace" : "Suspend this workspace and revoke access"}
|
| 160 |
+
icon={<AlertCircle size={18} />}
|
| 161 |
+
onClick={() => setSuspendModal(true)}
|
| 162 |
+
/>
|
| 163 |
+
<ActionCard
|
| 164 |
+
title="Override Plan"
|
| 165 |
+
description="Change the workspace subscription plan"
|
| 166 |
+
icon={<CreditCard size={18} />}
|
| 167 |
+
onClick={() => setPlanModal(true)}
|
| 168 |
+
/>
|
| 169 |
+
<ActionCard
|
| 170 |
+
title="Set Credits"
|
| 171 |
+
description="Top up or deduct workspace credits"
|
| 172 |
+
icon={<ShieldCheck size={18} />}
|
| 173 |
+
onClick={() => setCreditsModal(true)}
|
| 174 |
+
/>
|
| 175 |
+
<ActionCard
|
| 176 |
+
title="Transfer Owner"
|
| 177 |
+
description="Reassign workspace ownership"
|
| 178 |
+
icon={<User size={18} />}
|
| 179 |
+
onClick={() => setTransferModal(true)}
|
| 180 |
+
/>
|
| 181 |
+
</div>
|
| 182 |
+
</div>
|
| 183 |
+
|
| 184 |
+
{/* Suspend/Reactivate modal */}
|
| 185 |
+
{suspendModal && (
|
| 186 |
+
<Modal isOpen onClose={() => setSuspendModal(false)} size="md">
|
| 187 |
+
<ModalHeader>
|
| 188 |
+
<ModalTitle>{workspace.suspended ? "Reactivate Workspace" : "Suspend Workspace"}</ModalTitle>
|
| 189 |
+
</ModalHeader>
|
| 190 |
+
<ModalBody>
|
| 191 |
+
<p className="text-[var(--text-secondary)]">
|
| 192 |
+
{workspace.suspended
|
| 193 |
+
? "Reactivating will restore access to all workspace resources."
|
| 194 |
+
: "Suspending will revoke access and stop all processing for this workspace."}
|
| 195 |
+
</p>
|
| 196 |
+
<div className="mt-6 flex justify-end gap-2">
|
| 197 |
+
<Button type="button" variant="outline" onClick={() => setSuspendModal(false)}>
|
| 198 |
+
Cancel
|
| 199 |
+
</Button>
|
| 200 |
+
<Button variant={workspace.suspended ? "outline" : "destructive"} onClick={() => { setSuspendModal(false); }}>
|
| 201 |
+
{workspace.suspended ? "Reactivate" : "Suspend"}
|
| 202 |
+
</Button>
|
| 203 |
+
</div>
|
| 204 |
+
</ModalBody>
|
| 205 |
+
</Modal>
|
| 206 |
+
)}
|
| 207 |
+
|
| 208 |
+
{/* Plan modal */}
|
| 209 |
+
{planModal && (
|
| 210 |
+
<Modal isOpen onClose={() => setPlanModal(false)} size="md">
|
| 211 |
+
<ModalHeader>
|
| 212 |
+
<ModalTitle>Override Plan</ModalTitle>
|
| 213 |
+
</ModalHeader>
|
| 214 |
+
<ModalBody>
|
| 215 |
+
<form
|
| 216 |
+
onSubmit={(e) => {
|
| 217 |
+
e.preventDefault();
|
| 218 |
+
setPlanModal(false);
|
| 219 |
+
}}
|
| 220 |
+
className="space-y-4"
|
| 221 |
+
>
|
| 222 |
+
<div>
|
| 223 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">New Plan</label>
|
| 224 |
+
<Input
|
| 225 |
+
value={newPlan}
|
| 226 |
+
onChange={(e) => setNewPlan(e.target.value)}
|
| 227 |
+
placeholder="starter / professional / enterprise"
|
| 228 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 229 |
+
/>
|
| 230 |
+
</div>
|
| 231 |
+
<div className="flex justify-end gap-2">
|
| 232 |
+
<Button type="button" variant="outline" onClick={() => setPlanModal(false)}>
|
| 233 |
+
Cancel
|
| 234 |
+
</Button>
|
| 235 |
+
<Button type="submit" disabled={!newPlan}>
|
| 236 |
+
Save
|
| 237 |
+
</Button>
|
| 238 |
+
</div>
|
| 239 |
+
</form>
|
| 240 |
+
</ModalBody>
|
| 241 |
+
</Modal>
|
| 242 |
+
)}
|
| 243 |
+
|
| 244 |
+
{/* Credits modal */}
|
| 245 |
+
{creditsModal && (
|
| 246 |
+
<Modal isOpen onClose={() => setCreditsModal(false)} size="md">
|
| 247 |
+
<ModalHeader>
|
| 248 |
+
<ModalTitle>Set Credits</ModalTitle>
|
| 249 |
+
</ModalHeader>
|
| 250 |
+
<ModalBody>
|
| 251 |
+
<form
|
| 252 |
+
onSubmit={(e) => {
|
| 253 |
+
e.preventDefault();
|
| 254 |
+
setCreditsModal(false);
|
| 255 |
+
}}
|
| 256 |
+
className="space-y-4"
|
| 257 |
+
>
|
| 258 |
+
<div>
|
| 259 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">Credits</label>
|
| 260 |
+
<Input
|
| 261 |
+
type="number"
|
| 262 |
+
value={newCredits}
|
| 263 |
+
onChange={(e) => setNewCredits(e.target.value)}
|
| 264 |
+
placeholder="e.g. 1000"
|
| 265 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 266 |
+
/>
|
| 267 |
+
</div>
|
| 268 |
+
<div className="flex justify-end gap-2">
|
| 269 |
+
<Button type="button" variant="outline" onClick={() => setCreditsModal(false)}>
|
| 270 |
+
Cancel
|
| 271 |
+
</Button>
|
| 272 |
+
<Button type="submit" disabled={!newCredits}>
|
| 273 |
+
Save
|
| 274 |
+
</Button>
|
| 275 |
+
</div>
|
| 276 |
+
</form>
|
| 277 |
+
</ModalBody>
|
| 278 |
+
</Modal>
|
| 279 |
+
)}
|
| 280 |
+
|
| 281 |
+
{/* Transfer owner modal */}
|
| 282 |
+
{transferModal && (
|
| 283 |
+
<Modal isOpen onClose={() => setTransferModal(false)} size="md">
|
| 284 |
+
<ModalHeader>
|
| 285 |
+
<ModalTitle>Transfer Owner</ModalTitle>
|
| 286 |
+
</ModalHeader>
|
| 287 |
+
<ModalBody>
|
| 288 |
+
<form
|
| 289 |
+
onSubmit={(e) => {
|
| 290 |
+
e.preventDefault();
|
| 291 |
+
setTransferModal(false);
|
| 292 |
+
}}
|
| 293 |
+
className="space-y-4"
|
| 294 |
+
>
|
| 295 |
+
<div>
|
| 296 |
+
<label className="block text-xs text-[var(--text-tertiary)] mb-1">New Owner Email</label>
|
| 297 |
+
<Input
|
| 298 |
+
value={newOwner}
|
| 299 |
+
onChange={(e) => setNewOwner(e.target.value)}
|
| 300 |
+
placeholder="owner@example.com"
|
| 301 |
+
className="text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 302 |
+
/>
|
| 303 |
+
</div>
|
| 304 |
+
<div className="flex justify-end gap-2">
|
| 305 |
+
<Button type="button" variant="outline" onClick={() => setTransferModal(false)}>
|
| 306 |
+
Cancel
|
| 307 |
+
</Button>
|
| 308 |
+
<Button type="submit" disabled={!newOwner}>
|
| 309 |
+
Transfer
|
| 310 |
+
</Button>
|
| 311 |
+
</div>
|
| 312 |
+
</form>
|
| 313 |
+
</ModalBody>
|
| 314 |
+
</Modal>
|
| 315 |
+
)}
|
| 316 |
+
</div>
|
| 317 |
+
);
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
function ActionCard({ title, description, icon, onClick }: { title: string; description: string; icon: React.ReactNode; onClick: () => void }) {
|
| 321 |
+
return (
|
| 322 |
+
<Card className="border border-[var(--border-color)] hover:border-[var(--color-primary)]/50 transition-colors cursor-pointer" onClick={onClick}>
|
| 323 |
+
<CardContent className="p-5">
|
| 324 |
+
<div className="flex items-center gap-3 mb-3">
|
| 325 |
+
<div className="rounded-[var(--radius-md)] bg-[var(--bg-tertiary)] p-2">
|
| 326 |
+
{icon}
|
| 327 |
+
</div>
|
| 328 |
+
<h3 className="font-medium text-[var(--text-primary)]">{title}</h3>
|
| 329 |
+
</div>
|
| 330 |
+
<p className="text-xs text-[var(--text-tertiary)]">{description}</p>
|
| 331 |
+
</CardContent>
|
| 332 |
+
</Card>
|
| 333 |
+
);
|
| 334 |
+
}
|
apps/admin/src/app/(dashboard)/workspaces/page.tsx
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Building2, Search, RefreshCw, Users, Podcast } from "lucide-react";
|
| 5 |
+
import { trpc } from "@/lib/trpc";
|
| 6 |
+
import { AdminHeader } from "@/components/shell/AdminHeader";
|
| 7 |
+
import {
|
| 8 |
+
Card, CardContent, CardDescription, CardHeader, CardTitle,
|
| 9 |
+
} from "@micprotocol/ui";
|
| 10 |
+
import { Badge } from "@micprotocol/ui";
|
| 11 |
+
import { Button } from "@micprotocol/ui";
|
| 12 |
+
import { Input } from "@micprotocol/ui";
|
| 13 |
+
import { StatCard } from "@micprotocol/ui";
|
| 14 |
+
import Link from "next/link";
|
| 15 |
+
import { ago } from "@/lib/utils";
|
| 16 |
+
|
| 17 |
+
const planVariant = (plan: string) =>
|
| 18 |
+
plan === "studio"
|
| 19 |
+
? "brand"
|
| 20 |
+
: plan === "creator"
|
| 21 |
+
? "info"
|
| 22 |
+
: "default";
|
| 23 |
+
|
| 24 |
+
export default function WorkspacesPage() {
|
| 25 |
+
const [search, setSearch] = React.useState("");
|
| 26 |
+
const [suspended, setSuspended] = React.useState<string | undefined>(undefined);
|
| 27 |
+
const [cursor, setCursor] = React.useState<string | undefined>(undefined);
|
| 28 |
+
|
| 29 |
+
const { data, isLoading, isFetching, refetch } = trpc.admin.workspaces.list.useQuery({
|
| 30 |
+
search: search || undefined,
|
| 31 |
+
suspended: suspended === "true" ? true : suspended === "false" ? false : undefined,
|
| 32 |
+
cursor,
|
| 33 |
+
limit: 25,
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
const items = data?.items ?? [];
|
| 37 |
+
const nextCursor = data?.nextCursor ?? null;
|
| 38 |
+
|
| 39 |
+
const totalWorkspaces = data?.total ?? 0;
|
| 40 |
+
const suspendedCount = items.filter((w) => w.suspended).length;
|
| 41 |
+
const activeCount = totalWorkspaces - suspendedCount;
|
| 42 |
+
const totalMembers = items.reduce((sum, w) => sum + (w.memberCount ?? 0), 0);
|
| 43 |
+
const totalPodcasts = items.reduce((sum, w) => sum + (w.podcastCount ?? 0), 0);
|
| 44 |
+
|
| 45 |
+
return (
|
| 46 |
+
<div className="animate-mic-fade-in-up">
|
| 47 |
+
<AdminHeader
|
| 48 |
+
title="Platform Workspaces"
|
| 49 |
+
subtitle="Suspend, change plans, adjust credits, and transfer ownership"
|
| 50 |
+
onRefresh={refetch}
|
| 51 |
+
refreshing={isFetching}
|
| 52 |
+
actions={
|
| 53 |
+
<Badge tone={suspendedCount > 0 ? "warning" : "success"}>
|
| 54 |
+
{suspendedCount} suspended
|
| 55 |
+
</Badge>
|
| 56 |
+
}
|
| 57 |
+
/>
|
| 58 |
+
|
| 59 |
+
<div className="space-y-6 p-6">
|
| 60 |
+
{/* KPI strip */}
|
| 61 |
+
<div className="grid gap-4 sm:grid-cols-3 lg:grid-cols-4">
|
| 62 |
+
<StatCard
|
| 63 |
+
icon={<Building2 className="size-5" />}
|
| 64 |
+
value={totalWorkspaces}
|
| 65 |
+
label="Total Workspaces"
|
| 66 |
+
description={`${activeCount} active Β· ${suspendedCount} suspended`}
|
| 67 |
+
accentColor="var(--color-primary)"
|
| 68 |
+
animationDelay={1}
|
| 69 |
+
/>
|
| 70 |
+
<StatCard
|
| 71 |
+
icon={<Building2 className="size-5" />}
|
| 72 |
+
value={activeCount}
|
| 73 |
+
label="Active Workspaces"
|
| 74 |
+
description={totalWorkspaces > 0 ? `${((activeCount / totalWorkspaces) * 100).toFixed(0)}% of total` : "0% of total"}
|
| 75 |
+
accentColor="var(--color-success)"
|
| 76 |
+
animationDelay={2}
|
| 77 |
+
/>
|
| 78 |
+
<StatCard
|
| 79 |
+
icon={<Building2 className="size-5" />}
|
| 80 |
+
value={suspendedCount}
|
| 81 |
+
label="Suspended"
|
| 82 |
+
description="Require admin review"
|
| 83 |
+
accentColor="var(--color-error)"
|
| 84 |
+
animationDelay={3}
|
| 85 |
+
/>
|
| 86 |
+
<StatCard
|
| 87 |
+
icon={<Users className="size-5" />}
|
| 88 |
+
value={totalMembers}
|
| 89 |
+
label="Total Members"
|
| 90 |
+
description="Across all workspaces"
|
| 91 |
+
accentColor="var(--color-info)"
|
| 92 |
+
animationDelay={4}
|
| 93 |
+
/>
|
| 94 |
+
</div>
|
| 95 |
+
|
| 96 |
+
{/* Filter bar */}
|
| 97 |
+
<Card className="border border-[var(--border-color)]">
|
| 98 |
+
<CardContent className="p-5">
|
| 99 |
+
<div className="grid gap-4 sm:gap-6 sm:grid-cols-4 items-end">
|
| 100 |
+
<div className="relative w-full">
|
| 101 |
+
<Building2 className="absolute left-3 top-1/2 size-4 -translate-y-1/2 text-[var(--text-tertiary)]" />
|
| 102 |
+
<Input
|
| 103 |
+
className="pl-9 text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20"
|
| 104 |
+
placeholder="Search name or slugβ¦"
|
| 105 |
+
value={search}
|
| 106 |
+
onChange={(e) => { setSearch(e.target.value); setCursor(undefined); }}
|
| 107 |
+
/>
|
| 108 |
+
</div>
|
| 109 |
+
<select
|
| 110 |
+
value={suspended ?? ""}
|
| 111 |
+
onChange={(e) => { setSuspended(e.target.value || undefined); setCursor(undefined); }}
|
| 112 |
+
className="w-full text-[var(--text-primary)] bg-[var(--bg-elevated)] border-[var(--border-color)] rounded-[var(--radius-md)] px-3 py-2 text-sm focus:border-[var(--color-primary)] focus:ring-2 focus:ring-[var(--color-primary)]/20 outline-none"
|
| 113 |
+
>
|
| 114 |
+
<option value="">All statuses</option>
|
| 115 |
+
<option value="true">Suspended</option>
|
| 116 |
+
<option value="false">Active</option>
|
| 117 |
+
</select>
|
| 118 |
+
<div className="flex items-end gap-2">
|
| 119 |
+
<Button
|
| 120 |
+
onClick={() => void refetch()}
|
| 121 |
+
variant="ghost"
|
| 122 |
+
size="sm"
|
| 123 |
+
disabled={isFetching}
|
| 124 |
+
className="text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)]"
|
| 125 |
+
>
|
| 126 |
+
<RefreshCw className={isFetching ? "animate-spin" : ""} size={3} /> Refresh
|
| 127 |
+
</Button>
|
| 128 |
+
</div>
|
| 129 |
+
</div>
|
| 130 |
+
</CardContent>
|
| 131 |
+
</Card>
|
| 132 |
+
|
| 133 |
+
{/* Table */}
|
| 134 |
+
<Card>
|
| 135 |
+
<CardHeader>
|
| 136 |
+
<CardTitle className="flex items-center gap-2">
|
| 137 |
+
<Building2 className="size-4 text-[var(--color-primary)]" /> Workspace Directory
|
| 138 |
+
</CardTitle>
|
| 139 |
+
<CardDescription>Platform-level workspace oversight: suspend, override plans, set credits, and transfer ownership. Every action is audit-trailed.</CardDescription>
|
| 140 |
+
</CardHeader>
|
| 141 |
+
<CardContent>
|
| 142 |
+
<div className="overflow-auto">
|
| 143 |
+
<table className="w-full text-left border-collapse">
|
| 144 |
+
<thead>
|
| 145 |
+
<tr className="border-b border-[var(--border-color-subtle)]">
|
| 146 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Workspace</th>
|
| 147 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Slug</th>
|
| 148 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Plan</th>
|
| 149 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Status</th>
|
| 150 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Members</th>
|
| 151 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium">Podcasts</th>
|
| 152 |
+
<th className="pb-3 text-[var(--text-tertiary)] text-xs uppercase tracking-wider font-medium text-right">Action</th>
|
| 153 |
+
</tr>
|
| 154 |
+
</thead>
|
| 155 |
+
<tbody>
|
| 156 |
+
{isLoading ? (
|
| 157 |
+
[...Array(6)].map((_, i) => (
|
| 158 |
+
<tr key={i} className="border-b border-[var(--border-color-subtle)]">
|
| 159 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 160 |
+
<div className="skeleton w-full h-16 mx-auto max-w-xs" />
|
| 161 |
+
</td>
|
| 162 |
+
</tr>
|
| 163 |
+
))
|
| 164 |
+
) : items.length === 0 ? (
|
| 165 |
+
<tr>
|
| 166 |
+
<td colSpan={7} className="py-12 text-center text-[var(--text-tertiary)]">
|
| 167 |
+
No workspaces match your filters.
|
| 168 |
+
</td>
|
| 169 |
+
</tr>
|
| 170 |
+
) : (
|
| 171 |
+
items.map((w) => (
|
| 172 |
+
<tr key={w.id} className="border-b border-[var(--border-color-subtle)] hover:bg-[var(--bg-tertiary)]/30 transition-colors">
|
| 173 |
+
<td className="py-4 flex items-center gap-3">
|
| 174 |
+
<div className="flex size-8 items-center justify-center rounded-full bg-[var(--bg-tertiary)] text-xs font-semibold text-[var(--color-primary)]">
|
| 175 |
+
{w.name.slice(0, 1).toUpperCase()}
|
| 176 |
+
</div>
|
| 177 |
+
<div className="min-w-0">
|
| 178 |
+
<p className="text-sm font-medium text-[var(--text-primary)] truncate">{w.name}</p>
|
| 179 |
+
<p className="text-xs text-[var(--text-tertiary)] truncate">{w.slug}</p>
|
| 180 |
+
</div>
|
| 181 |
+
</td>
|
| 182 |
+
<td className="py-4 font-mono text-xs text-[var(--text-secondary)]">{w.slug}</td>
|
| 183 |
+
<td className="py-4">
|
| 184 |
+
<Badge tone={planVariant(w.subscriptionPlanId ?? "hobby") as any}>
|
| 185 |
+
{w.subscriptionPlanId ?? "hobby"}
|
| 186 |
+
</Badge>
|
| 187 |
+
</td>
|
| 188 |
+
<td className="py-4">
|
| 189 |
+
<Badge tone={w.suspended ? "error" : "success"}>
|
| 190 |
+
{w.suspended ? "suspended" : "active"}
|
| 191 |
+
</Badge>
|
| 192 |
+
</td>
|
| 193 |
+
<td className="py-4 text-sm text-[var(--text-secondary)]">{w.memberCount}</td>
|
| 194 |
+
<td className="py-4 text-sm text-[var(--text-secondary)]">{w.podcastCount}</td>
|
| 195 |
+
<td className="py-4 text-right">
|
| 196 |
+
<Link href={`/workspaces/${w.id}`} passHref legacyBehavior>
|
| 197 |
+
<Button variant="ghost" size="sm" className="w-9 h-9 p-0 text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)]">
|
| 198 |
+
<Building2 className="size-3.5" />
|
| 199 |
+
</Button>
|
| 200 |
+
</Link>
|
| 201 |
+
</td>
|
| 202 |
+
</tr>
|
| 203 |
+
))
|
| 204 |
+
)}
|
| 205 |
+
</tbody>
|
| 206 |
+
</table>
|
| 207 |
+
</div>
|
| 208 |
+
<div className="mt-4 flex items-center justify-between">
|
| 209 |
+
<span className="text-[var(--text-xs)] text-[var(--text-tertiary)]">
|
| 210 |
+
{data?.total != null ? `${data.total} total` : ""}
|
| 211 |
+
</span>
|
| 212 |
+
<div className="flex gap-2">
|
| 213 |
+
<Button
|
| 214 |
+
variant="ghost"
|
| 215 |
+
size="sm"
|
| 216 |
+
disabled={!cursor}
|
| 217 |
+
onClick={() => setCursor(undefined)}
|
| 218 |
+
className="text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)]"
|
| 219 |
+
>
|
| 220 |
+
First
|
| 221 |
+
</Button>
|
| 222 |
+
<Button
|
| 223 |
+
variant="ghost"
|
| 224 |
+
size="sm"
|
| 225 |
+
disabled={!nextCursor || isFetching}
|
| 226 |
+
onClick={() => setCursor(nextCursor ?? undefined)}
|
| 227 |
+
className="text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)]"
|
| 228 |
+
>
|
| 229 |
+
Next
|
| 230 |
+
</Button>
|
| 231 |
+
</div>
|
| 232 |
+
</div>
|
| 233 |
+
</CardContent>
|
| 234 |
+
</Card>
|
| 235 |
+
</div>
|
| 236 |
+
</div>
|
| 237 |
+
);
|
| 238 |
+
}
|
apps/admin/src/app/globals.css
ADDED
|
@@ -0,0 +1,567 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@100..900&family=DM+Sans:opsz,wght@9..40,100..900&display=swap");
|
| 2 |
+
|
| 3 |
+
@tailwind base;
|
| 4 |
+
@tailwind components;
|
| 5 |
+
@tailwind utilities;
|
| 6 |
+
|
| 7 |
+
/* ββ MicProtocol Design Tokens (Studio Desk) ββ */
|
| 8 |
+
/* Same CSS custom properties as the web app so the admin matches exactly. */
|
| 9 |
+
:root {
|
| 10 |
+
/* ββ Brand ββ */
|
| 11 |
+
--color-primary: #E8A64A;
|
| 12 |
+
--color-primary-light: #F2C477;
|
| 13 |
+
--color-primary-dark: #BD7828;
|
| 14 |
+
--color-primary-glow: rgba(232, 166, 74, 0.10);
|
| 15 |
+
--color-primary-glow-strong: rgba(232, 166, 74, 0.18);
|
| 16 |
+
--color-secondary: #8B80C7;
|
| 17 |
+
--color-accent: #5BC49A;
|
| 18 |
+
|
| 19 |
+
/* ββ Semantic ββ */
|
| 20 |
+
--color-success: #5BC49A;
|
| 21 |
+
--color-warning: #E6AB55;
|
| 22 |
+
--color-error: #E57373;
|
| 23 |
+
--color-info: #78A6E8;
|
| 24 |
+
|
| 25 |
+
/* ββ Backgrounds ββ */
|
| 26 |
+
--bg-primary: #141516;
|
| 27 |
+
--bg-secondary: #1B1D1F;
|
| 28 |
+
--bg-tertiary: #24272A;
|
| 29 |
+
--bg-elevated: #1D2023;
|
| 30 |
+
--bg-glass: rgba(28, 25, 36, 0.6);
|
| 31 |
+
|
| 32 |
+
/* ββ Borders ββ */
|
| 33 |
+
--border-color: #34373A;
|
| 34 |
+
--border-color-subtle: #282B2E;
|
| 35 |
+
--border-brand: rgba(232, 166, 74, 0.25);
|
| 36 |
+
|
| 37 |
+
/* ββ Text ββ */
|
| 38 |
+
--text-primary: #F3F1EC;
|
| 39 |
+
--text-secondary: #B5B1A8;
|
| 40 |
+
--text-tertiary: #89857D;
|
| 41 |
+
--text-inverse: #1C1812;
|
| 42 |
+
|
| 43 |
+
/* ββ Elevation ββ */
|
| 44 |
+
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.18);
|
| 45 |
+
--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.20);
|
| 46 |
+
--shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.24);
|
| 47 |
+
--shadow-xl: 0 20px 48px rgba(0, 0, 0, 0.28);
|
| 48 |
+
--shadow-glow: 0 0 16px rgba(232, 166, 74, 0.12);
|
| 49 |
+
--shadow-glow-strong: 0 0 28px rgba(232, 166, 74, 0.18);
|
| 50 |
+
|
| 51 |
+
/* ββ Spacing ββ */
|
| 52 |
+
--space-1: 0.25rem;
|
| 53 |
+
--space-2: 0.5rem;
|
| 54 |
+
--space-3: 0.75rem;
|
| 55 |
+
--space-4: 1rem;
|
| 56 |
+
--space-5: 1.25rem;
|
| 57 |
+
--space-6: 1.5rem;
|
| 58 |
+
--space-8: 2rem;
|
| 59 |
+
--space-10: 2.5rem;
|
| 60 |
+
--space-12: 3rem;
|
| 61 |
+
--space-16: 4rem;
|
| 62 |
+
--space-20: 5rem;
|
| 63 |
+
--space-24: 6rem;
|
| 64 |
+
|
| 65 |
+
/* ββ Typography ββ */
|
| 66 |
+
--font-display: "Space Grotesk", system-ui, sans-serif;
|
| 67 |
+
--font-sans: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
| 68 |
+
--font-mono: "JetBrains Mono", "Fira Code", "Consolas", monospace;
|
| 69 |
+
|
| 70 |
+
--text-xs: 0.75rem;
|
| 71 |
+
--text-sm: 0.875rem;
|
| 72 |
+
--text-base: 1rem;
|
| 73 |
+
--text-lg: 1.125rem;
|
| 74 |
+
--text-xl: 1.25rem;
|
| 75 |
+
--text-2xl: 1.5rem;
|
| 76 |
+
--text-3xl: 2rem;
|
| 77 |
+
--text-4xl: 2.75rem;
|
| 78 |
+
--text-5xl: 3.5rem;
|
| 79 |
+
|
| 80 |
+
--font-weight-normal: 400;
|
| 81 |
+
--font-weight-medium: 500;
|
| 82 |
+
--font-weight-semibold: 600;
|
| 83 |
+
--font-weight-bold: 700;
|
| 84 |
+
|
| 85 |
+
--line-height-tight: 1.1;
|
| 86 |
+
--line-height-snug: 1.25;
|
| 87 |
+
--line-height-normal: 1.55;
|
| 88 |
+
--line-height-relaxed: 1.7;
|
| 89 |
+
|
| 90 |
+
--letter-spacing-tight: -0.03em;
|
| 91 |
+
--letter-spacing-ultra-tight: -0.04em;
|
| 92 |
+
--letter-spacing-wide: 0.06em;
|
| 93 |
+
--letter-spacing-ultra-wide: 0.08em;
|
| 94 |
+
|
| 95 |
+
/* ββ Border radius ββ */
|
| 96 |
+
--radius-sm: 6px;
|
| 97 |
+
--radius-md: 10px;
|
| 98 |
+
--radius-lg: 14px;
|
| 99 |
+
--radius-xl: 18px;
|
| 100 |
+
--radius-full: 9999px;
|
| 101 |
+
|
| 102 |
+
/* ββ Transitions ββ */
|
| 103 |
+
--transition-fast: 120ms ease-out;
|
| 104 |
+
--transition-normal: 220ms ease-out;
|
| 105 |
+
--transition-slow: 350ms ease-out;
|
| 106 |
+
--spring: cubic-bezier(0.34, 1.56, 0.64, 1);
|
| 107 |
+
--ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
|
| 108 |
+
|
| 109 |
+
/* ββ Layout ββ */
|
| 110 |
+
--sidebar-width: 260px;
|
| 111 |
+
--header-height: 56px;
|
| 112 |
+
--content-max-width: 1280px;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
*,
|
| 116 |
+
*::before,
|
| 117 |
+
*::after {
|
| 118 |
+
box-sizing: border-box;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
html,
|
| 122 |
+
body {
|
| 123 |
+
background-color: var(--bg-primary);
|
| 124 |
+
color: var(--text-primary);
|
| 125 |
+
font-family: var(--font-sans);
|
| 126 |
+
font-size: var(--text-base);
|
| 127 |
+
line-height: var(--line-height-normal);
|
| 128 |
+
-webkit-font-smoothing: antialiased;
|
| 129 |
+
font-smoothing: antialiased;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
h1,
|
| 133 |
+
h2,
|
| 134 |
+
h3,
|
| 135 |
+
h4,
|
| 136 |
+
h5,
|
| 137 |
+
h6 {
|
| 138 |
+
font-family: var(--font-display);
|
| 139 |
+
line-height: var(--line-height-tight);
|
| 140 |
+
font-weight: var(--font-weight-bold);
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
/* ββ Utility classes (matching web app naming) ββ */
|
| 144 |
+
.font-display {
|
| 145 |
+
font-family: var(--font-display);
|
| 146 |
+
}
|
| 147 |
+
.font-sans {
|
| 148 |
+
font-family: var(--font-sans);
|
| 149 |
+
}
|
| 150 |
+
.font-mono {
|
| 151 |
+
font-family: var(--font-mono);
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.text-text-primary {
|
| 155 |
+
color: var(--text-primary);
|
| 156 |
+
}
|
| 157 |
+
.text-text-secondary {
|
| 158 |
+
color: var(--text-secondary);
|
| 159 |
+
}
|
| 160 |
+
.text-text-tertiary {
|
| 161 |
+
color: var(--text-tertiary);
|
| 162 |
+
}
|
| 163 |
+
.text-text-inverse {
|
| 164 |
+
color: var(--text-inverse);
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
.bg-bg-primary {
|
| 168 |
+
background-color: var(--bg-primary);
|
| 169 |
+
}
|
| 170 |
+
.bg-bg-secondary {
|
| 171 |
+
background-color: var(--bg-secondary);
|
| 172 |
+
}
|
| 173 |
+
.bg-bg-tertiary {
|
| 174 |
+
background-color: var(--bg-tertiary);
|
| 175 |
+
}
|
| 176 |
+
.bg-bg-elevated {
|
| 177 |
+
background-color: var(--bg-elevated);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
.text-color-primary {
|
| 181 |
+
color: var(--color-primary);
|
| 182 |
+
}
|
| 183 |
+
.text-color-secondary {
|
| 184 |
+
color: var(--color-secondary);
|
| 185 |
+
}
|
| 186 |
+
.text-color-accent {
|
| 187 |
+
color: var(--color-accent);
|
| 188 |
+
}
|
| 189 |
+
.text-color-success {
|
| 190 |
+
color: var(--color-success);
|
| 191 |
+
}
|
| 192 |
+
.text-color-warning {
|
| 193 |
+
color: var(--color-warning);
|
| 194 |
+
}
|
| 195 |
+
.text-color-error {
|
| 196 |
+
color: var(--color-error);
|
| 197 |
+
}
|
| 198 |
+
.text-color-info {
|
| 199 |
+
color: var(--color-info);
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
.bg-color-primary {
|
| 203 |
+
background-color: var(--color-primary);
|
| 204 |
+
}
|
| 205 |
+
.bg-color-secondary {
|
| 206 |
+
background-color: var(--color-secondary);
|
| 207 |
+
}
|
| 208 |
+
.bg-color-accent {
|
| 209 |
+
background-color: var(--color-accent);
|
| 210 |
+
}
|
| 211 |
+
.bg-color-success {
|
| 212 |
+
background-color: var(--color-success);
|
| 213 |
+
}
|
| 214 |
+
.bg-color-warning {
|
| 215 |
+
background-color: var(--color-warning);
|
| 216 |
+
}
|
| 217 |
+
.bg-color-error {
|
| 218 |
+
background-color: var(--color-error);
|
| 219 |
+
}
|
| 220 |
+
.bg-color-info {
|
| 221 |
+
background-color: var(--color-info);
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
.border-border-color {
|
| 225 |
+
border-color: var(--border-color);
|
| 226 |
+
}
|
| 227 |
+
.border-border-color-subtle {
|
| 228 |
+
border-color: var(--border-color-subtle);
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
.shadow-sm {
|
| 232 |
+
box-shadow: var(--shadow-sm);
|
| 233 |
+
}
|
| 234 |
+
.shadow-md {
|
| 235 |
+
box-shadow: var(--shadow-md);
|
| 236 |
+
}
|
| 237 |
+
.shadow-lg {
|
| 238 |
+
box-shadow: var(--shadow-lg);
|
| 239 |
+
}
|
| 240 |
+
.shadow-xl {
|
| 241 |
+
box-shadow: var(--shadow-xl);
|
| 242 |
+
}
|
| 243 |
+
.shadow-glow {
|
| 244 |
+
box-shadow: var(--shadow-glow);
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
.rounded-sm {
|
| 248 |
+
border-radius: var(--radius-sm);
|
| 249 |
+
}
|
| 250 |
+
.rounded-md {
|
| 251 |
+
border-radius: var(--radius-md);
|
| 252 |
+
}
|
| 253 |
+
.rounded-lg {
|
| 254 |
+
border-radius: var(--radius-lg);
|
| 255 |
+
}
|
| 256 |
+
.rounded-xl {
|
| 257 |
+
border-radius: var(--radius-xl);
|
| 258 |
+
}
|
| 259 |
+
.rounded-full {
|
| 260 |
+
border-radius: var(--radius-full);
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
.transition-fast {
|
| 264 |
+
transition: var(--transition-fast);
|
| 265 |
+
}
|
| 266 |
+
.transition-normal {
|
| 267 |
+
transition: var(--transition-normal);
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
/* ββ Web app utility classes ββ */
|
| 271 |
+
.btn {
|
| 272 |
+
display: inline-flex;
|
| 273 |
+
align-items: center;
|
| 274 |
+
justify-content: center;
|
| 275 |
+
gap: var(--space-2);
|
| 276 |
+
padding: var(--space-2) var(--space-4);
|
| 277 |
+
border: 1px solid transparent;
|
| 278 |
+
border-radius: var(--radius-md);
|
| 279 |
+
font-family: var(--font-sans);
|
| 280 |
+
font-size: var(--text-sm);
|
| 281 |
+
font-weight: 600;
|
| 282 |
+
cursor: pointer;
|
| 283 |
+
transition:
|
| 284 |
+
background-color var(--transition-fast),
|
| 285 |
+
border-color var(--transition-fast),
|
| 286 |
+
color var(--transition-fast),
|
| 287 |
+
box-shadow var(--transition-fast);
|
| 288 |
+
white-space: nowrap;
|
| 289 |
+
text-decoration: none;
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
.btn:active {
|
| 293 |
+
transform: scale(0.99);
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
.btn-primary {
|
| 297 |
+
background: var(--color-primary);
|
| 298 |
+
color: var(--text-inverse);
|
| 299 |
+
border-color: var(--color-primary);
|
| 300 |
+
box-shadow: var(--shadow-sm);
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
.btn-primary:hover {
|
| 304 |
+
background: var(--color-primary-dark);
|
| 305 |
+
border-color: var(--color-primary-dark);
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
.btn-secondary {
|
| 309 |
+
background: var(--bg-tertiary);
|
| 310 |
+
color: var(--text-primary);
|
| 311 |
+
border: 1px solid var(--border-color-subtle);
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
.btn-secondary:hover {
|
| 315 |
+
border-color: var(--color-primary);
|
| 316 |
+
color: var(--color-primary);
|
| 317 |
+
background: color-mix(in srgb, var(--color-primary) 6%, transparent);
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
.btn-ghost {
|
| 321 |
+
background: transparent;
|
| 322 |
+
color: var(--text-secondary);
|
| 323 |
+
border: none;
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
.btn-ghost:hover {
|
| 327 |
+
color: var(--text-primary);
|
| 328 |
+
background: var(--bg-tertiary);
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
.btn-icon {
|
| 332 |
+
padding: 0;
|
| 333 |
+
width: 2.5rem;
|
| 334 |
+
height: 2.5rem;
|
| 335 |
+
min-width: 2.5rem;
|
| 336 |
+
min-height: 2.5rem;
|
| 337 |
+
display: inline-flex;
|
| 338 |
+
align-items: center;
|
| 339 |
+
justify-content: center;
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
.input {
|
| 343 |
+
width: 100%;
|
| 344 |
+
padding: var(--space-2) var(--space-3);
|
| 345 |
+
border: 1px solid var(--border-color);
|
| 346 |
+
border-radius: var(--radius-md);
|
| 347 |
+
font-family: var(--font-sans);
|
| 348 |
+
font-size: var(--text-sm);
|
| 349 |
+
color: var(--text-primary);
|
| 350 |
+
background: var(--bg-elevated);
|
| 351 |
+
transition:
|
| 352 |
+
border-color var(--transition-fast),
|
| 353 |
+
box-shadow var(--transition-fast);
|
| 354 |
+
outline: none;
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
.input:focus {
|
| 358 |
+
border-color: var(--color-primary);
|
| 359 |
+
box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-primary) 20%, transparent);
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
.input::placeholder {
|
| 363 |
+
color: var(--text-tertiary);
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
.card {
|
| 367 |
+
background: var(--bg-elevated);
|
| 368 |
+
border: 1px solid var(--border-color-subtle);
|
| 369 |
+
border-radius: var(--radius-lg);
|
| 370 |
+
padding: var(--space-6);
|
| 371 |
+
transition:
|
| 372 |
+
border-color var(--transition-fast),
|
| 373 |
+
box-shadow var(--transition-fast);
|
| 374 |
+
position: relative;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
.card:hover {
|
| 378 |
+
border-color: var(--border-color);
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
.card-interactive {
|
| 382 |
+
cursor: pointer;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
.card-interactive:hover {
|
| 386 |
+
border-color: color-mix(in srgb, var(--color-primary) 30%, transparent);
|
| 387 |
+
box-shadow: var(--shadow-md);
|
| 388 |
+
transform: translateY(-1px);
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
.frosted {
|
| 392 |
+
background: var(--bg-elevated);
|
| 393 |
+
border: 1px solid var(--border-color);
|
| 394 |
+
position: relative;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
.frosted::after {
|
| 398 |
+
content: "";
|
| 399 |
+
position: absolute;
|
| 400 |
+
inset: 0;
|
| 401 |
+
opacity: 0.015;
|
| 402 |
+
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
|
| 403 |
+
pointer-events: none;
|
| 404 |
+
border-radius: inherit;
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
.stat-card {
|
| 408 |
+
background: var(--bg-elevated);
|
| 409 |
+
border: 1px solid var(--border-color-subtle);
|
| 410 |
+
border-radius: var(--radius-lg);
|
| 411 |
+
padding: var(--space-6);
|
| 412 |
+
display: flex;
|
| 413 |
+
align-items: center;
|
| 414 |
+
gap: var(--space-4);
|
| 415 |
+
transition:
|
| 416 |
+
box-shadow var(--transition-fast),
|
| 417 |
+
border-color var(--transition-fast);
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
.stat-card:hover {
|
| 421 |
+
border-color: var(--border-color);
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
.stat-icon {
|
| 425 |
+
width: 40px;
|
| 426 |
+
height: 40px;
|
| 427 |
+
border-radius: var(--radius-md);
|
| 428 |
+
background: var(--bg-tertiary);
|
| 429 |
+
display: flex;
|
| 430 |
+
align-items: center;
|
| 431 |
+
justify-content: center;
|
| 432 |
+
border: 1px solid var(--border-color);
|
| 433 |
+
flex-shrink: 0;
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
.stat-value {
|
| 437 |
+
font-size: var(--text-2xl);
|
| 438 |
+
font-weight: 700;
|
| 439 |
+
font-family: var(--font-display);
|
| 440 |
+
letter-spacing: -0.02em;
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
.stat-label {
|
| 444 |
+
font-size: var(--text-xs);
|
| 445 |
+
color: var(--text-tertiary);
|
| 446 |
+
letter-spacing: 0.02em;
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
/* ββ Animations ββ */
|
| 450 |
+
@keyframes fadeIn {
|
| 451 |
+
from {
|
| 452 |
+
opacity: 0;
|
| 453 |
+
transform: translateY(12px);
|
| 454 |
+
}
|
| 455 |
+
to {
|
| 456 |
+
opacity: 1;
|
| 457 |
+
transform: translateY(0);
|
| 458 |
+
}
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
@keyframes revealUp {
|
| 462 |
+
from {
|
| 463 |
+
opacity: 0;
|
| 464 |
+
transform: translateY(40px);
|
| 465 |
+
}
|
| 466 |
+
to {
|
| 467 |
+
opacity: 1;
|
| 468 |
+
transform: translateY(0);
|
| 469 |
+
}
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
@keyframes shimmer {
|
| 473 |
+
0% {
|
| 474 |
+
background-position: -200% 0;
|
| 475 |
+
}
|
| 476 |
+
100% {
|
| 477 |
+
background-position: 200% 0;
|
| 478 |
+
}
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
@keyframes spin {
|
| 482 |
+
to {
|
| 483 |
+
transform: rotate(360deg);
|
| 484 |
+
}
|
| 485 |
+
}
|
| 486 |
+
|
| 487 |
+
@keyframes mic-fade-in-up {
|
| 488 |
+
0% {
|
| 489 |
+
opacity: 0;
|
| 490 |
+
transform: translateY(12px);
|
| 491 |
+
}
|
| 492 |
+
100% {
|
| 493 |
+
opacity: 1;
|
| 494 |
+
transform: translateY(0);
|
| 495 |
+
}
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
.animate-fade-in {
|
| 499 |
+
animation: fadeIn 0.4s var(--ease-out-expo) forwards;
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
.animate-reveal {
|
| 503 |
+
opacity: 0;
|
| 504 |
+
animation: revealUp 0.7s var(--ease-out-expo) forwards;
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
.animate-reveal-delay-1 {
|
| 508 |
+
animation-delay: 0.1s;
|
| 509 |
+
}
|
| 510 |
+
.animate-reveal-delay-2 {
|
| 511 |
+
animation-delay: 0.2s;
|
| 512 |
+
}
|
| 513 |
+
.animate-reveal-delay-3 {
|
| 514 |
+
animation-delay: 0.3s;
|
| 515 |
+
}
|
| 516 |
+
.animate-reveal-delay-4 {
|
| 517 |
+
animation-delay: 0.4s;
|
| 518 |
+
}
|
| 519 |
+
.animate-reveal-delay-5 {
|
| 520 |
+
animation-delay: 0.5s;
|
| 521 |
+
}
|
| 522 |
+
.animate-reveal-delay-6 {
|
| 523 |
+
animation-delay: 0.6s;
|
| 524 |
+
}
|
| 525 |
+
|
| 526 |
+
.animate-mic-fade-in-up {
|
| 527 |
+
animation: mic-fade-in-up 0.4s ease-out both;
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
.animate-spin {
|
| 531 |
+
animation: spin 1s linear infinite;
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
/* ββ Focus rings ββ */
|
| 535 |
+
*:focus-visible {
|
| 536 |
+
outline: 2px solid var(--color-primary);
|
| 537 |
+
outline-offset: 2px;
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
/* ββ Scrollbar ββ */
|
| 541 |
+
::-webkit-scrollbar {
|
| 542 |
+
width: 6px;
|
| 543 |
+
height: 6px;
|
| 544 |
+
}
|
| 545 |
+
::-webkit-scrollbar-track {
|
| 546 |
+
background: var(--bg-secondary);
|
| 547 |
+
}
|
| 548 |
+
::-webkit-scrollbar-thumb {
|
| 549 |
+
background: var(--border-color);
|
| 550 |
+
border-radius: 3px;
|
| 551 |
+
}
|
| 552 |
+
::-webkit-scrollbar-thumb:hover {
|
| 553 |
+
background: var(--text-tertiary);
|
| 554 |
+
}
|
| 555 |
+
|
| 556 |
+
/* ββ Skeleton ββ */
|
| 557 |
+
.skeleton {
|
| 558 |
+
background: linear-gradient(
|
| 559 |
+
90deg,
|
| 560 |
+
var(--bg-tertiary) 25%,
|
| 561 |
+
var(--border-color) 50%,
|
| 562 |
+
var(--bg-tertiary) 75%
|
| 563 |
+
);
|
| 564 |
+
background-size: 200% 100%;
|
| 565 |
+
animation: shimmer 1.5s infinite;
|
| 566 |
+
border-radius: var(--radius-md);
|
| 567 |
+
}
|
apps/admin/src/app/layout.tsx
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Metadata, Viewport } from "next";
|
| 2 |
+
import { Providers } from "@/components/providers";
|
| 3 |
+
import "./globals.css";
|
| 4 |
+
|
| 5 |
+
export const metadata: Metadata = {
|
| 6 |
+
title: "MicProtocol Admin",
|
| 7 |
+
description: "MicProtocol Administration System β core infrastructure, queues, AI pipelines, integrations, and tenant governance.",
|
| 8 |
+
icons: { icon: "/favicon.svg" },
|
| 9 |
+
};
|
| 10 |
+
|
| 11 |
+
export const viewport: Viewport = {
|
| 12 |
+
themeColor: "#0A090D",
|
| 13 |
+
};
|
| 14 |
+
|
| 15 |
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
| 16 |
+
return (
|
| 17 |
+
<html lang="en" className="dark">
|
| 18 |
+
<body>
|
| 19 |
+
<Providers>{children}</Providers>
|
| 20 |
+
</body>
|
| 21 |
+
</html>
|
| 22 |
+
);
|
| 23 |
+
}
|