diff --git a/app/carnet/page.tsx b/app/carnet/page.tsx index 845c1da9..b5c97f2a 100644 --- a/app/carnet/page.tsx +++ b/app/carnet/page.tsx @@ -169,15 +169,25 @@ export default function CarnetPage() { const vcard = new VCard(); vcard.parse('BEGIN:VCARD' + section); + // Extract contact properties with proper type handling + const uid = vcard.getProperty('UID')?.value; + const fullName = vcard.getProperty('FN')?.value; + const email = vcard.getProperty('EMAIL')?.value; + const phone = vcard.getProperty('TEL')?.value; + const organization = vcard.getProperty('ORG')?.value; + const address = vcard.getProperty('ADR')?.value; + const notes = vcard.getProperty('NOTE')?.value; + const group = vcard.getProperty('CATEGORIES')?.value; + return { - id: vcard.getProperty('UID')?.value || Math.random().toString(36).substr(2, 9), - fullName: vcard.getProperty('FN')?.value || '', - email: vcard.getProperty('EMAIL')?.value || '', - phone: vcard.getProperty('TEL')?.value || '', - organization: vcard.getProperty('ORG')?.value || '', - address: vcard.getProperty('ADR')?.value || '', - notes: vcard.getProperty('NOTE')?.value || '', - group: vcard.getProperty('CATEGORIES')?.value || '' + id: uid || Math.random().toString(36).substr(2, 9), + fullName: fullName || 'Unknown Contact', + email: email || '', + phone: phone || '', + organization: organization || '', + address: address || '', + notes: notes || '', + group: group || '' }; }); } catch (error) { @@ -479,8 +489,11 @@ export default function CarnetPage() { const generateVCard = (contact: Contact): string => { const vcard = new VCard(); - vcard.setProperty('UID', contact.id); - vcard.setProperty('FN', contact.fullName); + // Ensure required fields are not undefined + vcard.setProperty('UID', contact.id || Math.random().toString(36).substr(2, 9)); + vcard.setProperty('FN', contact.fullName || 'Unknown Contact'); + + // Add optional fields only if they have values if (contact.email) vcard.setProperty('EMAIL', contact.email); if (contact.phone) vcard.setProperty('TEL', contact.phone); if (contact.organization) vcard.setProperty('ORG', contact.organization);