From 894aa4d0b4d2550f35683c5a8d3f56fe8cd1ece7 Mon Sep 17 00:00:00 2001 From: seaznCode Date: Sun, 12 Oct 2025 13:55:58 +0200 Subject: [PATCH] feat: Enhance validation logic and error messaging in personal sign contract page + send dummy pdf file not txt --- .../register-sign-contract/personal/page.tsx | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/app/quickaction-dashboard/register-sign-contract/personal/page.tsx b/src/app/quickaction-dashboard/register-sign-contract/personal/page.tsx index 2288167..40200ce 100644 --- a/src/app/quickaction-dashboard/register-sign-contract/personal/page.tsx +++ b/src/app/quickaction-dashboard/register-sign-contract/personal/page.tsx @@ -26,17 +26,28 @@ export default function PersonalSignContractPage() { setDate(new Date().toISOString().slice(0, 10)) }, []) - const valid = () => - fullName.trim().length > 4 && - location.trim().length > 1 && - agreeContract && - agreeData && - confirmSignature + const valid = () => { + const nameValid = fullName.trim().length >= 3 // Min 3 characters for name + const locationValid = location.trim().length >= 2 // Min 2 characters for location + const contractChecked = agreeContract + const dataChecked = agreeData + const signatureChecked = confirmSignature + + return nameValid && locationValid && contractChecked && dataChecked && signatureChecked + } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() 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 } @@ -65,9 +76,10 @@ export default function PersonalSignContractPage() { // Create FormData for the existing backend endpoint const formData = new FormData() formData.append('contractData', JSON.stringify(contractData)) - // Create a dummy file since the backend expects one (we'll update backend later) - const dummyFile = new Blob(['Electronic signature data'], { type: 'text/plain' }) - formData.append('contract', dummyFile, 'electronic_signature.txt') + // Create a dummy PDF file since the backend expects one (electronic signature) + 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' + 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`, { method: 'POST',