Skip to content

fix (management / userCard): Refactor PDF generation to use service functions#405

Merged
Strehk merged 4 commits into
mainfrom
claude/fix-download-error-OigNt
Mar 6, 2026
Merged

fix (management / userCard): Refactor PDF generation to use service functions#405
Strehk merged 4 commits into
mainfrom
claude/fix-download-error-OigNt

Conversation

@Strehk
Copy link
Copy Markdown
Member

@Strehk Strehk commented Mar 6, 2026

Summary

Refactored the PDF download functionality in the ParticipantStatusTab to use dedicated service functions (downloadCompletePostalRegistrationPDF and downloadCompleteCertificate) instead of manually handling base64 data and file downloads. This improves code maintainability and centralizes PDF generation logic.

Key Changes

  • Imports: Added imports for PDF generation service functions and related types (ParticipantData, RecipientData) and the formatNames utility
  • Props: Extended the component props to include the user object with personal details (name, address, birthday) needed for PDF generation
  • Conference data: Added postal address fields to the conference prop (postalName, postalStreet, postalApartment, postalZip, postalCity, postalCountry)
  • downloadPostalDocs():
    • Changed query to fetch base documents without requiring visitorId
    • Added validation for required postal address fields
    • Replaced manual base64 PDF handling with downloadCompletePostalRegistrationPDF() service call
    • Constructs ParticipantData and RecipientData objects with properly formatted names and addresses
    • Passes document content (contract, guardian consent, media consent, T&Cs) to the service function
  • downloadCertificate():
    • Replaced manual base64 PDF handling with downloadCompleteCertificate() service call
    • Extracts JWT data and validates required fields before processing
    • Passes certificate content to the service function
  • Error handling: Improved error logging with console.error for debugging
  • GraphQL query: Updated UserCardContent to fetch the new postal address fields from the conference

Implementation Details

  • PDF filenames are now generated using the formatNames utility with consistent formatting (family name first, underscores as delimiters)
  • The refactoring centralizes PDF generation logic in service functions, making it easier to maintain and modify PDF generation behavior in the future
  • User data is now passed as a prop to enable proper formatting of participant information in PDFs

https://claude.ai/code/session_015YUh1agS7xPiUo7iArRNL4

Summary by CodeRabbit

  • New Features

    • Users can now download complete postal registration documents with address information
    • Added certificate PDF download functionality with validation
  • Improvements

    • Enhanced error handling and user feedback when generating downloadable documents
    • Postal address data now properly integrated into document generation workflow

…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
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 6, 2026

📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Component Integration
src/lib/components/UserCard/UserCardContent.svelte
Extended GraphQL query to fetch additional postal fields (postalName, postalStreet, postalApartment, postalZip, postalCity, postalCountry) from conference object; passes new user prop to ParticipantStatusTab.
PDF Download Refactoring
src/lib/components/UserCard/tabs/ParticipantStatusTab.svelte
Added imports from pdfGenerator and formatNames; expanded component props to accept user object and extended conference with postal fields. Refactored downloadPostalDocs to fetch baseContent via getBaseDocumentsForPostal, construct RecipientData/ParticipantData structures, and call downloadCompletePostalRegistrationPDF. Refactored downloadCertificate to fetch certificate data and JWT, then call downloadCompleteCertificate. Both functions include error logging and toast notifications.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A PDF adventure springs to life,
With postal data, no more strife!
User props now flow down deep,
While certificates and docs we reap,
Error handling, graceful and bright! 📄✨

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main refactoring work: moving PDF generation logic to dedicated service functions, which is the central focus of the changes across both modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Boy Scout Scope ✅ Passed PR maintains proper scope by limiting changes to two files directly involved in PDF generation refactoring, with only necessary type mismatch fixes included.
Pr Label Required ✅ Passed The pull request has the PR: Bug label applied, which is one of the accepted release-category labels required by the check.
German Gender-Inclusive Language ✅ Passed The custom check for German gender-inclusive language in messages/de.json is not applicable to this PR as only component files were modified.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/fix-download-error-OigNt

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Strehk Strehk changed the title Refactor PDF generation to use service functions fix (management / userCard) Refactor PDF generation to use service functions Mar 6, 2026
@Strehk Strehk added the PR: Bug Something isn't working label Mar 6, 2026
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
@Strehk Strehk changed the title fix (management / userCard) Refactor PDF generation to use service functions fix (management / userCard): Refactor PDF generation to use service functions Mar 6, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between cbde180 and e043071.

📒 Files selected for processing (2)
  • src/lib/components/UserCard/UserCardContent.svelte
  • src/lib/components/UserCard/tabs/ParticipantStatusTab.svelte

Comment thread src/lib/components/UserCard/tabs/ParticipantStatusTab.svelte
Comment thread src/lib/components/UserCard/tabs/ParticipantStatusTab.svelte Outdated
Comment thread src/lib/components/UserCard/tabs/ParticipantStatusTab.svelte Outdated
Comment thread src/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
@Strehk Strehk merged commit 1d9f27f into main Mar 6, 2026
11 checks passed
@Strehk Strehk deleted the claude/fix-download-error-OigNt branch March 6, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants