'use client' import { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { RiAddLine, RiDeleteBinLine } from '@remixicon/react' import { deleteRedBlueChallenge, listRedBlueChallenges, updateRedBlueChallenge } from '@/service/console/challenges' import Button from '@/app/components/base/button' import Toast from '@/app/components/base/toast' import Confirm from '@/app/components/base/confirm' import CreateRedBlueModal from './create-red-blue-modal' export default function ConsoleRedBlueChallengesPage() { const { t } = useTranslation() const [items, setItems] = useState([]) const [showModal, setShowModal] = useState(false) const [loading, setLoading] = useState(false) const [pendingDeleteId, setPendingDeleteId] = useState(null) const load = async () => { setLoading(true) try { const data = await listRedBlueChallenges() setItems(data) } finally { setLoading(false) } } useEffect(() => { void load() }, []) const confirmDelete = async () => { if (!pendingDeleteId) return try { await deleteRedBlueChallenge(pendingDeleteId) Toast.notify({ type: 'success', message: 'Challenge deleted' }) await load() } catch (e: any) { Toast.notify({ type: 'error', message: e.message || 'Delete failed' }) } finally { setPendingDeleteId(null) } } const handleToggleActive = async (item: any) => { try { await updateRedBlueChallenge(item.id, { is_active: !item.is_active }) Toast.notify({ type: 'success', message: item.is_active ? 'Deactivated' : 'Activated' }) await load() } catch (e: any) { Toast.notify({ type: 'error', message: e.message || 'Update failed' }) } } return (

{t('challenges.redBlue.title')}

{loading ? (
{t('common.loading')}
) : items.length === 0 ? (
{t('challenges.console.empty')}
{t('challenges.console.emptyDesc')}
) : (
{items.map(item => (
{item.name}
RED
BLUE
{item.description && (
{item.description}
)}
{item.is_active ? t('challenges.console.status.active') : t('challenges.console.status.inactive')}
))}
)}
{showModal && ( setShowModal(false)} onSuccess={() => { setShowModal(false) void load() }} /> )} setPendingDeleteId(null)} onConfirm={confirmDelete} />
) }