From 40cbb745cd873bc8773e2eea1b7c772875b97401 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Sat, 13 Sep 2025 17:15:59 -0500 Subject: [PATCH] Fix bug where not setting a channel number would cause an error when creating a channel. --- frontend/src/api.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/frontend/src/api.js b/frontend/src/api.js index 110d6b75..74e138fa 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -323,14 +323,27 @@ export default class API { static async addChannel(channel) { try { let body = null; + // Prepare a copy to safely mutate + const channelData = { ...channel }; + + // Remove channel_number if empty, null, or not a valid number + if ( + channelData.channel_number === '' || + channelData.channel_number === null || + channelData.channel_number === undefined || + (typeof channelData.channel_number === 'string' && channelData.channel_number.trim() === '') + ) { + delete channelData.channel_number; + } + if (channel.logo_file) { // Must send FormData for file upload body = new FormData(); - for (const prop in channel) { - body.append(prop, channel[prop]); + for (const prop in channelData) { + body.append(prop, channelData[prop]); } } else { - body = { ...channel }; + body = { ...channelData }; delete body.logo_file; }