EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
ImpersonationAuditTable.jsx
Go to the documentation of this file.
1import React, { useEffect, useState } from 'react';
2import PropTypes from 'prop-types';
3import { apiFetch } from '../../lib/api';
4
5function ImpersonationAuditTable({ tenantId }) {
6 const [logs, setLogs] = useState([]);
7 const [loading, setLoading] = useState(true);
8 const [error, setError] = useState(null);
9
10 useEffect(() => {
11 async function fetchLogs() {
12 setLoading(true);
13 setError(null);
14 try {
15 const res = await apiFetch(`/tenants/${tenantId}/impersonation-audit`);
16 if (res.ok) {
17 const data = await res.json();
18 setLogs(data.logs || []);
19 } else {
20 setError('Failed to fetch audit logs');
21 }
22 } catch (err) {
23 setError('Error fetching audit logs');
24 }
25 setLoading(false);
26 }
27 if (tenantId) fetchLogs();
28 }, [tenantId]);
29
30 if (loading) return <div>Loading impersonation logs...</div>;
31 if (error) return <div style={{ color: 'red' }}>{error}</div>;
32 if (!logs.length) return <div>No impersonation activity found.</div>;
33
34 return (
35 <table className="impersonation-audit-table">
36 <thead>
37 <tr>
38 <th>Timestamp</th>
39 <th>Impersonator</th>
40 <th>Action</th>
41 <th>IP Address</th>
42 <th>User Agent</th>
43 </tr>
44 </thead>
45 <tbody>
46 {logs.map(log => (
47 <tr key={log.audit_id}>
48 <td>{new Date(log.timestamp).toLocaleString()}</td>
49 <td>{log.impersonator_name || log.impersonator_id}</td>
50 <td>{log.action}</td>
51 <td>{log.ip_address}</td>
52 <td>{log.user_agent}</td>
53 </tr>
54 ))}
55 </tbody>
56 </table>
57 );
58}
59
60ImpersonationAuditTable.propTypes = {
61 tenantId: PropTypes.string.isRequired,
62};
63
64export default ImpersonationAuditTable;