"use client"; import { Button } from "@heroui/button"; import { Image, Input, InputOtp, Modal, ModalBody, ModalContent, ModalFooter, ModalHeader, ModalProps, Textarea, useDisclosure, } from "@heroui/react"; import { ChevronLeftWhite, ChevronRightWhite } from "../icons"; import React, { useEffect, useState } from "react"; import Link from "next/link"; import { useTranslations } from "next-intl"; import * as z from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { Controller, useForm } from "react-hook-form"; import { close, error, loading } from "@/config/swal"; import OTPInput from "react-otp-input"; import { otpRequest, otpValidation } from "@/service/master-user"; import Swal from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; import { createFeedback } from "@/service/feedbacks"; const createArticleSchema = z.object({ email: z.string().min(2, { message: "Email harus diisi", }), name: z.string().min(2, { message: "Nama harus diisi", }), description: z.string().min(2, { message: "Deskripsi harus diisi", }), }); export default function SuggestionsModal(props: { opened: boolean; modalStatus: (status: boolean) => void; }) { const { isOpen, onOpen, onOpenChange } = useDisclosure(); const [needOtp, setNeedOtp] = useState(false); const [otpValue, setOtpValue] = useState(""); const MySwal = withReactContent(Swal); const t = useTranslations("Landing"); useEffect(() => { if (props.opened) { onOpen(); } }, [props.opened]); const formOptions = { resolver: zodResolver(createArticleSchema), defaultValues: { name: "", description: "", email: "" }, }; type UserSettingSchema = z.infer; const { control, handleSubmit, reset, formState: { errors }, } = useForm(formOptions); const onSubmit = async (values: z.infer) => { if (!needOtp) { loading(); const res = await otpRequest(values.email, values?.name); if (res?.error) { error(res.message); return false; } close(); setNeedOtp(true); } else { const validation = await otpValidation(values.email, otpValue); if (validation?.error) { error("OTP Tidak Sesuai"); return false; } const req = { commentFromName: values.name, message: values.description, commentFromEmail: values.email, }; const res = await createFeedback(req); if (res?.error) { error(res?.message); return false; } MySwal.fire({ title: "Berhasil Kirim", text: "", icon: "success", showCancelButton: false, confirmButtonColor: "#3085d6", confirmButtonText: "Oke", }).then((result) => { if (result.isConfirmed) { } }); reset(); setNeedOtp(false); setOtpValue(""); props.modalStatus(!props.opened); onOpenChange(); } }; return ( <> { props.modalStatus(!props.opened); onOpenChange(); }} size="3xl" className="bg-white" placement="top-center" > {(onClose) => ( <>

Kritik & Saran

{needOtp ? (

Kode verifikasi sudah dikirmkan. Silahkan cek Email Anda!

OTP

{/* -} renderInput={(props) => ( )} /> */}
) : ( <>

Nama

( )} /> {errors?.name && (

{errors.name?.message}

)}

Email

( )} /> {errors?.email && (

{errors.email?.message}

)}

Kritik & Saran

(