feat(i18n): traducir WhatsApp
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next'
|
||||
import { Badge, Switch } from '../../../components/ui'
|
||||
import { hasPlanFeature, useBillingStatus } from '../../billing'
|
||||
import { cn } from '../../../lib/utils'
|
||||
import { automationBlockedReason, useWhatsappStatus, WEEKLY_SEND_LABEL } from '../../whatsapp'
|
||||
import { automationBlockedReason, useWhatsappStatus, weeklySendLabel } from '../../whatsapp'
|
||||
import { useGroupDetail } from './GroupDetailProvider'
|
||||
|
||||
type Automation = {
|
||||
@@ -87,7 +87,7 @@ export function GroupAutomationsCard() {
|
||||
{expanded ? (
|
||||
<div id="group-automations" className="border-t border-border">
|
||||
<p className="px-4 pt-3 text-xs text-foreground/50">
|
||||
{WEEKLY_SEND_LABEL}
|
||||
{weeklySendLabel()}
|
||||
{includedInPlan ? null : (
|
||||
<>
|
||||
{' '}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { cn } from '../../lib/utils'
|
||||
import { defaultLinkMethod, linksWithPairingCode, type WhatsappLinkMethod } from './copy'
|
||||
import { useWhatsappStatus } from './useWhatsappStatus'
|
||||
import { WhatsappPairingCodePanel } from './WhatsappPairingCodePanel'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
|
||||
type WhatsappLinkModalProps = {
|
||||
isOpen: boolean
|
||||
@@ -14,10 +15,10 @@ type WhatsappLinkModalProps = {
|
||||
initialQrCode: string | null
|
||||
}
|
||||
|
||||
const METHOD_LABELS: Record<WhatsappLinkMethod, string> = {
|
||||
phone: 'Con tu número',
|
||||
qr: 'Con código QR',
|
||||
}
|
||||
const METHOD_LABELS = { phone: 'link.methodPhone', qr: 'link.methodQr' } as const satisfies Record<
|
||||
WhatsappLinkMethod,
|
||||
string
|
||||
>
|
||||
|
||||
/**
|
||||
* Vinculación de WhatsApp como "dispositivo vinculado", por QR o con el número
|
||||
@@ -29,6 +30,7 @@ const METHOD_LABELS: Record<WhatsappLinkMethod, string> = {
|
||||
*/
|
||||
export function WhatsappLinkModal({ isOpen, onClose, initialQrCode }: WhatsappLinkModalProps) {
|
||||
const toast = useToast()
|
||||
const { t } = useTranslation('whatsapp')
|
||||
const isMobile = useIsMobile()
|
||||
const statusQuery = useWhatsappStatus({ enabled: isOpen })
|
||||
const status = statusQuery.data?.status
|
||||
@@ -43,10 +45,10 @@ export function WhatsappLinkModal({ isOpen, onClose, initialQrCode }: WhatsappLi
|
||||
useEffect(() => {
|
||||
if (!isOpen) return
|
||||
if (status === 'active') {
|
||||
toast.success('¡Listo! Tu WhatsApp quedó vinculado.')
|
||||
toast.success(t('link.linked'))
|
||||
onClose()
|
||||
} else if (status === 'disconnected') {
|
||||
toast.error('La vinculación no se completó. Volvé a intentarlo.')
|
||||
toast.error(t('link.failed'))
|
||||
onClose()
|
||||
}
|
||||
}, [isOpen, status, onClose, toast])
|
||||
@@ -58,11 +60,11 @@ export function WhatsappLinkModal({ isOpen, onClose, initialQrCode }: WhatsappLi
|
||||
<Modal
|
||||
isOpen={isOpen}
|
||||
onClose={onClose}
|
||||
title="Vinculá tu WhatsApp"
|
||||
title={t('link.title')}
|
||||
description={
|
||||
activeMethod === 'phone'
|
||||
? 'Te damos un código para ingresar en WhatsApp, en el teléfono donde lo usás.'
|
||||
: 'Escaneá el código con el teléfono donde usás WhatsApp.'
|
||||
? t('link.phoneDescription')
|
||||
: t('link.qrDescription')
|
||||
}
|
||||
maxWidth="sm"
|
||||
>
|
||||
@@ -88,7 +90,7 @@ export function WhatsappLinkModal({ isOpen, onClose, initialQrCode }: WhatsappLi
|
||||
) : (
|
||||
<QrCode className="size-4" />
|
||||
)}
|
||||
{METHOD_LABELS[option]}
|
||||
{t(METHOD_LABELS[option])}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
@@ -100,26 +102,24 @@ export function WhatsappLinkModal({ isOpen, onClose, initialQrCode }: WhatsappLi
|
||||
<>
|
||||
<div className="mx-auto flex size-64 items-center justify-center rounded-xl border border-border bg-white p-2">
|
||||
{qrCode ? (
|
||||
<img src={qrCode} alt="Código QR para vincular WhatsApp" className="size-full" />
|
||||
<img src={qrCode} alt={t('link.qrAlt')} className="size-full" />
|
||||
) : (
|
||||
<Loader2 className="size-8 animate-spin text-foreground/40" />
|
||||
)}
|
||||
</div>
|
||||
<ol className="space-y-1.5 text-sm text-foreground/70">
|
||||
<li>1. Abrí WhatsApp en tu teléfono.</li>
|
||||
<li>1. {t('link.qrStep1')}</li>
|
||||
<li>
|
||||
2. Tocá <span className="font-medium text-primary">Dispositivos vinculados</span> y
|
||||
después <span className="font-medium text-primary">Vincular un dispositivo</span>.
|
||||
2. <Trans t={t} i18nKey="link.qrStep2" components={{ strong: <span className="font-medium text-primary" /> }} />
|
||||
</li>
|
||||
<li>3. Apuntá la cámara a este código.</li>
|
||||
<li>3. {t('link.qrStep3')}</li>
|
||||
</ol>
|
||||
</>
|
||||
)}
|
||||
|
||||
<p className="flex items-start gap-2 rounded-xl bg-primary-soft px-3 py-2 text-xs text-foreground/70">
|
||||
<Smartphone className="mt-0.5 size-4 shrink-0 text-accent" />
|
||||
Los mensajes van a salir desde tu número. Podés desvincularlo cuando quieras desde
|
||||
Ajustes o desde tu teléfono.
|
||||
{t('link.footnote')}
|
||||
</p>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { type FormEvent, useState } from 'react'
|
||||
import { Button, Input, Label } from '../../components/ui'
|
||||
import { formatPairingCode } from './copy'
|
||||
import { useRequestWhatsappPairingCode } from './useRequestWhatsappPairingCode'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
|
||||
/**
|
||||
* Vinculación con el número de teléfono: el profesor escribe su número,
|
||||
@@ -12,6 +13,7 @@ import { useRequestWhatsappPairingCode } from './useRequestWhatsappPairingCode'
|
||||
export function WhatsappPairingCodePanel() {
|
||||
const { requestCode, pairingCode, isRequesting, error, reset } = useRequestWhatsappPairingCode()
|
||||
const [phoneNumber, setPhoneNumber] = useState('')
|
||||
const { t } = useTranslation('whatsapp')
|
||||
const [copied, setCopied] = useState(false)
|
||||
|
||||
const handleSubmit = (event: FormEvent) => {
|
||||
@@ -39,31 +41,26 @@ export function WhatsappPairingCodePanel() {
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
aria-label="Copiar código"
|
||||
aria-label={t('pairing.copy')}
|
||||
onClick={() => void handleCopy(pairingCode)}
|
||||
>
|
||||
{copied ? <Check className="size-4 text-success" /> : <Copy className="size-4" />}
|
||||
</Button>
|
||||
</div>
|
||||
<ol className="space-y-1.5 text-sm text-foreground/70">
|
||||
<li>1. {t('pairing.step1')}</li>
|
||||
<li>
|
||||
1. Abrí WhatsApp. Te va a llegar una notificación para vincular un dispositivo:
|
||||
tocala.
|
||||
2. <Trans t={t} i18nKey="pairing.step2" components={{ strong: <span className="font-medium text-primary" /> }} />
|
||||
</li>
|
||||
<li>
|
||||
2. Si no te llega, tocá <span className="font-medium text-primary">Dispositivos vinculados</span>{' '}
|
||||
→ <span className="font-medium text-primary">Vincular un dispositivo</span> →{' '}
|
||||
<span className="font-medium text-primary">Vincular con el número de teléfono</span>.
|
||||
</li>
|
||||
<li>3. Ingresá este código. Esta pantalla se actualiza sola.</li>
|
||||
<li>3. {t('pairing.step3')}</li>
|
||||
</ol>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<p className="flex items-center gap-2 text-xs text-foreground/50">
|
||||
<Loader2 className="size-3.5 animate-spin" />
|
||||
Esperando el código…
|
||||
{t('pairing.waiting')}
|
||||
</p>
|
||||
<Button variant="ghost" size="sm" onClick={reset}>
|
||||
Usar otro número
|
||||
{t('pairing.otherNumber')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -73,20 +70,20 @@ export function WhatsappPairingCodePanel() {
|
||||
return (
|
||||
<form className="space-y-3" onSubmit={handleSubmit}>
|
||||
<div>
|
||||
<Label htmlFor="whatsapp-pairing-phone">Tu número de WhatsApp</Label>
|
||||
<Label htmlFor="whatsapp-pairing-phone">{t('pairing.phone')}</Label>
|
||||
<Input
|
||||
id="whatsapp-pairing-phone"
|
||||
type="tel"
|
||||
inputMode="tel"
|
||||
autoComplete="tel"
|
||||
autoFocus
|
||||
placeholder="11 2345-6789"
|
||||
placeholder={t('pairing.phonePlaceholder')}
|
||||
value={phoneNumber}
|
||||
invalid={Boolean(error)}
|
||||
onChange={(event) => setPhoneNumber(event.target.value)}
|
||||
/>
|
||||
<p className="mt-1 text-xs text-foreground/50">
|
||||
El del teléfono donde usás WhatsApp, con el código de área.
|
||||
{t('pairing.phoneHint')}
|
||||
</p>
|
||||
</div>
|
||||
{error ? (
|
||||
@@ -99,7 +96,7 @@ export function WhatsappPairingCodePanel() {
|
||||
disabled={isRequesting || !phoneNumber.trim()}
|
||||
>
|
||||
{isRequesting ? <Loader2 className="size-4 animate-spin" /> : <KeyRound className="size-4" />}
|
||||
{isRequesting ? 'Pidiendo código…' : 'Obtener código'}
|
||||
{isRequesting ? t('pairing.requesting') : t('pairing.request')}
|
||||
</Button>
|
||||
</form>
|
||||
)
|
||||
|
||||
@@ -6,7 +6,7 @@ import { formatMpConnectionDate } from '../mp'
|
||||
import {
|
||||
linksWithQr,
|
||||
readinessLabel,
|
||||
WEEKLY_SEND_LABEL,
|
||||
weeklySendLabel,
|
||||
whatsappStatusBadgeVariant,
|
||||
whatsappStatusErrorMessage,
|
||||
whatsappStatusLabel,
|
||||
@@ -15,6 +15,7 @@ import { useDisconnectWhatsapp } from './useDisconnectWhatsapp'
|
||||
import { useStartWhatsappConnection } from './useStartWhatsappConnection'
|
||||
import { useWhatsappStatus } from './useWhatsappStatus'
|
||||
import { WhatsappLinkModal } from './WhatsappLinkModal'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
/**
|
||||
* WhatsApp en Ajustes: vincular el número desde el que salen los recordatorios
|
||||
@@ -23,6 +24,7 @@ import { WhatsappLinkModal } from './WhatsappLinkModal'
|
||||
*/
|
||||
export function WhatsappStatusCard() {
|
||||
const statusQuery = useWhatsappStatus()
|
||||
const { t } = useTranslation(['whatsapp', 'common'])
|
||||
const connection = useStartWhatsappConnection()
|
||||
const { disconnectWhatsapp: disconnect, isDisconnecting } = useDisconnectWhatsapp()
|
||||
const [isConfirmingDisconnect, setIsConfirmingDisconnect] = useState(false)
|
||||
@@ -31,7 +33,7 @@ export function WhatsappStatusCard() {
|
||||
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 WhatsApp…</p>
|
||||
<p className="text-sm text-foreground/50">{t('card.loading')}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -63,7 +65,7 @@ export function WhatsappStatusCard() {
|
||||
<Badge variant={whatsappStatusBadgeVariant(status)}>{whatsappStatusLabel(status)}</Badge>
|
||||
</div>
|
||||
<p className="mt-0.5 text-xs text-foreground/50">
|
||||
Tu número para los recordatorios de pago y los mensajes de reenganche automáticos.
|
||||
{t('card.description')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -75,10 +77,10 @@ export function WhatsappStatusCard() {
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-sm text-primary">
|
||||
{data.displayPhoneNumber ?? 'Número vinculado'}
|
||||
{data.displayPhoneNumber ?? t('card.linkedNumber')}
|
||||
</p>
|
||||
{connectedAt ? (
|
||||
<p className="text-xs text-foreground/50">Vinculado el {connectedAt}</p>
|
||||
<p className="text-xs text-foreground/50">{t('card.linkedOn', { date: connectedAt })}</p>
|
||||
) : null}
|
||||
</div>
|
||||
<Button
|
||||
@@ -92,20 +94,20 @@ export function WhatsappStatusCard() {
|
||||
) : (
|
||||
<Unlink className="size-4" />
|
||||
)}
|
||||
Desvincular
|
||||
{t('card.disconnect')}
|
||||
</Button>
|
||||
</div>
|
||||
<dl className="space-y-1.5 px-4 py-3 text-sm">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<dt className="text-foreground/60">Recordatorio de pago</dt>
|
||||
<dt className="text-foreground/60">{t('card.paymentReminder')}</dt>
|
||||
<dd className="text-primary">{readinessLabel(data.readiness.PAYMENT_REMINDER)}</dd>
|
||||
</div>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<dt className="text-foreground/60">Mensaje de reenganche</dt>
|
||||
<dt className="text-foreground/60">{t('card.reengagement')}</dt>
|
||||
<dd className="text-primary">{readinessLabel(data.readiness.REENGAGEMENT)}</dd>
|
||||
</div>
|
||||
<p className="pt-1 text-xs text-foreground/50">
|
||||
Los activás en cada grupo. {WEEKLY_SEND_LABEL}
|
||||
{t('card.perGroup')} {weeklySendLabel()}
|
||||
</p>
|
||||
</dl>
|
||||
</>
|
||||
@@ -116,12 +118,12 @@ export function WhatsappStatusCard() {
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-sm text-primary">
|
||||
{status === 'requires_reconnect' ? 'Volvé a vincular tu número' : 'Vinculá tu número'}
|
||||
{status === 'requires_reconnect' ? t('card.relink') : t('card.linkNumber')}
|
||||
</p>
|
||||
<p className="text-xs text-foreground/50">
|
||||
{linksWithQr(data.provider)
|
||||
? 'Lo vinculás con tu número o con un código QR, como WhatsApp Web.'
|
||||
: 'Te llevamos a Meta para conectar tu cuenta de WhatsApp Business.'}
|
||||
? t('card.qrHint')
|
||||
: t('card.metaHint')}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
@@ -135,7 +137,7 @@ export function WhatsappStatusCard() {
|
||||
) : (
|
||||
<BadgeCheck className="size-4" />
|
||||
)}
|
||||
{connection.isStarting ? 'Abriendo…' : 'Vincular'}
|
||||
{connection.isStarting ? t('card.opening') : t('card.connect')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
@@ -154,13 +156,13 @@ export function WhatsappStatusCard() {
|
||||
<Modal
|
||||
isOpen={isConfirmingDisconnect}
|
||||
onClose={() => setIsConfirmingDisconnect(false)}
|
||||
title="Desvincular WhatsApp"
|
||||
description="Los recordatorios y los mensajes de reenganche automáticos dejan de enviarse hasta que lo vuelvas a vincular."
|
||||
title={t('disconnect.title')}
|
||||
description={t('disconnect.description')}
|
||||
maxWidth="sm"
|
||||
>
|
||||
<div className="flex justify-end gap-3">
|
||||
<Button variant="outline" onClick={() => setIsConfirmingDisconnect(false)}>
|
||||
Cancelar
|
||||
{t('common:actions.cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
@@ -171,7 +173,7 @@ export function WhatsappStatusCard() {
|
||||
}}
|
||||
>
|
||||
{isDisconnecting ? <Loader2 className="size-4 animate-spin" /> : null}
|
||||
Desvincular
|
||||
{t('disconnect.confirm')}
|
||||
</Button>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
@@ -5,16 +5,19 @@ import type {
|
||||
WhatsappReadiness,
|
||||
WhatsappStatusDto,
|
||||
} from '@gruperly/shared'
|
||||
import { i18n } from '../../i18n/instance'
|
||||
|
||||
/* Copy de WhatsApp en un solo lugar: el paso del onboarding, la tarjeta de
|
||||
Ajustes y las automatizaciones del grupo dicen exactamente lo mismo. Las
|
||||
funciones son puras para cubrirlas con tests sin renderizar nada. */
|
||||
|
||||
export const WHATSAPP_CONNECT_ERROR_MESSAGE =
|
||||
'No pudimos empezar la vinculación. Revisá tu conexión e intentá de nuevo.'
|
||||
export function whatsappConnectErrorMessage(): string {
|
||||
return i18n.t('whatsapp:connectError')
|
||||
}
|
||||
|
||||
export const WHATSAPP_UNAVAILABLE_MESSAGE =
|
||||
'La vinculación con WhatsApp no está disponible en este momento.'
|
||||
export function whatsappUnavailableMessage(): string {
|
||||
return i18n.t('whatsapp:unavailable')
|
||||
}
|
||||
|
||||
/**
|
||||
* Mensaje para un fallo al consultar el estado. Solo un 503 significa "WhatsApp
|
||||
@@ -22,13 +25,16 @@ export const WHATSAPP_UNAVAILABLE_MESSAGE =
|
||||
* 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.`
|
||||
if (httpStatus === 503) return whatsappUnavailableMessage()
|
||||
return httpStatus
|
||||
? i18n.t('whatsapp:statusErrorCode', { code: httpStatus })
|
||||
: i18n.t('whatsapp:statusError')
|
||||
}
|
||||
|
||||
/** 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).'
|
||||
export function weeklySendLabel(): string {
|
||||
return i18n.t('whatsapp:weeklySend')
|
||||
}
|
||||
|
||||
/** El resultado de una vinculación por redirect (Kapso), tal como vuelve en `?wa=`. */
|
||||
export type WhatsappCallbackFeedback =
|
||||
@@ -57,28 +63,19 @@ export function readWhatsappCallbackFeedback(
|
||||
}
|
||||
}
|
||||
|
||||
const REASON_MESSAGES: Record<WhatsappCallbackReason, string> = {
|
||||
invalid_setup: 'La vinculación venció o ya se había usado. Volvé a intentarlo.',
|
||||
setup_failed: 'No se pudo terminar la vinculación en Meta. Volvé a intentarlo.',
|
||||
provider_error: 'WhatsApp no pudo completar la vinculación.',
|
||||
number_in_use: 'Ese número de WhatsApp ya está vinculado a otro profesor.',
|
||||
}
|
||||
|
||||
export function whatsappCallbackErrorMessage(reason: WhatsappCallbackReason): string {
|
||||
return REASON_MESSAGES[reason]
|
||||
return i18n.t(`whatsapp:reason.${reason}`)
|
||||
}
|
||||
|
||||
export function whatsappStatusLabel(status: WhatsappAccountStatus): string {
|
||||
switch (status) {
|
||||
case 'active':
|
||||
return 'Vinculado'
|
||||
case 'pending':
|
||||
return 'Vinculando…'
|
||||
case 'requires_reconnect':
|
||||
return 'Necesita vincularse de nuevo'
|
||||
return i18n.t(`whatsapp:status.${status}`)
|
||||
case 'disconnected':
|
||||
case 'none':
|
||||
return 'Sin vincular'
|
||||
return i18n.t('whatsapp:status.none')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,11 +99,9 @@ export function whatsappStatusBadgeVariant(
|
||||
export function readinessLabel(readiness: WhatsappReadiness): string {
|
||||
switch (readiness) {
|
||||
case 'ready':
|
||||
return 'Listo para enviar'
|
||||
case 'pending':
|
||||
return 'En revisión por Meta'
|
||||
case 'blocked':
|
||||
return 'No disponible'
|
||||
return i18n.t(`whatsapp:readiness.${readiness}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,14 +141,14 @@ export function automationBlockedReason(
|
||||
kind: 'PAYMENT_REMINDER' | 'REENGAGEMENT',
|
||||
): string | null {
|
||||
if (!status || status.status !== 'active') {
|
||||
return 'Vinculá tu WhatsApp en Ajustes para activar los envíos automáticos.'
|
||||
return i18n.t('whatsapp:blocked.notLinked')
|
||||
}
|
||||
switch (status.readiness[kind]) {
|
||||
case 'ready':
|
||||
return null
|
||||
case 'pending':
|
||||
return 'Meta todavía está revisando el mensaje. Suele tardar hasta 24 horas.'
|
||||
return i18n.t('whatsapp:blocked.pending')
|
||||
case 'blocked':
|
||||
return 'Meta rechazó este mensaje. Escribinos para revisarlo.'
|
||||
return i18n.t('whatsapp:blocked.rejected')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ export {
|
||||
linksWithQr,
|
||||
readinessLabel,
|
||||
readWhatsappCallbackFeedback,
|
||||
WEEKLY_SEND_LABEL,
|
||||
weeklySendLabel,
|
||||
type WhatsappLinkMethod,
|
||||
type WhatsappCallbackFeedback,
|
||||
whatsappCallbackErrorMessage,
|
||||
|
||||
@@ -2,6 +2,8 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { useToast } from '../../components/ui'
|
||||
import { disconnectWhatsapp } from '../../lib/api'
|
||||
import { whatsappStatusQueryKey } from './useWhatsappStatus'
|
||||
import { errorMessage } from '../../i18n'
|
||||
import { i18n } from '../../i18n/instance'
|
||||
|
||||
export function useDisconnectWhatsapp() {
|
||||
const queryClient = useQueryClient()
|
||||
@@ -11,13 +13,13 @@ export function useDisconnectWhatsapp() {
|
||||
mutationFn: disconnectWhatsapp,
|
||||
onSuccess: (result) => {
|
||||
if (result.disconnected) {
|
||||
toast.success('Desvinculamos tu WhatsApp. Los envíos automáticos quedan en pausa.')
|
||||
toast.success(i18n.t('whatsapp:disconnect.done'))
|
||||
}
|
||||
void queryClient.invalidateQueries({ queryKey: whatsappStatusQueryKey })
|
||||
void queryClient.invalidateQueries({ queryKey: ['onboarding', 'status'] })
|
||||
},
|
||||
onError: (error: Error) => {
|
||||
toast.error(error.message || 'No pudimos desvincular tu WhatsApp.')
|
||||
toast.error(errorMessage(error, i18n.t('whatsapp:disconnect.error')))
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { requestWhatsappPairingCode } from '../../lib/api'
|
||||
import { errorMessage } from '../../i18n'
|
||||
import { i18n } from '../../i18n/instance'
|
||||
|
||||
/**
|
||||
* Pide el código para vincular con el número de teléfono. La vinculación ya
|
||||
@@ -13,7 +15,7 @@ export function useRequestWhatsappPairingCode() {
|
||||
requestCode: (phoneNumber: string) => mutation.mutate(phoneNumber),
|
||||
pairingCode: mutation.data?.pairingCode ?? null,
|
||||
isRequesting: mutation.isPending,
|
||||
error: mutation.error ? mutation.error.message || 'No pudimos pedir el código.' : null,
|
||||
error: mutation.error ? errorMessage(mutation.error, i18n.t('whatsapp:pairing.error')) : null,
|
||||
reset: mutation.reset,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { WhatsappReturnTo } from '@gruperly/shared'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { useState } from 'react'
|
||||
import { ApiError, startWhatsappConnection } from '../../lib/api'
|
||||
import { WHATSAPP_CONNECT_ERROR_MESSAGE, WHATSAPP_UNAVAILABLE_MESSAGE } from './copy'
|
||||
import { whatsappConnectErrorMessage, whatsappUnavailableMessage } from './copy'
|
||||
import { whatsappStatusQueryKey } from './useWhatsappStatus'
|
||||
|
||||
/**
|
||||
@@ -36,8 +36,8 @@ export function useStartWhatsappConnection() {
|
||||
} catch (caught) {
|
||||
setError(
|
||||
caught instanceof ApiError && caught.status === 503
|
||||
? WHATSAPP_UNAVAILABLE_MESSAGE
|
||||
: WHATSAPP_CONNECT_ERROR_MESSAGE,
|
||||
? whatsappUnavailableMessage()
|
||||
: whatsappConnectErrorMessage(),
|
||||
)
|
||||
}
|
||||
setIsStarting(false)
|
||||
|
||||
Reference in New Issue
Block a user