'use client'; // Modal shown the first time a plugin is enabled, listing every permission // the plugin's manifest declares. Accepting persists the grant on the // plugin record so future enables skip the prompt. import React, { useId, useSyncExternalStore } from 'react'; import { useTranslations } from 'next-intl'; import { head, resolveHead, subscribe } from '@/lib/plugin-sandbox/consent'; import { HIGH_RISK_PERMISSIONS } from '@/lib/plugin-sandbox/permission-text'; import { useFocusTrap } from '@/hooks/use-focus-trap'; import { Button } from '@/components/ui/button'; import { PluginPermissionList } from './plugin-permission-list'; export function PluginConsentDialog(): React.JSX.Element | null { const current = useSyncExternalStore(subscribe, head, () => null); const t = useTranslations('plugins.consent'); const id = useId(); const dialogRef = useFocusTrap({ isActive: !!current, onEscape: () => resolveHead(false), restoreFocus: true, }); if (!current) return null; const risky = current.permissions.some((p) => HIGH_RISK_PERMISSIONS.has(p)); return (
{ if (e.target === e.currentTarget) resolveHead(false); }} >

{t('title', { name: current.pluginName })}

{t('intro')}

{risky && (

{t('high_risk_note')}

)}
{t('revoke_hint')}
); }