Skip to content

Commit abeb8b7

Browse files
fix: fix fetching commissions (#616)
1 parent 84260f9 commit abeb8b7

4 files changed

Lines changed: 42 additions & 33 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "Commission" ADD COLUMN "archived" BOOLEAN;

prisma/schema.prisma

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
generator client {
22
provider = "prisma-client-js"
33
previewFeatures = ["fullTextSearch", "referentialActions"]
4-
engineType = "binary"
4+
engineType = "binary"
55
}
66

77
datasource db {
@@ -17,6 +17,7 @@ model Commission {
1717
dossiers Dossier[]
1818
lastSent DateTime?
1919
SendList SendList[]
20+
archived Boolean?
2021
}
2122

2223
model SocieteProduction {

src/pages/api/commissions/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ const getPastCommissions = async () => {
188188
},
189189
},
190190
orderBy: { date: "desc" },
191-
where: { date: { lt: new Date() }, dossiers: { some: {} } },
191+
where: { date: { lt: new Date() }, dossiers: { some: {} }, archived: false },
192192
});
193193
};
194194

src/pages/dossiers/index.tsx

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,32 +70,38 @@ const Page: React.FC = () => {
7070
const [showTable, setShowTable] = React.useState<boolean>(true);
7171
// eslint-disable-next-line @typescript-eslint/no-unused-vars
7272
const [status, setStatus] = React.useState<statusGroup>("futur");
73-
const [loadingPdf, setLoadingPdf] = React.useState<string>('')
73+
const [loadingPdf, setLoadingPdf] = React.useState<string>("");
7474

7575
// eslint-disable-next-line @typescript-eslint/no-shadow
7676
const handleStatus = (status: statusGroup) => {
7777
setStatus(status);
7878
};
7979

80-
const { commissions, ...swrCommissions } = useCommissions(
81-
"upcoming",
82-
//@ts-expect-error
83-
session.data.dbUser.role !== "MEMBRE"
84-
? "all"
85-
: //@ts-expect-error
86-
session.data.dbUser.departements
87-
);
80+
const { commissions, ...swrCommissions } =
81+
status === "futur"
82+
? useCommissions(
83+
"upcoming",
84+
//@ts-expect-error
85+
session.data.dbUser.role !== "MEMBRE"
86+
? "all"
87+
: //@ts-expect-error
88+
session.data.dbUser.departements
89+
)
90+
: { commissions: [] };
8891

8992
console.log("commissions : ", commissions);
9093

91-
const { ...commissionsPast } = useCommissions(
92-
"past",
93-
//@ts-expect-error
94-
session.data.dbUser.role !== "MEMBRE"
95-
? "all"
96-
: //@ts-expect-error
97-
session.data.dbUser.departements
98-
);
94+
const { ...commissionsPast } =
95+
status === "past"
96+
? useCommissions(
97+
"past",
98+
//@ts-expect-error
99+
session.data.dbUser.role !== "MEMBRE"
100+
? "all"
101+
: //@ts-expect-error
102+
session.data.dbUser.departements
103+
)
104+
: { commissions: [] };
99105

100106
const [searchValueInput, setSearchValueInput] = useState<string | undefined>(
101107
undefined
@@ -471,36 +477,36 @@ const Page: React.FC = () => {
471477
<ButtonLink
472478
light={true}
473479
onClick={async () => {
474-
setLoadingPdf('ODJ_' + commission.id);
480+
setLoadingPdf("ODJ_" + commission.id);
475481
await generateOdj(commission);
476-
setLoadingPdf('');
482+
setLoadingPdf("");
477483
}}
478484
>
479485
<RiDownloadLine
480486
style={{ marginRight: "10px" }}
481487
/>
482-
{loadingPdf === 'ODJ_' + commission.id ?
483-
(<IconLoader></IconLoader>)
484-
:
485-
(<span>Ordre du jour</span>)
486-
}
488+
{loadingPdf === "ODJ_" + commission.id ? (
489+
<IconLoader></IconLoader>
490+
) : (
491+
<span>Ordre du jour</span>
492+
)}
487493
</ButtonLink>
488494
<ButtonLink
489495
light={true}
490496
onClick={async () => {
491-
setLoadingPdf('PV_' + commission.id);
497+
setLoadingPdf("PV_" + commission.id);
492498
await generatePV(commission);
493-
setLoadingPdf('');
499+
setLoadingPdf("");
494500
}}
495501
>
496502
<RiDownloadLine
497503
style={{ marginRight: "10px" }}
498504
/>
499-
{loadingPdf === 'PV_' + commission.id ?
500-
(<IconLoader></IconLoader>)
501-
:
502-
(<span>Procès Verbal</span>)
503-
}
505+
{loadingPdf === "PV_" + commission.id ? (
506+
<IconLoader></IconLoader>
507+
) : (
508+
<span>Procès Verbal</span>
509+
)}
504510
</ButtonLink>
505511
</div>
506512
)}

0 commit comments

Comments
 (0)