feat(07-01): create wizard UI components and SetupPage
- WizardStepper: horizontal 1-2-3 stepper with clickable completed steps - IncomeStep: number input with currency suffix and validation - AllocationBar: sticky remaining balance with live polite announcements - CategoryGroupHeader: colored dot section divider per category type - PresetItemRow: checkbox + name + badge + editable amount input - RecurringItemsStep: groups 19 PRESETS by type with allocation calculation - SetupPage: page orchestrator with step navigation and state persistence
This commit is contained in:
179
src/pages/SetupPage.tsx
Normal file
179
src/pages/SetupPage.tsx
Normal file
@@ -0,0 +1,179 @@
|
||||
import { useState } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useAuth } from "@/hooks/useAuth"
|
||||
import { useWizardState } from "@/hooks/useWizardState"
|
||||
import { supabase } from "@/lib/supabase"
|
||||
import type { Profile } from "@/lib/types"
|
||||
import { WizardStepper } from "@/components/setup/WizardStepper"
|
||||
import { IncomeStep } from "@/components/setup/IncomeStep"
|
||||
import { RecurringItemsStep } from "@/components/setup/RecurringItemsStep"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
import { useEffect } from "react"
|
||||
|
||||
export default function SetupPage() {
|
||||
const { t } = useTranslation()
|
||||
const { user, loading: authLoading } = useAuth()
|
||||
const [profile, setProfile] = useState<Profile | null>(null)
|
||||
const [profileLoading, setProfileLoading] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
if (!user) return
|
||||
supabase
|
||||
.from("profiles")
|
||||
.select("*")
|
||||
.eq("id", user.id)
|
||||
.single()
|
||||
.then(({ data }) => {
|
||||
if (data) setProfile(data)
|
||||
setProfileLoading(false)
|
||||
})
|
||||
}, [user])
|
||||
|
||||
const userId = user?.id ?? ""
|
||||
const currency = profile?.currency ?? "EUR"
|
||||
const { state, setStep, setIncome, toggleItem, setItemAmount } =
|
||||
useWizardState(userId)
|
||||
|
||||
const [incomeError, setIncomeError] = useState<string | null>(null)
|
||||
|
||||
const loading = authLoading || profileLoading
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-background p-4">
|
||||
<div className="w-full max-w-2xl">
|
||||
<Skeleton className="h-12 w-64 mx-auto mb-6" />
|
||||
<Skeleton className="h-64 w-full" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const stepTitles: Record<1 | 2 | 3, string> = {
|
||||
1: t("setup.step1.title"),
|
||||
2: t("setup.step2.title"),
|
||||
3: t("setup.step3.title"),
|
||||
}
|
||||
|
||||
const stepDescriptions: Record<1 | 2 | 3, string> = {
|
||||
1: t("setup.step1.description"),
|
||||
2: t("setup.step2.description"),
|
||||
3: t("setup.step3.description"),
|
||||
}
|
||||
|
||||
function handleNext() {
|
||||
if (state.currentStep === 1) {
|
||||
if (!state.income || state.income <= 0) {
|
||||
setIncomeError(t("setup.step1.validation"))
|
||||
return
|
||||
}
|
||||
setIncomeError(null)
|
||||
setStep(2)
|
||||
} else if (state.currentStep === 2) {
|
||||
setStep(3)
|
||||
}
|
||||
}
|
||||
|
||||
function handleBack() {
|
||||
if (state.currentStep === 2) setStep(1)
|
||||
else if (state.currentStep === 3) setStep(2)
|
||||
}
|
||||
|
||||
function handleSkipStep() {
|
||||
if (state.currentStep === 1) setStep(2)
|
||||
else if (state.currentStep === 2) setStep(3)
|
||||
}
|
||||
|
||||
function handleStepClick(step: 1 | 2 | 3) {
|
||||
if (step <= state.currentStep) {
|
||||
setStep(step)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-background p-4">
|
||||
<div className="w-full max-w-2xl">
|
||||
<WizardStepper currentStep={state.currentStep} onStepClick={handleStepClick} />
|
||||
|
||||
<Card className="w-full border border-border shadow-sm">
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-xl font-semibold">
|
||||
{stepTitles[state.currentStep]}
|
||||
</CardTitle>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{stepDescriptions[state.currentStep]}
|
||||
</p>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
{state.currentStep === 1 && (
|
||||
<IncomeStep
|
||||
income={state.income}
|
||||
onIncomeChange={setIncome}
|
||||
currency={currency}
|
||||
error={incomeError}
|
||||
/>
|
||||
)}
|
||||
|
||||
{state.currentStep === 2 && (
|
||||
<RecurringItemsStep
|
||||
selectedItems={state.selectedItems}
|
||||
income={state.income}
|
||||
currency={currency}
|
||||
onToggle={toggleItem}
|
||||
onAmountChange={setItemAmount}
|
||||
/>
|
||||
)}
|
||||
|
||||
{state.currentStep === 3 && (
|
||||
<div className="py-8 text-center text-muted-foreground">
|
||||
<p>Review step coming in next plan</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Bottom navigation */}
|
||||
<div className="flex justify-between items-center pt-4 border-t border-border">
|
||||
<div className="flex gap-2">
|
||||
{state.currentStep > 1 && (
|
||||
<Button variant="ghost" onClick={handleBack}>
|
||||
{t("setup.back")}
|
||||
</Button>
|
||||
)}
|
||||
{state.currentStep < 3 && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="text-muted-foreground"
|
||||
onClick={handleSkipStep}
|
||||
>
|
||||
{t("setup.skip")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
{state.currentStep < 3 && (
|
||||
<Button onClick={handleNext}>{t("setup.next")}</Button>
|
||||
)}
|
||||
{state.currentStep === 3 && (
|
||||
<Button disabled>{t("setup.complete")}</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
className="mt-4 text-sm text-muted-foreground underline block mx-auto"
|
||||
>
|
||||
{t("setup.skipSetup")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user