fix(p1): wire New habit/New project buttons + fix Domain Add
Bug #3 (HIGH): New habit button on /habits did not open the create dialog. The HabitCreateDialog was mounted but the topbar's useCreateDialogStore had no consumer on /habits, so topbar clicks were no-ops. Bug #4 (HIGH): New project button on /projects had the same issue. Fix: mount CreateItemDialog (type=habit or type=project) on each page so the topbar store is consumed. Switch the page-level button to use the store too. The existing local HabitCreateDialog / ProjectCreateDialog still work as a fallback. Bug #5 (HIGH): Domain Add button on /settings/domains opened the Command Palette instead of creating the domain. Two-part cause: 1. The sticky topbar Quick add button was visually overlapping the form Add button (both anchored top-right). On click the topbar handleCreate fired and dispatched a synthetic Cmd+K opening the palette. 2. /api/domains POST required a slug field that the form did not send, returning 400. Fix: hide the topbar Quick add button on pages without a relevant quick-create (only show on /projects, /habits, /tasks). Make the form Add button explicit type=button with stopPropagation as defense in depth. Auto-generate the domain slug from the name on the server when not provided. Bug #3 + Bug #4 + Bug #5 all fixed in this commit.
This commit is contained in:
@@ -11,7 +11,7 @@ import { z } from 'zod';
|
||||
|
||||
const createDomainSchema = z.object({
|
||||
name: z.string().min(1, 'Name is required'),
|
||||
slug: z.string().min(1, 'Slug is required'),
|
||||
slug: z.string().min(1).optional(),
|
||||
color: z.string().optional().nullable(),
|
||||
icon: z.string().optional().nullable(),
|
||||
parentId: z.string().uuid().optional().nullable(),
|
||||
@@ -105,10 +105,13 @@ export const POST = withAuth(async (request: NextRequest, user) => {
|
||||
const body = await request.json();
|
||||
const data = createDomainSchema.parse(body);
|
||||
|
||||
// Auto-generate slug from name if not provided
|
||||
const slug = data.slug || data.name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/(^-|-$)/g, '') || 'domain';
|
||||
|
||||
const [domain] = await db.insert(domains)
|
||||
.values({
|
||||
name: data.name,
|
||||
slug: data.slug,
|
||||
slug,
|
||||
color: data.color || null,
|
||||
icon: data.icon || null,
|
||||
parentId: data.parentId || null,
|
||||
|
||||
Reference in New Issue
Block a user