'use client' import { useState, useActionState, useEffect, useRef } from 'react' import { X, Calendar, Clock, Loader2, Sparkles, AlertCircle } from 'lucide-react' import { generateInstantSchedule } from './action-jadwal' import { showSwal } from '@/lib/swal' interface Props { isOpen: boolean onClose: () => void adminName: string } export function InstantScheduleModal({ isOpen, onClose, adminName }: Props) { const [state, formAction, isPending] = useActionState(generateInstantSchedule, null) const processedStateRef = useRef(null) useEffect(() => { // Detect NEW result from action if (state && state !== processedStateRef.current) { // 1. Immediately close the modal so it doesn't block the alert or persist onClose() // 2. Show the alert after closing the modal if (state.success) { showSwal.success('Berhasil!', `${state.message} Silakan gunakan tombol "Cetak Semua Jadwal" untuk mengunduh seluruh laporan PDF.`) } else { showSwal.error('Gagal!', state.message) } // 3. Mark this specific state object as processed processedStateRef.current = state } }, [state, onClose]) // Reset processed state when modal is opened for a fresh experience useEffect(() => { if (isOpen) { processedStateRef.current = null } }, [isOpen]) if (!isOpen) return null const tomorrow = new Date() tomorrow.setDate(tomorrow.getDate() + 1) const minDate = tomorrow.toISOString().split('T')[0] return (

Penjadwalan Instan

Penjadwalan harus dilakukan minimal 1 hari sebelumnya.

Sesi: 08-10, 11-13, 14-16 (Selingan 1 Jam).

{/* Tanggal */}
08:00
10:00
Fixed Slot
) }