Skip to content

Commit

Permalink
feat: apply new pdf styles
Browse files Browse the repository at this point in the history
  • Loading branch information
ledouxm committed May 22, 2024
1 parent d3a95d8 commit 4cda7e5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/frontend/src/features/InfoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ export const InfoForm = () => {

const date = parse(`${day}T${time}`, "yyyy-MM-dd'T'HH:mm", new Date());

console.log(day, time, date);
if (!day || !time || Number.isNaN(date.getTime())) {
form.setValue("meetDate", undefined as any);
return;
}

form.setValue("meetDate", date);
form.setValue("meetDate", date.toISOString() as any);
};

const setTime = (e: any) => {
Expand Down
45 changes: 41 additions & 4 deletions packages/pdf/src/report.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ export const ReportPDFDocument = ({ udap, htmlString, images }: { udap: Udap; ht
text-align: right;
align-items: center;
font-size: 18px;
}
.meeting-date {
text-align: right;
display: flex;
justify-content: flex-end;
align-items: flex-end;
}
Expand Down Expand Up @@ -84,9 +90,22 @@ export const getReportHtmlString = (report: ReportWithUser, chipOptions: Clause[
const serviceInstructeur = report.serviceInstructeur
? serviceInstructeurs.find((service) => service.tiers === report.serviceInstructeur)
: null;
const meetDate = report.meetDate ? new Date(report.meetDate) : null;

return minifyHtml(`
<p>
${
meetDate
? `<span style='text-align: right;'>
Suite au rendez-vous du ${meetDate?.toLocaleDateString("fr-FR", {
year: "numeric",
month: "long",
day: "numeric",
})}
</span><br/><br/>`
: ""
}
<strong>Votre interlocuteur : ${report.user?.name ?? ""}</strong><br/>
Demandeur : ${report.applicantName ?? ""}<br/>
Adresse du projet : ${report.applicantAddress ?? ""}<br/>
Expand Down Expand Up @@ -117,9 +136,20 @@ export const getReportHtmlString = (report: ReportWithUser, chipOptions: Clause[
<p>
<strong>Contacts utiles : </strong><br/>
Vous pouvez contacter le service de la collectivité en charge de l’instruction de votre dossier : TODO (quelles informations afficher ?)<br/><br/>
${
serviceInstructeur
? `<span>
Vous pouvez contacter le service de la collectivité en charge de l’instruction de votre dossier : <br/>
${serviceInstructeur["libellé tiers"]}, ${serviceInstructeur["liste de diffusion"]}.
</span>
<br/><br/>`
: ""
}
${contacts.map((contact) => `<span>${contact}</span>`).join("<br/><br/>")}
Nous contacter : ${udap.name}, ${udap.email}, ${udap.phone}
<span>
Nous contacter : ${udap.name}, ${udap.email}, ${udap.phone ? formatPhoneNumber(udap.phone?.toString()) : ""}
</span>
</p>
<p>
Expand All @@ -128,11 +158,18 @@ export const getReportHtmlString = (report: ReportWithUser, chipOptions: Clause[
</p>
<p>
Ce compte rendu ne remplace pas la demande d’autorisation de travaux.
<strong>Ce compte rendu ne remplace pas la demande d’autorisation de travaux.</strong>
</p>
`);
};

const formatPhoneNumber = (phoneNumber: string) => {
return `0${phoneNumber.slice(0, 1)} ${phoneNumber.slice(1, 3)} ${phoneNumber.slice(3, 5)} ${phoneNumber.slice(
5,
7,
)} ${phoneNumber.slice(7, 9)}`;
};

const getMultipleChips = (chipOptions: Clause[], key: string, values: string) => {
return values
.split(",")
Expand Down

0 comments on commit 4cda7e5

Please sign in to comment.