Add personal dashboard flow and per-component website selection
This introduces a user-scoped dashboard with board-style view/edit pages while keeping it unavailable in team context, and moves website targeting to component config so dashboard components can each select their own website.
This commit is contained in:
1 parent
2633697585
commit
631cc46f7f
73 files changed
+418
-88
No files matched your search
@@ -0,0 +1,64 @@
|
||||
import { z } from 'zod';
|
||||
import { uuid } from '@/lib/crypto';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { createBoard, getBoard, updateBoard } from '@/queries/prisma';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { auth, error } = await parseRequest(request);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const board = await getBoard(auth.user.id);
|
||||
|
||||
if (board && board.userId !== auth.user.id) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
return json(board);
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const schema = z.object({
|
||||
name: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
parameters: z.object({}).passthrough().optional(),
|
||||
});
|
||||
|
||||
const { auth, body, error } = await parseRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const userId = auth.user.id;
|
||||
const existing = await getBoard(userId);
|
||||
|
||||
if (existing && existing.userId !== userId) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const data = {
|
||||
name: body.name,
|
||||
description: body.description,
|
||||
parameters: body.parameters ?? {},
|
||||
};
|
||||
|
||||
if (existing) {
|
||||
const result = await updateBoard(userId, data);
|
||||
|
||||
return json(result);
|
||||
}
|
||||
|
||||
const result = await createBoard({
|
||||
id: userId,
|
||||
type: 'dashboard',
|
||||
slug: uuid(),
|
||||
userId,
|
||||
...data,
|
||||
});
|
||||
|
||||
return json(result);
|
||||
}
|
||||
Reference in new issue
Block a user