forked from EduCraft/curriculum-project-hub
feat: validate team slug format and improve error handling in team creation
This commit is contained in:
@@ -38,12 +38,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
const SLUG_RE = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
|
||||
|
||||
async function createTeam() {
|
||||
if (!newSlug.trim() || !newName.trim()) return;
|
||||
const teamSlug = newSlug.trim().toLowerCase();
|
||||
if (!SLUG_RE.test(teamSlug)) {
|
||||
toastError('标识须为小写字母数字,可用连字符连接');
|
||||
return;
|
||||
}
|
||||
adding = true;
|
||||
try {
|
||||
await api.createTeam(slug, {
|
||||
slug: newSlug.trim(),
|
||||
slug: teamSlug,
|
||||
name: newName.trim(),
|
||||
...(newDesc.trim() ? { description: newDesc.trim() } : {})
|
||||
});
|
||||
@@ -134,7 +141,7 @@
|
||||
<div class="saas-card-pad mb-6">
|
||||
<h2 class="saas-section-title mb-4">新建团队</h2>
|
||||
<div class="grid gap-3 md:grid-cols-[1fr_1fr_1.2fr_auto]">
|
||||
<input class="saas-input" placeholder="标识(小写字母数字)" bind:value={newSlug} />
|
||||
<input class="saas-input" placeholder="标识(如 math-g7)" bind:value={newSlug} />
|
||||
<input class="saas-input" placeholder="名称" bind:value={newName} />
|
||||
<input class="saas-input" placeholder="描述(可选)" bind:value={newDesc} />
|
||||
<button class="saas-btn-primary" onclick={createTeam} disabled={adding}>新建</button>
|
||||
|
||||
Reference in New Issue
Block a user