"use client" import { useLocale, useTranslations } from "next-intl"; import type { Consent } from "@/types"; import { Item, ItemActions, ItemContent, ItemDescription, ItemTitle } from "@/components/ui/item"; import { Button } from "@/components/ui/button"; import { Spinner } from "@/components/ui/spinner"; import { localeMap } from "@/types"; import { enUS } from "date-fns/locale"; import { format } from "date-fns"; import { revokeConsent } from "@/actions/consents"; import { useState } from "react"; import { toast } from "sonner"; import { Check, X } from "lucide-react"; interface Props { consents: Consent[] | null; setConsents: (consents: Consent[]) => void; } export default function Consents({ consents, setConsents }: Props) { const t = useTranslations("MePage.items.consents"); const [list, setList] = useState(consents); const [revokingId, setRevokingId] = useState(null); const locale = useLocale(); const dateLocale = localeMap[locale as keyof typeof localeMap] ?? enUS; const handleRevoke = async (clientId: string) => { if (revokingId) return; setRevokingId(clientId); try { const result = await revokeConsent(clientId); if (result.success) { const updated = list?.filter((c) => c.client_id !== clientId) ?? []; setList(updated); setConsents(updated); toast(t("successfullyRevoked"), { icon: }); } else { toast(t("revocationError"), { icon: }); } } catch { toast(t("revocationError"), { icon: }); } finally { setRevokingId(null); } }; return (

{t("title")}

{t("subtitle")}

{list?.map((consent) => ( {consent.client_name} {t("authorized")}{" "} {format(consent.authorized_at, "PPP", { locale: dateLocale })} ))} {list == null &&

{t("noConsents")}

}
); }