Skip to content

Commit 33a3c29

Browse files
committed
feat: implement SurveyResultCount component to display survey response counts and update survey list rendering
1 parent cecee1c commit 33a3c29

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/client/routes/survey.tsx

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Layout } from '@/components/layout';
99
import { useCurrentWorkspaceId, useHasAdminPermission } from '@/store/user';
1010
import { routeAuthBeforeLoad } from '@/utils/route';
1111
import { cn } from '@/utils/style';
12+
import { formatNumber } from '@/utils/common';
1213
import { useTranslation } from '@i18next-toolkit/react';
1314
import {
1415
createFileRoute,
@@ -28,9 +29,6 @@ function PageComponent() {
2829
const { data = [], isLoading } = trpc.survey.all.useQuery({
2930
workspaceId,
3031
});
31-
const { data: allResultCount = {} } = trpc.survey.allResultCount.useQuery({
32-
workspaceId,
33-
});
3432
const navigate = useNavigate();
3533
const pathname = useRouterState({
3634
select: (state) => state.location.pathname,
@@ -40,7 +38,7 @@ function PageComponent() {
4038
const items = data.map((item) => ({
4139
id: item.id,
4240
title: item.name,
43-
number: allResultCount[item.id] ?? 0,
41+
content: <SurveyResultCount surveyId={item.id} />,
4442
href: `/survey/${item.id}`,
4543
}));
4644

@@ -91,6 +89,7 @@ function PageComponent() {
9189
<CommonList
9290
hasSearch={true}
9391
items={items}
92+
direction="horizontal"
9493
isLoading={isLoading}
9594
emptyDescription={t(
9695
'Not have any survey yet, create a survey to collect user feedback about your user service.'
@@ -101,3 +100,28 @@ function PageComponent() {
101100
/>
102101
);
103102
}
103+
104+
function SurveyResultCount({ surveyId }: { surveyId: string }) {
105+
const workspaceId = useCurrentWorkspaceId();
106+
const { data: count } = trpc.survey.count.useQuery(
107+
{
108+
workspaceId,
109+
surveyId,
110+
},
111+
{
112+
trpc: {
113+
context: {
114+
skipBatch: true,
115+
},
116+
},
117+
}
118+
);
119+
120+
if (!count || count <= 0) return null;
121+
122+
return (
123+
<span className="opacity-60" title={String(count)}>
124+
{formatNumber(count)}
125+
</span>
126+
);
127+
}

0 commit comments

Comments
 (0)