import { useEffect } from 'react' import { Button, cn, Dialog, DialogContent, DialogFooter, DialogHeader, DialogSection, DialogSectionSeparator, DialogTitle, Form, } from 'ui' import { Admonition } from 'ui-patterns/Admonition' import { AIOptInLevelSelector } from '@/components/interfaces/Organization/GeneralSettings/AIOptInLevelSelector' import { useAIOptInForm } from '@/hooks/forms/useAIOptInForm' import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2' import type { AiOptInLevel } from '@/hooks/misc/useOrgOptedIntoAi' import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization' import { isOptInLevelAtLeast } from '@/lib/ai/opt-in-level' interface AIOptInModalProps { visible: boolean onCancel: () => void /** The level the Assistant asked for. Shows it as proposed. */ requiredLevel?: AiOptInLevel /** Called after the level is saved. */ onSaved?: (level: AiOptInLevel) => void } export const AIOptInModal = ({ visible, onCancel, requiredLevel, onSaved }: AIOptInModalProps) => { const { data: organization } = useSelectedOrganizationQuery() const { form, onSubmit, isUpdating, currentOptInLevel } = useAIOptInForm((level) => { onSaved?.(level) onCancel() }) const { can: canUpdateOrganization } = useAsyncCheckPermissionsV2( FGA_PERMISSIONS.ORGANIZATION.ADMIN_WRITE ) const onOpenChange = (open: boolean) => { if (!open) { onCancel() } } const proposedLevel = requiredLevel && !isOptInLevelAtLeast(currentOptInLevel, requiredLevel) ? requiredLevel : undefined useEffect(() => { if (visible) { form.reset({ aiOptInLevel: currentOptInLevel }) } }, [visible, currentOptInLevel, form]) return (
Update Supabase Assistant Opt-in Level {!canUpdateOrganization && (

You need additional permissions to update the opt-in level

)}
) }