-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export groupé des fiches actions au format pdf
- Loading branch information
Showing
29 changed files
with
370 additions
and
129 deletions.
There are no files selected for viewing
16 changes: 8 additions & 8 deletions
16
...onDescription/ExportFicheActionButton.tsx → ...ons/ExportPdf/ExportFicheActionButton.tsx
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
78 changes: 78 additions & 0 deletions
78
...act/src/app/pages/collectivite/PlansActions/ExportPdf/ExportFicheActionGroupeesButton.tsx
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,78 @@ | ||
import { useEffect, useState } from 'react'; | ||
import ExportPDFButton from 'ui/export-pdf/ExportPDFButton'; | ||
import { useCurrentCollectivite } from 'core-logic/hooks/useCurrentCollectivite'; | ||
import { useFicheAction } from '../FicheAction/data/useFicheAction'; | ||
import { FicheActionPdfContent } from './ExportFicheActionButton'; | ||
import { useEventTracker } from '@tet/ui'; | ||
|
||
type FicheActionPdfWrapperProps = { | ||
ficheId: number; | ||
generateContent: (content: JSX.Element) => void; | ||
}; | ||
|
||
const FicheActionPdfWrapper = ({ | ||
ficheId, | ||
generateContent, | ||
}: FicheActionPdfWrapperProps) => { | ||
const { data: fiche } = useFicheAction(ficheId.toString()); | ||
|
||
return ( | ||
fiche && ( | ||
<FicheActionPdfContent fiche={fiche} generateContent={generateContent} /> | ||
) | ||
); | ||
}; | ||
|
||
const ExportFicheActionGroupeesButton = ({ | ||
fichesIds, | ||
}: { | ||
fichesIds: number[]; | ||
}) => { | ||
const collectivite = useCurrentCollectivite()!; | ||
const tracker = useEventTracker('app/actions-groupees-fiches-action'); | ||
|
||
const [isDataRequested, setIsDataRequested] = useState(false); | ||
const [content, setContent] = useState<JSX.Element[] | undefined>(undefined); | ||
|
||
const fileName = `fiches-actions-${collectivite.collectivite_id}`; | ||
|
||
useEffect(() => { | ||
if (content?.length === fichesIds.length) { | ||
setIsDataRequested(false); | ||
} | ||
}, [content?.length, fichesIds.length]); | ||
|
||
useEffect(() => setContent(undefined), [isDataRequested]); | ||
|
||
return ( | ||
<> | ||
<ExportPDFButton | ||
{...{ fileName }} | ||
content={content?.length === fichesIds.length ? content : undefined} | ||
requestData={() => setIsDataRequested(true)} | ||
icon="file-pdf-line" | ||
variant="outlined" | ||
onClick={() => | ||
tracker('export_PDF_telechargement_groupe', { | ||
collectivite_id: collectivite.collectivite_id, | ||
}) | ||
} | ||
> | ||
Exporter au format PDF | ||
</ExportPDFButton> | ||
|
||
{isDataRequested && | ||
fichesIds.map((id) => ( | ||
<FicheActionPdfWrapper | ||
key={id} | ||
ficheId={id} | ||
generateContent={(newContent) => { | ||
setContent((prevState) => [...(prevState ?? []), newContent]); | ||
}} | ||
/> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
export default ExportFicheActionGroupeesButton; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
Oops, something went wrong.