diff --git a/src/client/src/components/DataSheets/Sections/Establishment/Helps/EstablishmentHelps.js b/src/client/src/components/DataSheets/Sections/Establishment/Helps/EstablishmentHelps.js index cf12d20e..1def7b11 100644 --- a/src/client/src/components/DataSheets/Sections/Establishment/Helps/EstablishmentHelps.js +++ b/src/client/src/components/DataSheets/Sections/Establishment/Helps/EstablishmentHelps.js @@ -2,6 +2,7 @@ import PropTypes from "prop-types"; import React, { useState } from "react"; import BlocTitle from "../../SharedComponents/BlocTitle/BlocTitle.jsx"; +import AidesFinancieres from "./Subcategory/AidesFinancieres.jsx"; import Apprentissage from "./Subcategory/Apprentissage"; import ContratsAides from "./Subcategory/ContratsAides"; @@ -19,6 +20,7 @@ const EstablishmentHelps = ({ siret }) => {
+
)} diff --git a/src/client/src/components/DataSheets/Sections/Establishment/Helps/Subcategory/AidesFinancieres.gql.js b/src/client/src/components/DataSheets/Sections/Establishment/Helps/Subcategory/AidesFinancieres.gql.js new file mode 100644 index 00000000..94d08764 --- /dev/null +++ b/src/client/src/components/DataSheets/Sections/Establishment/Helps/Subcategory/AidesFinancieres.gql.js @@ -0,0 +1,38 @@ +import { gql, useQuery } from "@apollo/client"; +import { pipe, prop } from "lodash/fp"; + +import { BCE_CLIENT } from "../../../../../../services/GraphQL/GraphQL"; +import { mapQueryResult } from "../../../../../../utils/graphql/graphql"; + +const AidesFinancieresQuery = gql` + query GetAidesFinancieresParSiret($siretValue: String!) { + fce_ademe_aide( + where: { + siret: { + # relationship field on fce_ademe_aide + siret: { _eq: $siretValue } # the actual scalar column in fce_etablissements + } + } + ) { + dateConvention + objet + Nom_de_l_attribuant + montant + nomBeneficiaire + notificationUE + siret { + # must provide nested selection since it's an object + siret # the scalar field in the fce_etablissements table + } + } + } +`; + +export const useAidesFinancieresData = pipe( + (siretValue) => + useQuery(AidesFinancieresQuery, { + context: { clientName: BCE_CLIENT }, + variables: { siretValue }, + }), + mapQueryResult(prop("fce_ademe_aide")) +); diff --git a/src/client/src/components/DataSheets/Sections/Establishment/Helps/Subcategory/AidesFinancieres.jsx b/src/client/src/components/DataSheets/Sections/Establishment/Helps/Subcategory/AidesFinancieres.jsx new file mode 100644 index 00000000..39d32bd4 --- /dev/null +++ b/src/client/src/components/DataSheets/Sections/Establishment/Helps/Subcategory/AidesFinancieres.jsx @@ -0,0 +1,92 @@ +import PropTypes from "prop-types"; +import React from "react"; + +import { useRenderIfSiret } from "../../../../../../helpers/hoc/renderIfSiret"; +import { formatChiffre } from "../../../../../../utils/donnees-ecofi/donnees-ecofi.js"; +import LoadableContent from "../../../../../shared/LoadableContent/LoadableContent"; +import Value from "../../../../../shared/Value"; +import NonBorderedTable from "../../../SharedComponents/NonBorderedTable"; +import { useSortableData } from "../../../SharedComponents/NonBorderedTable/hooks"; +import SortableButton from "../../../SharedComponents/NonBorderedTable/SortableButton.jsx"; +import SeeDetailsLink from "../../../SharedComponents/SeeDetailsLink"; +import Subcategory from "../../../SharedComponents/Subcategory"; +import { useAidesFinancieresData } from "./AidesFinancieres.gql"; + +const AidesFinancieres = ({ siret }) => { + const { loading, data, error } = useAidesFinancieresData(siret); + const { items, requestSort, sortConfig } = useSortableData(data, { + direction: "descending", + key: "dateConvention", + }); + const shouldNotRender = useRenderIfSiret({ siret }); + + if (error || loading || shouldNotRender) { + return null; + } + + return ( + + + {data?.length > 0 && ( +
+ + + + + + + Beneficiaire + Objet + + + + + + + {items?.map((aide) => ( + + + {" "} + + + + {" "} + + + {aide?.objet} + {} + + ))} + + +
+ )} + {data?.length === 0 && ( +
+ {"Aucune aide financières connue"} +
+ )} +
+
+ ); +}; + +AidesFinancieres.propTypes = { + siret: PropTypes.string.isRequired, +}; + +export default AidesFinancieres;