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