"use client"; import { Button } from "@/components/ui/button"; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { toast } from "sonner"; import { Input } from "@/components/ui/input"; import { close, error, loading, successCallback } from "@/config/swal"; import { listData5Data, listDataAllNonPagination, mediaTrackingSave, } from "@/service/media-tracking/media-tracking"; import { useEffect, useState } from "react"; export default function TrackingMediaModal(props: { triggerFetch: () => void; }) { const [content, setContent] = useState([]); const [inputValue, setInputValue] = useState(""); const [selectedId, setSelectedId] = useState(0); useEffect(() => { initFecth(); }, []); const initFecth = async () => { const response = await listData5Data(); setContent(response?.data?.data.content); }; const fecthAll = async (search?: string) => { const response = await listDataAllNonPagination(search || inputValue); setContent(response?.data?.data.content); }; const handleInputChange = (e: React.ChangeEvent) => { const value = e.target.value; const nowLength = value.split(" ").length; const prevLength = inputValue.split(" ").length; setInputValue(value); if (value === "") { initFecth(); setSelectedId(0); } if (/\s/.test(value)) { console.log("Terdapat spasi dalam input"); fecthAll(); } if (nowLength !== prevLength) { fecthAll(); } }; const doSave = async () => { loading(); const req = { mediaUploadId: selectedId, duration: 24, scrapingPeriod: 3, }; const res = await mediaTrackingSave(req); if (res?.error) { error(res?.message); return false; } close(); toast("Berhasil Menambahkan", { description: "", }); props.triggerFetch(); return false; }; return ( Form Tracking Berita
{" "} {" "}
{/* */}
); }