"use client"; import axios from "axios" import { db } from "@/lib/db"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import * as z from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { cn } from "@/lib/utils"; const formSchema = z.object({ id: z.string().trim().min(12, { message: "Client ID should be at least 12 characters." }), secret: z.string().trim().min(12, { message: "Client secret should be at least 12 characters." }) }); export const ConnectTwitchModal = () => { const [isMounted, setIsMounted] = useState(false); const [twitchError, setTwitchError] = useState("") useEffect(() => { setIsMounted(true); }, []); const router = useRouter(); const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { id: "", secret: "" } }); const isLoading = form.formState.isSubmitting; if (!isMounted) { return null; } const onSubmit = async (values: z.infer) => { setTwitchError(""); try { const response = await axios.post("/api/settings/connections/twitch", values); console.log(response.data); } catch (error) { setTwitchError("Invalid client id and client secret combination."); console.log("[CONNECTIONS/TWITCH/POST]", error); return; } form.reset(); router.refresh(); window.location.reload(); } return ( Connect Your Twitch Account Provide permission to access your twitch account & read chat.
0 && "block px-5 py-2 bg-[#FF0000] text-center items-center justify-center")}> {twitchError}
( Client ID )} />
( Client secret )} />
); }