"use client"; import { useState } from "react"; import { toast } from "sonner"; import { ArrowLeft } from "lucide-react"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogTitle, DialogDescription, } from "@/components/ui/dialog"; import { Card, CardContent } from "@/components/ui/card"; import { useWorkspaceStore } from "@/features/workspace"; const SLUG_REGEX = /^[a-z0-9]+(?:-[a-z0-9]+)*$/; export function CreateWorkspaceModal({ onClose }: { onClose: () => void }) { const [name, setName] = useState(""); const [slug, setSlug] = useState(""); const [creating, setCreating] = useState(false); const slugError = slug.length > 0 && !SLUG_REGEX.test(slug) ? "Only lowercase letters, numbers, and hyphens" : null; const canSubmit = name.trim().length > 0 && slug.trim().length > 0 && !slugError; const handleNameChange = (value: string) => { setName(value); setSlug( value .toLowerCase() .replace(/[^a-z0-9]+/g, "-") .replace(/^-|-$/g, ""), ); }; const handleCreate = async () => { if (!canSubmit) return; setCreating(true); try { const { createWorkspace, switchWorkspace } = useWorkspaceStore.getState(); const ws = await createWorkspace({ name: name.trim(), slug: slug.trim(), }); onClose(); await switchWorkspace(ws.id); } catch { toast.error("Failed to create workspace"); } finally { setCreating(false); } }; return ( { if (!v) onClose(); }}>
Create a new workspace Workspaces are shared environments where teams can work on projects and issues.
handleNameChange(e.target.value)} placeholder="My Workspace" />
multica.app/ setSlug(e.target.value)} placeholder="my-workspace" className="border-0 shadow-none focus-visible:ring-0" />
{slugError && (

{slugError}

)}
); }