feat(07-02): register /setup route and add first-run redirect
- /setup route as protected standalone page (outside AppLayout) - DashboardPage redirects first-run users to /setup via useFirstRunState - All hooks called before conditional returns (React rules of hooks)
This commit is contained in:
@@ -3,6 +3,7 @@ import { useAuth } from "@/hooks/useAuth"
|
||||
import AppLayout from "@/components/AppLayout"
|
||||
import LoginPage from "@/pages/LoginPage"
|
||||
import RegisterPage from "@/pages/RegisterPage"
|
||||
import SetupPage from "@/pages/SetupPage"
|
||||
import DashboardPage from "@/pages/DashboardPage"
|
||||
import CategoriesPage from "@/pages/CategoriesPage"
|
||||
import TemplatePage from "@/pages/TemplatePage"
|
||||
@@ -44,6 +45,14 @@ export default function App() {
|
||||
</PublicRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/setup"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<SetupPage />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { useState, useMemo } from "react"
|
||||
import { Navigate } from "react-router-dom"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useFirstRunState } from "@/hooks/useFirstRunState"
|
||||
import { useBudgets, useBudgetDetail } from "@/hooks/useBudgets"
|
||||
import { useMonthParam } from "@/hooks/useMonthParam"
|
||||
import type { CategoryType } from "@/lib/types"
|
||||
@@ -271,6 +273,7 @@ function DashboardContent({ budgetId }: { budgetId: string }) {
|
||||
|
||||
export default function DashboardPage() {
|
||||
const { t } = useTranslation()
|
||||
const { isFirstRun, loading: firstRunLoading } = useFirstRunState()
|
||||
const { month } = useMonthParam()
|
||||
const { budgets, loading, createBudget, generateFromTemplate } = useBudgets()
|
||||
|
||||
@@ -286,6 +289,9 @@ export default function DashboardPage() {
|
||||
|
||||
const [parsedYear, parsedMonth] = month.split("-").map(Number)
|
||||
|
||||
if (firstRunLoading) return <DashboardSkeleton />
|
||||
if (isFirstRun) return <Navigate to="/setup" replace />
|
||||
|
||||
return (
|
||||
<PageShell
|
||||
title={t("dashboard.title")}
|
||||
|
||||
Reference in New Issue
Block a user