diff --git a/src/client/src/components/DataSheets/Sections/Establishment/ListEtablishments/ListEstablishment.jsx b/src/client/src/components/DataSheets/Sections/Establishment/ListEtablishments/ListEstablishment.jsx
index c73dc3c6..bbca6b6a 100644
--- a/src/client/src/components/DataSheets/Sections/Establishment/ListEtablishments/ListEstablishment.jsx
+++ b/src/client/src/components/DataSheets/Sections/Establishment/ListEtablishments/ListEstablishment.jsx
@@ -1,130 +1,25 @@
import React, { useState } from "react";
-import { Link, useHistory } from "react-router-dom";
-import { isActiveEstablishment } from "../../../../../helpers/Search";
-import {
- formatSiret,
- getLibelletFromCodeNaf,
- joinNoFalsy,
-} from "../../../../../helpers/utils";
-import Config from "../../../../../services/Config";
import { getEtablissements } from "../../../../../utils/entreprise/entreprise";
-import { isActive } from "../../../../../utils/establishment/establishment";
-import BadgeWithIcon from "../../../../shared/Badge/BadgeWithIcon.jsx";
-import Value from "../../../../shared/Value";
import { getEtablissementsCount } from "../../../Sidebar/Sidebar.gql";
import BlocTitle from "../../SharedComponents/BlocTitle/BlocTitle.jsx";
import { useEstablishmentData } from "../../SharedComponents/EstablishmentContext.jsx";
-import NonBorderedTable from "../../SharedComponents/NonBorderedTable/NonBorderedTable";
-import PaginationTable from "../../SharedComponents/PaginationTable/PaginationTable.jsx";
+import EstablishmentTable from "../../SharedComponents/EstablishmentTable/EstablishmentTable.jsx";
const ListEstablishment = () => {
const { loading, data: entreprise, error } = useEstablishmentData();
- const history = useHistory();
+
const [accordionOpen, setAccordionOpen] = useState(true);
- const [currentPage, setCurrentPage] = useState(1);
if (loading || error) {
return null;
}
- const rowsPerPage = 10;
- // Calculate the total number of pages
- const totalPages = Math.ceil(
- entreprise?.entreprise_nbr_etablissements_siren?.nb_eta / rowsPerPage
- );
-
- // Calculate the starting and ending index for the current page
- const startIndex = (currentPage - 1) * rowsPerPage;
- const endIndex = Math.min(
- startIndex + rowsPerPage,
- entreprise?.entreprise_nbr_etablissements_siren?.nb_eta
- );
const etablissements = entreprise ? getEtablissements(entreprise) : [];
- const staffSizeRanges = {
- ...Config.get("inseeSizeRanges"),
- "0 salarié": "0 salarié",
- };
+
const etablissementsCount = entreprise
? getEtablissementsCount(entreprise)
: 0;
- const handlePageClick = (page) => {
- if (page >= 1 && page <= totalPages) {
- setCurrentPage(page);
- }
- };
- const renderTableBody = () => {
- const data =
- etablissementsCount > rowsPerPage
- ? etablissements?.slice(startIndex, endIndex)
- : etablissements;
-
- return data?.map((etablissement) => {
- const isEtablissementActive = isActive(etablissement);
- const stateClass = isEtablissementActive
- ? "icon--success"
- : "icon--danger";
- const stateText = isEtablissementActive ? "ouvert" : "fermé";
- return (
-
history.push(`/establishment/${etablissement?.siret}`)}
- >
-
-
-
-
- |
-
-
- |
-
-
-
- |
-
-
- |
-
-
- |
- {`${etablissement?.activiteprincipaleetablissement || ""} - ${
- getLibelletFromCodeNaf(
- etablissement?.activiteprincipaleetablissement
- ) || ""
- }`} |
-
- );
- });
- };
return (
@@ -139,28 +34,10 @@ const ListEstablishment = () => {
{etablissementsCount > 0 && (
-
-
-
- SIRET |
- État |
- Code postal |
- Effectif (DSN) |
- Raison social / Nom |
- Activité |
-
-
- {renderTableBody()}
-
- {etablissementsCount > rowsPerPage && (
-
- )}
+
)}
diff --git a/src/client/src/components/DataSheets/Sections/ListEstablishmentsResult/Establishments.jsx b/src/client/src/components/DataSheets/Sections/ListEstablishmentsResult/Establishments.jsx
index 8629faa6..b4eb2c95 100644
--- a/src/client/src/components/DataSheets/Sections/ListEstablishmentsResult/Establishments.jsx
+++ b/src/client/src/components/DataSheets/Sections/ListEstablishmentsResult/Establishments.jsx
@@ -1,162 +1,34 @@
import "./ListEstablishmentsResult.scss";
-import React, { useState } from "react";
-import { useHistory } from "react-router";
-import { Link } from "react-router-dom";
+import React from "react";
-import { isActiveEstablishment } from "../../../../helpers/Search/Search.js";
-import { formatSiret } from "../../../../helpers/utils/format.js";
-import {
- getLibelletFromCodeNaf,
- joinNoFalsy,
-} from "../../../../helpers/utils/utils.js";
-import Config from "../../../../services/Config/Config.js";
import { getEtablissements } from "../../../../utils/entreprise/entreprise.js";
-import { isActive } from "../../../../utils/establishment/establishment.js";
-import BadgeWithIcon from "../../../shared/Badge/BadgeWithIcon.jsx";
import Value from "../../../shared/Value/Value.js";
import { getEtablissementsCount } from "../../Sidebar/Sidebar.gql.js";
import { useEstablishmentData } from "../SharedComponents/EstablishmentContext.jsx";
-import NonBorderedTable from "../SharedComponents/NonBorderedTable/NonBorderedTable.js";
-import PaginationTable from "../SharedComponents/PaginationTable/PaginationTable.jsx";
+import EstablishmentTable from "../SharedComponents/EstablishmentTable/EstablishmentTable.jsx";
export const Establishments = () => {
const { loading, data: entreprise, error } = useEstablishmentData();
- const history = useHistory();
- const [currentPage, setCurrentPage] = useState(1);
if (loading || error) {
return null;
}
-
- const rowsPerPage = 10;
- // Calculate the total number of pages
- const totalPages = Math.ceil(
- entreprise?.entreprise_nbr_etablissements_siren?.nb_eta / rowsPerPage
- );
-
- // Calculate the starting and ending index for the current page
- const startIndex = (currentPage - 1) * rowsPerPage;
- const endIndex = Math.min(
- startIndex + rowsPerPage,
- entreprise?.entreprise_nbr_etablissements_siren?.nb_eta
- );
- const etablissements = entreprise ? getEtablissements(entreprise) : [];
- const staffSizeRanges = {
- ...Config.get("inseeSizeRanges"),
- "0 salarié": "0 salarié",
- };
-
- const handlePageClick = (page) => {
- if (page >= 1 && page <= totalPages) {
- setCurrentPage(page);
- }
- };
-
const etablissementsCount = entreprise
? getEtablissementsCount(entreprise)
: 0;
- const renderTableBody = () => {
- const data =
- etablissementsCount > rowsPerPage
- ? etablissements?.slice(startIndex, endIndex)
- : etablissements;
- return data?.map((etablissement) => {
- const isEtablissementActive = isActive(etablissement);
- const stateClass = isEtablissementActive
- ? "icon--success"
- : "icon--danger";
- const stateText = isEtablissementActive ? "ouvert" : "fermé";
- return (
- history.push(`/establishment/${etablissement?.siret}`)}
- >
-
-
-
-
- |
-
-
- |
+ const etablissements = entreprise ? getEtablissements(entreprise) : [];
-
-
- |
-
-
- |
-
-
- |
- {`${etablissement?.activiteprincipaleetablissement || ""} - ${
- getLibelletFromCodeNaf(
- etablissement?.activiteprincipaleetablissement
- ) || ""
- }`} |
-
- );
- });
- };
return (
Liste des etablissements (
)
-
-
-
-
- SIRET |
- État |
- Code postal |
- Effectif (DSN) |
- Raison social / Nom |
- Activité |
-
-
- {renderTableBody()}
-
- {etablissementsCount > rowsPerPage && (
-
- )}
-
+
);
};
diff --git a/src/client/src/components/DataSheets/Sections/SharedComponents/EstablishmentTable/EstablishmentTable.jsx b/src/client/src/components/DataSheets/Sections/SharedComponents/EstablishmentTable/EstablishmentTable.jsx
new file mode 100644
index 00000000..fdacbf11
--- /dev/null
+++ b/src/client/src/components/DataSheets/Sections/SharedComponents/EstablishmentTable/EstablishmentTable.jsx
@@ -0,0 +1,152 @@
+import PropTypes from "prop-types";
+import React, { useState } from "react";
+import { Link, useHistory } from "react-router-dom";
+
+import { isActiveEstablishment } from "../../../../../helpers/Search/Search.js";
+import { formatSiret } from "../../../../../helpers/utils/format.js";
+import {
+ getLibelletFromCodeNaf,
+ joinNoFalsy,
+} from "../../../../../helpers/utils/utils.js";
+import Config from "../../../../../services/Config/Config.js";
+import { isActive } from "../../../../../utils/establishment/establishment.js";
+import BadgeWithIcon from "../../../../shared/Badge/BadgeWithIcon.jsx";
+import Value from "../../../../shared/Value/Value.js";
+import { getEtablissementsCount } from "../../../Sidebar/Sidebar.gql.js";
+import NonBorderedTable from "../NonBorderedTable/NonBorderedTable.js";
+import PaginationTable from "../PaginationTable/PaginationTable.jsx";
+
+const EstablishmentTable = ({ etablissements, entreprise }) => {
+ const history = useHistory();
+ const [currentPage, setCurrentPage] = useState(1);
+
+ const staffSizeRanges = {
+ ...Config.get("inseeSizeRanges"),
+ "0 salarié": "0 salarié",
+ };
+ const rowsPerPage = 10;
+ // Calculate the total number of pages
+ const totalPages = Math.ceil(
+ entreprise?.entreprise_nbr_etablissements_siren?.nb_eta / rowsPerPage
+ );
+
+ // Calculate the starting and ending index for the current page
+ const startIndex = (currentPage - 1) * rowsPerPage;
+ const endIndex = Math.min(
+ startIndex + rowsPerPage,
+ entreprise?.entreprise_nbr_etablissements_siren?.nb_eta
+ );
+
+ const handlePageClick = (page) => {
+ if (page >= 1 && page <= totalPages) {
+ setCurrentPage(page);
+ }
+ };
+
+ const etablissementsCount = entreprise
+ ? getEtablissementsCount(entreprise)
+ : 0;
+ const renderTableBody = () => {
+ const data =
+ etablissementsCount > rowsPerPage
+ ? etablissements?.slice(startIndex, endIndex)
+ : etablissements;
+ return data?.map((etablissement) => {
+ const isEtablissementActive = isActive(etablissement);
+ const stateClass = isEtablissementActive
+ ? "icon--success"
+ : "icon--danger";
+ const stateText = isEtablissementActive ? "ouvert" : "fermé";
+ return (
+ history.push(`/establishment/${etablissement?.siret}`)}
+ >
+
+
+
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+ |
+
+
+ |
+ {`${etablissement?.activiteprincipaleetablissement || ""} - ${
+ getLibelletFromCodeNaf(
+ etablissement?.activiteprincipaleetablissement
+ ) || ""
+ }`} |
+
+ );
+ });
+ };
+ return (
+
+
+
+
+ SIRET |
+ État |
+ Code postal |
+ Effectif (DSN) |
+ Raison social / Nom |
+ Activité |
+
+
+ {renderTableBody()}
+
+ {etablissementsCount > rowsPerPage && (
+
+ )}{" "}
+
+ );
+};
+
+EstablishmentTable.propTypes = {
+ entreprise: PropTypes.object.isRequired,
+ etablissements: PropTypes.array.isRequired,
+};
+export default EstablishmentTable;