Update telephone page: Added whatsapp integration
Deploy Frontend / build-and-deploy (push) Successful in 42s Details

This commit is contained in:
romanskijdev 2026-10-27 21:35:49 +03:00
parent f01687849b
commit ac2d2e3ddb
1 changed files with 16 additions and 9 deletions

View File

@ -181,7 +181,6 @@ function TelegramTab() {
)
}
// 4. НОВОЕ: Модальное окно для подключения WhatsApp (только по QR)
function AddWhatsappModal({ opened, onClose }: { opened: boolean, onClose: () => void }) {
const [qrData, setQrData] = useState<{ token: string, img: string } | null>(null)
const pollingIntervalRef = useRef<number | null>(null)
@ -191,10 +190,10 @@ function AddWhatsappModal({ opened, onClose }: { opened: boolean, onClose: () =>
stopPolling()
try {
const res = await whatsappManagersApi.startQr()
setQrData({ token: res.data.token, img: res.data.qr })
setQrData({ token: res.data.token, img: '' })
startPolling(res.data.token)
} catch (error) {
notifications.show({ title: 'Ошибка', message: 'Не удалось загрузить QR-код', color: 'red' })
notifications.show({ title: 'Ошибка', message: 'Не удалось запустить сессию', color: 'red' })
}
}
@ -202,20 +201,24 @@ function AddWhatsappModal({ opened, onClose }: { opened: boolean, onClose: () =>
pollingIntervalRef.current = window.setInterval(async () => {
try {
const res = await whatsappManagersApi.checkQrStatus(token)
if (res.data.status === 'success') {
if (res.data.status === 'pending' && res.data.qr) {
setQrData(prev => prev ? { ...prev, img: res.data.qr } : null)
}
else if (res.data.status === 'success') {
stopPolling()
notifications.show({ title: 'Успешно', message: 'WhatsApp успешно подключен!', color: 'green' })
queryClient.invalidateQueries({ queryKey: ['whatsapp-managers-status'] })
onClose()
} else if (res.data.status === 'failed') {
}
else if (res.data.status === 'failed') {
stopPolling()
notifications.show({ title: 'Ошибка', message: res.data.error || 'Ошибка сканирования', color: 'red' })
setQrData(null) // Сброс для возможности повторной генерации
setQrData(null)
}
} catch (err) {
// Игнорируем сетевые ошибки поллинга
}
}, 3000)
}, 2000)
}
const stopPolling = () => {
@ -238,7 +241,11 @@ function AddWhatsappModal({ opened, onClose }: { opened: boolean, onClose: () =>
Откройте WhatsApp на телефоне: <br/><b>Настройки → Связанные устройства → Привязка устройства</b>
</Text>
<Center style={{ width: 250, height: 250, border: '1px solid var(--mantine-color-gray-3)', borderRadius: 8 }}>
{qrData ? <Image src={qrData.img} w={230} h={230} fit="contain" /> : <Loader />}
{qrData?.img ? (
<Image src={qrData.img} w={230} h={230} fit="contain" />
) : (
<Loader />
)}
</Center>
{qrData && <Loader type="dots" size="sm" />}
</Stack>