PERF: Alterado Paths e variaveis para uso do env
This commit is contained in:
parent
2229a29af1
commit
bff4e18094
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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 = [
|
||||
|
||||
@ -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' },
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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}`, {
|
||||
|
||||
@ -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);
|
||||
|
||||
2
src/shared/services/apiConfig.js
Normal file
2
src/shared/services/apiConfig.js
Normal file
@ -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`;
|
||||
Loading…
Reference in New Issue
Block a user