import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { gdprApi } from '../../services/api'; import type { RepresentativeAuthorization } from '../../types'; import { FileCheck, ShieldCheck, ShieldAlert, FileText, } from 'lucide-react'; import Card from '../../components/ui/Card'; export default function PortalAuthorizations() { const queryClient = useQueryClient(); const { data: authData, isLoading } = useQuery({ queryKey: ['my-authorizations'], queryFn: () => gdprApi.getMyAuthorizations(), }); const toggleMutation = useMutation({ mutationFn: ({ representativeId, grant }: { representativeId: number; grant: boolean }) => gdprApi.toggleMyAuthorization(representativeId, grant), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['my-authorizations'] }); queryClient.invalidateQueries({ queryKey: ['my-authorization-status'] }); }, }); const authorizations: RepresentativeAuthorization[] = authData?.data || []; if (isLoading) { return
Laden...
; } return (

Vollmachten

Hier können Sie verwalten, welche Vertreter Zugriff auf Ihre Verträge und Daten haben. Ohne Ihre Vollmacht kann ein Vertreter Ihre Daten nicht einsehen.

{authorizations.length === 0 ? (
Keine Vollmachten vorhanden.
) : (
{authorizations.map((auth) => (
{auth.isGranted ? ( ) : ( )}

{auth.representative?.firstName} {auth.representative?.lastName}

{auth.isGranted ? 'Hat Vollmacht, Ihre Daten einzusehen' : 'Keine Vollmacht – kann Ihre Daten nicht einsehen' }

{auth.documentPath && (

Vollmacht liegt als Dokument vor

)} {auth.grantedAt && auth.isGranted && (

Erteilt am {new Date(auth.grantedAt).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit', })}

)}
))}
)} {toggleMutation.isError && (
Fehler beim Speichern. Bitte versuchen Sie es erneut.
)}
); }