fix: include missing files for tenant impersonation feature
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m7s

- Added backend impersonate endpoint.

- Added frontend impersonate button and functions.

- Fixed build failure by including missing exported functions in dataService.ts.
This commit is contained in:
Cauê Faleiros
2026-03-11 14:16:41 -03:00
parent b7f9efd0d1
commit bff54def9f
3 changed files with 94 additions and 4 deletions

View File

@@ -1,13 +1,16 @@
import React, { useState, useMemo } from 'react';
import { useNavigate } from 'react-router-dom';
import {
Building2, Users, MessageSquare, Plus, Search,
Edit, Trash2, ChevronDown, ChevronUp, ChevronsUpDown, X, CheckCircle2, Loader2
} from 'lucide-react';import { getTenants, createTenant, deleteTenant, updateTenant } from '../services/dataService';
Edit, Trash2, ChevronDown, ChevronUp, ChevronsUpDown, X, CheckCircle2, Loader2, LogIn
} from 'lucide-react';
import { getTenants, createTenant, deleteTenant, updateTenant, impersonateTenant } from '../services/dataService';
import { Tenant } from '../types';
import { DateRangePicker } from '../components/DateRangePicker';
import { KPICard } from '../components/KPICard';
export const SuperAdmin: React.FC = () => {
const navigate = useNavigate();
const [dateRange, setDateRange] = useState({
start: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000),
end: new Date()
@@ -90,6 +93,20 @@ export const SuperAdmin: React.FC = () => {
}
};
const handleImpersonate = async (tenantId: string) => {
try {
if (tenantId === 'system') {
alert('Você já está na organização do sistema.');
return;
}
await impersonateTenant(tenantId);
// Force a full reload to clear any cached context/state in the React app
window.location.href = '/';
} catch (err: any) {
alert(err.message || 'Erro ao tentar entrar na organização.');
}
};
const [successMessage, setSuccessMessage] = useState('');
const [errorMessage, setErrorMessage] = useState('');
const [isSaving, setIsSaving] = useState(false);
@@ -232,8 +249,13 @@ export const SuperAdmin: React.FC = () => {
<td className="px-6 py-4 text-center font-medium text-zinc-700 dark:text-zinc-300">{tenant.attendance_count?.toLocaleString()}</td>
<td className="px-6 py-4 text-right">
<div className="flex items-center justify-end gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
<button onClick={() => handleEdit(tenant)} className="p-2 text-zinc-400 hover:text-brand-yellow hover:bg-zinc-50 dark:hover:bg-dark-bg rounded-lg transition-colors"><Edit size={16} /></button>
<button onClick={() => handleDelete(tenant.id)} className="p-2 text-zinc-400 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900/30 rounded-lg transition-colors"><Trash2 size={16} /></button>
{tenant.id !== 'system' && (
<button onClick={() => handleImpersonate(tenant.id)} title="Entrar na Organização" className="p-2 text-zinc-400 hover:text-green-600 hover:bg-green-50 dark:hover:bg-green-900/30 rounded-lg transition-colors">
<LogIn size={16} />
</button>
)}
<button onClick={() => handleEdit(tenant)} title="Editar" className="p-2 text-zinc-400 hover:text-brand-yellow hover:bg-zinc-50 dark:hover:bg-dark-bg rounded-lg transition-colors"><Edit size={16} /></button>
<button onClick={() => handleDelete(tenant.id)} title="Excluir" className="p-2 text-zinc-400 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900/30 rounded-lg transition-colors"><Trash2 size={16} /></button>
</div>
</td>
</tr>