fix (management / userCard): Refactor PDF generation to use service functions#405
Conversation
…serCard The download functions in ParticipantStatusTab used wrong GraphQL variable names (visitorId instead of userId/conferenceId), expected non-existent response fields (postalRegistrationPDF, certificate), and tried to download via base64 data URLs instead of using the PDF generation functions. Rewrote both functions to match the working implementation in UserDrawer: - Use correct GraphQL variables for certificateQuery and getBaseDocumentsForPostal - Read correct response fields (getCertificateJWT, findUniqueConference) - Generate PDFs using downloadCompletePostalRegistrationPDF and downloadCompleteCertificate - Added user prop for participant data and postal fields to conference query https://claude.ai/code/session_015YUh1agS7xPiUo7iArRNL4
📝 WalkthroughWalkthroughThe changes extend UserCardContent to pass additional user profile data and conference postal fields to ParticipantStatusTab. The ParticipantStatusTab component is refactored to integrate with pdfGenerator utilities, fetching base documents and certificate data separately, then constructing participant/recipient data structures before generating downloadable PDFs with error handling. Changes
Sequence DiagramsequenceDiagram
actor User
participant ParticipantStatusTab
participant API
participant pdfGenerator
User->>ParticipantStatusTab: Click download postal docs
ParticipantStatusTab->>API: getBaseDocumentsForPostal(conferenceId)
API-->>ParticipantStatusTab: baseContent
ParticipantStatusTab->>ParticipantStatusTab: Construct RecipientData & ParticipantData
ParticipantStatusTab->>ParticipantStatusTab: Format names via formatNames
ParticipantStatusTab->>pdfGenerator: downloadCompletePostalRegistrationPDF(...)
pdfGenerator-->>User: Generated PDF file
User->>ParticipantStatusTab: Click download certificate
ParticipantStatusTab->>API: certificateQuery(conferenceId, userId)
API-->>ParticipantStatusTab: certificateData + JWT
ParticipantStatusTab->>pdfGenerator: downloadCompleteCertificate(...)
pdfGenerator-->>User: Generated PDF file
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Convert `string | null | undefined` to `string | undefined` using `?? undefined` for user.given_name and user.family_name arguments passed to formatNames. https://claude.ai/code/session_015YUh1agS7xPiUo7iArRNL4
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/lib/components/UserCard/tabs/ParticipantStatusTab.svelte`:
- Around line 155-156: The address construction in ParticipantStatusTab.svelte
currently interpolates user.street, user.apartment, user.zip, user.city, and
user.country directly and can produce "undefined"/"null" text; change the logic
that sets the address field to build an array of address segments (e.g., street
+ optional apartment, zip + city, country), push only truthy values from
user.street, user.apartment, user.zip, user.city, user.country, and join them
with appropriate separators so missing parts are omitted; keep the existing
birthday line but ensure any Date formatting still guards with
?.toLocaleDateString().
- Around line 192-201: The click handler currently bails silently if user is
undefined when calling downloadCompleteCertificate; update the logic in
ParticipantStatusTab.svelte so that when user is missing you still call
downloadCompleteCertificate using a fallback filename built from
jwtData.fullName (or jwtData.name) instead of formatNames(user...), and ensure
jwtData exists before proceeding (validate jwtData) so
downloadCompleteCertificate is invoked with
certificateData.data?.findUniqueConference?.certificateContent and a safe
filename like `${(jwtData.fullName ?? 'certificate')}_certificate.pdf`;
reference symbols: downloadCompleteCertificate, jwtData, certificateData,
formatNames, and user.
- Around line 139-172: The block that builds recipientData/participantData and
calls downloadCompletePostalRegistrationPDF silently does nothing when user is
undefined; ensure you validate user up-front and surface an error or toast
instead of silently returning: add an explicit guard that throws or shows an
error/toast when user is falsy, or move the download logic into a function and
only call it when user exists, and ensure the extra/mismatched closing brace
that prematurely ends the surrounding control flow is removed so the validation
and error handling run correctly; reference the
downloadCompletePostalRegistrationPDF call, the ofAgeAtConference check, and the
participantData/recipientData construction when making the change.
- Line 160: The code currently passes user.birthday ?? new Date() into
ofAgeAtConference which masks missing birthdays by using today and can produce
incorrect age results; update ParticipantStatusTab.svelte so you validate
user.birthday before calling ofAgeAtConference (e.g., check if user.birthday is
present and a valid Date), and if it's missing or invalid, handle it explicitly
(show an error/placeholder or disable PDF generation) instead of defaulting to
new Date(); change any logic that relies on ofAgeAtConference(user.birthday ??
new Date()) to first gate on the validated birthday and only call
ofAgeAtConference(birthday, conference.startConference) when birthday is a valid
value.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9b4d4fee-fff4-47ee-a168-2a507b12f62c
📒 Files selected for processing (2)
src/lib/components/UserCard/UserCardContent.sveltesrc/lib/components/UserCard/tabs/ParticipantStatusTab.svelte
…address construction - Add birthday validation before postal PDF generation, showing toast error if missing - Build address from truthy segments to avoid "undefined"/"null" text in output - Remove unsafe `user.birthday ?? new Date()` fallback in ofAgeAtConference call - Add httpMissingRequiredData translation key (DE/EN) https://claude.ai/code/session_015YUh1agS7xPiUo7iArRNL4
Summary
Refactored the PDF download functionality in the ParticipantStatusTab to use dedicated service functions (
downloadCompletePostalRegistrationPDFanddownloadCompleteCertificate) instead of manually handling base64 data and file downloads. This improves code maintainability and centralizes PDF generation logic.Key Changes
ParticipantData,RecipientData) and theformatNamesutilityuserobject with personal details (name, address, birthday) needed for PDF generationpostalName,postalStreet,postalApartment,postalZip,postalCity,postalCountry)visitorIddownloadCompletePostalRegistrationPDF()service callParticipantDataandRecipientDataobjects with properly formatted names and addressesdownloadCompleteCertificate()service callImplementation Details
formatNamesutility with consistent formatting (family name first, underscores as delimiters)https://claude.ai/code/session_015YUh1agS7xPiUo7iArRNL4
Summary by CodeRabbit
New Features
Improvements