import { licenseValidLength } from "@/constants"; import { useLicenseCodeStore } from "@/hooks/use_license_code_store"; import { useProductsStore } from "@/hooks/use_products_store"; import type { LicenseInfoForm } from "@/types"; import { Button, Flex, Group, Paper, Select, TextInput, Title } from "@mantine/core"; import { useForm } from "@mantine/form"; import { notifications } from "@mantine/notifications"; import { IconAt, IconCalendar, IconTag, IconUser } from "@tabler/icons-react"; import dayjs from "dayjs"; import { find, isEmpty, pluck, prop, propEq } from "ramda"; import { useCallback } from "react"; export function LicenseForm() { const form = useForm({ initialValues: { licenseName: "", assigneeName: "", assigneeEmail: "", validLength: licenseValidLength[0].label, }, validate: { licenseName: (value) => (isEmpty(value) ? "授权名称不能为空" : null), assigneeName: (value) => (isEmpty(value) ? "被授权人不能为空" : null), }, }); const selectedProducts = useProductsStore((state) => state.selectedProducts); const updateLicenseCode = useLicenseCodeStore((state) => state.setLicenseCode); const licenseGenAction = useCallback( async (formValue: LicenseInfoForm) => { const license = await generateLicense(formValue, selectedProducts); updateLicenseCode(license); }, [selectedProducts, updateLicenseCode] ); return (
授权信息 } {...form.getInputProps("licenseName")} /> } {...form.getInputProps("assigneeName")} /> } {...form.getInputProps("assigneeEmail")} />