Skip to content

Commit 44f58e1

Browse files
author
ledouxm
committed
feat: add Mailpit service for email testing, remove console logs from various components, and optimize PDF viewing logic
1 parent 22f2077 commit 44f58e1

File tree

10 files changed

+36
-68
lines changed

10 files changed

+36
-68
lines changed

docker-compose.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,14 @@ services:
148148
- ${KEYCLOAK_PORT:-8080}:8080
149149
depends_on:
150150
- pg
151+
152+
mailpit:
153+
image: axllent/mailpit
154+
restart: unless-stopped
155+
ports:
156+
- "${SMTP_PORT}:1025"
157+
- "${SMTP_WEB_PORT}:8025"
158+
environment:
159+
MP_MAX_MESSAGES: 500
160+
MP_SMTP_AUTH_ACCEPT_ANY: 1
161+
MP_SMTP_AUTH_ALLOW_INSECURE: 1

packages/frontend/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { RouterProvider, createRouter } from "@tanstack/react-router";
22
import { useAuthContext } from "./contexts/AuthContext";
33
import { routeTree } from "./routeTree.gen";
44
import "./features/polyfill";
5+
56
export const App = () => {
67
const { auth } = useAuthContext();
78
return <RouterProvider router={router} />;

packages/frontend/src/db/Connector.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export class Connector implements PowerSyncBackendConnector {
4040
}
4141

4242
export const getTokenOrRefresh = async () => {
43-
console.log("getting token or refresh");
4443
if (!apiStore.loaded) throw new Error("Auth not loaded");
4544

4645
if (!apiStore.accessToken || !apiStore.refreshToken || !apiStore.expiresAt) throw new Error("No token found");
@@ -68,7 +67,7 @@ export const getTokenOrRefresh = async () => {
6867
apiStore.expiresAt = resp.expiresAt;
6968
await apiStore.save();
7069
}
71-
} else console.log("token valid");
70+
}
7271

7372
return apiStore.accessToken;
7473
};

