Skip to content

Commit

Permalink
feat: Ajout du nom et du departement de l acheteur
Browse files Browse the repository at this point in the history
  • Loading branch information
ImenOuidou committed Sep 2, 2024
1 parent 049f319 commit cf617d7
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 81 deletions.
5 changes: 3 additions & 2 deletions src/client/src/components/App/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ const Layout = ({
hasSharedButton = false,
children,
displayMessage = false,
isNotFound = false,
}) => {
const isActiveMaintenanceMode = Config.get("maintenanceMode");

return (
<>
{hasLandingHeader ? (
{!isNotFound && hasLandingHeader ? (
<Header hasSharedButton={hasSharedButton} />
) : (
<>
Expand All @@ -42,6 +42,7 @@ Layout.propTypes = {
displayMessage: PropTypes.bool,
hasLandingHeader: PropTypes.bool,
hasSharedButton: PropTypes.bool,
isNotFound: PropTypes.bool,
};

export default Layout;
4 changes: 4 additions & 0 deletions src/client/src/components/App/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ a {
&--nowrap a {
white-space: nowrap;
}
&--sm-cell {
font-size: 0.5rem !important;
align-items: center !important;
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/client/src/components/DataSheets/NotFound/NotFound.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import "./notFound.scss";

import React from "react";

const NotFound = () => {
return (
<section className="data-sheet container is-fluid">
<div className="">
<div className="notFound">
<div>0 entreprise correspond à votre requête</div>
</div>
</div>
</section>
);
};

export default NotFound;
7 changes: 7 additions & 0 deletions src/client/src/components/DataSheets/NotFound/notFound.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.notFound {
display: flex;
justify-content: center;
align-items: center;
font-size: 22px;
font-weight: bold;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ import { formatSiret } from "../../../../../helpers/utils/format.js";
import { convertirMoisEnAnnees } from "../../../../../helpers/utils/utils.js";
import { formatChiffre } from "../../../../../utils/donnees-ecofi/donnees-ecofi.js";
import { formatUpperCase } from "../../../../../utils/entreprise/entreprise.js";
import { getCity } from "../../../../../utils/establishment/establishment";
import LoadableContent from "../../../../shared/LoadableContent/LoadableContent.js";
import Value from "../../../../shared/Value/index.js";
import BlocTitle from "../../SharedComponents/BlocTitle/BlocTitle.jsx";
import NonBorderedTable from "../../SharedComponents/NonBorderedTable/NonBorderedTable.js";
import SeeDetailsLink from "../../SharedComponents/SeeDetailsLink/SeeDetailsLink.js";
import Subcategory from "../../SharedComponents/Subcategory/index.js";
import { useMarchesPublic } from "./marchesPublic.gql.js";
import { useMarchesPublicWithEtablissements } from "./marchesPublic.gql.js";

const MarchesPublic = ({ siret }) => {
const { loading, data, error } = useMarchesPublic(siret);
const { enrichedMarches, loading, error } =
useMarchesPublicWithEtablissements(siret);

const [accordionOpen, setAccordionOpen] = useState(true);

if (loading || error || !siret) {
if (error || !siret) {
return null;
}

Expand All @@ -40,72 +44,86 @@ const MarchesPublic = ({ siret }) => {
sourceDate={null}
/>
</div>
<div className="data-sheet--table data-sheet--table-to-left">
{data?.marches?.length > 0 && (
<NonBorderedTable
className="direccte-interactions-establishment__table"
isScrollable={data?.marches?.length > 10}
>
<thead>
<tr>
<th>Acheteur</th>
<th>Objet</th>
<th>CPV</th>
<th>Procédure</th>
<th>Montant</th>
<th>Notifié le</th>
<th>Durée</th>
</tr>
</thead>
<tbody>
{data?.marches?.map(
({
acheteur_id,
objet,
cpv_libelle,
procedure,
montant,
dateNotification,
dureeMois,
}) => (
<tr key={acheteur_id + dateNotification}>
<td className="table-cell--nowrap">
<SeeDetailsLink
text={formatSiret(acheteur_id)}
link={`/establishment/${acheteur_id}/`}
/>
</td>
<LoadableContent loading={loading} error={error}>
<div className="data-sheet--table data-sheet--table-to-left">
{enrichedMarches?.length > 0 && (
<NonBorderedTable
className="direccte-interactions-establishment__table"
isScrollable={enrichedMarches?.length > 10}
>
<thead>
<tr>
<th>Acheteur</th>
<th>Objet</th>
<th>CPV</th>
<th>Procédure</th>
<th>Montant</th>
<th>Notifié le</th>
<th>Durée</th>
</tr>
</thead>
<tbody>
{enrichedMarches?.map((marche) => {
const adresse = getCity(marche?.etablissement);

<td>
<Value value={formatUpperCase(objet)} />
</td>
<td>
<Value value={formatUpperCase(cpv_libelle)} />
</td>
<td>
<Value value={formatUpperCase(procedure)} />
</td>
<td>
<Value value={formatChiffre(montant)} />
</td>
<td>
<Value value={dateNotification} />
</td>
<td>
<Value value={convertirMoisEnAnnees(dureeMois)} />
</td>
</tr>
)
)}
</tbody>
</NonBorderedTable>
)}
</div>
{data?.marches?.length === 0 && (
<div className="data-value is-centred">
{"Aucun appel d'offres connu"}
return (
<tr
key={marche?.acheteur_id + marche?.dateNotification}
>
<td className="table-cell--sm-cell">
<SeeDetailsLink
text={
formatUpperCase(
marche?.etablissement?.etb_raisonsociale
) || formatSiret(marche?.acheteur_id)
}
link={`/establishment/${marche?.acheteur_id}/`}
description={formatUpperCase(adresse)}
className={"list"}
/>
</td>
{/* <td className="table-cell--sm-cell ">
{" "}
<Value value={adresse} />
</td> */}

<td>
<Value value={formatUpperCase(marche?.objet)} />
</td>
<td>
<Value
value={formatUpperCase(marche?.cpv_libelle)}
/>
</td>
<td>
<Value
value={formatUpperCase(marche?.procedure)}
/>
</td>
<td>
<Value value={formatChiffre(marche?.montant)} />
</td>
<td>
<Value value={marche?.dateNotification} />
</td>
<td>
<Value
value={convertirMoisEnAnnees(marche?.dureeMois)}
/>
</td>
</tr>
);
})}
</tbody>
</NonBorderedTable>
)}
</div>
)}
{enrichedMarches?.length === 0 && (
<div className="data-value is-centred">
{"Aucun appel d'offres connu"}
</div>
)}
</LoadableContent>
</Subcategory>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,93 @@
import { gql, useQuery } from "@apollo/client";
import { gql, useApolloClient, useQuery } from "@apollo/client";
import { useEffect, useState } from "react";

import { BCE_CLIENT } from "../../../../../services/GraphQL/GraphQL";

const marchesPublicQuery = gql`
query getMarchesPublic($siret: String!) {
marches: fce_marches_valides(where: { siret: { _eq: $siret } }) {
marches: fce_marches_valides(
where: { siret: { _eq: $siret } }
order_by: { dateNotification: desc }
) {
acheteur_id
codeCPV
cpv_libelle
dateNotification
dureeMois
montant
objet
procedure
sousTraitanceDeclaree
}
}
`;

export const useMarchesPublic = (siret) =>
useQuery(marchesPublicQuery, {
const etablissementQuery = gql`
query getEtablissement($acheteurId: String!) {
etablissement: fce_etablissements(where: { siret: { _eq: $acheteurId } }) {
siret
etb_raisonsociale
codepostaletablissement
numerovoieetablissement
indicerepetitionetablissement
typevoieetablissement
complementadresseetablissement
libellevoieetablissement
libellecommuneetablissement
codecommune2etablissement
codecommuneetablissement
libellepaysetrangeretablissement
}
}
`;

export const useMarchesPublicWithEtablissements = (siret) => {
const client = useApolloClient(); // Accéder à l'instance du client Apollo
const {
data: marcheData,
loading: marcheLoading,
error: marcheError,
} = useQuery(marchesPublicQuery, {
context: { clientName: BCE_CLIENT },
variables: { siret },
});

const [enrichedMarches, setEnrichedMarches] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);

useEffect(() => {
if (marcheData && marcheData.marches.length > 0) {
const fetchEtablissements = async () => {
try {
setLoading(true);
const results = await Promise.all(
marcheData.marches.map(async (marche) => {
const { data: etablissementData } = await client.query({
context: { clientName: BCE_CLIENT },
query: etablissementQuery,
variables: { acheteurId: marche.acheteur_id },
});
return {
...marche,
etablissement: etablissementData.etablissement[0],
};
})
);
setEnrichedMarches(results);
setLoading(false);
} catch (e) {
setError(e);
setLoading(false);
}
};

fetchEtablissements();
} else {
setLoading(false);
}
}, [marcheData, client]); // Ajoutez 'client' comme dépendance

return {
enrichedMarches,
error: marcheError || error,
loading: marcheLoading || loading,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,44 @@ import PropTypes from "prop-types";
import React from "react";
import { HashLink as Link } from "react-router-hash-link";

import BuildingIcon from "../../../../shared/Icons/BuildingIcon.jsx";

const scrollWithOffset = (el) => {
const yCoordinate = el.getBoundingClientRect().top + window.pageYOffset;
const yOffset = -60;
window.scrollTo({ behavior: "smooth", top: yCoordinate + yOffset });
};

const SeeDetailsLink = ({ link, text = "Voir la fiche établissement" }) => {
const SeeDetailsLink = ({
link,
text = "Voir la fiche établissement",
description,
className,
}) => {
return (
<div className="details-link">
<Link
to={link}
className="see-details-link__link"
className={`see-details-link__link ${className}`}
scroll={(el) => scrollWithOffset(el)}
>
{text}
</Link>
{description && (
<div className="details-link-text">
<span className="data-sheet-header-address-icon">
<BuildingIcon color="black" />
</span>{" "}
{description}
</div>
)}
</div>
);
};

SeeDetailsLink.propTypes = {
className: PropTypes.string,
description: PropTypes.string,
link: PropTypes.string.isRequired,
text: PropTypes.string,
};
Expand Down
Loading

0 comments on commit cf617d7

Please sign in to comment.