'use client' import CreateEditor from '@/app/admin/(dashboard)/_com/createEditor'; import stateGallery from '@/app/admin/(dashboard)/_state/desa/gallery'; import colors from '@/con/colors'; import { Box, Button, Group, Paper, Stack, Text, TextInput, Title } from '@mantine/core'; import { IconArrowBack } from '@tabler/icons-react'; import { useRouter } from 'next/navigation'; import { useState } from 'react'; import { toast } from 'react-toastify'; import { useProxy } from 'valtio/utils'; import { convertYoutubeUrlToEmbed } from '../../lib/youtube-utils'; function CreateVideo() { const videoState = useProxy(stateGallery.video) const router = useRouter(); const [link, setLink] = useState(""); const embedLink = convertYoutubeUrlToEmbed(link); const resetForm = () => { videoState.create.form = { name: "", deskripsi: "", linkVideo: "", }; }; const handleSubmit = async () => { if (!embedLink) { toast.error("Link YouTube tidak valid. Pastikan formatnya benar."); return; } videoState.create.form.linkVideo = embedLink; // pastikan diset di sini juga (jaga-jaga) await videoState.create.create(); resetForm(); router.push("/admin/desa/gallery/video"); }; return ( Create Video Judul Video} placeholder='Masukkan judul video' value={videoState.create.form.name} onChange={(val) => { videoState.create.form.name = val.target.value; }} /> { setLink(e.currentTarget.value); }} required /> {embedLink && ( )} Deskripsi Video { videoState.create.form.deskripsi = val; }} /> ); } export default CreateVideo;