- Implemented MpReauthNotice component to notify users when reauthorization is needed. - Created MpStatusCard component to display the current status of the Mercado Pago account. - Added utility functions and constants for handling Mercado Pago status and messages. - Introduced hooks for managing the connection and disconnection of Mercado Pago accounts. - Developed a disconnect confirmation modal for user actions. - Added tests for the new functionality and utility functions. - Defined schemas for Mercado Pago account status and callback reasons in shared package.
99 lines
3.1 KiB
TypeScript
99 lines
3.1 KiB
TypeScript
import { useNavigate } from '@tanstack/react-router'
|
|
import { Loader2 } from 'lucide-react'
|
|
import { useEffect } from 'react'
|
|
import { Logo, LogoIcon } from '../../components/brand'
|
|
import { Button } from '../../components/ui'
|
|
import { useAuth } from '../../context/AuthProvider'
|
|
import { ConfirmationStep } from './ConfirmationStep'
|
|
import { FirstGroupStep } from './FirstGroupStep'
|
|
import { useOnboarding } from './OnboardingProvider'
|
|
import { PaymentStep } from './PaymentStep'
|
|
import { Stepper } from './Stepper'
|
|
import { WelcomeStep } from './WelcomeStep'
|
|
|
|
const STEPS = [
|
|
{ label: 'Bienvenida' },
|
|
{ label: 'Cobros' },
|
|
{ label: 'Tu grupo' },
|
|
{ label: 'Listo' },
|
|
]
|
|
|
|
export function OnboardingView() {
|
|
const { user, isPending: authPending } = useAuth()
|
|
const navigate = useNavigate()
|
|
const { step, setStep, mpFeedback, createdGroup, setCreatedGroup, statusQuery } = useOnboarding()
|
|
|
|
useEffect(() => {
|
|
if (statusQuery.data?.completed) {
|
|
void navigate({ to: '/' })
|
|
}
|
|
}, [statusQuery.data, navigate])
|
|
|
|
if (authPending) {
|
|
return (
|
|
<div className="flex min-h-dvh items-center justify-center">
|
|
<Loader2 className="size-6 animate-spin text-foreground/40" />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (!user) {
|
|
return (
|
|
<div className="flex min-h-dvh items-center justify-center px-4">
|
|
<div className="w-full max-w-sm space-y-4 text-center">
|
|
<span className="mx-auto flex size-14 items-center justify-center rounded-2xl bg-accent-soft">
|
|
<LogoIcon className="size-8" />
|
|
</span>
|
|
<h1 className="text-2xl font-bold text-primary">Tu cuenta, lista</h1>
|
|
<p className="text-sm text-foreground/60">
|
|
Iniciá sesión para configurar tus cobros y crear tu primer grupo.
|
|
</p>
|
|
<Button
|
|
variant="primary"
|
|
className="w-full"
|
|
onClick={() => void navigate({ to: '/login' })}
|
|
>
|
|
Iniciar sesión
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (statusQuery.isPending) {
|
|
return (
|
|
<div className="flex min-h-dvh items-center justify-center">
|
|
<Loader2 className="size-6 animate-spin text-foreground/40" />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
const firstName = user.name?.trim().split(/\s+/)[0] ?? 'profesor/a'
|
|
|
|
return (
|
|
<main className="mx-auto flex min-h-dvh w-full max-w-md flex-col px-4 pb-12 pt-8 sm:pt-12">
|
|
<header className="mb-6 flex items-center justify-center">
|
|
<Logo className="h-6" />
|
|
</header>
|
|
|
|
<Stepper steps={STEPS} current={step} />
|
|
|
|
<div key={step} className="mt-8 animate-step-enter">
|
|
{step === 0 ? <WelcomeStep name={firstName} onNext={() => setStep(1)} /> : null}
|
|
{step === 1 ? (
|
|
<PaymentStep feedback={mpFeedback} onNext={() => setStep(2)} onBack={() => setStep(0)} />
|
|
) : null}
|
|
{step === 2 ? (
|
|
<FirstGroupStep
|
|
onBack={() => setStep(1)}
|
|
onCompleted={(group) => {
|
|
setCreatedGroup(group)
|
|
setStep(3)
|
|
}}
|
|
/>
|
|
) : null}
|
|
{step === 3 && createdGroup ? <ConfirmationStep group={createdGroup} /> : null}
|
|
</div>
|
|
</main>
|
|
)
|
|
} |