'use client'; import colors from '@/con/colors'; import { Box, Button, Group, Loader, Paper, Stack, Text, TextInput, Title } from '@mantine/core'; import { IconArrowBack } from '@tabler/icons-react'; import { useRouter } from 'next/navigation'; import { useProxy } from 'valtio/utils'; import CreateEditor from '../../../_com/createEditor'; import lowonganKerjaState from '../../../_state/ekonomi/lowongan-kerja'; import { useState } from 'react'; import { toast } from 'react-toastify'; function CreateLowonganKerja() { const lowonganState = useProxy(lowonganKerjaState); const router = useRouter(); const [isSubmitting, setIsSubmitting] = useState(false); // Helper function to check if HTML content is empty const isHtmlEmpty = (html: string) => { // Remove all HTML tags and check if there's any text content const textContent = html.replace(/<[^>]*>/g, '').trim(); return textContent === ''; }; // Check if form is valid const isFormValid = () => { return ( lowonganState.create.form.posisi?.trim() !== '' && lowonganState.create.form.namaPerusahaan?.trim() !== '' && lowonganState.create.form.notelp?.trim() !== '' && lowonganState.create.form.lokasi?.trim() !== '' && lowonganState.create.form.tipePekerjaan?.trim() !== '' && lowonganState.create.form.gaji?.trim() !== '' && !isHtmlEmpty(lowonganState.create.form.deskripsi) && !isHtmlEmpty(lowonganState.create.form.kualifikasi) ); }; const resetForm = () => { lowonganState.create.form = { posisi: '', namaPerusahaan: '', lokasi: '', tipePekerjaan: '', gaji: '', deskripsi: '', kualifikasi: '', notelp: '', }; }; const handleSubmit = async () => { try { setIsSubmitting(true); await lowonganState.create.create(); resetForm(); router.push('/admin/ekonomi/lowongan-kerja-lokal'); } catch (error) { console.error('Error creating lowongan kerja:', error); toast.error( error instanceof Error ? error.message : 'Gagal membuat lowongan kerja' ); } finally { setIsSubmitting(false); } }; return ( Tambah Lowongan Kerja Lokal {/* Card Form */} (lowonganState.create.form.posisi = val.target.value) } label="Posisi" placeholder="Masukkan posisi" required /> (lowonganState.create.form.namaPerusahaan = val.target.value) } label="Nama Perusahaan" placeholder="Masukkan nama perusahaan" required /> (lowonganState.create.form.notelp = val.target.value) } label="Nomor Yang Dapat Dihubungi" placeholder="Masukkan nomor yang dapat dihubungi" required /> (lowonganState.create.form.lokasi = val.target.value) } label="Lokasi" placeholder="Masukkan lokasi" required /> (lowonganState.create.form.tipePekerjaan = val.target.value) } label="Tipe Pekerjaan" placeholder="Masukkan tipe pekerjaan" required /> (lowonganState.create.form.gaji = val.target.value) } label="Gaji (per bulan)" placeholder="Masukkan gaji" required /> Deskripsi Lowongan Kerja { lowonganState.create.form.deskripsi = val; }} /> Kualifikasi Lowongan Kerja { lowonganState.create.form.kualifikasi = val; }} /> {/* Tombol Simpan */} {/* Tombol Simpan */} ); } export default CreateLowonganKerja;