Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687import * as borogove from "borogove";import { useState } from "react";import { Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, TextField,} from "@mui/material";
export const CreateChannelDialog = ({ open, client, onClose, onCreated,}: { open: boolean; client: borogove.Client; onClose: () => void; onCreated: (channel: borogove.Channel) => void;}) => { const [name, setName] = useState(""); const [creating, setCreating] = useState(false); const [error, setError] = useState<string | null>(null);
const close = () => { if (creating) return; setName(""); setError(null); onClose(); };
const createChannel = async (event: React.FormEvent<HTMLFormElement>) => { event.preventDefault(); if (creating) return;
setCreating(true); setError(null);
try { const channel = await client.createChannelInstant(name.trim() || null); setName(""); onCreated(channel); } catch (e) { setError(e instanceof Error ? e.message : String(e)); } setCreating(false); };
return ( <Dialog open={open} onClose={close} fullWidth maxWidth="sm"> <DialogTitle>New Private Channel</DialogTitle> <form onSubmit={createChannel}> <DialogContent> <DialogContentText>Create an invite-only channel.</DialogContentText> <TextField autoFocus fullWidth margin="dense" label="Channel name" helperText="Optional. Leave blank to generate one automatically." value={name} onChange={(e) => setName(e.target.value)} disabled={creating} error={!!error} /> {error && ( <DialogContentText role="alert" color="error"> {error} </DialogContentText> )} </DialogContent> <DialogActions> <Button onClick={close} disabled={creating}> Cancel </Button> <Button type="submit" variant="contained" disabled={creating}> {creating ? "Creating..." : "Create Channel"} </Button> </DialogActions> </form> </Dialog> );};