Skip to content

Commit f5f8bd5

Browse files
author
ledouxm
committed
feat: enhance state report handling by adding validation status and attachment_id management
1 parent 974b101 commit f5f8bd5

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

packages/backend/src/features/mail.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ export const sendValidationRequestMail = ({
116116
<p>${creatorName} vous soumet un constat d'état${title} pour validation.</p>
117117
<p>Veuillez consulter le document et l'accepter ou le refuser en cliquant sur le lien ci-dessous :</p>
118118
<p><a href="${link}">${link}</a></p>
119-
<p>Ce lien est valable 7 jours.</p>
120-
<p>Cordialement</p>`,
119+
<p>Ce lien est valable 7 jours.</p>`,
121120
});
122121

123122
return transporter.sendMail({
@@ -149,8 +148,7 @@ export const sendValidationResultMail = ({
149148
title: `Constat d'état${title}${accepted ? "Accepté" : "Refusé"}`,
150149
content: `<p>Bonjour,</p>
151150
<p>Votre constat d'état${title} a été <strong>${decision}</strong> par ${validatorEmail}.</p>
152-
${comment ? `<p>Commentaire : ${comment}</p>` : ""}
153-
<p>Cordialement</p>`,
151+
${comment ? `<p>Commentaire : ${comment}</p>` : ""}`,
154152
});
155153

156154
return transporter.sendMail({

packages/backend/src/routes/validationRoutes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export const validationPlugin: FastifyPluginAsyncTypebox = async (fastify, _) =>
122122

123123
await trx
124124
.updateTable("state_report")
125-
.set({ validation_status: "accepted" })
125+
.set({ validation_status: "accepted", attachment_id: validation.pdf_path })
126126
.where("id", "=", validation.state_report_id!)
127127
.execute();
128128
});

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ import { StateReportActions } from "./StateReportActions";
1717
export const StateReportListItem = ({
1818
report,
1919
isLast,
20-
isPendingValidation,
2120
onClick,
2221
}: {
2322
report: StateReportWithUser;
2423
isLast?: boolean;
25-
isPendingValidation?: boolean;
2624
onClick?: () => void;
2725
}) => {
2826
const ref = useRef<HTMLButtonElement>(null);
@@ -34,6 +32,8 @@ export const StateReportListItem = ({
3432
const byText = report.redacted_by ? `par ${report.redacted_by}` : null;
3533
const isDraft = !report.attachment_id;
3634

35+
const status = (report.validation_status as "pending" | "accepted" | "declined") || (isDraft ? "draft" : "published");
36+
3737
return (
3838
<Flex className="report-list-item" position="relative" flexDirection="column" width="100%">
3939
<Link
@@ -77,7 +77,7 @@ export const StateReportListItem = ({
7777
{byText}
7878
</Box>
7979
<Box mt="8px" mb={whereText ? "0" : "24px"}>
80-
<ReportBadge status={isPendingValidation ? "pending_validation" : isDraft ? "draft" : "published"} />
80+
<ReportBadge status={status} />
8181
</Box>
8282
</Box>
8383
</Link>
@@ -168,16 +168,27 @@ const MenuMobileModalContent = ({ onClose, report }: MenuProps) => {
168168

169169
type MenuProps = { onClose: (e: Event) => void; report: StateReportWithUser };
170170

171-
type ReportStatus = "draft" | "pending_validation" | "published";
171+
type ReportStatus = "draft" | "pending" | "accepted" | "declined" | "published";
172172
const ReportBadge = ({ status }: { status: ReportStatus }) => {
173173
const labels: Record<ReportStatus, string> = {
174174
draft: "Brouillon",
175-
pending_validation: "En attente de validation",
175+
pending: "En attente de validation",
176+
accepted: "Envoyé",
177+
declined: "Refusé",
176178
published: "Envoyé",
177179
};
180+
181+
const severities: Record<ReportStatus, "info" | "success" | "error"> = {
182+
draft: "info",
183+
pending: "info",
184+
accepted: "success",
185+
declined: "info",
186+
published: "success",
187+
};
188+
178189
return (
179190
<Badge
180-
severity={status === "draft" ? "info" : "success"}
191+
severity={severities[status]}
181192
noIcon
182193
small
183194
style={{
@@ -205,12 +216,16 @@ const ReportBadge = ({ status }: { status: ReportStatus }) => {
205216

206217
const icons: Record<ReportStatus, string> = {
207218
draft: "ri-timer-fill",
208-
pending_validation: "ri-time-line",
219+
pending: "ri-time-line",
220+
accepted: "ri-send-plane-fill",
221+
declined: "ri-close-line",
209222
published: "ri-send-plane-fill",
210223
};
211224

212225
const colors: Record<ReportStatus, [string, string]> = {
213226
draft: ["#716043", "#FEECC2"] as const,
214-
pending_validation: ["#695240", "#FFE9E6"] as const,
227+
pending: ["#695240", "#FFE9E6"] as const,
228+
accepted: ["#18753C", "#D1F1D9"] as const,
229+
declined: ["#B00020", "#FFCDD2"] as const,
215230
published: ["#18753C", "#D1F1D9"] as const,
216231
};

packages/frontend/src/features/state-report/utils.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@ export type StateReportStep = z.infer<typeof stateReportStepSchema>;
2121

2222
export const useIsStateReportDisabled = () => {
2323
const form = useStateReportFormContext();
24-
const hasAttachment = useWatch({ control: form.control, name: "attachment_id" });
25-
return getIsStateReportDisabled({ attachment_id: hasAttachment });
24+
const [hasAttachment, validationStatus] = useWatch({
25+
control: form.control,
26+
name: ["attachment_id", "validation_status"],
27+
});
28+
return getIsStateReportDisabled({ attachment_id: hasAttachment, validation_status: validationStatus });
2629
};
2730

28-
export const getIsStateReportDisabled = (stateReport: { attachment_id: string | null }) => {
29-
return !!stateReport.attachment_id;
31+
export const getIsStateReportDisabled = (stateReport: {
32+
attachment_id: string | null;
33+
validation_status: string | null;
34+
}) => {
35+
return !!stateReport.attachment_id && stateReport.validation_status !== "declined";
3036
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ const ConstatPdf = () => {
157157
// propagate isDisabled to children
158158
useEffect(() => {
159159
if (!stateReport) return;
160-
const isStateReportDisabled = getIsStateReportDisabled({ attachment_id: stateReport.attachment_id });
160+
const isStateReportDisabled = getIsStateReportDisabled({ ...stateReport });
161161
form.setValue("isStateReportDisabled", isStateReportDisabled);
162162
}, [stateReport]);
163163

0 commit comments

Comments
 (0)