Files
ProjectE/apps/web/app/api/domains/[domainId]/dashboard/layout/route.ts
T
mbatchelder eba1d78fb9 feat: Phase 5 - Calendar + Dashboard + Search
Calendar:
- GET /api/domains/[domainId]/calendar/events?from=&to= — returns tasks, habits, projects, milestones
- PATCH /api/domains/[domainId]/tasks/[id]/schedule — drag-to-reschedule with activity feed
- Calendar UI with month/week/day views via react-big-calendar
- Drag-to-reschedule with SSE updates
- Filter by entity type and domain
- Keyboard shortcuts: t=today, m/w/d=view, ←/→=navigate
- Mobile: auto-switches to day view on small screens

Dashboard:
- GET/PUT /api/domains/[domainId]/dashboard — layout stored in domain custom_fields
- 8 per-widget data endpoints (today-tasks, habit-checklist, weekly-stats, project-progress, upcoming-calendar, recent-notes, activity-feed, quick-capture)
- react-grid-layout with responsive breakpoints (12/8/4 cols)
- Drag-to-reorder, resize, add/remove widgets
- Edit mode toggle, per-workspace layout persistence
- Widget error boundary

Search:
- tsvector columns + GIN indexes on tasks, notes, projects, habits, domains
- GET /api/search?q=&types=&domain= — ranked results with ts_headline snippets
- Dedicated search page with grouped results, filters, recent searches (localStorage)
- Empty state with hints

Schema:
- Added custom_fields jsonb column to domains table (migration 0002)
- Removed stale root app/ directory

Build: passes, typecheck: passes, tests: 18/18 wikilink-parser tests pass
2026-07-29 07:32:47 -04:00

74 lines
2.5 KiB
TypeScript

// AGENT INSTRUCTION: After every write (INSERT/UPDATE/DELETE), you MUST:
// 1. Insert activity feed entry
// 2. Call pg.notify('project_e_events', JSON.stringify({ type, action, id, workspace_id }))
// See AGENTS.md for full rules.
import { NextRequest, NextResponse } from 'next/server';
import { withAuth, requireWorkspaceAccess, createErrorResponse, ApiError } from '@/lib/auth';
import { recordActivity } from '@/lib/activity';
import { db, domains } from '@project-e/db';
import { eq } from 'drizzle-orm';
import { z } from 'zod';
type RouteContext = { params: Promise<{ domainId: string }> };
const layoutItemSchema = z.object({
widgetId: z.string(),
order: z.number().int(),
enabled: z.boolean(),
config: z.record(z.string(), z.unknown()).optional(),
});
const updateLayoutSchema = z.object({
layout: z.array(layoutItemSchema),
});
// PUT /api/domains/[domainId]/dashboard/layout — Update dashboard layout
export const PUT = withAuth<RouteContext>(async (request: NextRequest, user, context) => {
const { domainId } = await context!.params;
await requireWorkspaceAccess(domainId);
try {
const body = await request.json();
const data = updateLayoutSchema.parse(body);
const [domain] = await db.select({ id: domains.id, customFields: domains.customFields })
.from(domains)
.where(eq(domains.id, domainId))
.limit(1);
if (!domain) {
return createErrorResponse('NOT_FOUND', 'Domain not found', 404);
}
// Store layout in domain's custom_fields
const existingFields = (domain.customFields as Record<string, unknown>) || {};
await db.update(domains)
.set({
customFields: { ...existingFields, dashboard_layout: data.layout },
updatedAt: new Date(),
})
.where(eq(domains.id, domainId));
await recordActivity({
actor: user.name,
action: 'updated',
entityType: 'domain',
entityId: domainId,
changes: { dashboardLayout: data.layout },
workspaceId: domainId,
});
return NextResponse.json({ layout: data.layout });
} catch (error) {
if (error instanceof z.ZodError) {
return createErrorResponse('VALIDATION_ERROR', 'Invalid input', 400, error.issues);
}
if (error instanceof ApiError) {
return createErrorResponse(error.code, error.message, error.status);
}
console.error('[dashboard/layout PUT] error:', error);
return createErrorResponse('INTERNAL_ERROR', 'Failed to update dashboard layout', 500);
}
});