'use client'; import { useMutation, useQuery } from '@tanstack/react-query'; import { useRef, useState } from 'react'; import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { useT } from '@/i18n/t'; import { api } from '@/lib/api'; import { authClient } from '@/lib/auth-client'; /** * "Tus datos", the trust section of FLOWS.md E3: what we hold, the consent behind it, * and the two ways to take it back. The export is a plain link so the browser downloads * it; deletion is a native dialog that will not proceed until the email is typed out. */ export function DangerZone() { const t = useT(); const dialog = useRef(null); const [confirmText, setConfirmText] = useState(''); const session = useQuery({ queryKey: ['session'], queryFn: async () => (await authClient.getSession()).data, }); const email = session.data?.user.email ?? ''; const revoke = useMutation({ mutationFn: () => api.postConsent({ kind: 'data_processing', granted: false }), onSuccess: () => window.location.assign('/'), }); const remove = useMutation({ mutationFn: () => api.deleteAccount({ confirmText }), onSuccess: () => window.location.assign('/'), }); return (

{t('profile.myData.title')}

{t('profile.myData.body')}

{t('profile.myData.stored')}

{/* A plain link, not a fetch: the browser saves the file and the API sets the name. */} {t('profile.myData.export')}

{t('profile.consent.revokeWarn')}

{t('profile.myData.deleteWarn')}

{t('profile.myData.delete')}

{t('profile.myData.deleteWarn')}

setConfirmText(event.target.value)} />
{remove.isError ? (

{t('common.error.generic')}

) : null}
); }