diff --git a/apps/web/src/features/onboarding/WhatsappStep.tsx b/apps/web/src/features/onboarding/WhatsappStep.tsx index 550f36b..7ea0386 100644 --- a/apps/web/src/features/onboarding/WhatsappStep.tsx +++ b/apps/web/src/features/onboarding/WhatsappStep.tsx @@ -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) { Consultando tu WhatsApp…

+ ) : statusQuery.isError ? ( +

+ {whatsappStatusErrorMessage( + statusQuery.error instanceof ApiError ? statusQuery.error.status : null, + )} +

) : (

{usesQr diff --git a/apps/web/src/features/whatsapp/WhatsappStatusCard.tsx b/apps/web/src/features/whatsapp/WhatsappStatusCard.tsx index a579d98..ad1aa8c 100644 --- a/apps/web/src/features/whatsapp/WhatsappStatusCard.tsx +++ b/apps/web/src/features/whatsapp/WhatsappStatusCard.tsx @@ -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 (

WhatsApp

-

{WHATSAPP_UNAVAILABLE_MESSAGE}

+

+ {whatsappStatusErrorMessage( + statusQuery.error instanceof ApiError ? statusQuery.error.status : null, + )} +

) } diff --git a/apps/web/src/features/whatsapp/copy.ts b/apps/web/src/features/whatsapp/copy.ts index 03766b3..2154f4c 100644 --- a/apps/web/src/features/whatsapp/copy.ts +++ b/apps/web/src/features/whatsapp/copy.ts @@ -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).' diff --git a/apps/web/src/features/whatsapp/index.ts b/apps/web/src/features/whatsapp/index.ts index dac39ee..9344783 100644 --- a/apps/web/src/features/whatsapp/index.ts +++ b/apps/web/src/features/whatsapp/index.ts @@ -7,6 +7,7 @@ export { type WhatsappCallbackFeedback, whatsappCallbackErrorMessage, whatsappStatusBadgeVariant, + whatsappStatusErrorMessage, whatsappStatusLabel, } from './copy' export { useDisconnectWhatsapp } from './useDisconnectWhatsapp' diff --git a/apps/web/test/whatsapp-copy.test.ts b/apps/web/test/whatsapp-copy.test.ts index 4f35b8c..4cd670a 100644 --- a/apps/web/test/whatsapp-copy.test.ts +++ b/apps/web/test/whatsapp-copy.test.ts @@ -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') + }) +})