-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajout des questions au gouvernements
- Loading branch information
1 parent
8afc5ad
commit caffbad
Showing
4 changed files
with
193 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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">N°{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é à: | ||
<Typography component="span" variant="body2"> | ||
{minIntRef?.libelleAbrege} | ||
</Typography> | ||
</Typography> | ||
|
||
<Typography fontWeight="light" variant="body2"> | ||
Date de dépôt: | ||
<Typography component="span" variant="body2"> | ||
{dateDepot && dateDepot.toLocaleDateString("fr-FR")} | ||
</Typography> | ||
</Typography> | ||
|
||
<Typography fontWeight="light" variant="body2"> | ||
Date de cloture: | ||
<Typography component="span" variant="body2"> | ||
{dateCloture && dateCloture.toLocaleDateString("fr-FR")} | ||
</Typography> | ||
</Typography> | ||
</Stack> | ||
</Stack> | ||
</AccordionDetails> | ||
</Accordion> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |