Skip to content

Commit

Permalink
Export groupé des fiches actions au format pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
mariheck committed Dec 9, 2024
1 parent 1eaee4f commit 777966d
Show file tree
Hide file tree
Showing 29 changed files with 370 additions and 129 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { createElement, useEffect, useState } from 'react';
import { FicheAction } from '@tet/api/plan-actions';
import { useFicheActionChemins } from '../../PlanAction/data/usePlanActionChemin';
import { useIndicateurDefinitions } from '../../../Indicateurs/Indicateur/useIndicateurDefinition';
import { useFichesActionLiees } from '../data/useFichesActionLiees';
import { useActionListe } from '../data/options/useActionListe';
import { useAnnexesFicheActionInfos } from '../data/useAnnexesFicheActionInfos';
import { useFicheActionNotesSuivi } from '../data/useFicheActionNotesSuivi';
import { useFicheActionChemins } from '../PlanAction/data/usePlanActionChemin';
import { useIndicateurDefinitions } from '../../Indicateurs/Indicateur/useIndicateurDefinition';
import { useFichesActionLiees } from '../FicheAction/data/useFichesActionLiees';
import { useActionListe } from '../FicheAction/data/options/useActionListe';
import { useAnnexesFicheActionInfos } from '../FicheAction/data/useAnnexesFicheActionInfos';
import { useFicheActionNotesSuivi } from '../FicheAction/data/useFicheActionNotesSuivi';
import ExportPDFButton from 'ui/export-pdf/ExportPDFButton';
import FicheActionPdf from '../FicheActionPdf/FicheActionPdf';
import FicheActionPdf from './FicheActionPdf/FicheActionPdf';

type FicheActionPdfContentProps = {
fiche: FicheAction;
generateContent: (content: JSX.Element) => void;
};

