"use client"; import { Button, Input, Select, SelectItem, SelectSection, Textarea, } from "@heroui/react"; import { FormEvent, useEffect, useState } from "react"; import { Controller, useForm } from "react-hook-form"; import * as z from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { close, error, loading } from "@/config/swal"; import { getGenerateRewriter } from "@/services/generate-article"; import TranscriptDraftTable from "@/components/table/disestages/transcript-draft-table"; import ArticleDraftTable from "@/components/table/disestages/article-draft-table"; const writingStyle = [ { id: 1, name: "Friendly", }, { id: 1, name: "Professional", }, { id: 3, name: "Informational", }, { id: 4, name: "Neutral", }, { id: 5, name: "Witty", }, ]; const articleSize = [ { id: 1, name: "News (300 - 900 words)", value: "News", }, { id: 2, name: "Info (900 - 2000 words)", value: "Info", }, { id: 3, name: "Detail (2000 - 5000 words)", value: "Detail", }, ]; const formSchema = z.object({ field1: z.string().min(2, { message: "Required", }), advancedConfiguration: z.string().optional(), }); export default function GenerateRewriteArticle(props: { articleId: (data: number) => void; initTranscript?: number; }) { const [selectedWritingSyle, setSelectedWritingStyle] = useState("Informational"); const [selectedArticleSize, setSelectedArticleSize] = useState("News"); const [selectedLanguage, setSelectedLanguage] = useState("id"); const [contextType, setContextType] = useState("text"); useEffect(() => { if (props.initTranscript) { setContextType("transcript"); } }, [props.initTranscript]); const formOptions = { resolver: zodResolver(formSchema) }; type UserSettingSchema = z.infer; const { control, handleSubmit, formState: { errors }, setValue, } = useForm(formOptions); const onSubmit = async (values: z.infer) => { loading(); const request = { advConfig: values.advancedConfiguration || "", context: contextType == "url" ? null : values.field1, style: selectedWritingSyle, sentiment: "Humorous", clientId: "humasClientIdtest", createdBy: "123123", contextType: contextType, urlContext: contextType === "url" ? values.field1 : null, lang: selectedLanguage, }; const res = await getGenerateRewriter(request); close(); if (res?.error) { error("Error"); } props.articleId(res?.data?.data?.id); }; useEffect(() => { setValue("field1", ""); }, [contextType]); return (
{(contextType === "text" || contextType === "url") && (

{contextType === "text" ? "Enter your text here" : "Insert URL"}

)} {(contextType === "text" || contextType === "url") && ( contextType === "text" ? (