Bulk Import & Export
Relevant source files
The following files were used as context for generating this wiki page:
The Bulk Import & Export system in the Boda-Cris project provides administrative tools to manage guest lists at scale. It allows event organizers to migrate data between the application and external spreadsheet software (like Excel or Google Sheets) or technical formats like JSON. This feature ensures that large wedding guest lists can be populated quickly and backed up reliably.
The system is integrated within the Admin panel, specifically accessible through the Guest List management interface. It supports comma-separated values (CSV) and JSON formats, including a specialized template system to guide users through the correct data structure for imports.
Sources: src/components/admin/GuestImportExport.jsx:1-15, src/components/admin/GuestList.jsx:105-115
Data Management Architecture
The import/export functionality is encapsulated in the GuestImportExport component, which interacts with the GuestContext to update the global guest state. The component uses a tabbed interface to separate Import and Export workflows.
Workflow Visualization
This diagram illustrates how data flows from a local file through the parsing logic into the application state.
Export Module
The export module transforms the internal guest data array into downloadable file formats. It handles encoding to ensure special characters (like those in Spanish names) are preserved correctly using UTF-8 BOM.
Supported Formats
| Format | Implementation | Usage |
|---|---|---|
| CSV | exportToCSV() | Standard for Excel/Google Sheets. Includes headers and quoted values. |
| JSON | exportToJSON() | Technical backup or migration between application instances. |
Technical Details
The exportToCSV function maps guest objects to a specific order of columns: Name, Email, Phone, Status, Adults, Children, Restrictions, Message, and Registration Date. It uses a helper function downloadFile to create a Blob and trigger a browser download action.
Sources: src/components/admin/GuestImportExport.jsx:31-66
Import Module
The import module allows users to upload files and preview the data before committing it to the database.
Parsing Logic
- CSV Parsing: The
parseCSVfunction skips header rows and processes each line usingparseCSVLine. This custom line parser handles quoted strings containing commas, ensuring that messages with punctuation do not break the column structure. - JSON Parsing: The
parseJSONfunction validates the structure and maps it to the standard guest schema. - Attendance Normalization: A specialized
normalizeAttendancefunction maps various input strings (e.g., "sí", "yes", "confirmado") to the internal "confirmed", "declined", or "pending" status.
Sources: src/components/admin/GuestImportExport.jsx:91-143
Sequence of Import Operation
The following sequence diagram shows the interaction between the user, the component, and the global state.
Data Schema Mapping
The following table describes the fields expected during a bulk import and produced during an export.
| Field | CSV Column | Data Type | Notes |
|---|---|---|---|
name | Nombre | String | Required. Used as the primary identifier. |
email | String | Optional. | |
phone | Teléfono | String | Used for WhatsApp Broadcast. |
attendance | Estado | Enum | Maps confirmed/pending/declined. |
adults | Adultos | Integer | Default: 1. |
children | Niños | Integer | Default: 0. |
dietaryRestrictions | Restricciones | String | Includes allergies or preferences. |
message | Mensaje | String | Personal note from the guest. |
Sources: src/components/admin/GuestImportExport.jsx:32-34, src/data/defaultContent.js:101-112
WhatsApp Integration
While not a direct file export, the WhatsAppBroadcast system utilizes the bulk data collected via imports to facilitate mass communication.
Broadcast Architecture
The system allows selecting multiple guests from the imported list to send personalized messages via templates. It supports variables such as {{nombre}}, {{novio}}, and {{fecha}}, which are dynamically replaced before launching the WhatsApp API.
// Variable replacement logic
const replaceVariables = (message, guest) => {
return message
.replace(/\{\{nombre\}\}/g, guest.name || '')
.replace(/\{\{adultos\}\}/g, guest.adults?.toString() || '1')
.replace(/\{\{link\}\}/g, window.location.origin);
};
Sources: src/components/admin/WhatsAppBroadcast.jsx:177-195, src/components/admin/WhatsAppBroadcast.jsx:215-230
Conclusion
The Bulk Import & Export system provides a robust bridge between the Boda-Cris application and external data sources. By supporting both CSV and JSON, and providing a visual preview with error handling (via importErrors), it minimizes the risk of data corruption during large-scale guest list updates. This module is essential for the administrative scalability of the wedding invitation platform.