MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / NewChannelModal

Function NewChannelModal

apps/web/ui/NewChannelModal/index.tsx:32–184  ·  view source on GitHub ↗
({
  permissions,
  show,
  close,
  api,
  CustomRouterPush,
}: Props)

Source from the content-addressed store, hash-verified

30}
31
32export default function NewChannelModal({
33 permissions,
34 show,
35 close,
36 api,
37 CustomRouterPush,
38}: Props) {
39 const [loading, setLoading] = useState(false);
40 const [channelPrivate, setChannelPrivate] = useState(false);
41 const [viewType, setViewType] = useState<ChannelViewType>(
42 ChannelViewType.CHAT
43 );
44 const [users, setUsers] = useState<SerializedUser[]>(
45 permissions.user ? [permissions.user] : []
46 );
47
48 async function onSubmit(e: any) {
49 setLoading(true);
50 try {
51 e.preventDefault();
52 const form = e.target;
53 const channelName = form.channelName.value;
54
55 if (channelPrivate) {
56 await api.createChannel({
57 accountId: permissions.accountId!,
58 channelName,
59 channelPrivate: true,
60 viewType,
61 usersId: users.map((u) => u.id),
62 });
63 } else {
64 await api.createChannel({
65 accountId: permissions.accountId!,
66 channelName,
67 viewType,
68 });
69 }
70
71 close();
72 CustomRouterPush({
73 path: `/c/${channelName}`,
74 });
75 } catch (error) {
76 Toast.error('Something went wrong');
77 } finally {
78 setLoading(false);
79 }
80 }
81
82 function onPrivateToggle(checked: boolean) {
83 setChannelPrivate(checked);
84 }
85
86 function removeUser(user: SerializedUser) {
87 setUsers((users) => users.filter((u) => u.id !== user.id));
88 }
89

Callers

nothing calls this directly

Calls 1

onPrivateToggleFunction · 0.85

Tested by

no test coverage detected