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

chore: ロボットタイプの自動設定 #788

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion packages/kcmsf/src/pages/register.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Box, Button, Group, SegmentedControl, TextInput } from "@mantine/core";
import { notifications } from "@mantine/notifications";
import { config, DepartmentType, RobotType } from "config";
import { useState } from "react";
import { useEffect, useState } from "react";
import { CreateTeamArgs } from "../types/team";

export const Register = () => {
Expand All @@ -15,6 +15,13 @@ export const Register = () => {
);
const [member, setMember] = useState<[string, string]>(["", ""]);

// カテゴリーが変更されたとき、ロボットタイプが自明な場合は自動で設定する
useEffect(() => {
if (config.department[category].robotTypes.length === 1) {
setRobotType(config.department[category].robotTypes[0]);
}
}, [category]);

Comment on lines +18 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • useEffectは、避けられる場合は避けるべきフックです(詳細はReactのドキュメントを参照してください)。この場合L103にこれらの処理を足せば済むので、そうしてください。
  • これだと、変えた後に2つ以上の選択肢があると何も選ばれていない状態になってしまいます。「変えたカテゴリのrobotTypesに今のrobotTypeがあるか見て、なければ許可されるもののうちの0番目をsetする」のような感じはどうでしょうか?

async function submit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
// メンバーは、オープン部門または小学生部門かつメンバーが1人の場合は配列の要素数を1つにする
Expand Down
Loading