"use client"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; import { z } from "zod"; import { useToast } from "./hooks/use-toast"; import { invoke } from "@tauri-apps/api/core"; import { useNavigate } from "react-router-dom"; import { Button } from "@/components/ui/button"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { Checkbox } from "@/components/ui/checkbox"; import { validate_password, open_website } from "./global"; import { TermsConditions } from "./terms"; import { PrivacyPolicy } from "./privacy"; import { Dialog, DialogTrigger, DialogOverlay } from "@/components/ui/dialog"; async function validate_license(license: string): Promise { const isValid: boolean = await invoke("validate_license", { license: license, }); return new Promise((resolve) => { setTimeout(() => { resolve(isValid); }, 1000); }); } async function validate_username(username: string): Promise { const isValid: boolean = await invoke("validate_username", { username: username, }); return new Promise((resolve) => { setTimeout(() => { resolve(isValid); }, 1000); }); } const formSchema = z.object({ license: z .string() .refine(async (license) => await validate_license(license), { message: "Invalid license. Please provide a valid license key.", }), username: z .string() .min(3, { message: "Username must be at least 3 characters long.", }) .refine(async (username) => await validate_username(username), { message: "Username is already in use. Please choose a different one.", }), password: z .string() .min(8, { message: "Password must be at least 8 characters long.", }) .refine(async (password) => await validate_password(password), { message: "Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character.", }), terms: z.boolean().refine((val) => val === true, { message: "You must accept the Terms and Conditions.", }), }); const Sign_up = () => { const nav = useNavigate(); const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { username: "", password: "", license: "", terms: false, }, }); const { toast } = useToast(); async function onSubmit(_values: any) { const version: string = await invoke("get_app_version"); toast({ title: "Success: Signed up", description: `Loading Angel Panel v${version}...`, }); setTimeout(() => { nav("/dash"); }, 2500); } return (

Create an account

( Username )} /> ( Password )} /> ( License )} />
-
(
)} />
); }; export default Sign_up;