mudanca requisicoes API do metodo PUT para POST e limpeza / organizacao dos códigos
This commit is contained in:
@@ -48,7 +48,7 @@ import {
|
||||
PaginationPrevious,
|
||||
} from "@/components/ui/pagination";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { userProfileService, FinancialIndicators, ExpenseItem, ExpensesResponse, ExpensesFilters, ExpenseCategory } from "@/services/userProfile";
|
||||
import { personalAgent, FinancialIndicators, ExpenseItem, ExpensesResponse, ExpensesFilters, ExpenseCategory } from "@/services/personalAgent";
|
||||
import { GlobalFunctions, TransferAreaProperties } from "@/GlobalFunctions";
|
||||
import { toast } from "@/hooks/use-toast";
|
||||
|
||||
@@ -175,7 +175,7 @@ export default function Financas() {
|
||||
}
|
||||
|
||||
// Busca os indicadores financeiros da API
|
||||
const response = await userProfileService.getFinancialIndicators(userEmail);
|
||||
const response = await personalAgent.getFinancialIndicators(userEmail);
|
||||
|
||||
if (response.success) {
|
||||
setIndicators(response);
|
||||
@@ -265,7 +265,7 @@ export default function Financas() {
|
||||
filters.data_final = format(endDate, "yyyy-MM-dd");
|
||||
}
|
||||
|
||||
const response = await userProfileService.getExpenses(emailToUse, filters);
|
||||
const response = await personalAgent.getExpenses(emailToUse, filters);
|
||||
|
||||
if (response.success) {
|
||||
// Garante que a resposta tenha estrutura válida mesmo quando não há dados
|
||||
@@ -308,8 +308,7 @@ export default function Financas() {
|
||||
// Carrega categorias
|
||||
try {
|
||||
setLoadingCategories(true);
|
||||
const categoriesData = await userProfileService.getCategories();
|
||||
console.log("Categorias carregadas:", categoriesData);
|
||||
const categoriesData = await personalAgent.getCategories();
|
||||
setCategories(categoriesData);
|
||||
} catch (error) {
|
||||
console.error("Erro ao carregar categorias:", error);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { GoogleCalendarCard } from "@/modules/intelligence-ia/components/integra
|
||||
import { GoogleSheetsCard } from "@/modules/intelligence-ia/components/integrations/GoogleSheetsCard";
|
||||
import { AsanaCard } from "@/modules/intelligence-ia/components/integrations/AsanaCard";
|
||||
import { asanaService } from "@/services/asana";
|
||||
import { userProfileService } from "@/services/userProfile";
|
||||
import { personalAgent } from "@/services/personalAgent";
|
||||
import { GlobalFunctions, TransferAreaProperties } from "@/GlobalFunctions";
|
||||
|
||||
interface Workspace {
|
||||
@@ -199,16 +199,14 @@ export default function Integrations() {
|
||||
}
|
||||
|
||||
if (!userEmail) {
|
||||
console.log("Integrations: Não foi possível obter email do usuário");
|
||||
setLoadingIntegration(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Busca o perfil do usuário para obter o ID
|
||||
const userProfile = await userProfileService.getUserProfile(userEmail);
|
||||
const userProfile = await personalAgent.getUserProfile(userEmail);
|
||||
|
||||
if (!userProfile.success || !userProfile.id) {
|
||||
console.log("Integrations: Usuário não encontrado ou sem ID");
|
||||
setLoadingIntegration(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
} from "@/components/ui/dialog";
|
||||
import { User, Mail, Phone, Save, Bell, Loader2, Plus } from "lucide-react";
|
||||
import { toast } from "@/hooks/use-toast";
|
||||
import { userProfileService, UserProfile } from "@/services/userProfile";
|
||||
import { personalAgent, UserProfile } from "@/services/personalAgent";
|
||||
import { GlobalFunctions, TransferAreaProperties } from "@/GlobalFunctions";
|
||||
|
||||
const formatPhoneNumber = (value: string) => {
|
||||
@@ -54,20 +54,15 @@ const MeuPerfil = () => {
|
||||
// Verifica se há token no sessionStorage primeiro
|
||||
const jsonUsuario = sessionStorage.getItem('usuarioLogado');
|
||||
if (!jsonUsuario) {
|
||||
console.log("MeuPerfil: Não há token no sessionStorage");
|
||||
window.location.replace(import.meta.env.VITE_BASE_URL_HGTX_CORE || 'https://core.hgtx.com.br');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("MeuPerfil: Token encontrado no sessionStorage");
|
||||
|
||||
// Tenta obter o email do usuário logado
|
||||
let userEmail = GlobalFunctions.getUsuarioLogado().email;
|
||||
console.log("MeuPerfil: Email obtido:", userEmail);
|
||||
|
||||
// Se não tem email, tenta fazer refresh do token
|
||||
if (!userEmail) {
|
||||
console.log("MeuPerfil: Email vazio, tentando fazer refresh do token");
|
||||
try {
|
||||
await GlobalFunctions.getToken();
|
||||
// Aguarda um pouco para o refresh ser processado (se necessário)
|
||||
@@ -75,7 +70,6 @@ const MeuPerfil = () => {
|
||||
|
||||
// Verifica novamente após refresh
|
||||
userEmail = GlobalFunctions.getUsuarioLogado().email;
|
||||
console.log("MeuPerfil: Email após refresh:", userEmail);
|
||||
} catch (error) {
|
||||
console.error("MeuPerfil: Erro ao obter token:", error);
|
||||
}
|
||||
@@ -85,24 +79,17 @@ const MeuPerfil = () => {
|
||||
// Se o token existe mas não tem email, pode ser problema na decodificação
|
||||
if (!userEmail) {
|
||||
const usuarioData = GlobalFunctions.getUsuarioLogado();
|
||||
console.log("MeuPerfil: Dados do usuário após tentativas:", usuarioData);
|
||||
|
||||
// Se não tem email mas tem token no sessionStorage, tenta carregar mesmo assim
|
||||
// O loadUserProfile vai tratar o erro adequadamente se o email for necessário
|
||||
// Só redireciona se o token estiver completamente inválido (sem UID e sem EID)
|
||||
if (!usuarioData.email && usuarioData.UID === "0" && usuarioData.EID === "0") {
|
||||
console.log("MeuPerfil: Token completamente inválido (sem UID/EID), redirecionando");
|
||||
window.location.replace(import.meta.env.VITE_BASE_URL_HGTX_CORE || 'https://core.hgtx.com.br');
|
||||
return;
|
||||
}
|
||||
|
||||
// Se tem token mas não tem email, pode ser que o email esteja em outro campo
|
||||
// ou o token precisa ser renovado. Tenta carregar o perfil mesmo assim.
|
||||
console.log("MeuPerfil: Token existe mas email vazio, tentando carregar perfil mesmo assim");
|
||||
}
|
||||
|
||||
// Se passou na verificação (ou tem token válido), carrega o perfil
|
||||
console.log("MeuPerfil: Carregando perfil do usuário");
|
||||
loadUserProfile();
|
||||
};
|
||||
|
||||
@@ -116,13 +103,11 @@ const MeuPerfil = () => {
|
||||
|
||||
// Se não tem email, tenta obter do Transfer Area como fallback
|
||||
if (!userEmail) {
|
||||
console.log("MeuPerfil: Email não encontrado no token, tentando Transfer Area");
|
||||
const transferEmail = GlobalFunctions.getTransferProperty(
|
||||
TransferAreaProperties.UsuarioEmail
|
||||
);
|
||||
if (transferEmail) {
|
||||
userEmail = transferEmail as string;
|
||||
console.log("MeuPerfil: Email do Transfer Area:", userEmail);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +117,6 @@ const MeuPerfil = () => {
|
||||
await GlobalFunctions.getToken();
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
userEmail = GlobalFunctions.getUsuarioLogado().email;
|
||||
console.log("MeuPerfil: Email após refresh no loadUserProfile:", userEmail);
|
||||
} catch (error) {
|
||||
console.error("MeuPerfil: Erro ao fazer refresh no loadUserProfile:", error);
|
||||
}
|
||||
@@ -151,7 +135,7 @@ const MeuPerfil = () => {
|
||||
}
|
||||
|
||||
setEmail(userEmail);
|
||||
const response = await userProfileService.getUserProfile(userEmail);
|
||||
const response = await personalAgent.getUserProfile(userEmail);
|
||||
|
||||
if (response.success && response.id) {
|
||||
// Usuário existe
|
||||
@@ -203,7 +187,7 @@ const MeuPerfil = () => {
|
||||
|
||||
try {
|
||||
setSaving(true);
|
||||
const response = await userProfileService.updateUser(userId, {
|
||||
const response = await personalAgent.updateUser(userId, {
|
||||
nome: nomeCompleto,
|
||||
whatsapp: whatsapp,
|
||||
followup: receberLembretes,
|
||||
@@ -255,7 +239,7 @@ const MeuPerfil = () => {
|
||||
|
||||
try {
|
||||
setCreating(true);
|
||||
const response = await userProfileService.createUser({
|
||||
const response = await personalAgent.createUser({
|
||||
nome: createNome.trim(),
|
||||
email: email,
|
||||
whatsapp: createWhatsapp,
|
||||
|
||||
Reference in New Issue
Block a user