fix(p1): wire New habit + New project buttons to useCreateDialogStore
The HabitCreateDialog and ProjectCreateDialog were mounted with local state but the topbar uses useCreateDialogStore, and the store had no consumer on /habits or /projects. So topbar clicks did nothing, and the page-level button may have been dead too due to a stale build. Mount <CreateItemDialog> in both pages so: - The topbar New habit / New project button opens the dialog - The page-level buttons open the same dialog via the store - A single CreateItemDialog handles task/project/habit creation Bug #3 (New habit) + Bug #4 (New project) are fixed by this commit.
This commit is contained in:
@@ -25,6 +25,8 @@ import { HabitEditDialog } from "@/components/habits/habit-edit-dialog";
|
|||||||
import { HabitCompletionDialog } from "@/components/habits/habit-completion-dialog";
|
import { HabitCompletionDialog } from "@/components/habits/habit-completion-dialog";
|
||||||
import { HabitCalendarHeatmap } from "@/components/habits/habit-calendar-heatmap";
|
import { HabitCalendarHeatmap } from "@/components/habits/habit-calendar-heatmap";
|
||||||
import { HabitAnalytics } from "@/components/habits/habit-analytics";
|
import { HabitAnalytics } from "@/components/habits/habit-analytics";
|
||||||
|
import { CreateItemDialog } from "@/components/create-item-dialog";
|
||||||
|
import { useCreateDialogStore } from "@/lib/stores/use-create-dialog-store";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
||||||
interface Habit {
|
interface Habit {
|
||||||
@@ -54,6 +56,7 @@ export default function HabitsPage() {
|
|||||||
const [domainId, setDomainId] = useState<string | null>(null);
|
const [domainId, setDomainId] = useState<string | null>(null);
|
||||||
const [domains, setDomains] = useState<{ id: string; name: string }[]>([]);
|
const [domains, setDomains] = useState<{ id: string; name: string }[]>([]);
|
||||||
const [createOpen, setCreateOpen] = useState(false);
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
|
const { open: storeOpen, openCreate, closeCreate } = useCreateDialogStore();
|
||||||
const [editHabit, setEditHabit] = useState<Habit | null>(null);
|
const [editHabit, setEditHabit] = useState<Habit | null>(null);
|
||||||
const [completionHabit, setCompletionHabit] = useState<Habit | null>(null);
|
const [completionHabit, setCompletionHabit] = useState<Habit | null>(null);
|
||||||
const [deleteHabit, setDeleteHabit] = useState<Habit | null>(null);
|
const [deleteHabit, setDeleteHabit] = useState<Habit | null>(null);
|
||||||
@@ -154,7 +157,7 @@ export default function HabitsPage() {
|
|||||||
Active
|
Active
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<Button onClick={() => setCreateOpen(true)}>
|
<Button onClick={() => { setCreateOpen(true); openCreate('habit'); }}>
|
||||||
<Plus className="mr-2 h-4 w-4" aria-hidden="true" />
|
<Plus className="mr-2 h-4 w-4" aria-hidden="true" />
|
||||||
New habit
|
New habit
|
||||||
</Button>
|
</Button>
|
||||||
@@ -255,11 +258,19 @@ export default function HabitsPage() {
|
|||||||
|
|
||||||
<HabitCreateDialog
|
<HabitCreateDialog
|
||||||
open={createOpen}
|
open={createOpen}
|
||||||
onOpenChange={setCreateOpen}
|
onOpenChange={(o) => { setCreateOpen(o); if (!o) closeCreate(); }}
|
||||||
domainId={domainId || ''}
|
domainId={domainId || ''}
|
||||||
onCreated={fetchHabits}
|
onCreated={fetchHabits}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* Global CreateItemDialog from useCreateDialogStore — opened by topbar 'New habit' button */}
|
||||||
|
<CreateItemDialog
|
||||||
|
type="habit"
|
||||||
|
open={storeOpen}
|
||||||
|
onOpenChange={(o) => { if (!o) closeCreate(); else openCreate('habit'); }}
|
||||||
|
onCreated={fetchHabits}
|
||||||
|
/>
|
||||||
|
|
||||||
{editHabit && (
|
{editHabit && (
|
||||||
<HabitEditDialog
|
<HabitEditDialog
|
||||||
open={!!editHabit}
|
open={!!editHabit}
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import {
|
|||||||
} from "@/components/ui/alert-dialog";
|
} from "@/components/ui/alert-dialog";
|
||||||
import { ProjectCreateDialog } from "@/components/projects/project-create-dialog";
|
import { ProjectCreateDialog } from "@/components/projects/project-create-dialog";
|
||||||
import { ProjectEditDialog } from "@/components/projects/project-edit-dialog";
|
import { ProjectEditDialog } from "@/components/projects/project-edit-dialog";
|
||||||
|
import { CreateItemDialog } from "@/components/create-item-dialog";
|
||||||
|
import { useCreateDialogStore } from "@/lib/stores/use-create-dialog-store";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
||||||
@@ -54,6 +56,7 @@ export default function ProjectsPage() {
|
|||||||
const [domainId, setDomainId] = useState<string | null>(null);
|
const [domainId, setDomainId] = useState<string | null>(null);
|
||||||
const [domains, setDomains] = useState<{ id: string; name: string }[]>([]);
|
const [domains, setDomains] = useState<{ id: string; name: string }[]>([]);
|
||||||
const [createOpen, setCreateOpen] = useState(false);
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
|
const { open: storeOpen, openCreate, closeCreate } = useCreateDialogStore();
|
||||||
const [editProject, setEditProject] = useState<Project | null>(null);
|
const [editProject, setEditProject] = useState<Project | null>(null);
|
||||||
const [archiveProject, setArchiveProject] = useState<Project | null>(null);
|
const [archiveProject, setArchiveProject] = useState<Project | null>(null);
|
||||||
const [archiving, setArchiving] = useState(false);
|
const [archiving, setArchiving] = useState(false);
|
||||||
@@ -119,7 +122,7 @@ export default function ProjectsPage() {
|
|||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
)}
|
)}
|
||||||
<Button onClick={() => setCreateOpen(true)}>
|
<Button onClick={() => { setCreateOpen(true); openCreate('project'); }}>
|
||||||
<Plus className="mr-2 h-4 w-4" aria-hidden="true" />
|
<Plus className="mr-2 h-4 w-4" aria-hidden="true" />
|
||||||
New project
|
New project
|
||||||
</Button>
|
</Button>
|
||||||
@@ -220,11 +223,19 @@ export default function ProjectsPage() {
|
|||||||
|
|
||||||
<ProjectCreateDialog
|
<ProjectCreateDialog
|
||||||
open={createOpen}
|
open={createOpen}
|
||||||
onOpenChange={setCreateOpen}
|
onOpenChange={(o) => { setCreateOpen(o); if (!o) closeCreate(); }}
|
||||||
domainId={domainId || ''}
|
domainId={domainId || ''}
|
||||||
onCreated={fetchProjects}
|
onCreated={fetchProjects}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* Global CreateItemDialog from useCreateDialogStore — opened by topbar 'New project' button */}
|
||||||
|
<CreateItemDialog
|
||||||
|
type="project"
|
||||||
|
open={storeOpen}
|
||||||
|
onOpenChange={(o) => { if (!o) closeCreate(); else openCreate('project'); }}
|
||||||
|
onCreated={fetchProjects}
|
||||||
|
/>
|
||||||
|
|
||||||
{editProject && (
|
{editProject && (
|
||||||
<ProjectEditDialog
|
<ProjectEditDialog
|
||||||
open={!!editProject}
|
open={!!editProject}
|
||||||
|
|||||||
Reference in New Issue
Block a user