Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dashboard): init services deps #1664

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading