Skip to content

Commit f6f0d3c

Browse files
committed
fix: 修正された集計結果の表示と型の明示化
1 parent 999af7b commit f6f0d3c

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

frontend/src/components/SurveyForm.tsx

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from "react";
21
import { useForm, Controller } from "react-hook-form";
32
import { zodResolver } from "@hookform/resolvers/zod";
43
import { z } from "zod";
@@ -14,11 +13,12 @@ import {
1413
Radio,
1514
RadioGroup,
1615
} from "@mui/material";
17-
import type { Survey } from "../types/survey";
16+
import type { SubmitHandler } from "react-hook-form";
1817

19-
// Zodスキーマ
20-
21-
const communityAffiliationOptions = ["VS Code Meetup", "GitHub dockyard"];
18+
const communityAffiliationOptions = [
19+
"VS Code Meetup",
20+
"GitHub dockyard",
21+
] as const;
2222
const jobRoleOptions = [
2323
"フロントエンドエンジニア",
2424
"バックエンドエンジニア",
@@ -27,13 +27,10 @@ const jobRoleOptions = [
2727
"データエンジニア",
2828
"モバイルエンジニア",
2929
"その他",
30-
];
30+
] as const;
3131

3232
const schema = z.object({
33-
communityAffiliation: z
34-
.array(z.enum(["VS Code Meetup", "GitHub dockyard"]))
35-
.optional()
36-
.default([]),
33+
communityAffiliation: z.array(z.enum(["VS Code Meetup", "GitHub dockyard"])),
3734
jobRole: z
3835
.array(
3936
z.enum([
@@ -60,10 +57,12 @@ const schema = z.object({
6057

6158
type FormValues = z.infer<typeof schema>;
6259

63-
export const SurveyForm: React.FC<{
64-
onSubmit: (data: Survey) => void;
60+
type SurveyFormProps = {
61+
onSubmit: SubmitHandler<FormValues>;
6562
loading?: boolean;
66-
}> = ({ onSubmit, loading }) => {
63+
};
64+
65+
export function SurveyForm({ onSubmit, loading }: SurveyFormProps) {
6766
const {
6867
control,
6968
handleSubmit,
@@ -101,7 +100,7 @@ export const SurveyForm: React.FC<{
101100
field.onChange([...(field.value || []), c]);
102101
else
103102
field.onChange(
104-
(field.value || []).filter((v: string) => v !== c)
103+
(field.value || []).filter((v) => v !== c)
105104
);
106105
}}
107106
/>
@@ -134,9 +133,7 @@ export const SurveyForm: React.FC<{
134133
if (e.target.checked)
135134
field.onChange([...field.value, role]);
136135
else
137-
field.onChange(
138-
field.value.filter((v: string) => v !== role)
139-
);
136+
field.onChange(field.value.filter((v) => v !== role));
140137
}}
141138
/>
142139
}
@@ -224,4 +221,4 @@ export const SurveyForm: React.FC<{
224221
</Button>
225222
</Box>
226223
);
227-
};
224+
}

frontend/src/components/SurveyResult.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const SurveyResult: React.FC<{ result: SurveyResultType }> = ({
2020
<Typography variant="h6" sx={{ mb: 2 }}>
2121
集計結果
2222
</Typography>
23-
<Typography>総回答数: {result.total}</Typography>
23+
<Typography>総回答数: {result.data.totalResponses}</Typography>
2424
<Typography variant="subtitle1" sx={{ mt: 2 }}>
2525
職種別集計
2626
</Typography>
@@ -33,10 +33,10 @@ export const SurveyResult: React.FC<{ result: SurveyResultType }> = ({
3333
</TableRow>
3434
</TableHead>
3535
<TableBody>
36-
{Object.entries(result.jobRoleStats).map(([role, count]) => (
36+
{Object.entries(result.data.jobRole).map(([role, count]) => (
3737
<TableRow key={role}>
3838
<TableCell>{role}</TableCell>
39-
<TableCell>{count}</TableCell>
39+
<TableCell>{count as number}</TableCell>
4040
</TableRow>
4141
))}
4242
</TableBody>
@@ -52,12 +52,14 @@ export const SurveyResult: React.FC<{ result: SurveyResultType }> = ({
5252
</TableRow>
5353
</TableHead>
5454
<TableBody>
55-
{Object.entries(result.eventRatingStats).map(([rating, count]) => (
56-
<TableRow key={rating}>
57-
<TableCell>{rating}</TableCell>
58-
<TableCell>{count}</TableCell>
59-
</TableRow>
60-
))}
55+
{Object.entries(result.data.eventRating.distribution).map(
56+
([rating, count]) => (
57+
<TableRow key={rating}>
58+
<TableCell>{rating}</TableCell>
59+
<TableCell>{count as number}</TableCell>
60+
</TableRow>
61+
)
62+
)}
6163
</TableBody>
6264
</Table>
6365
</TableContainer>

0 commit comments

Comments
 (0)