All files / features/events/pages EventDashboardPage.tsx

100% Statements 14/14
58.33% Branches 7/12
100% Functions 2/2
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199                                  1x 2x 2x 2x 2x   2x   2x   1x 2x 2x 2x       2x                                                                                                                                                                                                                                                                                                                                        
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@core/components/ui/card'
import {
    Target,
    Users,
    TrendingUp,
    Calendar,
    ExternalLink,
    Settings,
    Smartphone,
} from 'lucide-react'
import { Button } from '@core/components/ui/button'
import { Link, useParams } from 'react-router-dom'
import { RecentDonationsList } from '../components/RecentDonationsList'
import { useEvents } from '@features/events/hooks/useEvents'
import { useCurrencyFormatter } from '@core/hooks/useCurrencyFormatter'
import { useTranslation } from 'react-i18next'
 
export const EventDashboardPage = () => {
    const { slug } = useParams<{ slug: string }>()
    const { t } = useTranslation('common')
    const { events } = useEvents()
    const { formatCurrency } = useCurrencyFormatter()
 
    const event = events.find((e) => e.slug === slug)
 
    if (!event) return null
 
    const raised = event.raised || 0
    const goal = event.goalAmount || 1
    const progress = Math.min(100, Math.round((raised / goal) * 100))
    const donors = event.donorCount || 0
    // const status = event.status?.toUpperCase() || 'DRAFT';
    // Using translation for status would require mapping, for now let's keep it simple or allow backend string if it matches key
 
    return (
        <div className="space-y-6">
            <div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
                <div>
                    <h2
                        className="text-3xl font-bold tracking-tight"
                        style={{ color: 'var(--admin-heading-color)' }}
                    >
                        {event.name}
                    </h2>
                    <p className="text-muted-foreground mt-1">
                        {t('admin_events.dashboard.overview')}
                    </p>
                </div>
                <div className="flex gap-2">
                    <Button variant="outline" asChild>
                        <Link to={`/admin/events/${event.slug}/settings`}>
                            <Settings className="mr-2 h-4 w-4" />
                            {t('nav.settings')}
                        </Link>
                    </Button>
                    <Button variant="outline" asChild>
                        <Link to={`/${event.slug}/staff`} target="_blank">
                            <Smartphone className="mr-2 h-4 w-4" />
                            {t('admin_events.dashboard.collector_app')}
                        </Link>
                    </Button>
                    <Button asChild>
                        <Link to={`/${event.slug}/live`} target="_blank">
                            <ExternalLink className="mr-2 h-4 w-4" />
                            {t('admin_events.dashboard.launch_live')}
                        </Link>
                    </Button>
                </div>
            </div>
 
            {/* Stats Grid */}
            <div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
                <Card
                    style={{
                        backgroundColor: 'var(--admin-card-bg)',
                        borderColor: 'var(--admin-border-color)',
                    }}
                >
                    <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
                        <CardTitle className="text-sm font-medium">
                            {t('admin_events.total_raised')}
                        </CardTitle>
                        <TrendingUp className="h-4 w-4 text-muted-foreground" />
                    </CardHeader>
                    <CardContent>
                        <div
                            className="text-2xl font-bold"
                            style={{ color: 'var(--admin-card-text)' }}
                        >
                            {formatCurrency(raised)}
                        </div>
                        <p className="text-xs text-muted-foreground">
                            {t('admin_events.dashboard.progress_of_goal', { progress })}
                        </p>
                    </CardContent>
                </Card>
 
                <Card
                    style={{
                        backgroundColor: 'var(--admin-card-bg)',
                        borderColor: 'var(--admin-border-color)',
                    }}
                >
                    <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
                        <CardTitle className="text-sm font-medium">
                            {t('admin_events.donors')}
                        </CardTitle>
                        <Users className="h-4 w-4 text-muted-foreground" />
                    </CardHeader>
                    <CardContent>
                        <div
                            className="text-2xl font-bold"
                            style={{ color: 'var(--admin-card-text)' }}
                        >
                            {donors}
                        </div>
                        <p className="text-xs text-muted-foreground">
                            {t('admin_events.dashboard.unique_contributors')}
                        </p>
                    </CardContent>
                </Card>
 
                <Card
                    style={{
                        backgroundColor: 'var(--admin-card-bg)',
                        borderColor: 'var(--admin-border-color)',
                    }}
                >
                    <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
                        <CardTitle className="text-sm font-medium">
                            {t('admin_events.goal')}
                        </CardTitle>
                        <Target className="h-4 w-4 text-muted-foreground" />
                    </CardHeader>
                    <CardContent>
                        <div
                            className="text-2xl font-bold"
                            style={{ color: 'var(--admin-card-text)' }}
                        >
                            {formatCurrency(goal)}
                        </div>
                        <p className="text-xs text-muted-foreground">
                            {t('admin_events.dashboard.target_amount')}
                        </p>
                    </CardContent>
                </Card>
 
                <Card
                    style={{
                        backgroundColor: 'var(--admin-card-bg)',
                        borderColor: 'var(--admin-border-color)',
                    }}
                >
                    <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
                        <CardTitle className="text-sm font-medium">
                            {t('admin_events.event_date')}
                        </CardTitle>
                        <Calendar className="h-4 w-4 text-muted-foreground" />
                    </CardHeader>
                    <CardContent>
                        <div
                            className="text-2xl font-bold"
                            style={{ color: 'var(--admin-card-text)' }}
                        >
                            {event.date ? new Date(event.date).toLocaleDateString() : 'N/A'}
                        </div>
                        <span
                            className={`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold ${event.status === 'ACTIVE' ? 'bg-green-100 text-green-800' : 'bg-gray-100 text-gray-800'}`}
                        >
                            {event.status}
                        </span>
                    </CardContent>
                </Card>
            </div>
 
            {/* Recent Donations List */}
            <Card
                className="col-span-4"
                style={{
                    backgroundColor: 'var(--admin-card-bg)',
                    borderColor: 'var(--admin-border-color)',
                }}
            >
                <CardHeader>
                    <CardTitle>{t('dashboard.recent_donations')}</CardTitle>
                    <CardDescription>
                        {t('admin_events.dashboard.latest_transactions_for', {
                            name: event.name,
                        })}
                    </CardDescription>
                </CardHeader>
                <CardContent>
                    <RecentDonationsList eventId={event.id} />
                </CardContent>
            </Card>
        </div>
    )
}