Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/lib/components/UserCard/UserCardContent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@
startConference
endConference
title
postalName
postalStreet
postalApartment
postalZip
postalCity
postalCountry
}
}
`);
Expand Down Expand Up @@ -279,6 +285,7 @@
status={participantStatus}
{userId}
{conferenceId}
{user}
{conference}
birthday={user?.birthday}
{isConferenceSupervisor}
Expand Down
119 changes: 101 additions & 18 deletions src/lib/components/UserCard/tabs/ParticipantStatusTab.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
import { getBaseDocumentsForPostal } from '$lib/queries/getBaseDocuments';
import { ofAgeAtConference } from '$lib/services/ageChecker';
import GuardianConsentNotNeeded from '$lib/components/GuardianConsentNotNeeded.svelte';
import {
downloadCompletePostalRegistrationPDF,
downloadCompleteCertificate,
type ParticipantData,
type RecipientData
} from '$lib/services/pdfGenerator';
import formatNames from '$lib/services/formatNames';

type AdministrativeStatus = 'DONE' | 'PENDING' | 'PROBLEM';

Expand All @@ -44,12 +51,32 @@
| undefined;
userId: string;
conferenceId: string;
user:
| {
id: string;
given_name?: string | null;
family_name?: string | null;
street?: string | null;
apartment?: string | null;
zip?: string | null;
city?: string | null;
country?: string | null;
birthday?: Date | null;
}
| null
| undefined;
conference:
| {
id: string;
startConference?: string | null;
endConference?: string | null;
title?: string | null;
postalName?: string | null;
postalStreet?: string | null;
postalApartment?: string | null;
postalZip?: number | null;
postalCity?: string | null;
postalCountry?: string | null;
}
| null
| undefined;
Expand All @@ -62,6 +89,7 @@
status,
userId,
conferenceId,
user,
conference,
birthday,
isConferenceSupervisor,
Expand All @@ -88,36 +116,91 @@

const downloadPostalDocs = async () => {
try {
const result = await getBaseDocumentsForPostal.fetch({
variables: { visitorId: userId, conferenceId }
const baseContent = await getBaseDocumentsForPostal.fetch({
variables: { conferenceId }
});
if (result.data?.postalRegistrationPDF) {
const a = document.createElement('a');
a.href = `data:application/pdf;base64,${result.data.postalRegistrationPDF}`;
a.download = `postal-registration-${userId}.pdf`;
a.click();
} else {

if (baseContent.errors) {
toast.error(m.httpGenericError());
return;
}

if (
!conference?.postalName ||
!conference?.postalStreet ||
!conference?.postalZip ||
!conference?.postalCity ||
!conference?.postalCountry
) {
toast.error(m.httpGenericError());
return;
}

if (user) {
const recipientData: RecipientData = {
name: `${conference.postalName}`,
address: `${conference.postalStreet} ${conference.postalApartment ?? ''}`,
zip: conference.postalZip?.toString() ?? '',
city: conference.postalCity ?? '',
country: conference.postalCountry ?? ''
};

const participantData: ParticipantData = {
id: user.id,
name: formatNames(user.given_name ?? undefined, user.family_name ?? undefined, {
givenNameFirst: true,
familyNameUppercase: true,
givenNameUppercase: true
}),
address: `${user.street} ${user.apartment ?? ''}, ${user.zip} ${user.city}, ${user.country}`,
birthday: user.birthday?.toLocaleDateString() ?? ''
Comment thread
Strehk marked this conversation as resolved.
Outdated
};

await downloadCompletePostalRegistrationPDF(
ofAgeAtConference(conference.startConference, user.birthday ?? new Date()),
Comment thread
Strehk marked this conversation as resolved.
Outdated
participantData,
recipientData,
baseContent.data?.findUniqueConference?.contractContent ?? undefined,
baseContent.data?.findUniqueConference?.guardianConsentContent ?? undefined,
baseContent.data?.findUniqueConference?.mediaConsentContent ?? undefined,
baseContent.data?.findUniqueConference?.termsAndConditionsContent ?? undefined,
`${formatNames(user.given_name ?? undefined, user.family_name ?? undefined, {
givenNameFirst: false,
delimiter: '_'
})}_postal_registration.pdf`
);
}
Comment thread
Strehk marked this conversation as resolved.
} catch {
} catch (error) {
console.error('Error generating PDF:', error);
toast.error(m.httpGenericError());
}
};

const downloadCertificate = async () => {
try {
const result = await certificateQuery.fetch({
variables: { visitorId: userId, conferenceId }
const certificateData = await certificateQuery.fetch({
variables: { conferenceId, userId }
});
if (result.data?.certificate) {
const a = document.createElement('a');
a.href = `data:application/pdf;base64,${result.data.certificate}`;
a.download = `certificate-${userId}.pdf`;
a.click();
} else {

const jwtData = certificateData.data?.getCertificateJWT;

if (!jwtData?.fullName || !jwtData?.jwt) {
toast.error(m.certificateDownloadError());
return;
}

if (user) {
await downloadCompleteCertificate(
jwtData,
certificateData.data?.findUniqueConference?.certificateContent ?? undefined,
`${formatNames(user.given_name ?? undefined, user.family_name ?? undefined, {
givenNameFirst: false,
delimiter: '_'
})}_certificate.pdf`
);
}
Comment thread
Strehk marked this conversation as resolved.
} catch {
} catch (error) {
console.error('Error generating PDF:', error);
toast.error(m.certificateDownloadError());
}
};
Expand Down
Loading