import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; import { z } from "zod"; import { ChannelType } from "~/lib/api/types"; import { ModalType, useModalStore, type CreateServerChannelModalData, } 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 { Input } from "../ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "../ui/select"; const schema = z.object({ name: z.string().min(1).max(32), type: z.nativeEnum(ChannelType), }); export default function CreateServerChannelModal() { const { type, data, isOpen, onClose } = useModalStore(); const isModalOpen = type === ModalType.CREATE_SERVER_CHANNEL && isOpen; let form = useForm>({ resolver: zodResolver(schema), defaultValues: { type: ChannelType.SERVER_TEXT, }, }); const onOpenChange = () => { form.reset(); onClose(); }; const onSubmit = async (values: z.infer) => { const response = await import("~/lib/api/client/server").then((m) => m.default.createChannel( (data as CreateServerChannelModalData["data"]).serverId, values, ), ); form.reset(); onClose(); }; return ( Create channel Give your channel a name and choose a channel type.
( Name )} /> ( Type )} />
); }