import { z } from "zod/v4"; import React, { useRef } from "react"; import { Button, Divider, Group, Modal, Stack, Textarea } from "@mantine/core"; import { useForm } from "@mantine/form"; import { zod4Resolver } from "mantine-form-zod-resolver"; import { useTranslation } from "react-i18next"; import { useActivateMutation } from "@/ee/licence/queries/license-query.ts"; import { useDisclosure } from "@mantine/hooks"; import { useAtom } from "jotai"; import { entitlementAtom } from "@/ee/entitlement/entitlement-atom"; import RemoveLicense from "@/ee/licence/components/remove-license.tsx"; export default function ActivateLicense() { const { t } = useTranslation(); const [opened, { open, close }] = useDisclosure(false); const [entitlements] = useAtom(entitlementAtom); const hasLicense = entitlements != null && entitlements.tier !== "free"; return ( {hasLicense && } ); } const formSchema = z.object({ licenseKey: z.string().min(1), }); type FormValues = z.infer; interface ActivateLicenseFormProps { onClose?: () => void; } export function ActivateLicenseForm({ onClose }: ActivateLicenseFormProps) { const { t } = useTranslation(); const activateLicenseMutation = useActivateMutation(); const fileInputRef = useRef(null); const form = useForm({ validate: zod4Resolver(formSchema), initialValues: { licenseKey: "", }, }); async function handleSubmit(data: { licenseKey: string }) { await activateLicenseMutation.mutateAsync(data.licenseKey); form.reset(); onClose?.(); } function handleFileUpload(event: React.ChangeEvent) { const file = event.target.files?.[0]; if (!file) return; const reader = new FileReader(); reader.onload = (e) => { const content = (e.target?.result as string)?.trim(); if (content) { form.setFieldValue("licenseKey", content); handleSubmit({ licenseKey: content }); } }; reader.readAsText(file); if (fileInputRef.current) { fileInputRef.current.value = ""; } } return (