import { Button } from "@nextui-org/button"; import { Input, Textarea } from "@nextui-org/input"; import React, { useState } from "react"; import { Controller, useForm } from "react-hook-form"; import * as z from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { otpRequest, otpValidation } from "@/service/master-user"; import { error } from "@/config/swal"; const commentSchema = z.object({ name: z.string().min(1, { message: "Judul harus diisi", }), email: z .string() .email({ message: "Email tidak valid", }) .min(1, { message: "Harus diisi", }), comment: z.string().min(1, { message: "Deskripsi harus diisi", }), }); export default function Comment() { const [needOtp, setNeedOtp] = useState(false); const [otpValue, setOtpValue] = useState(""); const formOptions = { resolver: zodResolver(commentSchema), }; type UserSettingSchema = z.infer; const { control, handleSubmit, formState: { errors }, setValue, } = useForm(formOptions); const onSubmit = async (values: z.infer) => { if (!needOtp) { const res = await otpRequest(values.email); if (res?.error) { error(res.message); return false; } setNeedOtp(true); } else { const validation = await otpValidation(values.email, otpValue); if (validation?.error) { error("OTP Tidak Sesuai"); return false; } const req = { email: values.email, name: values.name, comment: values.comment, }; console.log("req", req); } }; return (
Tinggalkan balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai{" "} *

Komentar

(