diff --git a/src/modules/auth/services/authService.js b/src/modules/auth/services/authService.js index 1dde66f..5061ae1 100644 --- a/src/modules/auth/services/authService.js +++ b/src/modules/auth/services/authService.js @@ -1,4 +1,4 @@ -const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:3001'; +import { API_BASE_URL } from '../../../shared/services/apiConfig'; async function parseJsonResponse(response) { const data = await response.json().catch(() => null); diff --git a/src/modules/chat/hooks/useChat.js b/src/modules/chat/hooks/useChat.js index f614190..47bbcb3 100644 --- a/src/modules/chat/hooks/useChat.js +++ b/src/modules/chat/hooks/useChat.js @@ -1,13 +1,12 @@ import { useEffect, useMemo, useRef, useState } from 'react'; import { useWhatsappSocket } from '../../../shared/hooks/useWhatsappSocket'; +import { API_BASE_URL } from '../../../shared/services/apiConfig'; import { attendantsByArea, chatContacts, transferAreas, } from '../services/chatMocks'; -const API_BASE_URL = 'http://localhost:3001'; - function buildInitialMessages() { return chatContacts.reduce((acc, contact) => { acc[contact.id] = contact.messages; diff --git a/src/modules/home/services/homeMocks.js b/src/modules/home/services/homeMocks.js index ea7614a..6edba4b 100644 --- a/src/modules/home/services/homeMocks.js +++ b/src/modules/home/services/homeMocks.js @@ -3,6 +3,8 @@ export const sidebarItems = [ { id: 'personal-reports', label: 'Relatorios pessoais' }, { id: 'mass-message', label: 'Disparo em massa' }, { id: 'knowledge-base', label: 'Base de conhecimento' }, + { id: 'completed', label: 'Finalizados', count: 24 }, + { id: 'contacts', label: 'Contatos', count: 128 }, ]; export const conversations = [ diff --git a/src/modules/management/pages/SupervisorPage.jsx b/src/modules/management/pages/SupervisorPage.jsx index acf6365..eb9d3e3 100644 --- a/src/modules/management/pages/SupervisorPage.jsx +++ b/src/modules/management/pages/SupervisorPage.jsx @@ -6,6 +6,7 @@ import { MetricGrid } from '../components/MetricGrid'; import { areaRows, queueRows, supervisorMetrics } from '../services/managementMocks'; import { useViewport } from '../../../shared/hooks/useViewport'; import { getCurrentUserDisplay } from '../../auth/services/sessionService'; +import { API_BASE_URL } from '../../../shared/services/apiConfig'; const queueColumns = [ { key: 'customer', label: 'Cliente' }, @@ -51,7 +52,7 @@ export function SupervisorPage() { const fetchTemplates = async () => { try { - const res = await fetch('http://localhost:3001/whatsapp/templates'); + const res = await fetch(`${API_BASE_URL}/whatsapp/templates`); if (res.ok) { const data = await res.json(); setTemplates(data); @@ -77,8 +78,8 @@ export function SupervisorPage() { if (!editName || !editContent) return; try { const url = editingTemplate - ? `http://localhost:3001/whatsapp/templates/update/${editingTemplate.id}` - : 'http://localhost:3001/whatsapp/templates'; + ? `${API_BASE_URL}/whatsapp/templates/update/${editingTemplate.id}` + : `${API_BASE_URL}/whatsapp/templates`; const res = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, diff --git a/src/modules/management/pages/WhatsappAdminPage.jsx b/src/modules/management/pages/WhatsappAdminPage.jsx index 7d75059..6f252d6 100644 --- a/src/modules/management/pages/WhatsappAdminPage.jsx +++ b/src/modules/management/pages/WhatsappAdminPage.jsx @@ -1,5 +1,6 @@ import React, { useEffect, useState } from 'react'; import { io } from 'socket.io-client'; +import { API_BASE_URL, WHATSAPP_SOCKET_URL } from '../../../shared/services/apiConfig'; export const WhatsappAdminPage = () => { const [qrCode, setQrCode] = useState(null); @@ -7,11 +8,11 @@ export const WhatsappAdminPage = () => { useEffect(() => { // Conecta ao namespace /whatsapp - const socket = io('http://localhost:3001/whatsapp'); + const socket = io(WHATSAPP_SOCKET_URL); socket.on('connect', () => { console.log('Connected to WhatsApp WebSocket'); - fetch('http://localhost:3001/whatsapp/status') + fetch(`${API_BASE_URL}/whatsapp/status`) .then((response) => response.json()) .then((data) => setStatus(data.status)) .catch(console.error); diff --git a/src/modules/management/services/adminAccessService.js b/src/modules/management/services/adminAccessService.js index 86a2573..6fb83ea 100644 --- a/src/modules/management/services/adminAccessService.js +++ b/src/modules/management/services/adminAccessService.js @@ -1,5 +1,4 @@ -const API_BASE_URL = - import.meta.env.VITE_API_BASE_URL || import.meta.env.VITE_API_URL || 'http://localhost:3001'; +import { API_BASE_URL } from '../../../shared/services/apiConfig'; async function request(path, options = {}) { const response = await fetch(`${API_BASE_URL}${path}`, { diff --git a/src/shared/hooks/useWhatsappSocket.js b/src/shared/hooks/useWhatsappSocket.js index 26b4b09..b150c9a 100644 --- a/src/shared/hooks/useWhatsappSocket.js +++ b/src/shared/hooks/useWhatsappSocket.js @@ -1,5 +1,6 @@ import { useEffect, useState, useRef } from 'react'; import io from 'socket.io-client'; +import { API_BASE_URL, WHATSAPP_SOCKET_URL } from '../services/apiConfig'; export function useWhatsappSocket() { const [socket, setSocket] = useState(null); @@ -13,7 +14,7 @@ export function useWhatsappSocket() { if (socketRef.current) return; // Conectar ao namespace /whatsapp - const newSocket = io('http://localhost:3001/whatsapp', { + const newSocket = io(WHATSAPP_SOCKET_URL, { reconnectionAttempts: 5, }); @@ -23,7 +24,7 @@ export function useWhatsappSocket() { newSocket.on('connect', () => { console.log('Conectado ao WebSocket do WhatsApp'); // Fetch status atual - fetch('http://localhost:3001/whatsapp/status') + fetch(`${API_BASE_URL}/whatsapp/status`) .then(res => res.json()) .then(data => setStatus(data.status)) .catch(console.error); diff --git a/src/shared/services/apiConfig.js b/src/shared/services/apiConfig.js new file mode 100644 index 0000000..80d583e --- /dev/null +++ b/src/shared/services/apiConfig.js @@ -0,0 +1,2 @@ +export const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:3001'; +export const WHATSAPP_SOCKET_URL = `${API_BASE_URL}/whatsapp`;