fix: Giveaway bugs

This commit is contained in:
smueller
2026-07-24 10:33:56 +02:00
parent bd1b55fff7
commit f2406fb6d7
7 changed files with 74 additions and 25 deletions

View File

@@ -83,9 +83,18 @@ export function GiveawaysManager({ guildId, initialGiveaways }: GiveawaysManager
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action })
});
const body = (await response.json().catch(() => null)) as (GiveawayDashboard & { error?: string }) | null;
if (!response.ok || !body) {
toast.error(body?.error ?? t('common.saveError'));
const body = (await response.json().catch(() => null)) as
| (GiveawayDashboard & { error?: string })
| { error?: string }
| null;
if (!response.ok || !body || !('id' in body)) {
toast.error(
(body && 'error' in body && body.error) || t('common.saveError')
);
return;
}
if (action === 'end' && !body.endedAt) {
toast.error(t('common.saveError'));
return;
}
setGiveaways((prev) => prev.map((entry) => (entry.id === giveaway.id ? body : entry)));