diff --git a/license_ui/src/components/LicenseCode.module.css b/license_ui/src/components/LicenseCode.module.css index 29a03bf..e6fbca1 100644 --- a/license_ui/src/components/LicenseCode.module.css +++ b/license_ui/src/components/LicenseCode.module.css @@ -1,5 +1,6 @@ .container { flex-grow: 1; + overflow-y: hidden; } .license-code-area { flex-grow: 1; diff --git a/license_ui/src/components/LicenseCode.tsx b/license_ui/src/components/LicenseCode.tsx index cac2f70..062e26a 100644 --- a/license_ui/src/components/LicenseCode.tsx +++ b/license_ui/src/components/LicenseCode.tsx @@ -1,22 +1,34 @@ -import { useLicenseCode } from "@/hooks/use_license_code"; +import { useLicenseCodeStore } from "@/hooks/use_license_code_store"; import { ActionIcon, Box, Flex, Group, Paper, Title, Tooltip } from "@mantine/core"; +import { notifications } from "@mantine/notifications"; import { IconCopy } from "@tabler/icons-react"; +import { isEmpty, not } from "ramda"; import classes from "./LicenseCode.module.css"; export function LicenseCode() { - const [licenseCode] = useLicenseCode(); + const licenseCode = useLicenseCodeStore((state) => state.licenceCode); + const copyLicenseCode = async () => { + if (not(isEmpty(licenseCode))) { + await navigator.clipboard.writeText(licenseCode); + notifications.show({ + title: "授权码已复制", + color: "green", + }); + } + }; + return ( - + 授权码 - + - + {licenseCode} diff --git a/license_ui/src/components/LicenseForm.tsx b/license_ui/src/components/LicenseForm.tsx index 80d5435..c0e31bb 100644 --- a/license_ui/src/components/LicenseForm.tsx +++ b/license_ui/src/components/LicenseForm.tsx @@ -1,63 +1,104 @@ +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 { pluck } from "ramda"; - -const licenseValidLength = [ - { value: 1, label: "一年" }, - { value: 2, label: "两年" }, - { value: 3, label: "三年" }, - { value: 4, label: "四年" }, - { value: 5, label: "五年" }, - { value: 6, label: "六年" }, - { value: 7, label: "七年" }, - { value: 8, label: "八年" }, - { value: 9, label: "九年" }, - { value: 10, label: "十年" }, - { value: 15, label: "十五年" }, - { value: 20, label: "二十年" }, - { value: 25, label: "二十五年" }, - { value: 30, label: "三十年" }, - { value: 35, label: "三十五年" }, - { value: 40, label: "四十年" }, - { value: 45, label: "四十五年" }, - { value: 50, label: "五十年" }, -]; +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")} />