import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; import { z } from "zod"; import file from "~/lib/api/client/file"; import server from "~/lib/api/client/server"; import { ModalType, useModalStore } from "~/stores/modal-store"; import { Button } from "../ui/button"; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "../ui/dialog"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "../ui/form"; import { IconUploadField } from "../ui/icon-upload-field"; import { Input } from "../ui/input"; const schema = z.object({ name: z.string().min(1).max(32), icon: z.instanceof(File).optional(), }); export default function CreateServerModal() { const { type, isOpen, onClose } = useModalStore(); const isModalOpen = type === ModalType.CREATE_SERVER && isOpen let form = useForm>({ resolver: zodResolver(schema), }); const onOpenChange = (openState: boolean) => { form.reset() onClose() } const onSubmit = async (values: z.infer) => { let iconId = undefined if (values.icon) { iconId = (await file.uploadFile(values.icon))[0] } const response = await server.create({ name: values.name, iconId }) form.reset() onClose() } return ( Create server Give your server a name and choose a server icon.
( Icon
)} /> ( Name )} />
) }