Skip to content

Commit da558a4

Browse files
committed
refactor: use WithLoading in Summary
1 parent 9de5086 commit da558a4

File tree

2 files changed

+56
-42
lines changed

2 files changed

+56
-42
lines changed

apps/web/src/components/Layout/Layout.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
import { Outlet } from 'react-router-dom';
1+
import { useEffect } from 'react';
2+
3+
import { Outlet, useLocation } from 'react-router-dom';
4+
5+
import { queryClient } from '@/services/react-query';
26

37
import { Footer } from '../Footer';
48
import { Navbar } from '../Navbar';
59
import { Sidebar } from '../Sidebar';
610

711
export const Layout = () => {
12+
// const location = useLocation();
13+
14+
// useEffect(() => {
15+
// queryClient.clear();
16+
// }, [location.pathname]);
17+
818
return (
919
<div className="flex h-screen w-screen flex-col md:flex-row">
1020
<div className="absolute md:hidden">
Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { useTranslation } from '@douglasneuroinformatics/libui/hooks';
22
import { ClipboardDocumentIcon, DocumentTextIcon, UserIcon, UsersIcon } from '@heroicons/react/24/solid';
3+
import type { Summary as SummaryType } from '@opendatacapture/schemas/summary';
34

4-
import { LoadingFallback } from '@/components/LoadingFallback';
5+
import { WithFallback } from '@/components/WithFallback';
56
import { useAppStore } from '@/store';
67

78
import { StatisticCard } from '../components/StatisticCard';
@@ -17,46 +18,49 @@ export const Summary = () => {
1718
}
1819
});
1920

20-
if (!summaryQuery.data) {
21-
return <LoadingFallback />;
22-
}
23-
2421
return (
25-
<div className="body-font">
26-
<div className="grid grid-cols-1 gap-5 text-center lg:grid-cols-2">
27-
<StatisticCard
28-
icon={<UsersIcon className="h-12 w-12" />}
29-
label={t({
30-
en: 'Total Users',
31-
fr: "Nombre d'utilisateurs"
32-
})}
33-
value={summaryQuery.data.counts.users}
34-
/>
35-
<StatisticCard
36-
icon={<UserIcon className="h-12 w-12" />}
37-
label={t({
38-
en: 'Total Subjects',
39-
fr: 'Nombre de clients'
40-
})}
41-
value={summaryQuery.data.counts.subjects}
42-
/>
43-
<StatisticCard
44-
icon={<ClipboardDocumentIcon className="h-12 w-12" />}
45-
label={t({
46-
en: 'Total Instruments',
47-
fr: "Nombre d'instruments"
48-
})}
49-
value={summaryQuery.data.counts.instruments}
50-
/>
51-
<StatisticCard
52-
icon={<DocumentTextIcon className="h-12 w-12" />}
53-
label={t({
54-
en: 'Total Records',
55-
fr: "Nombre d'enregistrements"
56-
})}
57-
value={summaryQuery.data.counts.records}
58-
/>
59-
</div>
60-
</div>
22+
<WithFallback
23+
Component={({ data }: { data: SummaryType }) => (
24+
<div className="body-font">
25+
<div className="grid grid-cols-1 gap-5 text-center lg:grid-cols-2">
26+
<StatisticCard
27+
icon={<UsersIcon className="h-12 w-12" />}
28+
label={t({
29+
en: 'Total Users',
30+
fr: "Nombre d'utilisateurs"
31+
})}
32+
value={data.counts.users}
33+
/>
34+
<StatisticCard
35+
icon={<UserIcon className="h-12 w-12" />}
36+
label={t({
37+
en: 'Total Subjects',
38+
fr: 'Nombre de clients'
39+
})}
40+
value={data.counts.subjects}
41+
/>
42+
<StatisticCard
43+
icon={<ClipboardDocumentIcon className="h-12 w-12" />}
44+
label={t({
45+
en: 'Total Instruments',
46+
fr: "Nombre d'instruments"
47+
})}
48+
value={data.counts.instruments}
49+
/>
50+
<StatisticCard
51+
icon={<DocumentTextIcon className="h-12 w-12" />}
52+
label={t({
53+
en: 'Total Records',
54+
fr: "Nombre d'enregistrements"
55+
})}
56+
value={data.counts.records}
57+
/>
58+
</div>
59+
</div>
60+
)}
61+
props={{
62+
data: summaryQuery.data
63+
}}
64+
/>
6165
);
6266
};

0 commit comments

Comments
 (0)