fix(web): distinguir WhatsApp no configurado de otros errores de estado

Ajustes y el paso del onboarding mostraban "no está disponible" ante
cualquier fallo de GET /whatsapp/status. Ahora solo un 503 da ese
mensaje; el resto muestra el código del error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jose Selesan
2026-10-22 19:02:14 -03:00
parent 2467ebc0f6
commit bef4056f8e
5 changed files with 40 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import { ArrowLeft, ArrowRight, BadgeCheck, CheckCircle2, Loader2 } from 'lucide-react'
import { Badge, Button } from '../../components/ui'
import { ApiError } from '../../lib/api'
import type { WhatsappCallbackFeedback } from '../whatsapp'
import {
linksWithQr,
@@ -8,6 +9,7 @@ import {
WhatsappQrModal,
whatsappCallbackErrorMessage,
whatsappStatusBadgeVariant,
whatsappStatusErrorMessage,
whatsappStatusLabel,
} from '../whatsapp'
@@ -69,6 +71,12 @@ export function WhatsappStep({ feedback, onNext, onBack }: WhatsappStepProps) {
<Loader2 className="size-4 animate-spin" />
Consultando tu WhatsApp…
</p>
) : statusQuery.isError ? (
<p className="text-sm text-foreground/60">
{whatsappStatusErrorMessage(
statusQuery.error instanceof ApiError ? statusQuery.error.status : null,
)}
</p>
) : (
<p className="text-sm text-foreground/60">
{usesQr

View File

@@ -1,13 +1,14 @@
import { BadgeCheck, Loader2, MessageCircle, Unlink } from 'lucide-react'
import { useState } from 'react'
import { Badge, Button, Modal } from '../../components/ui'
import { ApiError } from '../../lib/api'
import { formatMpConnectionDate } from '../mp'
import {
linksWithQr,
readinessLabel,
WEEKLY_SEND_LABEL,
WHATSAPP_UNAVAILABLE_MESSAGE,
whatsappStatusBadgeVariant,
whatsappStatusErrorMessage,
whatsappStatusLabel,
} from './copy'
import { useDisconnectWhatsapp } from './useDisconnectWhatsapp'
@@ -39,7 +40,11 @@ export function WhatsappStatusCard() {
return (
<div className="rounded-xl border border-border bg-surface px-4 py-3">
<p className="text-sm font-medium text-primary">WhatsApp</p>
<p className="mt-0.5 text-xs text-foreground/50">{WHATSAPP_UNAVAILABLE_MESSAGE}</p>
<p className="mt-0.5 text-xs text-foreground/50">
{whatsappStatusErrorMessage(
statusQuery.error instanceof ApiError ? statusQuery.error.status : null,
)}
</p>
</div>
)
}

View File

@@ -16,6 +16,17 @@ export const WHATSAPP_CONNECT_ERROR_MESSAGE =
export const WHATSAPP_UNAVAILABLE_MESSAGE =
'La vinculación con WhatsApp no está disponible en este momento.'
/**
* Mensaje para un fallo al consultar el estado. Solo un 503 significa "WhatsApp
* no está configurado en este servidor"; cualquier otro código es un error de
* verdad y se muestra con su número para poder rastrearlo.
*/
export function whatsappStatusErrorMessage(httpStatus: number | null): string {
if (httpStatus === 503) return WHATSAPP_UNAVAILABLE_MESSAGE
const code = httpStatus ? ` (error ${httpStatus})` : ''
return `No pudimos consultar el estado de tu WhatsApp${code}. Intentá de nuevo en un rato.`
}
/** Día y hora en que salen los mensajes automáticos (lo fija el job del backend). */
export const WEEKLY_SEND_LABEL = 'Se envían los lunes a las 10:00 (hora de Argentina).'

View File

@@ -7,6 +7,7 @@ export {
type WhatsappCallbackFeedback,
whatsappCallbackErrorMessage,
whatsappStatusBadgeVariant,
whatsappStatusErrorMessage,
whatsappStatusLabel,
} from './copy'
export { useDisconnectWhatsapp } from './useDisconnectWhatsapp'

View File

@@ -6,7 +6,9 @@ import {
readinessLabel,
readWhatsappCallbackFeedback,
whatsappCallbackErrorMessage,
WHATSAPP_UNAVAILABLE_MESSAGE,
whatsappStatusBadgeVariant,
whatsappStatusErrorMessage,
whatsappStatusLabel,
} from '../src/features/whatsapp/copy'
@@ -77,3 +79,14 @@ describe('automationBlockedReason', () => {
expect(automationBlockedReason(status(), 'PAYMENT_REMINDER')).toBeNull()
})
})
describe('whatsappStatusErrorMessage', () => {
test('solo un 503 dice que no está disponible', () => {
expect(whatsappStatusErrorMessage(503)).toBe(WHATSAPP_UNAVAILABLE_MESSAGE)
})
test('otro error muestra su código', () => {
expect(whatsappStatusErrorMessage(500)).toContain('error 500')
expect(whatsappStatusErrorMessage(null)).not.toContain('error')
})
})