fix(frontend): require guildId for channel creation and fallback from channel list
This commit is contained in:
@@ -10,7 +10,7 @@ type MessageItem = {
|
||||
isDeleted?: boolean
|
||||
}
|
||||
|
||||
type GuildChannel = { id: string; name: string }
|
||||
type GuildChannel = { id: string; name: string; guildId?: string }
|
||||
type GuildRecord = { id: string; name: string }
|
||||
type GuildMember = { id: string; userId: string; guildId: string; status: string }
|
||||
|
||||
@@ -69,6 +69,7 @@ export default function ChatPage() {
|
||||
})
|
||||
const list = Array.isArray(res.data) ? (res.data as GuildChannel[]) : []
|
||||
setChannels(list)
|
||||
if (!guildDbId && list[0]?.guildId) setGuildDbId(list[0].guildId)
|
||||
if (!selectedChannelId && list.length) setSelectedChannelId(list[0].id)
|
||||
} catch {
|
||||
setError('Failed to load channels')
|
||||
@@ -129,10 +130,13 @@ export default function ChatPage() {
|
||||
|
||||
async function createChannel() {
|
||||
if (!guild || !guildToken || !newChannelName.trim()) return
|
||||
if (!guildDbId) {
|
||||
setError('Cannot create channel: guildId is missing')
|
||||
return
|
||||
}
|
||||
setError('')
|
||||
try {
|
||||
const payload = guildDbId ? { name: newChannelName.trim(), guildId: guildDbId } : { name: newChannelName.trim() }
|
||||
const res = await guildApi().post('/channels', payload)
|
||||
const res = await guildApi().post('/channels', { name: newChannelName.trim(), guildId: guildDbId })
|
||||
const createdId = res.data?.id as string | undefined
|
||||
setNewChannelName('')
|
||||
await loadChannels()
|
||||
|
||||
Reference in New Issue
Block a user