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

Function EditChannelModal

apps/web/ui/EditChannelModal/index.tsx:30–155  ·  view source on GitHub ↗
({
  open,
  close,
  channel,
  currentCommunity,
  api,
}: Props)

Source from the content-addressed store, hash-verified

28}
29
30export default function EditChannelModal({
31 open,
32 close,
33 channel,
34 currentCommunity,
35 api,
36}: Props) {
37 const [loading, setLoading] = useState(false);
38 const [viewType, setViewType] = useState<ChannelViewType>(channel.viewType);
39 const [channelPrivate, setChannelPrivate] = useState(
40 channel.type === 'PRIVATE'
41 );
42
43 function updateChannel({
44 accountId,
45 channelId,
46 channelName,
47 viewType,
48 }: {
49 accountId: string;
50 channelId: string;
51 channelName: string;
52 viewType: ChannelViewType;
53 }) {
54 setLoading(true);
55 return api
56 .updateChannel({
57 accountId,
58 channelId,
59 channelName,
60 channelPrivate,
61 viewType,
62 })
63 .then(() => {
64 // changing channel name changes the path
65 // we'd need to dynamically update it
66 // we should most likely send this through websockets
67 // to other users to update the channel name dynamically
68 // otherwise they'll get a 404 on the previous channel name
69 setLoading(false);
70 window.location.href = window.location.href.replace(
71 `/${channel.channelName}`,
72 `/${channelName}`
73 );
74 close();
75 })
76 .catch(() => {
77 setLoading(false);
78 close();
79 });
80 }
81
82 function onSubmit(event: React.FormEvent<HTMLFormElement>) {
83 event.preventDefault();
84 const form = event.target as typeof event.target & {
85 channelName: { value: string };
86 slackDomain: { value: string };
87 };

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected