feat: Enhance validation logic and error messaging in personal sign contract page + send dummy pdf file not txt

This commit is contained in:
seaznCode 2025-10-12 13:55:58 +02:00
parent 0ba58d7538
commit 894aa4d0b4

View File

@ -26,17 +26,28 @@ export default function PersonalSignContractPage() {
setDate(new Date().toISOString().slice(0, 10)) setDate(new Date().toISOString().slice(0, 10))
}, []) }, [])
const valid = () => const valid = () => {
fullName.trim().length > 4 && const nameValid = fullName.trim().length >= 3 // Min 3 characters for name
location.trim().length > 1 && const locationValid = location.trim().length >= 2 // Min 2 characters for location
agreeContract && const contractChecked = agreeContract
agreeData && const dataChecked = agreeData
confirmSignature const signatureChecked = confirmSignature
return nameValid && locationValid && contractChecked && dataChecked && signatureChecked
}
const handleSubmit = async (e: React.FormEvent) => { const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault() e.preventDefault()
if (!valid()) { if (!valid()) {
setError('Bitte alle Pflichtfelder & Bestätigungen ausfüllen.') // Detailed error message to help debug
const issues = []
if (fullName.trim().length < 3) issues.push('Vollständiger Name (mindestens 3 Zeichen)')
if (location.trim().length < 2) issues.push('Ort (mindestens 2 Zeichen)')
if (!agreeContract) issues.push('Vertrag gelesen und verstanden')
if (!agreeData) issues.push('Datenschutzerklärung zugestimmt')
if (!confirmSignature) issues.push('Elektronische Signatur bestätigt')
setError(`Bitte vervollständigen: ${issues.join(', ')}`)
return return
} }
@ -65,9 +76,10 @@ export default function PersonalSignContractPage() {
// Create FormData for the existing backend endpoint // Create FormData for the existing backend endpoint
const formData = new FormData() const formData = new FormData()
formData.append('contractData', JSON.stringify(contractData)) formData.append('contractData', JSON.stringify(contractData))
// Create a dummy file since the backend expects one (we'll update backend later) // Create a dummy PDF file since the backend expects one (electronic signature)
const dummyFile = new Blob(['Electronic signature data'], { type: 'text/plain' }) const dummyPdfContent = '%PDF-1.4\n1 0 obj\n<<\n/Type /Catalog\n/Pages 2 0 R\n>>\nendobj\n2 0 obj\n<<\n/Type /Pages\n/Kids [3 0 R]\n/Count 1\n>>\nendobj\n3 0 obj\n<<\n/Type /Page\n/Parent 2 0 R\n/MediaBox [0 0 612 792]\n/Contents 4 0 R\n>>\nendobj\n4 0 obj\n<<\n/Length 44\n>>\nstream\nBT\n/F1 12 Tf\n100 700 Td\n(Electronic Signature) Tj\nET\nendstream\nendobj\nxref\n0 5\n0000000000 65535 f \n0000000010 00000 n \n0000000079 00000 n \n0000000136 00000 n \n0000000225 00000 n \ntrailer\n<<\n/Size 5\n/Root 1 0 R\n>>\nstartxref\n319\n%%EOF'
formData.append('contract', dummyFile, 'electronic_signature.txt') const dummyFile = new Blob([dummyPdfContent], { type: 'application/pdf' })
formData.append('contract', dummyFile, 'electronic_signature.pdf')
const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/upload/contract/personal`, { const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/upload/contract/personal`, {
method: 'POST', method: 'POST',