Skip to content

Commit e5726d2

Browse files
committed
option github_url
1 parent 3c8c0a2 commit e5726d2

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

app/hackathon/(components)/register-form.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ const FormSchema = z.object({
2626
.min(11, { message: "学号必须是至少 11 位数字。" })
2727
.regex(/^\d+$/, { message: "学号只能包含数字。" }),
2828
nickname: z.string().min(2, { message: "昵称至少需要 2 个字符。" }),
29-
github_url: z.string().regex(/^https:\/\/github\.com\/[^\/]+\/[^\/]+$/, {
30-
message:
31-
"请输入有效的 GitHub 项目主页链接(例如:https://github.com/user/repo)。",
32-
}),
29+
github_url: z
30+
.string()
31+
.optional()
32+
.refine(
33+
(val) => !val || /^https:\/\/github\.com\/[^\/]+\/[^\/]+$/.test(val),
34+
{
35+
message:
36+
"请输入有效的 GitHub 项目主页链接(例如:https://github.com/user/repo)。",
37+
}
38+
),
3339
});
3440

3541
type FormFields = z.infer<typeof FormSchema>;
@@ -47,7 +53,7 @@ const formFields = [
4753
},
4854
{
4955
name: "github_url",
50-
label: "GitHub 项目链接",
56+
label: "GitHub 项目链接(可后续添加或修改)",
5157
placeholder: "https://github.com/username/project",
5258
},
5359
] as const;

convex/register.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const createRegister = mutation({
66
userId: v.string(),
77
studentId: v.string(),
88
nickname: v.string(),
9-
githubLink: v.string(),
9+
githubLink: v.optional(v.string()),
1010
},
1111
handler: async (ctx, args) => {
1212
const existingRegister = await ctx.db
@@ -24,7 +24,7 @@ export const createRegister = mutation({
2424
userId: args.userId,
2525
studentId: args.studentId,
2626
nickname: args.nickname,
27-
githubLink: args.githubLink,
27+
githubLink: args.githubLink ? args.githubLink : "https://example.com",
2828
});
2929
console.log(`Created register with ID ${registerId}`);
3030
}

0 commit comments

Comments
 (0)