feat: redesign superadmin agencies list, implement flat design, add date filters, and fix UI bugs

This commit is contained in:
Erik Silva
2025-12-11 23:39:54 -03:00
parent 053e180321
commit dc98d5dccc
129 changed files with 20730 additions and 1611 deletions

View File

@@ -0,0 +1,56 @@
/**
* API Configuration - URLs e funções de requisição
*/
// URL base da API - pode ser alterada por variável de ambiente
export const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || 'http://api.localhost';
/**
* Endpoints da API
*/
export const API_ENDPOINTS = {
// Auth
register: `${API_BASE_URL}/api/auth/register`,
login: `${API_BASE_URL}/api/auth/login`,
logout: `${API_BASE_URL}/api/auth/logout`,
refresh: `${API_BASE_URL}/api/auth/refresh`,
me: `${API_BASE_URL}/api/me`,
// Admin / Agencies
adminAgencyRegister: `${API_BASE_URL}/api/admin/agencies/register`,
// Health
health: `${API_BASE_URL}/health`,
apiHealth: `${API_BASE_URL}/api/health`,
} as const;
/**
* Wrapper para fetch com tratamento de erros
*/
export async function apiRequest<T = any>(
url: string,
options?: RequestInit
): Promise<T> {
try {
const response = await fetch(url, {
...options,
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.message || `Erro ${response.status}`);
}
return data;
} catch (error) {
if (error instanceof Error) {
throw error;
}
throw new Error('Erro desconhecido na requisição');
}
}

View File

@@ -0,0 +1,79 @@
/**
* Auth utilities - Gerenciamento de autenticação no cliente
*/
export interface User {
id: string;
email: string;
name: string;
role: string;
tenantId?: string;
company?: string;
subdomain?: string;
}
const TOKEN_KEY = 'token';
const USER_KEY = 'user';
/**
* Salva token e dados do usuário no localStorage
*/
export function saveAuth(token: string, user: User): void {
if (typeof window === 'undefined') return;
localStorage.setItem(TOKEN_KEY, token);
localStorage.setItem(USER_KEY, JSON.stringify(user));
}
/**
* Retorna o token JWT armazenado
*/
export function getToken(): string | null {
if (typeof window === 'undefined') return null;
return localStorage.getItem(TOKEN_KEY);
}
/**
* Retorna os dados do usuário armazenados
*/
export function getUser(): User | null {
if (typeof window === 'undefined') return null;
const userStr = localStorage.getItem(USER_KEY);
if (!userStr) return null;
try {
return JSON.parse(userStr);
} catch {
return null;
}
}
/**
* Verifica se o usuário está autenticado
*/
export function isAuthenticated(): boolean {
return !!getToken() && !!getUser();
}
/**
* Remove token e dados do usuário (logout)
*/
export function clearAuth(): void {
if (typeof window === 'undefined') return;
localStorage.removeItem(TOKEN_KEY);
localStorage.removeItem(USER_KEY);
}
/**
* Retorna headers com Authorization para requisições autenticadas
*/
export function getAuthHeaders(): HeadersInit {
const token = getToken();
return {
'Content-Type': 'application/json',
...(token ? { 'Authorization': `Bearer ${token}` } : {}),
};
}