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) {
|
async function parseJsonResponse(response) {
|
||||||
const data = await response.json().catch(() => null);
|
const data = await response.json().catch(() => null);
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { useWhatsappSocket } from '../../../shared/hooks/useWhatsappSocket';
|
import { useWhatsappSocket } from '../../../shared/hooks/useWhatsappSocket';
|
||||||
|
import { API_BASE_URL } from '../../../shared/services/apiConfig';
|
||||||
import {
|
import {
|
||||||
attendantsByArea,
|
attendantsByArea,
|
||||||
chatContacts,
|
chatContacts,
|
||||||
transferAreas,
|
transferAreas,
|
||||||
} from '../services/chatMocks';
|
} from '../services/chatMocks';
|
||||||
|
|
||||||
const API_BASE_URL = 'http://localhost:3001';
|
|
||||||
|
|
||||||
function buildInitialMessages() {
|
function buildInitialMessages() {
|
||||||
return chatContacts.reduce((acc, contact) => {
|
return chatContacts.reduce((acc, contact) => {
|
||||||
acc[contact.id] = contact.messages;
|
acc[contact.id] = contact.messages;
|
||||||
|
|||||||
@ -3,6 +3,8 @@ export const sidebarItems = [
|
|||||||
{ id: 'personal-reports', label: 'Relatorios pessoais' },
|
{ id: 'personal-reports', label: 'Relatorios pessoais' },
|
||||||
{ id: 'mass-message', label: 'Disparo em massa' },
|
{ id: 'mass-message', label: 'Disparo em massa' },
|
||||||
{ id: 'knowledge-base', label: 'Base de conhecimento' },
|
{ id: 'knowledge-base', label: 'Base de conhecimento' },
|
||||||
|
{ id: 'completed', label: 'Finalizados', count: 24 },
|
||||||
|
{ id: 'contacts', label: 'Contatos', count: 128 },
|
||||||
];
|
];
|
||||||
|
|
||||||
export const conversations = [
|
export const conversations = [
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import { MetricGrid } from '../components/MetricGrid';
|
|||||||
import { areaRows, queueRows, supervisorMetrics } from '../services/managementMocks';
|
import { areaRows, queueRows, supervisorMetrics } from '../services/managementMocks';
|
||||||
import { useViewport } from '../../../shared/hooks/useViewport';
|
import { useViewport } from '../../../shared/hooks/useViewport';
|
||||||
import { getCurrentUserDisplay } from '../../auth/services/sessionService';
|
import { getCurrentUserDisplay } from '../../auth/services/sessionService';
|
||||||
|
import { API_BASE_URL } from '../../../shared/services/apiConfig';
|
||||||
|
|
||||||
const queueColumns = [
|
const queueColumns = [
|
||||||
{ key: 'customer', label: 'Cliente' },
|
{ key: 'customer', label: 'Cliente' },
|
||||||
@ -51,7 +52,7 @@ export function SupervisorPage() {
|
|||||||
|
|
||||||
const fetchTemplates = async () => {
|
const fetchTemplates = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch('http://localhost:3001/whatsapp/templates');
|
const res = await fetch(`${API_BASE_URL}/whatsapp/templates`);
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
setTemplates(data);
|
setTemplates(data);
|
||||||
@ -77,8 +78,8 @@ export function SupervisorPage() {
|
|||||||
if (!editName || !editContent) return;
|
if (!editName || !editContent) return;
|
||||||
try {
|
try {
|
||||||
const url = editingTemplate
|
const url = editingTemplate
|
||||||
? `http://localhost:3001/whatsapp/templates/update/${editingTemplate.id}`
|
? `${API_BASE_URL}/whatsapp/templates/update/${editingTemplate.id}`
|
||||||
: 'http://localhost:3001/whatsapp/templates';
|
: `${API_BASE_URL}/whatsapp/templates`;
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { io } from 'socket.io-client';
|
import { io } from 'socket.io-client';
|
||||||
|
import { API_BASE_URL, WHATSAPP_SOCKET_URL } from '../../../shared/services/apiConfig';
|
||||||
|
|
||||||
export const WhatsappAdminPage = () => {
|
export const WhatsappAdminPage = () => {
|
||||||
const [qrCode, setQrCode] = useState(null);
|
const [qrCode, setQrCode] = useState(null);
|
||||||
@ -7,11 +8,11 @@ export const WhatsappAdminPage = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Conecta ao namespace /whatsapp
|
// Conecta ao namespace /whatsapp
|
||||||
const socket = io('http://localhost:3001/whatsapp');
|
const socket = io(WHATSAPP_SOCKET_URL);
|
||||||
|
|
||||||
socket.on('connect', () => {
|
socket.on('connect', () => {
|
||||||
console.log('Connected to WhatsApp WebSocket');
|
console.log('Connected to WhatsApp WebSocket');
|
||||||
fetch('http://localhost:3001/whatsapp/status')
|
fetch(`${API_BASE_URL}/whatsapp/status`)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => setStatus(data.status))
|
.then((data) => setStatus(data.status))
|
||||||
.catch(console.error);
|
.catch(console.error);
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
const API_BASE_URL =
|
import { API_BASE_URL } from '../../../shared/services/apiConfig';
|
||||||
import.meta.env.VITE_API_BASE_URL || import.meta.env.VITE_API_URL || 'http://localhost:3001';
|
|
||||||
|
|
||||||
async function request(path, options = {}) {
|
async function request(path, options = {}) {
|
||||||
const response = await fetch(`${API_BASE_URL}${path}`, {
|
const response = await fetch(`${API_BASE_URL}${path}`, {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { useEffect, useState, useRef } from 'react';
|
import { useEffect, useState, useRef } from 'react';
|
||||||
import io from 'socket.io-client';
|
import io from 'socket.io-client';
|
||||||
|
import { API_BASE_URL, WHATSAPP_SOCKET_URL } from '../services/apiConfig';
|
||||||
|
|
||||||
export function useWhatsappSocket() {
|
export function useWhatsappSocket() {
|
||||||
const [socket, setSocket] = useState(null);
|
const [socket, setSocket] = useState(null);
|
||||||
@ -13,7 +14,7 @@ export function useWhatsappSocket() {
|
|||||||
if (socketRef.current) return;
|
if (socketRef.current) return;
|
||||||
|
|
||||||
// Conectar ao namespace /whatsapp
|
// Conectar ao namespace /whatsapp
|
||||||
const newSocket = io('http://localhost:3001/whatsapp', {
|
const newSocket = io(WHATSAPP_SOCKET_URL, {
|
||||||
reconnectionAttempts: 5,
|
reconnectionAttempts: 5,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ export function useWhatsappSocket() {
|
|||||||
newSocket.on('connect', () => {
|
newSocket.on('connect', () => {
|
||||||
console.log('Conectado ao WebSocket do WhatsApp');
|
console.log('Conectado ao WebSocket do WhatsApp');
|
||||||
// Fetch status atual
|
// Fetch status atual
|
||||||
fetch('http://localhost:3001/whatsapp/status')
|
fetch(`${API_BASE_URL}/whatsapp/status`)
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(data => setStatus(data.status))
|
.then(data => setStatus(data.status))
|
||||||
.catch(console.error);
|
.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