const FicheActionPdfContent = ({
export const FicheActionPdfContent = ({
fiche,
generateContent,
}: FicheActionPdfContentProps) => {
Expand Down
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;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { preset } from '@tet/ui';
import { TAxeRow } from 'types/alias';
import { Paragraph, Stack } from 'ui/export-pdf/components';
import { ArrowRightIcon } from 'ui/export-pdf/assets/icons';
import { generateTitle } from '../data/utils';
import { generateTitle } from '../../FicheAction/data/utils';

const { colors } = preset.theme.extend;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
} from 'ui/export-pdf/components';
import { DiscussIcon, FileIcon, LinkIcon } from 'ui/export-pdf/assets/icons';
import { getAuthorAndDate } from 'ui/shared/preuves/Bibliotheque/utils';
import { AnnexeInfo } from '../data/useAnnexesFicheActionInfos';
import { generateTitle } from '../data/utils';
import { AnnexeInfo } from '../../FicheAction/data/useAnnexesFicheActionInfos';
import { generateTitle } from '../../FicheAction/data/utils';

const { colors } = preset.theme.extend;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@tet/api/plan-actions';
import { TActionStatutsRow, TAxeRow } from 'types/alias';
import { IndicateurDefinition } from '@tet/api/indicateurs/domain';
import { AnnexeInfo } from '../data/useAnnexesFicheActionInfos';
import { AnnexeInfo } from '../../FicheAction/data/useAnnexesFicheActionInfos';
import { Divider, Stack, Title } from 'ui/export-pdf/components';

import Acteurs from './Acteurs';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
LoopLeftIcon,
UserIcon,
} from 'ui/export-pdf/assets/icons';
import { generateTitle } from '../data/utils';
import { generateTitle } from '../../FicheAction/data/utils';

const { colors } = preset.theme.extend;

Expand Down Expand Up @@ -80,7 +80,7 @@ const FicheLieeCard = ({ ficheLiee }: FicheLieeCardProps) => {
<Stack className="mt-auto" gap={1}>
{/* Pilotes et date de fin prévisionnelle */}
{(hasPilotes || hasDateDeFin || ameliorationContinue) && (
<Stack direction="row" gap={2}>
<Stack direction="row" gap={2} className="flex-wrap">
{/* Personnes pilote */}
{hasPilotes && (
<Stack gap={1} direction="row" className="items-center">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { format } from 'date-fns';
import { FicheActionNote } from '@tet/api/plan-actions';
import { preset } from '@tet/ui';
import { Card, Paragraph, Stack, Title } from 'ui/export-pdf/components';
import { format } from 'date-fns';
import { EditIcon, UserIcon } from 'ui/export-pdf/assets/icons';

const { colors } = preset.theme.extend;

type NotesDeSuiviCardProps = {
noteSuivi: FicheActionNote;
Expand All @@ -22,20 +26,25 @@ const NotesDeSuiviCard = ({ noteSuivi }: NotesDeSuiviCardProps) => {
<Title variant="h6">{new Date(dateNote).getFullYear()}</Title>

{/* Contenu */}
<Paragraph className="text-[0.65rem] text-grey-8 font-medium">
{note}
</Paragraph>
<Paragraph className="text-[0.65rem]">{note}</Paragraph>

{/* Créée par... / modifiée par... */}
<Paragraph className="text-[0.65rem]">
Créée le {format(new Date(createdAt), 'dd/MM/yyyy')} par {createdBy}
<Stack gap={1} direction="row" className="items-center">
<UserIcon fill={colors.grey[8]} />
<Paragraph className="text-[0.65rem] text-grey-8">
Créée le {format(new Date(createdAt), 'dd/MM/yyyy')} par {createdBy}
</Paragraph>
{modifiedAt !== createdAt && (
<>
| Modifiée le {format(new Date(modifiedAt), 'dd/MM/yyyy')} par{' '}
{modifiedBy}
<Paragraph className="text-[0.65rem] text-grey-8">| </Paragraph>
<EditIcon fill={colors.grey[8]} />
<Paragraph className="text-[0.65rem] text-grey-8">
Modifiée le {format(new Date(modifiedAt), 'dd/MM/yyyy')} par{' '}
{modifiedBy}
</Paragraph>
</>
)}
</Paragraph>
</Stack>
</Stack>
</Card>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Pilotes = ({ fiche }: FicheActionPdfProps) => {

return (
<Card className="justify-center">
<PersonnePilotePicto className="h-15 w-15 mx-auto" />
<PersonnePilotePicto className="h-14 w-14 mx-auto" />
<Stack gap={1} className="text-center items-center">
<Title variant="h6" className="uppercase text-center">
Personnes pilotes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FicheResume } from '@tet/api/plan-actions/domain';
import { Button, Card, Notification, Tooltip } from '@tet/ui';
import { Button, Card, Checkbox, Notification, Tooltip } from '@tet/ui';
import classNames from 'classnames';
import { useCurrentCollectivite } from 'core-logic/hooks/useCurrentCollectivite';
import { useState } from 'react';
Expand All @@ -24,8 +24,12 @@ type FicheActionCardProps = {
/** Pour invalider la liste des fiches d'un axe à la suppression de la fiche */
axeIdToInvalidate?: number;
editKeysToInvalidate?: QueryKey[];
/** Etat sélectionné ou non de la fiche */
isSelected?: boolean;
/** Dissociation de la fiche action */
onUnlink?: () => void;
/** Sélection de la fiche action */
onSelect?: (isSelected: boolean) => void;
};

const FicheActionCard = ({
Expand All @@ -35,7 +39,9 @@ const FicheActionCard = ({
isEditable = false,
axeIdToInvalidate,
editKeysToInvalidate,
isSelected = false,
onUnlink,
onSelect,
}: FicheActionCardProps) => {
const collectivite = useCurrentCollectivite();

Expand All @@ -60,7 +66,7 @@ const FicheActionCard = ({
onClick={onUnlink}
/>
)}
{isEditable && (
{isEditable && !onSelect && (
<>
<>
{isEditOpen && (
Expand Down Expand Up @@ -117,8 +123,10 @@ const FicheActionCard = ({
'hover:border-primary-3 hover:!bg-primary-1': !isNotClickable,
}
)}
href={link}
href={onSelect ? undefined : link}
onClick={onSelect ? () => onSelect(!isSelected) : undefined}
disabled={isNotClickable}
isSelected={isSelected}
external={openInNewTab}
header={
// Badges priorité et statut de la fiche
Expand Down Expand Up @@ -171,9 +179,12 @@ const FicheActionCard = ({
}
>
{/* Titre de la fiche action */}
<span className="text-base font-bold text-primary-9">
{generateTitle(ficheAction.titre)}
</span>
<div className="flex min-w-min">
{onSelect && <Checkbox checked={isSelected} />}
<span className="text-base font-bold text-primary-9">
{generateTitle(ficheAction.titre)}
</span>
</div>

{/* Plans d'action dans lesquels sont la fiche */}
<span title="Emplacements" className="text-sm font-medium">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FicheAction } from '@tet/api/plan-actions';
import ModaleDescription from './ModaleDescription';
import ModaleEmplacement from './EmplacementFiche/ModaleEmplacement';
import ModaleSuppression from './ModaleSuppression';
import ExportFicheActionButton from './ExportFicheActionButton';
import ExportFicheActionButton from '../../ExportPdf/ExportFicheActionButton';

type MenuDescriptionProps = {
isReadonly: boolean;
Expand Down
Loading

0 comments on commit 777966d

Please sign in to comment.