diff --git a/src/apps/officer-web/Screens/Dashboard/ChatHistory/CreateGroupDialog.tsx b/src/apps/officer-web/Screens/Dashboard/ChatHistory/CreateGroupDialog.tsx new file mode 100644 index 00000000..5ae11530 --- /dev/null +++ b/src/apps/officer-web/Screens/Dashboard/ChatHistory/CreateGroupDialog.tsx @@ -0,0 +1,138 @@ +import { useState } from 'react'; +import { X } from 'lucide-react'; +import { useChatGroups } from '@/state/useChatGroups'; + +type CreateGroupDialogProps = { + onClose: () => void; +}; + +function toSlug(name: string): string { + return name + .toLowerCase() + .replace(/[^a-z0-9]+/g, '-') + .replace(/^-|-$/g, ''); +} + +export function CreateGroupDialog({ onClose }: CreateGroupDialogProps) { + const { createGroup } = useChatGroups(); + const [name, setName] = useState(''); + const [description, setDescription] = useState(''); + const [isSubmitting, setIsSubmitting] = useState(false); + const [error, setError] = useState(null); + + async function handleSubmit(e: React.FormEvent) { + e.preventDefault(); + + if (!name.trim()) { + setError('Name is required'); + return; + } + + const slug = toSlug(name); + if (!slug) { + setError('Name must contain at least one alphanumeric character'); + return; + } + + setIsSubmitting(true); + setError(null); + + try { + await createGroup(name.trim(), slug, description.trim() || undefined); + onClose(); + } catch (err) { + setError(err instanceof Error ? err.message : 'Failed to create group'); + setIsSubmitting(false); + } + } + + function handleBackdropClick(e: React.MouseEvent) { + if (e.target === e.currentTarget) { + onClose(); + } + } + + return ( +
+
+ {/* Header */} +
+

Create Group

+ +
+ + {/* Form */} +
+
+ + setName(e.target.value)} + placeholder="e.g., Work Projects" + className="w-full px-3 py-2 rounded-md border border-duck-dark/20 dark:border-foreground/20 bg-background text-duck-dark dark:text-foreground placeholder:text-duck-dark/40 dark:placeholder:text-foreground/40 focus:outline-none focus:ring-2 focus:ring-duck-teal/50" + autoFocus + disabled={isSubmitting} + /> + {name && ( +

+ Slug: {toSlug(name) || '(invalid)'} +

+ )} +
+ +
+ +