Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions front/src/actions/event/register/viewmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ const BaseSchema = z.object({
description: z.string({
required_error: 'イベントの説明は必須です。',
}),
userGroupId: z.coerce.number({
required_error: 'ユーザーグループは必須です。',
}),
userGroupId: z.string()
.refine((val) => val.length > 0 && !isNaN(Number(val)), { message: 'ユーザーグループの指定が不正です。' }),
eventDate: z.string()
.regex(DATE_PATTERN, 'イベント日はYYYY-MM-DD形式で入力してください。')
.refine((date) => !isNaN(Date.parse(date)), '有効な日付を入力してください。'),
Expand Down Expand Up @@ -108,6 +107,7 @@ export async function registerEvent(
...rest,
startDateTime: new Date(`${eventDate}T${eventStartTime}:00.000`),
endDateTime: new Date(`${eventDate}T${eventEndTime}:00.000`),
userGroupId: Number(rest.userGroupId)
};

// イベントの登録処理(トランザクションは正直なくてもいいけど、lib/db側の記述がシンプルになるために使用)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function EventRegisterTemplate({ userGroups }: Readonly<EventRegi
field?.name === 'userGroupId'
? {
...field,
defaultValue: userGroups[0].id.toString(),
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

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

Accessing userGroups[0] without checking if the array is empty will cause a runtime error when no user groups exist. Add a check to ensure userGroups.length > 0 before accessing the first element.

Suggested change
defaultValue: userGroups[0].id.toString(),
defaultValue: userGroups.length > 0 ? userGroups[0].id.toString() : '',

Copilot uses AI. Check for mistakes.
options: userGroups.map(group => ({
value: group.id.toString(),
label: group.name
Expand Down