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,
|
||||
|
||||
@@ -203,7 +203,7 @@ export function SettingsDomains() {
|
||||
</div>
|
||||
|
||||
{/* Add new domain */}
|
||||
<div className="flex gap-2">
|
||||
<div className="relative z-50 flex gap-2">
|
||||
<label htmlFor="new-domain-name" className="sr-only">
|
||||
New domain name
|
||||
</label>
|
||||
@@ -226,7 +226,7 @@ export function SettingsDomains() {
|
||||
disabled={creating}
|
||||
/>
|
||||
</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" />
|
||||
{creating ? 'Adding...' : 'Add'}
|
||||
</Button>
|
||||
|
||||
@@ -17,9 +17,11 @@ export function TopBar() {
|
||||
if (pathname.startsWith('/projects')) openCreate('project');
|
||||
else if (pathname.startsWith('/habits')) openCreate('habit');
|
||||
else if (pathname.startsWith('/tasks')) openCreate('task');
|
||||
else {
|
||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'k', metaKey: true }));
|
||||
}
|
||||
// On other pages (e.g. /settings) the topbar's "Quick add" button
|
||||
// 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'
|
||||
@@ -39,10 +41,14 @@ export function TopBar() {
|
||||
</Button>
|
||||
</div>
|
||||
<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()}`}>
|
||||
<Plus className="mr-1 h-4 w-4" aria-hidden="true" />
|
||||
{label}
|
||||
</Button>
|
||||
{(pathname.startsWith('/projects') ||
|
||||
pathname.startsWith('/habits') ||
|
||||
pathname.startsWith('/tasks')) && (
|
||||
<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 />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
Reference in New Issue
Block a user