import React, { useState, useEffect } from 'react' import { FaTimes, FaUser, FaBuilding, FaCreditCard, FaPhoneAlt } from 'react-icons/fa' import { FiCurrentAccount, AccountTypeEnum, RiskGroupEnum } from '../../../types/fi' import { mockBusinessParties } from '../../../mocks/mockBusinessParties' import { getAccountTypeText, getRiskGroupText } from '../../../utils/erp' import { mockCurrencies } from '@/mocks/mockCurrencies' interface CurrentAccountFormProps { account?: FiCurrentAccount isOpen: boolean onClose: () => void onSave: (account: Partial) => void } const CurrentAccountForm: React.FC = ({ account, isOpen, onClose, onSave, }) => { const [formData, setFormData] = useState< Partial & { id?: string } >({ accountCode: '', businessPartyId: '', type: AccountTypeEnum.Customer, contactPerson: '', phone: '', email: '', address: '', taxNumber: '', taxOffice: '', creditLimit: 0, currency: 'TRY', riskGroup: RiskGroupEnum.Low, paymentTerm: 30, isActive: true, }) const [errors, setErrors] = useState>({}) useEffect(() => { if (account) { setFormData({ ...account, creditLimit: account.creditLimit || 0, paymentTerm: account.paymentTerm || 30, }) } else { setFormData({ accountCode: '', businessPartyId: '', type: AccountTypeEnum.Customer, contactPerson: '', phone: '', email: '', address: '', taxNumber: '', taxOffice: '', creditLimit: 0, currency: 'TRY', riskGroup: RiskGroupEnum.Low, paymentTerm: 30, isActive: true, }) } setErrors({}) }, [account, isOpen]) const handleInputChange = ( e: React.ChangeEvent, ) => { const { name, value, type } = e.target let parsedValue: string | number | boolean = value if (type === 'number') { parsedValue = value === '' ? 0 : parseFloat(value) } else if (type === 'checkbox') { parsedValue = (e.target as HTMLInputElement).checked } setFormData((prev) => ({ ...prev, [name]: parsedValue, })) // Clear error when user starts typing if (errors[name]) { setErrors((prev) => ({ ...prev, [name]: '', })) } } const validateForm = () => { const newErrors: Record = {} if (!formData.accountCode?.trim()) { newErrors.accountCode = 'Hesap kodu zorunludur' } if (!formData.businessPartyId?.trim()) { newErrors.businessPartyId = 'Ünvan zorunludur' } if (formData.email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) { newErrors.email = 'Geçerli bir e-posta adresi giriniz' } if (formData.creditLimit && formData.creditLimit < 0) { newErrors.creditLimit = 'Kredi limiti negatif olamaz' } if (formData.paymentTerm && formData.paymentTerm < 0) { newErrors.paymentTerm = 'Ödeme vadesi negatif olamaz' } setErrors(newErrors) return Object.keys(newErrors).length === 0 } const handleSubmit = (e: React.FormEvent) => { e.preventDefault() if (validateForm()) { onSave(formData) onClose() } } if (!isOpen) return null return (

{account ? 'Cari Hesap Düzenle' : 'Yeni Cari Hesap'}

{/* Temel Bilgiler */}

Temel Bilgiler

{errors.accountCode && (

{errors.accountCode}

)}
{errors.title &&

{errors.title}

}
{/* İletişim Bilgileri */}

İletişim Bilgileri

{errors.email &&

{errors.email}

}