Skip to content

Commit

Permalink
Added tables & corresponding requests for coutry tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjyhy committed Dec 5, 2024
1 parent 5118ed9 commit 337e0cd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions server/controllers/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ statisticsController.get({ path: '/countries/:countryId' }, async (_req, res) =>
familyAccountsCount: await getFamilyAccountsCountForCountry(countryId, phase),
childrenCodesCount: await getChildrenCodesCountForCountry(countryId, phase),
connectedFamiliesCount: await getConnectedFamiliesCountForCountry(countryId, phase),
//familiesWithoutAccount: await getFamiliesWithoutAccountForCountry(countryId),
//floatingAccounts: await getFloatingAccountsForCountry(countryId),
familiesWithoutAccount: await getFamiliesWithoutAccountForCountry(countryId),
floatingAccounts: await getFloatingAccountsForCountry(countryId),
});
});

Expand Down
2 changes: 1 addition & 1 deletion server/stats/countryStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const getConnectedFamiliesCountForCountry = async (countryId: string, pha
};

export const getFamiliesWithoutAccountForCountry = async (countryId: string) => {
return getFamiliesWithoutAccount('classroom.villageId = :villageId', { countryId });
return getFamiliesWithoutAccount('classroom.countryCode = :countryId', { countryId });
};

export const getFloatingAccountsForCountry = async (countryId: string) => {
Expand Down
3 changes: 2 additions & 1 deletion server/stats/queryStatsByFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ export const getConnectedFamiliesCount = async (filterParams: StatsFilterParams)
};

export const getFloatingAccounts = async (filterParams: StatsFilterParams) => {
const { villageId } = filterParams;
const { villageId, countryId } = filterParams;
const query = userRepository.createQueryBuilder('user').where('user.hasStudentLinked = 0').andWhere('user.type = 4');

if (villageId) query.andWhere('user.villageId = :villageId', { villageId });
if (countryId) query.andWhere('user.countryCode = :countryId', { countryId });

query.select(['user.id', 'user.firstname', 'user.lastname', 'user.language', 'user.email', 'user.createdAt']);
const floatingAccounts = await query.getMany();
Expand Down
18 changes: 15 additions & 3 deletions src/components/admin/dashboard-statistics/CountryStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { mockClassroomsStats, mockConnectionsStats } from './mocks/mocks';
import { PelicoCard } from './pelico-card';
import styles from './styles/charts.module.css';
import { sumContribution } from './utils/sumData';
import { createFamiliesWithoutAccountRows } from './utils/tableCreator';
import { FamiliesWithoutAccountHeaders } from './utils/tableHeaders';
import { createFamiliesWithoutAccountRows, createFloatingAccountsRows } from './utils/tableCreator';
import { FamiliesWithoutAccountHeaders, FloatingAccountsHeaders } from './utils/tableHeaders';
import { useGetCountriesStats } from 'src/api/statistics/statistics.get';
import { useCountries } from 'src/services/useCountries';
import type { OneVillageTableRow } from 'types/statistics.type';
Expand All @@ -48,11 +48,16 @@ const CountryStats = () => {
const countriesStats = useGetCountriesStats(selectedCountry, selectedPhase);

const [familiesWithoutAccountRows, setFamiliesWithoutAccountRows] = React.useState<Array<OneVillageTableRow>>([]);
const [floatingAccountsRows, setFloatingAccountsRows] = React.useState<Array<OneVillageTableRow>>([]);
React.useEffect(() => {
if (countriesStats.data?.familiesWithoutAccount) {
setFamiliesWithoutAccountRows(createFamiliesWithoutAccountRows(countriesStats.data?.familiesWithoutAccount));
}
}, [countriesStats.data?.familiesWithoutAccount]);
if (countriesStats.data?.floatingAccounts) {
setFloatingAccountsRows([]);
setFloatingAccountsRows(createFloatingAccountsRows(countriesStats.data?.floatingAccounts));
}
}, [countriesStats.data?.familiesWithoutAccount, countriesStats.data?.floatingAccounts]);

const handleCountryChange = (country: string) => {
setSelectedCountry(country);
Expand Down Expand Up @@ -224,6 +229,13 @@ const CountryStats = () => {
columns={FamiliesWithoutAccountHeaders}
titleContent={`À surveiller : comptes non créés (${familiesWithoutAccountRows.length})`}
/>
<OneVillageTable
admin={false}
emptyPlaceholder={<p>{'Pas de données'}</p>}
data={floatingAccountsRows}
columns={FloatingAccountsHeaders}
titleContent={`À surveiller : comptes flottants (${floatingAccountsRows.length})`}
/>
<Box
className={styles.classroomStats}
sx={{
Expand Down

0 comments on commit 337e0cd

Please sign in to comment.