/* eslint-disable react-hooks/exhaustive-deps */ 'use client' import infoSekolahPaud from '@/app/admin/(dashboard)/_state/pendidikan/info-sekolah-paud'; import colors from '@/con/colors'; import { Box, Button, Group, Loader, Paper, Select, Stack, Text, TextInput, Title } from '@mantine/core'; import { IconArrowBack } from '@tabler/icons-react'; import { useRouter } from 'next/navigation'; import { useEffect, useState } from 'react'; import { toast } from 'react-toastify'; import { useProxy } from 'valtio/utils'; function CreateSiswa() { const router = useRouter(); const stateCreate = useProxy(infoSekolahPaud.siswa); const [isSubmitting, setIsSubmitting] = useState(false); // Check if form is valid const isFormValid = () => { return ( stateCreate.create.form.nama?.trim() !== '' && stateCreate.create.form.lembagaId?.trim() !== '' ); }; useEffect(() => { stateCreate.findMany.load(); infoSekolahPaud.lembagaPendidikan.findMany.load(); }, []); const resetForm = () => { stateCreate.create.form = { nama: '', lembagaId: '', }; }; const handleSubmit = async () => { try { setIsSubmitting(true); await stateCreate.create.create(); resetForm(); router.push('/admin/pendidikan/info-sekolah/siswa'); } catch (error) { console.error('Error creating siswa:', error); toast.error('Gagal menambahkan siswa'); } finally { setIsSubmitting(false); } }; return ( {/* Header + Back Button */} Tambah Siswa {/* Form Card */} { stateCreate.create.form.nama = val.target.value; }} label={Nama} placeholder="Masukkan nama siswa" required />