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({
|
const createDomainSchema = z.object({
|
||||||
name: z.string().min(1, 'Name is required'),
|
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(),
|
color: z.string().optional().nullable(),
|
||||||
icon: z.string().optional().nullable(),
|
icon: z.string().optional().nullable(),
|
||||||
parentId: z.string().uuid().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 body = await request.json();
|
||||||
const data = createDomainSchema.parse(body);
|
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)
|
const [domain] = await db.insert(domains)
|
||||||
.values({
|
.values({
|
||||||
name: data.name,
|
name: data.name,
|
||||||
slug: data.slug,
|
slug,
|
||||||
color: data.color || null,
|
color: data.color || null,
|
||||||
icon: data.icon || null,
|
icon: data.icon || null,
|
||||||
parentId: data.parentId || null,
|
parentId: data.parentId || null,
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ export function SettingsDomains() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Add new domain */}
|
{/* Add new domain */}
|
||||||
<div className="flex gap-2">
|
<div className="relative z-50 flex gap-2">
|
||||||
<label htmlFor="new-domain-name" className="sr-only">
|
<label htmlFor="new-domain-name" className="sr-only">
|
||||||
New domain name
|
New domain name
|
||||||
</label>
|
</label>
|
||||||
@@ -226,7 +226,7 @@ export function SettingsDomains() {
|
|||||||
disabled={creating}
|
disabled={creating}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Button onClick={addDomain} disabled={creating || !newDomainName.trim()}>
|
<Button type="button" onClick={(e) => { e.stopPropagation(); addDomain(); }} disabled={creating || !newDomainName.trim()}>
|
||||||
<Plus className="mr-1 h-4 w-4" />
|
<Plus className="mr-1 h-4 w-4" />
|
||||||
{creating ? 'Adding...' : 'Add'}
|
{creating ? 'Adding...' : 'Add'}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -17,9 +17,11 @@ export function TopBar() {
|
|||||||
if (pathname.startsWith('/projects')) openCreate('project');
|
if (pathname.startsWith('/projects')) openCreate('project');
|
||||||
else if (pathname.startsWith('/habits')) openCreate('habit');
|
else if (pathname.startsWith('/habits')) openCreate('habit');
|
||||||
else if (pathname.startsWith('/tasks')) openCreate('task');
|
else if (pathname.startsWith('/tasks')) openCreate('task');
|
||||||
else {
|
// On other pages (e.g. /settings) the topbar's "Quick add" button
|
||||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'k', metaKey: true }));
|
// visually overlaps form action buttons (e.g. Domain "Add") because
|
||||||
}
|
// both are anchored top-right. Dispatching Cmd+K here would cause
|
||||||
|
// those form clicks to be mis-interpreted as opening the palette.
|
||||||
|
// So we no-op on those pages — the form buttons handle their own actions.
|
||||||
}
|
}
|
||||||
|
|
||||||
const label = pathname.startsWith('/projects') ? 'New project'
|
const label = pathname.startsWith('/projects') ? 'New project'
|
||||||
@@ -39,10 +41,14 @@ export function TopBar() {
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-auto flex items-center gap-2">
|
<div className="ml-auto flex items-center gap-2">
|
||||||
<Button variant="outline" size="sm" onClick={handleCreate} aria-label={label === 'Quick add' ? 'Quick add' : `Create ${label.toLowerCase()}`}>
|
{(pathname.startsWith('/projects') ||
|
||||||
<Plus className="mr-1 h-4 w-4" aria-hidden="true" />
|
pathname.startsWith('/habits') ||
|
||||||
{label}
|
pathname.startsWith('/tasks')) && (
|
||||||
</Button>
|
<Button variant="outline" size="sm" onClick={handleCreate} aria-label={label === 'Quick add' ? 'Quick add' : `Create ${label.toLowerCase()}`}>
|
||||||
|
<Plus className="mr-1 h-4 w-4" aria-hidden="true" />
|
||||||
|
{label}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
<NotificationBell />
|
<NotificationBell />
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
Reference in New Issue
Block a user