'use client'; import { useState, useEffect } from 'react'; import { format } from 'date-fns'; import { Loader2 } from 'lucide-react'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { DatePicker } from '@/components/ui/date-picker'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import { QuantityInput } from '@/components/ui/quantity-input'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import type { VacationGrantFormData, VacationType } from './types'; import { VACATION_TYPE_LABELS } from './types'; import { getActiveEmployees, type EmployeeOption } from './actions'; interface VacationGrantDialogProps { open: boolean; onOpenChange: (open: boolean) => void; onSave: (data: VacationGrantFormData) => void; } export function VacationGrantDialog({ open, onOpenChange, onSave, }: VacationGrantDialogProps) { const today = format(new Date(), 'yyyy-MM-dd'); const [formData, setFormData] = useState({ employeeId: '', vacationType: 'annual', grantDate: today, grantDays: 1, reason: '', }); const [employees, setEmployees] = useState([]); const [isLoadingEmployees, setIsLoadingEmployees] = useState(false); // 직원 목록 로드 useEffect(() => { if (open && employees.length === 0) { setIsLoadingEmployees(true); getActiveEmployees() .then((result) => { if (result.success && result.data) { setEmployees(result.data); } }) .finally(() => setIsLoadingEmployees(false)); } }, [open, employees.length]); useEffect(() => { if (open) { setFormData({ employeeId: '', vacationType: 'annual', grantDate: format(new Date(), 'yyyy-MM-dd'), grantDays: 1, reason: '', }); } }, [open]); const handleSave = () => { if (!formData.employeeId) { alert('사원을 선택해주세요.'); return; } if (!formData.grantDate) { alert('부여일을 선택해주세요.'); return; } if (formData.grantDays < 1) { alert('부여 일수는 1 이상이어야 합니다.'); return; } onSave(formData); }; const handleCancel = () => { onOpenChange(false); }; return ( 휴가 부여 등록
{/* 사원 선택 */}
{/* 휴가 유형 */}
{/* 부여일 */}
setFormData(prev => ({ ...prev, grantDate: date }))} />
{/* 부여 일수 */}
setFormData(prev => ({ ...prev, grantDays: value ?? 1 }))} />
{/* 사유 */}