carnet panel contact

This commit is contained in:
alma 2025-04-20 21:56:05 +02:00
parent ef6f08b6bc
commit 6cef226948

View File

@ -169,15 +169,25 @@ export default function CarnetPage() {
const vcard = new VCard(); const vcard = new VCard();
vcard.parse('BEGIN:VCARD' + section); 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 { return {
id: vcard.getProperty('UID')?.value || Math.random().toString(36).substr(2, 9), id: uid || Math.random().toString(36).substr(2, 9),
fullName: vcard.getProperty('FN')?.value || '', fullName: fullName || 'Unknown Contact',
email: vcard.getProperty('EMAIL')?.value || '', email: email || '',
phone: vcard.getProperty('TEL')?.value || '', phone: phone || '',
organization: vcard.getProperty('ORG')?.value || '', organization: organization || '',
address: vcard.getProperty('ADR')?.value || '', address: address || '',
notes: vcard.getProperty('NOTE')?.value || '', notes: notes || '',
group: vcard.getProperty('CATEGORIES')?.value || '' group: group || ''
}; };
}); });
} catch (error) { } catch (error) {
@ -479,8 +489,11 @@ export default function CarnetPage() {
const generateVCard = (contact: Contact): string => { const generateVCard = (contact: Contact): string => {
const vcard = new VCard(); const vcard = new VCard();
vcard.setProperty('UID', contact.id); // Ensure required fields are not undefined
vcard.setProperty('FN', contact.fullName); 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.email) vcard.setProperty('EMAIL', contact.email);
if (contact.phone) vcard.setProperty('TEL', contact.phone); if (contact.phone) vcard.setProperty('TEL', contact.phone);
if (contact.organization) vcard.setProperty('ORG', contact.organization); if (contact.organization) vcard.setProperty('ORG', contact.organization);