import React, { useState } from 'react'; import { Modal } from '../ui/Modal'; import { useUIStore } from '../../stores/uiStore'; import { useServerStore } from '../../stores/serverStore'; export function CreateChannelModal() { const [name, setName] = useState(''); const [type, setType] = useState<'text' | 'voice' | 'video'>('text'); const [topic, setTopic] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); const activeModal = useUIStore((s) => s.activeModal); const closeModal = useUIStore((s) => s.closeModal); const createChannel = useServerStore((s) => s.createChannel); const currentServerId = useServerStore((s) => s.currentServerId); const isOpen = activeModal === 'createChannel'; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); if (!name.trim()) { setError('Channel name is required'); return; } if (!currentServerId) { setError('No server selected'); return; } setIsLoading(true); try { await createChannel(currentServerId, name.trim(), type, topic.trim() || undefined); closeModal(); setName(''); setTopic(''); setType('text'); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to create channel'); } finally { setIsLoading(false); } }; return (
{error && (
{error}
)}
{(['text', 'voice', 'video'] as const).map((t) => ( ))}
setName(e.target.value)} className="w-full px-3 py-2 bg-surface-input rounded text-txt-primary outline-none focus:ring-2 focus:ring-accent-primary" placeholder="new-channel" autoFocus />
{type === 'text' && (
setTopic(e.target.value)} className="w-full px-3 py-2 bg-surface-input rounded text-txt-primary outline-none focus:ring-2 focus:ring-accent-primary" placeholder="What's this channel about?" />
)}
); }