Onboarding: - Keep the current step in ?step= so the device back gesture moves one step back; effectiveStep guards skipping the plan and re-opening the group form after the group exists. Show Back on mobile. - Format prices with the chosen country's currency (form prefix and confirmation). - Welcome describes the real flow and previews the WhatsApp payment reminder; the last step shares the group's invite link instead of listing settings chores. - Accessibility: named stepper steps with aria-current, focus moves to the new step heading, alerts on errors, reduced-motion and direction-aware step animation, 48px primary actions. - Group form split into "classes" and "billing", due day hidden for per-class billing; Stripe skips the empty Pro confirmation; Free features read "in Pro" instead of struck through. Home: - Payments section follows the plan: Free gets a locked preview with an upgrade link and is never asked to link Mercado Pago. - Secondary text meets 4.5:1 contrast; accent-fg for links in dark. - Class times use a 24h clock in Spanish and Portuguese. - Drop the summary tiles; one hero for the current or next class, the rest of the day as compact rows; two columns on desktop. - "Para atender" reads the shared ['attention'] query, so resolved alerts match "Requiere atención", with WhatsApp shortcuts and a link to the full list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
123 lines
4.3 KiB
TypeScript
123 lines
4.3 KiB
TypeScript
import { ArrowLeft, ArrowRight, BadgeCheck, CheckCircle2, Loader2 } from 'lucide-react'
|
|
import { Badge, Button } from '../../components/ui'
|
|
import type { MpCallbackFeedback } from '../mp'
|
|
import {
|
|
formatMpConnectionDate,
|
|
mpCallbackErrorMessage,
|
|
mpStatusBadgeVariant,
|
|
mpStatusLabel,
|
|
useMpStatus,
|
|
useStartMpAuthorization,
|
|
} from '../mp'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
type PaymentStepProps = {
|
|
/** Resultado de la vinculación, leído de `?mp=` al volver de Mercado Pago. */
|
|
feedback: MpCallbackFeedback | null
|
|
onNext: () => void
|
|
onBack: () => void
|
|
}
|
|
|
|
/**
|
|
* Paso "Cobros" del onboarding.
|
|
*
|
|
* Es salteable a propósito: el profesor puede crear su grupo y empezar a usar
|
|
* Gruperly sin vincular Mercado Pago, y hacerlo después desde Ajustes. Por eso no
|
|
* es un radiogroup con proveedores sino una sola acción: vincular la cuenta.
|
|
*/
|
|
export function PaymentStep({ feedback, onNext, onBack }: PaymentStepProps) {
|
|
const statusQuery = useMpStatus()
|
|
const { t } = useTranslation(['onboarding', 'common', 'groups'])
|
|
const startAuthorization = useStartMpAuthorization()
|
|
|
|
const status = statusQuery.data?.status ?? 'none'
|
|
const isConnected = status === 'active'
|
|
const connectedAt = formatMpConnectionDate(statusQuery.data?.connectedAt ?? null)
|
|
|
|
return (
|
|
<section className="space-y-5">
|
|
<header className="space-y-1">
|
|
<h2 className="text-2xl font-bold text-primary">{t('payment.title')}</h2>
|
|
<p className="text-sm text-foreground/60">
|
|
{t('payment.description')}
|
|
</p>
|
|
</header>
|
|
|
|
{feedback?.kind === 'success' ? (
|
|
<p className="flex items-start gap-2 rounded-xl bg-success-soft px-4 py-3 text-sm text-success">
|
|
<CheckCircle2 className="mt-0.5 size-4 shrink-0" />
|
|
{t('payment.linked')}
|
|
</p>
|
|
) : null}
|
|
|
|
{feedback?.kind === 'error' ? (
|
|
<p role="alert" className="rounded-xl bg-danger-soft px-4 py-3 text-sm text-danger">
|
|
{mpCallbackErrorMessage(feedback.reason)}
|
|
</p>
|
|
) : null}
|
|
|
|
<div className="divide-y divide-border rounded-xl border border-border bg-surface">
|
|
<div className="flex items-center justify-between gap-3 px-4 py-3">
|
|
<p className="text-sm font-medium text-primary">Mercado Pago</p>
|
|
<Badge variant={mpStatusBadgeVariant(status)}>{mpStatusLabel(status)}</Badge>
|
|
</div>
|
|
|
|
<div className="px-4 py-3">
|
|
{statusQuery.isPending ? (
|
|
<p className="flex items-center gap-2 text-sm text-foreground/50">
|
|
<Loader2 className="size-4 animate-spin" />
|
|
{t('payment.loading')}
|
|
</p>
|
|
) : isConnected ? (
|
|
<p className="text-sm text-foreground/60">
|
|
{connectedAt ? `${t('payment.linkedOn', { date: connectedAt })} ` : ''}
|
|
{t('payment.connectedHint')}
|
|
</p>
|
|
) : (
|
|
<p className="text-sm text-foreground/60">
|
|
{t('payment.connectHint')}
|
|
</p>
|
|
)}
|
|
</div>
|
|
|
|
<div className="px-4 py-3">
|
|
<Button
|
|
variant={isConnected ? 'outline' : 'primary'}
|
|
size="lg"
|
|
className="w-full"
|
|
disabled={startAuthorization.isStarting}
|
|
onClick={() => void startAuthorization.start('onboarding')}
|
|
>
|
|
{startAuthorization.isStarting ? (
|
|
<Loader2 className="size-4 animate-spin" />
|
|
) : (
|
|
<BadgeCheck className="size-4" />
|
|
)}
|
|
{startAuthorization.isStarting
|
|
? t('payment.opening')
|
|
: isConnected
|
|
? t('payment.change')
|
|
: t('payment.connect')}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
{startAuthorization.error ? (
|
|
<p role="alert" className="rounded-xl bg-danger-soft px-4 py-3 text-sm text-danger">
|
|
{startAuthorization.error}
|
|
</p>
|
|
) : null}
|
|
|
|
<div className="flex items-center gap-3">
|
|
<Button variant="outline" size="lg" onClick={onBack}>
|
|
<ArrowLeft className="size-4" />
|
|
{t('common:actions.back')}
|
|
</Button>
|
|
<Button variant={isConnected ? 'primary' : 'outline'} size="lg" className="flex-1" onClick={onNext}>
|
|
{isConnected ? t('continue') : t('later')}
|
|
<ArrowRight className="size-4" />
|
|
</Button>
|
|
</div>
|
|
</section>
|
|
)
|
|
} |