'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 { ActionIcon, Box, Button, Group, Paper, Stack, Text, TextInput, Title, Loader } from '@mantine/core'; import { IconArrowBack, IconX } 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 [isSubmitting, setIsSubmitting] = useState(false); const resetForm = () => { videoState.create.form = { name: '', deskripsi: '', linkVideo: '', }; setLink(''); }; const handleSubmit = async () => { try { setIsSubmitting(true); if (!embedLink) { toast.error('Link YouTube tidak valid. Pastikan formatnya benar.'); return; } videoState.create.form.linkVideo = embedLink; await videoState.create.create(); resetForm(); router.push('/admin/desa/gallery/video'); } catch (error) { console.error("Error creating video:", error); toast.error("Terjadi kesalahan saat menambahkan video"); } finally { setIsSubmitting(false); } }; return ( {/* Header Back Button + Title */} Tambah Video {/* Card Form */} {/* Judul */} { videoState.create.form.name = e.currentTarget.value; }} required /> {/* Link YouTube */} setLink(e.currentTarget.value)} required /> {/* Preview Video */} {embedLink && (