'use client'; import { useState, useEffect } from 'react'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } 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 { CurrencyInput } from '@/components/ui/currency-input'; import { PhoneInput } from '@/components/ui/phone-input'; import { PersonalNumberInput } from '@/components/ui/personal-number-input'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import { Separator } from '@/components/ui/separator'; import { Switch } from '@/components/ui/switch'; import { Plus, Trash2 } from 'lucide-react'; import type { EmployeeDialogProps, EmployeeFormData, DepartmentPosition, } from './types'; import { EMPLOYMENT_TYPE_LABELS, GENDER_LABELS, USER_ROLE_LABELS, USER_ACCOUNT_STATUS_LABELS, EMPLOYEE_STATUS_LABELS, } from './types'; const initialFormData: EmployeeFormData = { name: '', residentNumber: '', phone: '', email: '', salary: '', bankAccount: { bankName: '', accountNumber: '', accountHolder: '' }, profileImage: '', employeeCode: '', gender: '', address: { zipCode: '', address1: '', address2: '' }, hireDate: '', employmentType: '', rank: '', status: 'active', departmentPositions: [], hasUserAccount: false, userId: '', password: '', confirmPassword: '', role: 'user', accountStatus: 'active', clockInLocation: '', clockOutLocation: '', resignationDate: '', resignationReason: '', }; export function EmployeeDialog({ open, onOpenChange, mode, employee, onSave, fieldSettings, }: EmployeeDialogProps) { const [formData, setFormData] = useState(initialFormData); // 모드별 타이틀 const title = { create: '사원 등록', edit: '사원 수정', view: '사원 상세', }[mode]; const isViewMode = mode === 'view'; // 데이터 초기화 useEffect(() => { if (open && employee && mode !== 'create') { setFormData({ name: employee.name, residentNumber: employee.residentNumber || '', phone: employee.phone || '', email: employee.email || '', salary: employee.salary?.toString() || '', bankAccount: employee.bankAccount || { bankName: '', accountNumber: '', accountHolder: '' }, profileImage: employee.profileImage || '', employeeCode: employee.employeeCode || '', gender: employee.gender || '', address: employee.address || { zipCode: '', address1: '', address2: '' }, hireDate: employee.hireDate || '', employmentType: employee.employmentType || '', rank: employee.rank || '', status: employee.status, departmentPositions: employee.departmentPositions || [], hasUserAccount: !!employee.userInfo, userId: employee.userInfo?.userId || '', password: '', confirmPassword: '', role: employee.userInfo?.role || 'user', accountStatus: employee.userInfo?.accountStatus || 'active', clockInLocation: employee.clockInLocation || '', clockOutLocation: employee.clockOutLocation || '', resignationDate: employee.resignationDate || '', resignationReason: employee.resignationReason || '', }); } else if (open && mode === 'create') { setFormData(initialFormData); } }, [open, employee, mode]); // 입력 변경 핸들러 const handleChange = (field: keyof EmployeeFormData, value: unknown) => { setFormData(prev => ({ ...prev, [field]: value })); }; // 부서/직책 추가 const handleAddDepartmentPosition = () => { const newDP: DepartmentPosition = { id: String(Date.now()), departmentId: '', departmentName: '', positionId: '', positionName: '', }; setFormData(prev => ({ ...prev, departmentPositions: [...prev.departmentPositions, newDP], })); }; // 부서/직책 삭제 const handleRemoveDepartmentPosition = (id: string) => { setFormData(prev => ({ ...prev, departmentPositions: prev.departmentPositions.filter(dp => dp.id !== id), })); }; // 부서/직책 변경 const handleDepartmentPositionChange = (id: string, field: keyof DepartmentPosition, value: string) => { setFormData(prev => ({ ...prev, departmentPositions: prev.departmentPositions.map(dp => dp.id === id ? { ...dp, [field]: value } : dp ), })); }; // 저장 const handleSubmit = () => { onSave(formData); }; return ( {title} {mode === 'create' ? '새로운 사원 정보를 입력합니다' : '사원 정보를 확인/수정합니다'}
{/* 기본 사원정보 */}

기본 정보

handleChange('name', e.target.value)} disabled={isViewMode} placeholder="이름을 입력하세요" />
handleChange('residentNumber', value)} disabled={isViewMode} placeholder="000000-0000000" />
handleChange('phone', value)} disabled={isViewMode} placeholder="010-0000-0000" />
handleChange('email', e.target.value)} disabled={isViewMode} placeholder="email@company.com" />
handleChange('salary', value?.toString() ?? '')} disabled={isViewMode} placeholder="연봉" />
{/* 급여 계좌 */}
handleChange('bankAccount', { ...formData.bankAccount, bankName: e.target.value })} disabled={isViewMode} placeholder="은행명" /> handleChange('bankAccount', { ...formData.bankAccount, accountNumber: e.target.value })} disabled={isViewMode} placeholder="계좌번호" /> handleChange('bankAccount', { ...formData.bankAccount, accountHolder: e.target.value })} disabled={isViewMode} placeholder="예금주" />
{/* 선택적 필드 (설정에 따라 표시) */} {(fieldSettings.showEmployeeCode || fieldSettings.showGender || fieldSettings.showAddress) && ( <>

추가 정보

{fieldSettings.showEmployeeCode && (
handleChange('employeeCode', e.target.value)} disabled={isViewMode} placeholder="자동생성 또는 직접입력" />
)} {fieldSettings.showGender && (
)}
{fieldSettings.showAddress && (
handleChange('address', { ...formData.address, zipCode: e.target.value })} disabled={isViewMode} placeholder="우편번호" className="w-32" />
handleChange('address', { ...formData.address, address1: e.target.value })} disabled={isViewMode} placeholder="기본주소" /> handleChange('address', { ...formData.address, address2: e.target.value })} disabled={isViewMode} placeholder="상세주소" />
)}
)} {/* 인사 정보 */}

인사 정보

{fieldSettings.showHireDate && (
handleChange('hireDate', date)} disabled={isViewMode} />
)} {fieldSettings.showEmploymentType && (
)} {fieldSettings.showRank && (
handleChange('rank', e.target.value)} disabled={isViewMode} placeholder="직급 입력" />
)} {fieldSettings.showStatus && (
)}
{/* 부서/직책 (복수 가능) */} {(fieldSettings.showDepartment || fieldSettings.showPosition) && (
{!isViewMode && ( )}
{formData.departmentPositions.length === 0 ? (

부서/직책을 추가해주세요

) : (
{formData.departmentPositions.map((dp) => (
handleDepartmentPositionChange(dp.id, 'departmentName', e.target.value)} disabled={isViewMode} placeholder="부서명" className="flex-1" /> handleDepartmentPositionChange(dp.id, 'positionName', e.target.value)} disabled={isViewMode} placeholder="직책" className="flex-1" /> {!isViewMode && ( )}
))}
)}
)}
{/* 사용자 정보 */}

사용자 정보

{!isViewMode && (
handleChange('hasUserAccount', checked)} />
)}
{(formData.hasUserAccount || (isViewMode && employee?.userInfo)) && (
handleChange('userId', e.target.value)} disabled={isViewMode} placeholder="사용자 아이디" />
{!isViewMode && mode === 'create' && ( <>
handleChange('password', e.target.value)} placeholder="비밀번호" />
handleChange('confirmPassword', e.target.value)} placeholder="비밀번호 확인" />
)}
)}
{!isViewMode && ( )}
); }