feat(i18n): traducir el plan (billing)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,8 +4,10 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { useNavigate, useSearch } from '@tanstack/react-router'
|
||||
import type { ReactNode } from 'react'
|
||||
import { createContext, useContext, useEffect, useRef, useState } from 'react'
|
||||
import { errorMessage } from '../../i18n'
|
||||
import { i18n } from '../../i18n/instance'
|
||||
import { useToast } from '../../components/ui'
|
||||
import { ApiError, cancelSubscription, getBillingCharges } from '../../lib/api'
|
||||
import { cancelSubscription, getBillingCharges } from '../../lib/api'
|
||||
import { billingStatusQueryKey, useBillingStatus } from './useBillingStatus'
|
||||
import { useSubscriptionReturnPolling } from './useSubscriptionReturnPolling'
|
||||
|
||||
@@ -54,7 +56,7 @@ export function BillingProvider({ children }: { children: ReactNode }) {
|
||||
if (!polling.isPolling || announced.current) return
|
||||
if (statusQuery.data?.status === 'AUTHORIZED') {
|
||||
announced.current = true
|
||||
toast.success('¡Listo! Ya tenés Gruperly Pro.')
|
||||
toast.success(i18n.t('billing:cancel.welcome'))
|
||||
void queryClient.invalidateQueries({ queryKey: ['billing', 'charges'] })
|
||||
}
|
||||
// `toast` cambia en cada aviso: el efecto depende solo del estado.
|
||||
@@ -63,11 +65,11 @@ export function BillingProvider({ children }: { children: ReactNode }) {
|
||||
const cancelMutation = useMutation({
|
||||
mutationFn: cancelSubscription,
|
||||
onSuccess: () => {
|
||||
toast.success('Cancelaste tu suscripción. Seguís con Pro hasta el fin del período pago.')
|
||||
toast.success(i18n.t('billing:cancel.done'))
|
||||
void queryClient.invalidateQueries({ queryKey: billingStatusQueryKey })
|
||||
},
|
||||
onError: (error: Error) => {
|
||||
toast.error(error instanceof ApiError ? error.message : 'No pudimos cancelar la suscripción.')
|
||||
toast.error(errorMessage(error, i18n.t('billing:cancel.error')))
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -10,15 +10,19 @@ import { ChargesList } from './ChargesList'
|
||||
import { PlanOptionCard } from './PlanOptionCard'
|
||||
import { PlanSummaryCard } from './PlanSummaryCard'
|
||||
import { SubscribeModal } from './SubscribeModal'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
export function BillingView() {
|
||||
const { statusQuery, openSubscribe, cancel, isCancelling } = useBilling()
|
||||
const [isConfirmingCancel, setIsConfirmingCancel] = useState(false)
|
||||
const { t } = useTranslation(['billing', 'common'])
|
||||
const status = statusQuery.data
|
||||
|
||||
const subscribed = status?.status === 'AUTHORIZED' || status?.status === 'PAUSED'
|
||||
const pending = status?.status === 'PENDING'
|
||||
const proPrice = status ? `${formatPrice(status.priceAmount, status.currency)} / mes` : undefined
|
||||
const proPrice = status
|
||||
? t('view.perMonth', { price: formatPrice(status.priceAmount, status.currency) })
|
||||
: undefined
|
||||
|
||||
return (
|
||||
<section className="space-y-6">
|
||||
@@ -28,10 +32,10 @@ export function BillingView() {
|
||||
className="mb-2 hidden items-center gap-1 text-sm text-foreground/60 hover:text-primary lg:inline-flex"
|
||||
>
|
||||
<ChevronLeft className="size-4" />
|
||||
Ajustes
|
||||
{t('view.back')}
|
||||
</Link>
|
||||
<h1 className="text-2xl font-bold text-primary">Tu plan</h1>
|
||||
<p className="mt-1 text-sm text-foreground/60">Elegí cómo usar Gruperly.</p>
|
||||
<h1 className="text-2xl font-bold text-primary">{t('view.title')}</h1>
|
||||
<p className="mt-1 text-sm text-foreground/60">{t('view.subtitle')}</p>
|
||||
</div>
|
||||
|
||||
<PlanSummaryCard />
|
||||
@@ -48,15 +52,15 @@ export function BillingView() {
|
||||
>
|
||||
{subscribed ? (
|
||||
<Button variant="outline" className="w-full" onClick={() => setIsConfirmingCancel(true)}>
|
||||
Cancelar suscripción
|
||||
{t('cancel.confirm')}
|
||||
</Button>
|
||||
) : status.availableInCountry ? (
|
||||
<Button variant="primary" className="w-full" onClick={openSubscribe}>
|
||||
<Sparkles className="size-4" />
|
||||
{pending ? 'Reintentar el pago' : 'Pasar a Pro'}
|
||||
{pending ? t('view.retry') : t('view.upgrade')}
|
||||
</Button>
|
||||
) : (
|
||||
<p className="text-xs text-foreground/50">Todavía no está disponible en tu país.</p>
|
||||
<p className="text-xs text-foreground/50">{t('view.unavailable')}</p>
|
||||
)}
|
||||
</PlanOptionCard>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { Button, Modal } from '../../components/ui'
|
||||
import { formatBillingDate } from './copy'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
type CancelSubscriptionModalProps = {
|
||||
isOpen: boolean
|
||||
@@ -19,25 +20,26 @@ export function CancelSubscriptionModal({
|
||||
onConfirm,
|
||||
}: CancelSubscriptionModalProps) {
|
||||
const until = formatBillingDate(paidThrough)
|
||||
const { t } = useTranslation(['billing', 'common'])
|
||||
return (
|
||||
<Modal
|
||||
isOpen={isOpen}
|
||||
onClose={onClose}
|
||||
title="Cancelar Pro"
|
||||
title={t('cancel.title')}
|
||||
description={
|
||||
until
|
||||
? `No te vamos a cobrar más. Seguís con Pro hasta el ${until}; después tu cuenta pasa a Free.`
|
||||
: 'No te vamos a cobrar más y tu cuenta pasa a Free.'
|
||||
? t('cancel.descriptionUntil', { date: until })
|
||||
: t('cancel.description')
|
||||
}
|
||||
maxWidth="sm"
|
||||
>
|
||||
<div className="flex justify-end gap-3">
|
||||
<Button variant="outline" onClick={onClose}>
|
||||
Volver
|
||||
{t('cancel.back')}
|
||||
</Button>
|
||||
<Button variant="primary" disabled={isPending} onClick={onConfirm}>
|
||||
{isPending ? <Loader2 className="size-4 animate-spin" /> : null}
|
||||
Cancelar suscripción
|
||||
{t('cancel.confirm')}
|
||||
</Button>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
@@ -2,19 +2,15 @@ import { Button } from '../../components/ui'
|
||||
import { formatPrice } from '../../lib/format'
|
||||
import { useBilling } from './BillingProvider'
|
||||
import { formatBillingDate } from './copy'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
const CHARGE_STATUS_LABELS: Record<string, string> = {
|
||||
approved: 'Pagado',
|
||||
rejected: 'Rechazado',
|
||||
pending: 'Pendiente',
|
||||
in_process: 'En proceso',
|
||||
cancelled: 'Cancelado',
|
||||
refunded: 'Devuelto',
|
||||
}
|
||||
/** Mercado Pago / Stripe statuses with copy in `billing:charges.<status>`. */
|
||||
const KNOWN_CHARGE_STATUSES = new Set(['approved', 'rejected', 'pending', 'in_process', 'cancelled', 'refunded'])
|
||||
|
||||
/** Historial de cobros de la suscripción a Pro. */
|
||||
export function ChargesList() {
|
||||
const { chargesQuery, chargesPage, setChargesPage } = useBilling()
|
||||
const { t } = useTranslation(['billing', 'common'])
|
||||
const charges = chargesQuery.data?.data ?? []
|
||||
const totalPages = chargesQuery.data?.pagination.totalPages ?? 0
|
||||
|
||||
@@ -22,7 +18,7 @@ export function ChargesList() {
|
||||
|
||||
return (
|
||||
<section className="space-y-2">
|
||||
<h2 className="text-sm font-semibold text-primary">Historial de pagos</h2>
|
||||
<h2 className="text-sm font-semibold text-primary">{t('charges.title')}</h2>
|
||||
<ul className="divide-y divide-border rounded-xl border border-border bg-surface">
|
||||
{charges.map((charge) => (
|
||||
<li key={charge.id} className="flex items-center justify-between gap-3 px-4 py-3">
|
||||
@@ -33,7 +29,7 @@ export function ChargesList() {
|
||||
</p>
|
||||
</div>
|
||||
<span className="text-xs text-foreground/60">
|
||||
{CHARGE_STATUS_LABELS[charge.status] ?? charge.status}
|
||||
{KNOWN_CHARGE_STATUSES.has(charge.status) ? t(`charges.${charge.status}` as 'charges.approved') : charge.status}
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
@@ -46,7 +42,7 @@ export function ChargesList() {
|
||||
disabled={chargesPage <= 1}
|
||||
onClick={() => setChargesPage(chargesPage - 1)}
|
||||
>
|
||||
Anteriores
|
||||
{t('charges.prev')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -54,7 +50,7 @@ export function ChargesList() {
|
||||
disabled={chargesPage >= totalPages}
|
||||
onClick={() => setChargesPage(chargesPage + 1)}
|
||||
>
|
||||
Siguientes
|
||||
{t('charges.next')}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useAuth } from '../../context/AuthProvider'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { planNoticeMessage } from './copy'
|
||||
import { useBillingStatus } from './useBillingStatus'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
/**
|
||||
* Aviso global del plan: cuenta en solo lectura o Pro en período de gracia.
|
||||
@@ -12,6 +13,7 @@ import { useBillingStatus } from './useBillingStatus'
|
||||
*/
|
||||
export function PlanNotice() {
|
||||
const { user } = useAuth()
|
||||
const { t } = useTranslation(['billing', 'common'])
|
||||
const statusQuery = useBillingStatus({ enabled: !!user })
|
||||
const pathname = useLocation({ select: (location) => location.pathname })
|
||||
|
||||
@@ -36,7 +38,7 @@ export function PlanNotice() {
|
||||
danger ? 'text-danger' : 'text-warning',
|
||||
)}
|
||||
>
|
||||
Ver plan
|
||||
{t('notice.seePlan')}
|
||||
</Link>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { ReactNode } from 'react'
|
||||
import { Badge } from '../../components/ui'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { PLAN_NAMES, planFeatureList } from './copy'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
type PlanOptionCardProps = {
|
||||
plan: Plan
|
||||
@@ -18,6 +19,7 @@ type PlanOptionCardProps = {
|
||||
|
||||
/** Una tarjeta de plan, igual en la pantalla del plan y en el onboarding. */
|
||||
export function PlanOptionCard({ plan, limits, price, current, highlighted, children }: PlanOptionCardProps) {
|
||||
const { t } = useTranslation(['billing', 'common'])
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
@@ -27,9 +29,9 @@ export function PlanOptionCard({ plan, limits, price, current, highlighted, chil
|
||||
>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<p className="text-base font-semibold text-primary">{PLAN_NAMES[plan]}</p>
|
||||
{current ? <Badge variant="info">Tu plan</Badge> : null}
|
||||
{current ? <Badge variant="info">{t('option.yourPlan')}</Badge> : null}
|
||||
</div>
|
||||
<p className="mt-1 text-sm text-foreground/60">{price ?? 'Gratis'}</p>
|
||||
<p className="mt-1 text-sm text-foreground/60">{price ?? t('option.free')}</p>
|
||||
|
||||
<ul className="mt-3 flex-1 space-y-1.5">
|
||||
{planFeatureList(limits).map((feature) => (
|
||||
|
||||
@@ -3,10 +3,12 @@ import { ChevronRight, Sparkles } from 'lucide-react'
|
||||
import { Badge } from '../../components/ui'
|
||||
import { PLAN_NAMES, planBadgeVariant } from './copy'
|
||||
import { useBillingStatus } from './useBillingStatus'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
/** Entrada a la pantalla del plan desde Ajustes. */
|
||||
export function PlanSettingsCard() {
|
||||
const statusQuery = useBillingStatus()
|
||||
const { t } = useTranslation(['billing', 'common'])
|
||||
const status = statusQuery.data
|
||||
|
||||
return (
|
||||
@@ -16,12 +18,12 @@ export function PlanSettingsCard() {
|
||||
<Sparkles className="size-4 text-accent-fg" />
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-sm font-medium text-primary">Plan</p>
|
||||
<p className="text-xs text-foreground/50">Tu plan de Gruperly y tus pagos</p>
|
||||
<p className="text-sm font-medium text-primary">{t('settings.title')}</p>
|
||||
<p className="text-xs text-foreground/50">{t('settings.description')}</p>
|
||||
</div>
|
||||
{status ? (
|
||||
<Badge variant={planBadgeVariant(status)}>
|
||||
{status.readOnly ? 'Solo lectura' : PLAN_NAMES[status.plan]}
|
||||
{status.readOnly ? t('settings.readOnly') : PLAN_NAMES[status.plan]}
|
||||
</Badge>
|
||||
) : null}
|
||||
<ChevronRight className="size-4 text-foreground/40" />
|
||||
|
||||
@@ -11,17 +11,19 @@ import {
|
||||
planNoticeMessage,
|
||||
subscriptionStatusLabel,
|
||||
} from './copy'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
/** El plan actual: estado de la suscripción, próximo cobro y uso contra los límites. */
|
||||
export function PlanSummaryCard() {
|
||||
const { statusQuery } = useBilling()
|
||||
const { t } = useTranslation(['billing', 'common'])
|
||||
const status = statusQuery.data
|
||||
|
||||
if (!status) {
|
||||
return (
|
||||
<div className="flex items-center gap-3 rounded-xl border border-border bg-surface px-4 py-3">
|
||||
<Loader2 className="size-4 animate-spin text-foreground/40" />
|
||||
<p className="text-sm text-foreground/50">Consultando tu plan…</p>
|
||||
<p className="text-sm text-foreground/50">{t('summary.loading')}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -34,27 +36,27 @@ export function PlanSummaryCard() {
|
||||
<div className="divide-y divide-border rounded-xl border border-border bg-surface">
|
||||
<div className="px-4 py-3">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<p className="text-sm font-medium text-primary">Plan {PLAN_NAMES[status.plan]}</p>
|
||||
<p className="text-sm font-medium text-primary">{t('summary.plan', { plan: PLAN_NAMES[status.plan] })}</p>
|
||||
<Badge variant={planBadgeVariant(status)}>
|
||||
{status.readOnly ? 'Solo lectura' : subscriptionStatusLabel(status.status)}
|
||||
{status.readOnly ? t('settings.readOnly') : subscriptionStatusLabel(status.status)}
|
||||
</Badge>
|
||||
</div>
|
||||
{status.status === 'AUTHORIZED' && nextPayment ? (
|
||||
<p className="mt-0.5 text-xs text-foreground/50">
|
||||
Próximo cobro: {formatPrice(status.priceAmount, status.currency)} el {nextPayment}
|
||||
{t('summary.next', { amount: formatPrice(status.priceAmount, status.currency), date: nextPayment })}
|
||||
</p>
|
||||
) : null}
|
||||
{status.status === 'PENDING' ? (
|
||||
<p className="mt-0.5 text-xs text-foreground/50">
|
||||
Estamos esperando que {BILLING_PROVIDER_NAMES[status.provider]} confirme tu suscripción.
|
||||
{t('summary.pending', { provider: BILLING_PROVIDER_NAMES[status.provider] })}
|
||||
</p>
|
||||
) : null}
|
||||
{status.status === 'CANCELLED' && status.plan === 'PRO' && paidThrough ? (
|
||||
<p className="mt-0.5 text-xs text-foreground/50">Pagado hasta el {paidThrough}.</p>
|
||||
<p className="mt-0.5 text-xs text-foreground/50">{t('summary.paidThrough', { date: paidThrough })}</p>
|
||||
) : null}
|
||||
{!status.enforced ? (
|
||||
<p className="mt-0.5 text-xs text-foreground/50">
|
||||
Por ahora todas las funciones están habilitadas para todas las cuentas.
|
||||
{t('summary.notEnforced')}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
@@ -73,13 +75,13 @@ export function PlanSummaryCard() {
|
||||
|
||||
<dl className="grid grid-cols-2 gap-3 px-4 py-3">
|
||||
<div>
|
||||
<dt className="text-xs text-foreground/50">Grupos</dt>
|
||||
<dt className="text-xs text-foreground/50">{t('summary.groups')}</dt>
|
||||
<dd className="text-sm font-medium text-primary">
|
||||
{formatUsage(status.usage.groups, status.limits.maxGroups)}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-xs text-foreground/50">Alumnos activos</dt>
|
||||
<dt className="text-xs text-foreground/50">{t('summary.students')}</dt>
|
||||
<dd className="text-sm font-medium text-primary">
|
||||
{formatUsage(status.usage.attendees, status.limits.maxAttendees)}
|
||||
</dd>
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useNavigate } from '@tanstack/react-router'
|
||||
import { Sparkles } from 'lucide-react'
|
||||
import { Button, Modal } from '../../components/ui'
|
||||
import { dismissPlanPrompt, usePlanPrompt } from './plan-prompt'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
/**
|
||||
* Aviso de "esto es de Pro". Lo dispara cualquier 402 de plan (ver el
|
||||
@@ -10,19 +11,20 @@ import { dismissPlanPrompt, usePlanPrompt } from './plan-prompt'
|
||||
*/
|
||||
export function PlanUpgradePrompt() {
|
||||
const detail = usePlanPrompt()
|
||||
const { t } = useTranslation(['billing', 'common'])
|
||||
const navigate = useNavigate()
|
||||
|
||||
return (
|
||||
<Modal
|
||||
isOpen={detail !== null}
|
||||
onClose={dismissPlanPrompt}
|
||||
title="Disponible en Pro"
|
||||
title={t('upgrade.title')}
|
||||
description={detail ?? undefined}
|
||||
maxWidth="sm"
|
||||
>
|
||||
<div className="flex justify-end gap-3">
|
||||
<Button variant="outline" onClick={dismissPlanPrompt}>
|
||||
Ahora no
|
||||
{t('upgrade.later')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
@@ -32,7 +34,7 @@ export function PlanUpgradePrompt() {
|
||||
}}
|
||||
>
|
||||
<Sparkles className="size-4" />
|
||||
Ver planes
|
||||
{t('upgrade.seePlans')}
|
||||
</Button>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Loader2 } from 'lucide-react'
|
||||
import { type FormEvent, useState } from 'react'
|
||||
import { Button, Input, Label } from '../../components/ui'
|
||||
import { BILLING_PROVIDER_NAMES } from './copy'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
type SubscribeFormProps = {
|
||||
provider: BillingProviderId
|
||||
@@ -26,11 +27,12 @@ export function SubscribeForm({
|
||||
defaultEmail,
|
||||
isPending,
|
||||
error,
|
||||
submitLabel = `Ir a ${BILLING_PROVIDER_NAMES[provider]}`,
|
||||
submitLabel,
|
||||
onSubmit,
|
||||
onCancel,
|
||||
}: SubscribeFormProps) {
|
||||
const [email, setEmail] = useState(defaultEmail)
|
||||
const { t } = useTranslation(['billing', 'common'])
|
||||
const asksEmail = provider === 'MERCADO_PAGO'
|
||||
|
||||
const handleSubmit = (event: FormEvent) => {
|
||||
@@ -42,7 +44,7 @@ export function SubscribeForm({
|
||||
<form className="space-y-4" onSubmit={handleSubmit}>
|
||||
{asksEmail ? (
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="payer-email">Email de tu cuenta de Mercado Pago</Label>
|
||||
<Label htmlFor="payer-email">{t('subscribe.payerEmail')}</Label>
|
||||
<Input
|
||||
id="payer-email"
|
||||
type="email"
|
||||
@@ -53,7 +55,7 @@ export function SubscribeForm({
|
||||
onChange={(event) => setEmail(event.target.value)}
|
||||
/>
|
||||
<p className="text-xs text-foreground/50">
|
||||
Tenés que entrar a Mercado Pago con este mismo email para autorizar el débito mensual.
|
||||
{t('subscribe.payerEmailHint')}
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
@@ -63,12 +65,12 @@ export function SubscribeForm({
|
||||
<div className="flex justify-end gap-3">
|
||||
{onCancel ? (
|
||||
<Button type="button" variant="outline" onClick={onCancel}>
|
||||
Cancelar
|
||||
{t('common:actions.cancel')}
|
||||
</Button>
|
||||
) : null}
|
||||
<Button type="submit" variant="primary" disabled={isPending || (asksEmail && !email.trim())}>
|
||||
{isPending ? <Loader2 className="size-4 animate-spin" /> : null}
|
||||
{isPending ? 'Abriendo…' : submitLabel}
|
||||
{isPending ? t('subscribe.opening') : (submitLabel ?? t('subscribe.goTo', { provider: BILLING_PROVIDER_NAMES[provider] }))}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -4,9 +4,11 @@ import { useBilling } from './BillingProvider'
|
||||
import { subscribeDescription } from './copy'
|
||||
import { SubscribeForm } from './SubscribeForm'
|
||||
import { useStartSubscription } from './useStartSubscription'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
export function SubscribeModal() {
|
||||
const { user } = useAuth()
|
||||
const { t } = useTranslation(['billing', 'common'])
|
||||
const { isSubscribeOpen, closeSubscribe, statusQuery } = useBilling()
|
||||
const subscription = useStartSubscription()
|
||||
const provider = statusQuery.data?.provider ?? 'MERCADO_PAGO'
|
||||
@@ -15,7 +17,7 @@ export function SubscribeModal() {
|
||||
<Modal
|
||||
isOpen={isSubscribeOpen}
|
||||
onClose={closeSubscribe}
|
||||
title="Pasate a Pro"
|
||||
title={t('subscribe.title')}
|
||||
description={subscribeDescription(provider)}
|
||||
maxWidth="sm"
|
||||
>
|
||||
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
SubscriptionStatus,
|
||||
} from '@gruperly/shared'
|
||||
import type { BadgeVariant } from '../../components/ui'
|
||||
import { i18n } from '../../i18n/instance'
|
||||
|
||||
/* Copy del plan de Gruperly en un solo lugar: Ajustes, la pantalla del plan, el
|
||||
paso del onboarding y los avisos tienen que decir lo mismo. Funciones puras,
|
||||
@@ -14,8 +15,9 @@ import type { BadgeVariant } from '../../components/ui'
|
||||
|
||||
export const PLAN_NAMES: Record<Plan, string> = { FREE: 'Free', PRO: 'Pro' }
|
||||
|
||||
export const SUBSCRIBE_ERROR_MESSAGE =
|
||||
'No pudimos abrir la página de pago. Revisá tu conexión e intentá de nuevo.'
|
||||
export function subscribeErrorMessage(): string {
|
||||
return i18n.t('billing:subscribeError')
|
||||
}
|
||||
|
||||
/* Quién cobra Pro: Mercado Pago en Argentina, Stripe en el resto. Es solo la
|
||||
suscripción a Gruperly; los cobros a alumnos siguen siendo con Mercado Pago. */
|
||||
@@ -26,9 +28,7 @@ export const BILLING_PROVIDER_NAMES: Record<BillingProviderId, string> = {
|
||||
|
||||
/** Qué pasa al tocar "Pasar a Pro", según quién cobra. */
|
||||
export function subscribeDescription(provider: BillingProviderId): string {
|
||||
return provider === 'STRIPE'
|
||||
? 'Te llevamos a Stripe para cargar tu tarjeta. El cobro es mensual y podés cancelarlo cuando quieras.'
|
||||
: 'Te llevamos a Mercado Pago para autorizar el débito mensual. Podés cancelarlo cuando quieras.'
|
||||
return i18n.t(`billing:subscribeDescription.${provider}`)
|
||||
}
|
||||
|
||||
/** Lo que incluye cada plan, como lista para las tarjetas de comparación. */
|
||||
@@ -37,25 +37,25 @@ export function planFeatureList(limits: PlanLimits): { label: string; included:
|
||||
{
|
||||
label:
|
||||
limits.maxGroups === null
|
||||
? 'Grupos ilimitados'
|
||||
: `${limits.maxGroups} ${limits.maxGroups === 1 ? 'grupo' : 'grupos'}`,
|
||||
? i18n.t('billing:features.unlimitedGroups')
|
||||
: i18n.t('billing:features.groups', { count: limits.maxGroups }),
|
||||
included: true,
|
||||
},
|
||||
{
|
||||
label:
|
||||
limits.maxAttendees === null
|
||||
? 'Alumnos ilimitados'
|
||||
: `Hasta ${limits.maxAttendees} alumnos activos`,
|
||||
? i18n.t('billing:features.unlimitedStudents')
|
||||
: i18n.t('billing:features.students', { count: limits.maxAttendees }),
|
||||
included: true,
|
||||
},
|
||||
{ label: 'Cobros con Mercado Pago', included: limits.mpCharges },
|
||||
{ label: 'Mensajes automáticos por WhatsApp', included: limits.whatsappAutomations },
|
||||
{ label: i18n.t('billing:features.mpCharges'), included: limits.mpCharges },
|
||||
{ label: i18n.t('billing:features.whatsapp'), included: limits.whatsappAutomations },
|
||||
]
|
||||
}
|
||||
|
||||
export const PLAN_FEATURE_REQUIRED_MESSAGES: Record<PlanFeature, string> = {
|
||||
mpCharges: 'Cobrar con Mercado Pago está disponible en el plan Pro.',
|
||||
whatsappAutomations: 'Los mensajes automáticos de WhatsApp están disponibles en el plan Pro.',
|
||||
/** The same copy as the backend's `plan_feature_required` problem. */
|
||||
export function planFeatureRequiredMessage(feature: PlanFeature): string {
|
||||
return i18n.t(`errors:codes.plan_feature_required_${feature}`)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,15 +69,12 @@ export function hasPlanFeature(status: BillingStatusDto | undefined, feature: Pl
|
||||
export function subscriptionStatusLabel(status: SubscriptionStatus | null): string {
|
||||
switch (status) {
|
||||
case 'AUTHORIZED':
|
||||
return 'Activa'
|
||||
case 'PENDING':
|
||||
return 'Pendiente de pago'
|
||||
case 'PAUSED':
|
||||
return 'Pausada'
|
||||
case 'CANCELLED':
|
||||
return 'Cancelada'
|
||||
return i18n.t(`billing:subscriptionStatus.${status}`)
|
||||
default:
|
||||
return 'Sin suscripción'
|
||||
return i18n.t('billing:subscriptionStatus.NONE')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,14 +88,14 @@ export function formatBillingDate(iso: string | null): string | null {
|
||||
if (!iso) return null
|
||||
const date = new Date(iso)
|
||||
if (Number.isNaN(date.getTime())) return null
|
||||
return new Intl.DateTimeFormat('es', { day: 'numeric', month: 'short', year: 'numeric' }).format(
|
||||
return new Intl.DateTimeFormat(i18n.language, { day: 'numeric', month: 'short', year: 'numeric' }).format(
|
||||
date,
|
||||
)
|
||||
}
|
||||
|
||||
/** "3 de 15": el uso contra el límite, o solo el uso cuando no hay límite. */
|
||||
export function formatUsage(used: number, limit: number | null): string {
|
||||
return limit === null ? `${used}` : `${used} de ${limit}`
|
||||
return limit === null ? `${used}` : i18n.t('billing:usage', { used, limit })
|
||||
}
|
||||
|
||||
const PLAN_PROBLEM_CODES = ['plan_limit_reached', 'plan_feature_required', 'plan_read_only']
|
||||
@@ -124,7 +121,7 @@ export function planNoticeMessage(status: BillingStatusDto): { tone: 'danger' |
|
||||
if (status.readOnly) {
|
||||
return {
|
||||
tone: 'danger',
|
||||
text: 'Tu cuenta está en solo lectura: superás los límites del plan Free. Pasate a Pro o reducí tus alumnos para volver a editar.',
|
||||
text: i18n.t('billing:notice.readOnly'),
|
||||
}
|
||||
}
|
||||
const graceUntil = formatBillingDate(status.graceUntil)
|
||||
@@ -133,8 +130,11 @@ export function planNoticeMessage(status: BillingStatusDto): { tone: 'danger' |
|
||||
tone: 'warning',
|
||||
text:
|
||||
status.status === 'CANCELLED'
|
||||
? `Cancelaste Pro: lo seguís teniendo hasta el ${graceUntil}.`
|
||||
: `No pudimos cobrar tu suscripción a Pro. Revisá tu medio de pago en ${BILLING_PROVIDER_NAMES[status.provider]} antes del ${graceUntil}.`,
|
||||
? i18n.t('billing:notice.cancelled', { date: graceUntil })
|
||||
: i18n.t('billing:notice.paymentFailed', {
|
||||
provider: BILLING_PROVIDER_NAMES[status.provider],
|
||||
date: graceUntil,
|
||||
}),
|
||||
}
|
||||
}
|
||||
return null
|
||||
|
||||
@@ -4,7 +4,7 @@ export {
|
||||
formatUsage,
|
||||
hasPlanFeature,
|
||||
isPlanProblem,
|
||||
PLAN_FEATURE_REQUIRED_MESSAGES,
|
||||
planFeatureRequiredMessage,
|
||||
PLAN_NAMES,
|
||||
planFeatureList,
|
||||
planNoticeMessage,
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { BillingReturnTo } from '@gruperly/shared'
|
||||
import { useState } from 'react'
|
||||
import { ApiError, subscribeToPro } from '../../lib/api'
|
||||
import { SUBSCRIBE_ERROR_MESSAGE } from './copy'
|
||||
import { subscribeToPro } from '../../lib/api'
|
||||
import { errorMessage } from '../../i18n'
|
||||
import { subscribeErrorMessage } from './copy'
|
||||
|
||||
/**
|
||||
* Empieza la suscripción a Pro. Como la vinculación de Mercado Pago, no se
|
||||
@@ -19,7 +20,7 @@ export function useStartSubscription() {
|
||||
const { checkoutUrl } = await subscribeToPro({ payerEmail, returnTo })
|
||||
window.location.assign(checkoutUrl)
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError && caught.problem?.detail ? caught.problem.detail : SUBSCRIBE_ERROR_MESSAGE)
|
||||
setError(errorMessage(caught, subscribeErrorMessage()))
|
||||
setIsStarting(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { useState } from 'react'
|
||||
import { Button } from '../../../components/ui'
|
||||
import {
|
||||
hasPlanFeature,
|
||||
PLAN_FEATURE_REQUIRED_MESSAGES,
|
||||
planFeatureRequiredMessage,
|
||||
showPlanPrompt,
|
||||
useBillingStatus,
|
||||
} from '../../billing'
|
||||
@@ -41,7 +41,7 @@ export function GroupDetailView() {
|
||||
const billingQuery = useBillingStatus({ enabled: isGroupOwner })
|
||||
const handleCharge = () => {
|
||||
if (isGroupOwner && !hasPlanFeature(billingQuery.data, 'mpCharges')) {
|
||||
showPlanPrompt(PLAN_FEATURE_REQUIRED_MESSAGES.mpCharges)
|
||||
showPlanPrompt(planFeatureRequiredMessage('mpCharges'))
|
||||
return
|
||||
}
|
||||
setIsChargeModalOpen(true)
|
||||
|
||||
Reference in New Issue
Block a user