'use client'; import stateBanjar from '@/app/admin/(dashboard)/_state/desa/banjar'; import colors from '@/con/colors'; import { Box, Button, Group, Loader, Paper, Stack, 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'; function CreateBanjar() { const state = useProxy(stateBanjar); const router = useRouter(); const [isSubmitting, setIsSubmitting] = useState(false); const isFormValid = () => state.create.form.name?.trim() !== ''; const resetForm = () => { state.create.form = { name: '' }; }; const handleSubmit = async () => { if (!state.create.form.name?.trim()) { toast.error('Nama banjar wajib diisi'); return; } setIsSubmitting(true); try { await state.create.create(); resetForm(); router.push('/admin/desa/banjar'); } catch (error) { console.error('Error creating banjar:', error); toast.error('Gagal menambahkan banjar'); } finally { setIsSubmitting(false); } }; return ( Tambah Banjar (state.create.form.name = e.target.value)} required /> ); } export default CreateBanjar;