Skip to content

Commit

Permalink
Ajout des questions au gouvernements
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette committed Aug 22, 2024
1 parent 8afc5ad commit caffbad
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/depute/[slug]/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export default function DeputeTabs({ slug }: { slug: string }) {
component={Link}
href={`/depute/${slug}/votes`}
/>
<Tab
value="qag"
label="Questions"
component={Link}
href={`/depute/${slug}/qag`}
/>
</Tabs>
);
}
2 changes: 1 addition & 1 deletion app/depute/[slug]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default async function Page({
<>
<br />
Fin de mandat le{" "}
{new Date(circonscription.dateFin).toLocaleDateString()}
{new Date(circonscription.dateFin).toLocaleDateString("fr-FR")}
</>
)}
</Typography>
Expand Down
146 changes: 146 additions & 0 deletions app/depute/[slug]/qag/QuestionCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
"use client";
import * as React from "react";

import Typography from "@mui/material/Typography";
import Stack from "@mui/material/Stack";
import Accordion from "@mui/material/Accordion";
import AccordionDetails from "@mui/material/AccordionDetails";
import AccordionSummary from "@mui/material/AccordionSummary";

import ExpandMoreIcon from "@mui/icons-material/ExpandMore";

import { Organe, Question } from "@prisma/client";
import StatusChip from "@/components/StatusChip";

type QuestionCardProps = {
question: Question & { minIntRef: Organe | null };
};

export default function QuestionCard(props: QuestionCardProps) {
const {
question: {
uid,
type,
numero,
dateDepot,
dateCloture,
titre,
rubrique,
texteQuestion,
erratumQuestion,
texteReponse,
erratumReponse,
minIntRef,
},
} = props;

const pannelId = `${uid}-pannel`;
const headerId = `${uid}-header`;

return (
<Accordion
elevation={0}
disableGutters
sx={(theme) => ({
borderBottom: `solid ${theme.palette.divider} 1px`,
borderRadius: 0,
})}
>
<AccordionSummary
aria-controls={pannelId}
id={headerId}
expandIcon={<ExpandMoreIcon />}
>
<Stack
direction="row"
alignItems="center"
spacing={1}
sx={{ width: "100%", mr: 2 }}
>
{titre && <Typography>{titre}</Typography>}
{rubrique && <StatusChip size="small" label={rubrique} />}
{type && <StatusChip size="small" label={type} />}
</Stack>
</AccordionSummary>
<AccordionDetails>
<Stack direction="column" spacing={2}>
<Typography variant="caption">{numero}</Typography>
{texteQuestion && (
<Typography
fontWeight="light"
variant="body1"
flexGrow={1}
flexShrink={1}
flexBasis={0}
component="div"
sx={{ bgcolor: "grey.50", p: 1 }}
>
{texteQuestion}
</Typography>
)}
{texteReponse && (
<Typography
fontWeight="light"
variant="body1"
flexGrow={1}
flexShrink={1}
flexBasis={0}
component="div"
sx={{ bgcolor: "grey.50", p: 1 }}
>
{texteReponse}
</Typography>
)}
{erratumQuestion && (
<Typography
fontWeight="light"
variant="body1"
flexGrow={1}
flexShrink={1}
flexBasis={0}
component="div"
sx={{ bgcolor: "grey.50", p: 1 }}
>
{erratumQuestion}
</Typography>
)}
{erratumReponse && (
<Typography
fontWeight="light"
variant="body1"
flexGrow={1}
flexShrink={1}
flexBasis={0}
component="div"
sx={{ bgcolor: "grey.50", p: 1 }}
>
{erratumReponse}
</Typography>
)}
<Stack direction="row" justifyContent="space-between" flexBasis={0}>
<Typography fontWeight="light" variant="body2">
Envoyé à:&nbsp;
<Typography component="span" variant="body2">
{minIntRef?.libelleAbrege}
</Typography>
</Typography>

<Typography fontWeight="light" variant="body2">
Date de dépôt:&nbsp;
<Typography component="span" variant="body2">
{dateDepot && dateDepot.toLocaleDateString("fr-FR")}
</Typography>
</Typography>

<Typography fontWeight="light" variant="body2">
Date de cloture:&nbsp;
<Typography component="span" variant="body2">
{dateCloture && dateCloture.toLocaleDateString("fr-FR")}
</Typography>
</Typography>
</Stack>
</Stack>
</AccordionDetails>
</Accordion>
);
}
40 changes: 40 additions & 0 deletions app/depute/[slug]/qag/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from "react";

import { prisma } from "@/prisma";
import QuestionCard from "./QuestionCard";

async function getDeputeQuestionsUnCached(slug: string) {
try {
return await prisma.acteur.findFirst({
where: { slug },
include: {
questions: {
include: {
minIntRef: true,
},
},
},
});
} catch (error) {
console.error(`Error fetching QAG from depute ${slug}:`, error);
throw error;
}
}

const getDeputeQuestions = React.cache(getDeputeQuestionsUnCached);

export default async function Votes({ params }: { params: { slug: string } }) {
const deputeWithQuestions = await getDeputeQuestions(params.slug);

if (!deputeWithQuestions) {
return <p>Deputé inconnu</p>;
}
const { questions = [] } = deputeWithQuestions;
return (
<div>
{questions?.map((question) => {
return <QuestionCard key={question.uid} question={question} />;
})}
</div>
);
}

0 comments on commit caffbad

Please sign in to comment.