import React, { useState, useEffect } from "react"; import { FaSave, FaTimes } from "react-icons/fa"; import { HrCostCenter, CostCenterType } from "../../../types/hr"; import { mockEmployees } from "../../../mocks/mockEmployees"; import { mockCostCenters } from "../../../mocks/mockCostCenters"; import { getCostCenterTypeText } from "../../../utils/erp"; interface CostCenterFormModalProps { isOpen: boolean; onClose: () => void; onSave: (costCenter: Partial) => void; costCenter?: HrCostCenter; title: string; } const CostCenterFormModal: React.FC = ({ isOpen, onClose, onSave, costCenter, title, }) => { const [formData, setFormData] = useState({ costCenterCode: "", name: "", description: "", costCenterType: CostCenterType.Standard, responsibleEmployeeId: "", parentCostCenterId: "", budgetedAmount: 0, actualAmount: 0, currency: "TRY", fiscalYear: "2025", isActive: true, }); useEffect(() => { if (costCenter) { setFormData({ costCenterCode: costCenter.code, name: costCenter.name, description: costCenter.description || "", costCenterType: costCenter.costCenterType, responsibleEmployeeId: costCenter.responsibleEmployeeId || "", parentCostCenterId: costCenter.parentCostCenterId || "", budgetedAmount: costCenter.budgetedAmount, actualAmount: costCenter.actualAmount, currency: costCenter.currency, fiscalYear: costCenter.fiscalYear, isActive: costCenter.isActive, }); } else { setFormData({ costCenterCode: "", name: "", description: "", costCenterType: CostCenterType.Standard, responsibleEmployeeId: "", parentCostCenterId: "", budgetedAmount: 0, actualAmount: 0, currency: "TRY", fiscalYear: "2025", isActive: true, }); } }, [costCenter]); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); onSave(formData); }; return ( isOpen && (

{title}

setFormData({ ...formData, costCenterCode: e.target.value }) } className="w-full px-2 py-1 text-sm border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required />
setFormData({ ...formData, name: e.target.value }) } className="w-full px-2 py-1 text-sm border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required />