packages/frontend/src/features/state-report/WithReferencePop.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ export const WithReferencePop = () => {
3333
const hasReferencePop = !!referencePop;
3434
if (!hasReferencePop) return null;
3535

36-
console.log(referencePop);
37-
3836
return (
3937
<>
4038
<Box width="100%" height="100%">

packages/frontend/src/features/state-report/alerts/StateReportAlertsMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const AlertSectionsForm = ({
106106
defaultValues: { alertSections },
107107
});
108108
const fieldArray = useFieldArray({ name: "alertSections", control: sectionsForm.control });
109-
console.log("AlertSectionsForm render", { alertSections, selectedSection });
109+
110110
return (
111111
<>
112112
<AlertSectionSync form={sectionsForm} baseAlerts={alertSections} />

packages/frontend/src/features/state-report/pdf/ConstatPdf.queries.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const constatPdfQueries = {
6161
attachmentQuery.map(async (attachment) => {
6262
const file = await attachmentLocalStorage.readFile(attachment.local_uri!);
6363
const url = URL.createObjectURL(new Blob([file], { type: attachment.media_type || undefined }));
64-
console.log(file, url);
64+
6565
return {
6666
...attachment,
6767
file: url,
Lines changed: 19 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,32 @@
1-
import { useEffect, useRef, useState } from "react";
2-
import { useQuery } from "@tanstack/react-query";
3-
import { getStateReportHtmlString, StateReportPDFDocument, StateReportPDFDocumentProps } from "@cr-vif/pdf/constat";
4-
import { pdf, BlobProvider, PDFViewer } from "@react-pdf/renderer";
5-
import { Center } from "#components/MUIDsfr.tsx";
6-
import { Spinner } from "#components/Spinner.tsx";
7-
import { PdfCanvas } from "../../../routes/pdf.$reportId";
1+
import { getStateReportHtmlString, StateReportPDFDocument } from "@cr-vif/pdf/constat";
2+
import { PDFViewer } from "@react-pdf/renderer";
3+
import { useMemo } from "react";
84
import { useUser } from "../../../contexts/AuthContext";
95
import { useHtmlString } from "./ConstatPdf.hook";
10-
11-
const supportsPromiseWithResolvers = typeof (Promise as any).withResolvers === "function";
6+
import { Center } from "#components/MUIDsfr.tsx";
127

138
export const ViewConstatPdf = () => {
149
const htmlString = useHtmlString();
1510
const user = useUser()!;
1611

12+
const document = useMemo(
13+
() => (
14+
<StateReportPDFDocument
15+
htmlString={htmlString}
16+
images={{ marianne: "/marianne.png", marianneFooter: "/marianne_footer.png" }}
17+
service={user.service as any}
18+
/>
19+
),
20+
[htmlString, user.service?.id],
21+
);
22+
1723
return (
1824
<Center>
19-
<Center width="800px" flexDirection="column">
20-
<View
21-
htmlString={htmlString}
22-
images={{ marianne: "/marianne.png", marianneFooter: "/marianne_footer.png" }}
23-
service={user.service as any}
24-
/>
25+
<Center width="800px" flexDirection="column" paddingX="16px" marginTop="32px" marginBottom="96px">
26+
<PDFViewer style={{ height: "calc(100vh - 80px)", maxWidth: "100vw" }} width="100%" showToolbar={false}>
27+
{document}
28+
</PDFViewer>
2529
</Center>
2630
</Center>
2731
);
2832
};
29-
30-
const View = (props: StateReportPDFDocumentProps) => <LegacyView {...props} />;
31-
// supportsPromiseWithResolvers ? <ModernView {...props} /> : <LegacyView {...props} />;
32-
33-
const ModernView = (props: StateReportPDFDocumentProps) => {
34-
const [height, setHeight] = useState(window.innerHeight);
35-
36-
useEffect(() => {
37-
const onResize = () => setHeight(window.innerHeight);
38-
window.addEventListener("resize", onResize);
39-
return () => window.removeEventListener("resize", onResize);
40-
}, []);
41-
42-
return (
43-
<PDFViewer width="100%" height={height} showToolbar={false}>
44-
<StateReportPDFDocument {...props} />
45-
</PDFViewer>
46-
);
47-
};
48-
49-
const LegacyView = (props: StateReportPDFDocumentProps) => {
50-
const query = useQuery({
51-
queryKey: ["state-report-pdf", props.htmlString],
52-
queryFn: async () => {
53-
const blob = await pdf(<StateReportPDFDocument {...props} />).toBlob();
54-
return blob;
55-
},
56-
gcTime: 0,
57-
refetchOnWindowFocus: false,
58-
enabled: !!props.htmlString,
59-
});
60-
61-
if (query.isLoading || !query.data)
62-
return (
63-
<Center height="100%" mt="100px">
64-
<Spinner />
65-
</Center>
66-
);
67-
68-
return <PdfCanvas blob={query.data as Blob} />;
69-
};

packages/frontend/src/features/upload/UploadImage.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ export const UploadImage = ({
1616
const attachment = attachments.length > 0 ? attachments[0] : null;
1717
const hideButton = !multiple && !!attachment;
1818

19-
console.log(imageTable, attachments);
20-
2119
return (
2220
<Box>
2321
{hideButton ? null : (

packages/frontend/src/routes/constat_.$constatId.pdf.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ const ConstatPdf = () => {
110110
const sectionsQuery = useQuery(constatPdfQueries.sections({ constatId }));
111111
const alertsQuery = useQuery(constatPdfQueries.alerts({ constatId }));
112112

113-
console.log("stateReportQuery", stateReportQuery);
114113
const stateReport = stateReportQuery.data;
115114
const sections = sectionsQuery.data;
116115
const alerts = alertsQuery.data;
@@ -146,13 +145,11 @@ const ConstatPdf = () => {
146145
// generate html string (only once since displaying it is a heavy operation)
147146
const isSetRef = useRef(false);
148147

149-
console.log(sections, stateReport, alerts);
150-
151148
useEffect(() => {
152149
if (isSetRef.current) return;
153150
if (!sections || !stateReport || !alerts) return;
154151
const htmlString = getStateReportHtmlString({ stateReport: stateReport, visitedSections: sections as any, alerts });
155-
console.log("HTML STRING GENERATED", htmlString);
152+
156153
form.setValue("htmlString", htmlString);
157154

158155
isSetRef.current = true;

pnpm-lock.yaml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)