diff --git a/gsm-frontend/src/api.js b/gsm-frontend/src/api.js index 7bceeb1..30a8bad 100644 --- a/gsm-frontend/src/api.js +++ b/gsm-frontend/src/api.js @@ -323,5 +323,14 @@ export async function saveDisplaySettings(token, serverId, address, hint) { }) } +// Discord Updates +export async function sendDiscordUpdate(token, title, description, serverType, color) { + return fetchAPI('/servers/discord/send-update', { + method: 'POST', + headers: { Authorization: `Bearer ${token}` }, + body: JSON.stringify({ title, description, serverType, color }), + }) +} + // Alias for backwards compatibility export const setDisplaySettings = saveDisplaySettings diff --git a/gsm-frontend/src/components/SendUpdateModal.jsx b/gsm-frontend/src/components/SendUpdateModal.jsx new file mode 100644 index 0000000..c9b35c7 --- /dev/null +++ b/gsm-frontend/src/components/SendUpdateModal.jsx @@ -0,0 +1,189 @@ +import { useState } from 'react' +import { sendDiscordUpdate } from '../api' +import { useUser } from '../context/UserContext' + +const SERVER_TYPES = [ + { value: 'general', label: 'Allgemein', icon: '📢', titleTemplate: '' }, + { value: 'minecraft', label: 'Minecraft', icon: '⛏️', titleTemplate: 'Minecraft Server Update' }, + { value: 'factorio', label: 'Factorio', icon: '⚙️', titleTemplate: 'Factorio Server Update' }, + { value: 'terraria', label: 'Terraria', icon: '⚔️', titleTemplate: 'Terraria Server Update' }, + { value: 'palworld', label: 'Palworld', icon: '🦎', titleTemplate: 'Palworld Server Update' }, + { value: 'vrising', label: 'V Rising', icon: '🧛', titleTemplate: 'V Rising Server Update' }, + { value: 'zomboid', label: 'Project Zomboid', icon: '🧟', titleTemplate: 'Project Zomboid Server Update' }, + { value: 'hytale', label: 'Hytale', icon: '🏰', titleTemplate: 'Hytale Server Update' }, +] + +const COLORS = [ + { value: 0x5865F2, label: 'Blau', hex: '#5865F2' }, + { value: 0x57F287, label: 'Grün', hex: '#57F287' }, + { value: 0xFEE75C, label: 'Gelb', hex: '#FEE75C' }, + { value: 0xED4245, label: 'Rot', hex: '#ED4245' }, + { value: 0x00BFFF, label: 'Cyan', hex: '#00BFFF' }, +] + +export default function SendUpdateModal({ onClose }) { + const { token } = useUser() + const [serverType, setServerType] = useState('general') + const [title, setTitle] = useState('') + const [description, setDescription] = useState('') + const [color, setColor] = useState(COLORS[0].value) + const [loading, setLoading] = useState(false) + const [success, setSuccess] = useState(false) + const [error, setError] = useState('') + + const handleServerTypeChange = (e) => { + const newType = e.target.value + setServerType(newType) + const template = SERVER_TYPES.find(t => t.value === newType)?.titleTemplate || '' + setTitle(template) + } + + const handleSubmit = async (e) => { + e.preventDefault() + if (!title.trim() || !description.trim()) { + setError('Titel und Beschreibung sind erforderlich') + return + } + + setLoading(true) + setError('') + setSuccess(false) + + try { + await sendDiscordUpdate(token, title.trim(), description.trim(), serverType, color) + setSuccess(true) + setTimeout(() => { + onClose() + }, 1500) + } catch (err) { + setError(err.message || 'Fehler beim Senden') + } finally { + setLoading(false) + } + } + + return ( +