-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6aa4d44
commit 2876f9d
Showing
3 changed files
with
132 additions
and
0 deletions.
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
38 changes: 38 additions & 0 deletions
38
...rc/components/DataSheets/Sections/Establishment/Helps/Subcategory/AidesFinancieres.gql.js
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,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")) | ||
); |
92 changes: 92 additions & 0 deletions
92
...t/src/components/DataSheets/Sections/Establishment/Helps/Subcategory/AidesFinancieres.jsx
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,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 ( | ||
<Subcategory subtitle="Aides financières" sourceSi="DataGouv"> | ||
<LoadableContent loading={loading} error={error}> | ||
{data?.length > 0 && ( | ||
<div className="data-sheet--table"> | ||
<NonBorderedTable> | ||
<thead> | ||
<tr> | ||
<th> | ||
<SortableButton | ||
sortConfig={sortConfig} | ||
columnKey="dateConvention" | ||
requestSort={requestSort} | ||
label="Date de convention" | ||
/> | ||
</th> | ||
<th className="th">Beneficiaire</th> | ||
<th className="th">Objet</th> | ||
<th> | ||
<SortableButton | ||
sortConfig={sortConfig} | ||
columnKey="montant" | ||
requestSort={requestSort} | ||
label="Montant" | ||
/> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{items?.map((aide) => ( | ||
<tr key={aide?.nomBeneficiaire}> | ||
<td> | ||
{" "} | ||
<Value value={aide?.dateConvention} /> | ||
</td> | ||
<td> | ||
{" "} | ||
<SeeDetailsLink | ||
text={aide?.nomBeneficiaire} | ||
link={`/establishment/${aide?.siret?.siret}/`} | ||
className={"list"} | ||
/> | ||
</td> | ||
<td>{aide?.objet}</td> | ||
<td>{<Value value={formatChiffre(aide?.montant)} />}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</NonBorderedTable> | ||
</div> | ||
)} | ||
{data?.length === 0 && ( | ||
<div className="data-value is-centred"> | ||
{"Aucune aide financières connue"} | ||
</div> | ||
)} | ||
</LoadableContent> | ||
</Subcategory> | ||
); | ||
}; | ||
|
||
AidesFinancieres.propTypes = { | ||
siret: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default AidesFinancieres; |