Skip to content

Commit

Permalink
fix(dashboard): init services deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed Sep 20, 2023
1 parent dd56bb8 commit 9a9f484
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions dashboard/src/components/ReceptionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ const ReceptionService = ({ report, team, dateString, dataTestIdPrefix = '', ser
useEffect(
// Init services for a team. We need to fetch services from legacy report and database and merge them.
function initServices() {
console.log('init services');
console.log('INIT SERVICE FROM ReceptionService ?');
if (!dateString || !team?._id || dateString === 'undefined') {
return capture('Missing params for initServices in reception', { extra: { dateString, team, report } });
}
console.log('INIT SERVICE FROM ReceptionService ');
API.get({ path: `/service/team/${team._id}/date/${dateString}` }).then((res) => {
if (!res.ok) return toast.error(<ErrorOnGetServices />);
const servicesFromLegacyReport = report?.services?.length ? JSON.parse(report?.services) : {};
Expand All @@ -33,7 +34,8 @@ const ReceptionService = ({ report, team, dateString, dataTestIdPrefix = '', ser
setServices(mergedServices);
});
},
[dateString, report, team, organisation.services, setServices]
// eslint-disable-next-line react-hooks/exhaustive-deps
[dateString, report, team]
);

const selectedServices = groupedServices.find((e) => e.groupTitle === selected)?.services || [];
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/scenes/report/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ const List = () => {

const [servicesCountByDay, setServicesCountByDay] = useState({});
useEffect(
function fetchServicesStats() {
function fetchServicesCountByDay() {
if (!(viewAllOrganisationData ? allTeamIds : selectedTeamIds)?.length) return;
console.log('INIT SERVICE FROM fetchServicesCountByDay');
API.get({ path: `/service/team/${(viewAllOrganisationData ? allTeamIds : selectedTeamIds).join(',')}/month-stats/${startOfMonth}` }).then(
(res) => {
if (!res.ok) return toast.error("Erreur lors du chargement des statistiques des services de l'accueil");
Expand Down
7 changes: 5 additions & 2 deletions dashboard/src/scenes/report/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,10 @@ const Reception = ({ reports, selectedTeamsObject, dateString }) => {
function initServices() {
// Init services for a team. We need to fetch services from legacy report and database and merge them.
async function getServicesForTeam(team, report) {
if (!dateString || !team || dateString === 'undefined')
if (!dateString || !team || dateString === 'undefined') {
return capture('Missing params for initServices in report', { extra: { dateString, team, report } });
}
console.log('INIT SERVICE FROM REPORT VIEW');
const res = await API.get({ path: `/service/team/${team}/date/${dateString}` });
if (!res.ok) return toast.error(<ErrorOnGetServices />);
const servicesFromLegacyReport = report?.services?.length ? JSON.parse(report?.services) : {};
Expand All @@ -918,7 +920,8 @@ const Reception = ({ reports, selectedTeamsObject, dateString }) => {
setServices(results.reduce((acc, curr) => ({ ...acc, ...curr }), {}));
});
},
[dateString, reports, organisation.services]
// eslint-disable-next-line react-hooks/exhaustive-deps
[dateString, reports]
);

if (!organisation.receptionEnabled || !organisation?.services) return null;
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/scenes/stats/Services.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const ServicesStats = ({ period, teamIds }) => {
setServicesFromDatabase({});
return;
}
console.log('INIT SERVICE FROM SERVICES STATS');
API.get({ path: `/service/team/${teamIds.join(',')}/stats`, query: startDate ? { from: startDate, to: endDate || startDate } : {} }).then(
(res) => {
if (!res.ok) return toast.error("Erreur lors du chargement des statistiques des services de l'accueil");
Expand Down

0 comments on commit 9a9f484

Please sign in to comment.