diff --git a/app/admin/NoticeTab.tsx b/app/admin/NoticeTab.tsx new file mode 100644 index 0000000..d046c8b --- /dev/null +++ b/app/admin/NoticeTab.tsx @@ -0,0 +1,115 @@ +// app/admin/NoticeTab.tsx + +"use client"; + +import { AlertCircle, AlertTriangle, BellRing, Info, Loader2, Save, CheckCircle } from 'lucide-react'; +import React, { useEffect, useState } from 'react'; +import { readJsonFile, writeJsonFile } from '../actions/jsonEditor'; + +interface NoticeData { + isActive: boolean; + type: 'notice' | 'warning' | 'important'; + message: string; +} + +export const NoticeTab = ({ isOffline }: { isOffline: boolean }) => { + const [notice, setNotice] = useState({ isActive: false, type: 'warning', message: '' }); + const [isLoading, setIsLoading] = useState(true); + const [isSaving, setIsSaving] = useState(false); + const [saveStatus, setSaveStatus] = useState<'idle' | 'success' | 'error'>('idle'); + + useEffect(() => { + const fetchNotice = async () => { + const res = await readJsonFile('notice.json'); + if (res.success && res.data) { + setNotice(res.data); + } + setIsLoading(false); + }; + fetchNotice(); + }, []); + + const handleSave = async () => { + setIsSaving(true); + setSaveStatus('idle'); + const res = await writeJsonFile('notice.json', notice); + if (res.success) { + setSaveStatus('success'); + setTimeout(() => setSaveStatus('idle'), 3000); + } else { + setSaveStatus('error'); + } + setIsSaving(false); + }; + + if (isLoading) return
; + + return ( +
+
+
+

+
+ +
+ Meddelande på startsidan +

+ + {/* Av/På Switch */} + +
+ +
+
+
+ +
+ + + +
+
+ +
+ +