'use client'; import type { StarboardConfigDashboard } from '@nexumi/shared'; import { useId } from 'react'; import { FieldAnchor } from '@/components/layout/field-anchor'; import { useTranslations } from '@/components/locale-provider'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { DiscordChannelMultiSelect, DiscordChannelSelect } from '@/components/ui/discord-channel-select'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Switch } from '@/components/ui/switch'; import type { SettingsSaveResult } from '@/components/settings/settings-form'; import { SettingsForm } from '@/components/settings/settings-form'; async function saveStarboard(guildId: string, value: StarboardConfigDashboard): Promise { try { const response = await fetch(`/api/guilds/${guildId}/starboard`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(value) }); if (!response.ok) { const body = (await response.json().catch(() => null)) as { error?: string } | null; return { ok: false, error: body?.error ?? `Request failed with status ${response.status}` }; } return { ok: true }; } catch { return { ok: false, error: 'Network error' }; } } interface StarboardFormProps { guildId: string; initialValue: StarboardConfigDashboard; } export function StarboardForm({ guildId, initialValue }: StarboardFormProps) { const t = useTranslations(); const emojiId = useId(); const thresholdId = useId(); return ( initialValue={initialValue} onSave={(value) => saveStarboard(guildId, value)} > {({ value, setValue }) => ( {t('modulePages.starboard.title')} {t('modulePages.starboard.description')}
setValue((prev) => ({ ...prev, enabled }))} />
setValue((prev) => ({ ...prev, channelId }))} />
setValue((prev) => ({ ...prev, emoji: event.target.value }))} />
setValue((prev) => ({ ...prev, threshold: Number(event.target.value) || 1 }))} />
setValue((prev) => ({ ...prev, allowSelfStar }))} />
setValue((prev) => ({ ...prev, ignoredChannelIds }))} />
)} ); }