Complete admin dashboard implementation with comprehensive features

🚀 Major Update: v2.0.0 - Complete Administrative Dashboard

## Phase 1: Dashboard Overview & Authentication 
- Secure admin authentication with JWT tokens
- Beautiful overview dashboard with key metrics
- Role-based access control (admin, moderator permissions)
- Professional MUI design with responsive layout

## Phase 2: User Management & Content Moderation 
- Complete user management with advanced data grid
- Prayer request content moderation system
- User actions: view, suspend, activate, promote, delete
- Content approval/rejection workflows

## Phase 3: Analytics Dashboard 
- Comprehensive analytics with interactive charts (Recharts)
- User activity analytics with retention tracking
- Content engagement metrics and trends
- Real-time statistics and performance monitoring

## Phase 4: Chat Monitoring & System Administration 
- Advanced conversation monitoring with content analysis
- System health monitoring and backup management
- Security oversight and automated alerts
- Complete administrative control panel

## Key Features Added:
 **32 new API endpoints** for complete admin functionality
 **Material-UI DataGrid** with advanced filtering and pagination
 **Interactive Charts** using Recharts library
 **Real-time Monitoring** with auto-refresh capabilities
 **System Health Dashboard** with performance metrics
 **Database Backup System** with automated scheduling
 **Content Filtering** with automated moderation alerts
 **Role-based Permissions** with granular access control
 **Professional UI/UX** with consistent MUI design
 **Visit Website Button** in admin header for easy navigation

## Technical Implementation:
- **Frontend**: Material-UI components with responsive design
- **Backend**: 32 new API routes with proper authentication
- **Database**: Optimized queries with proper indexing
- **Security**: Admin-specific JWT authentication
- **Performance**: Efficient data loading with pagination
- **Charts**: Interactive visualizations with Recharts

The Biblical Guide application now provides world-class administrative capabilities for complete platform management!

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-23 12:01:34 +00:00
parent ee99e93ec2
commit 39b6899315
48 changed files with 8525 additions and 5198 deletions

View File

@@ -0,0 +1,415 @@
'use client';
import { useState, useEffect } from 'react';
import {
Typography,
Box,
Breadcrumbs,
Link,
Card,
CardContent,
Grid,
FormControl,
InputLabel,
Select,
MenuItem,
CircularProgress,
Alert,
Chip,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
Paper
} from '@mui/material';
import {
Home,
Analytics,
TrendingUp,
People,
Chat,
FavoriteBorder,
Bookmarks
} from '@mui/icons-material';
import {
LineChart,
Line,
AreaChart,
Area,
BarChart,
Bar,
PieChart,
Pie,
Cell,
XAxis,
YAxis,
CartesianGrid,
Tooltip,
Legend,
ResponsiveContainer
} from 'recharts';
interface AnalyticsData {
period: number;
overview: {
users: { total: number; new: number; active: number };
prayerRequests: { total: number; active: number; new: number };
prayers: { total: number; new: number };
conversations: { total: number; active: number; new: number };
messages: { total: number; new: number };
bookmarks: { total: number; new: number };
};
distributions: {
usersByRole: Array<{ role: string; _count: { role: number } }>;
prayersByCategory: Array<{ category: string; _count: { category: number } }>;
};
topContent: {
prayerRequests: Array<{
id: string;
title: string;
category: string;
prayerCount: number;
author: string;
}>;
};
activity: {
daily: Array<{
date: string;
newUsers: number;
newPrayers: number;
newConversations: number;
newBookmarks: number;
}>;
};
}
interface MetricCardProps {
title: string;
value: number;
change: number;
icon: React.ReactNode;
color: string;
}
function MetricCard({ title, value, change, icon, color }: MetricCardProps) {
return (
<Card>
<CardContent>
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
<Box>
<Typography color="textSecondary" gutterBottom variant="body2">
{title}
</Typography>
<Typography variant="h4">
{value.toLocaleString()}
</Typography>
<Box sx={{ display: 'flex', alignItems: 'center', mt: 1 }}>
<TrendingUp sx={{ fontSize: 16, mr: 0.5, color: change >= 0 ? 'success.main' : 'error.main' }} />
<Typography
variant="body2"
sx={{ color: change >= 0 ? 'success.main' : 'error.main' }}
>
{change >= 0 ? '+' : ''}{change}
</Typography>
<Typography variant="body2" color="textSecondary" sx={{ ml: 0.5 }}>
this period
</Typography>
</Box>
</Box>
<Box sx={{ color, fontSize: 40 }}>
{icon}
</Box>
</Box>
</CardContent>
</Card>
);
}
const COLORS = ['#8884d8', '#82ca9d', '#ffc658', '#ff7300', '#0088fe', '#00c49f'];
export default function AdminAnalyticsPage() {
const [data, setData] = useState<AnalyticsData | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState('');
const [period, setPeriod] = useState('30');
useEffect(() => {
const fetchAnalytics = async () => {
setLoading(true);
try {
const response = await fetch(`/api/admin/analytics/overview?period=${period}`, {
credentials: 'include'
});
if (response.ok) {
const analyticsData = await response.json();
setData(analyticsData);
} else {
setError('Failed to load analytics data');
}
} catch (error) {
setError('Network error loading analytics');
} finally {
setLoading(false);
}
};
fetchAnalytics();
}, [period]);
if (loading) {
return (
<Box sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: 400 }}>
<CircularProgress />
</Box>
);
}
if (error) {
return (
<Alert severity="error" sx={{ mb: 3 }}>
{error}
</Alert>
);
}
if (!data) return null;
return (
<Box>
{/* Breadcrumbs */}
<Breadcrumbs aria-label="breadcrumb" sx={{ mb: 3 }}>
<Link
underline="hover"
sx={{ display: 'flex', alignItems: 'center' }}
color="inherit"
href="/admin"
>
<Home sx={{ mr: 0.5 }} fontSize="inherit" />
Admin
</Link>
<Typography color="text.primary" sx={{ display: 'flex', alignItems: 'center' }}>
<Analytics sx={{ mr: 0.5 }} fontSize="inherit" />
Analytics
</Typography>
</Breadcrumbs>
{/* Page Header */}
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 4 }}>
<Box>
<Typography variant="h4" component="h1" gutterBottom>
Analytics Dashboard
</Typography>
<Typography variant="body1" color="text.secondary">
Comprehensive insights into user behavior and content engagement
</Typography>
</Box>
<FormControl size="small" sx={{ minWidth: 150 }}>
<InputLabel>Time Period</InputLabel>
<Select
value={period}
label="Time Period"
onChange={(e) => setPeriod(e.target.value)}
>
<MenuItem value="7">Last 7 days</MenuItem>
<MenuItem value="30">Last 30 days</MenuItem>
<MenuItem value="90">Last 90 days</MenuItem>
</Select>
</FormControl>
</Box>
{/* Metric Cards */}
<Box
sx={{
display: 'grid',
gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))',
gap: 3,
mb: 4
}}
>
<Box sx={{ cursor: 'pointer' }} onClick={() => window.location.href = '/admin/analytics/users'}>
<MetricCard
title="Total Users"
value={data.overview.users.total}
change={data.overview.users.new}
icon={<People />}
color="#1976d2"
/>
</Box>
<MetricCard
title="Prayer Requests"
value={data.overview.prayerRequests.total}
change={data.overview.prayerRequests.new}
icon={<FavoriteBorder />}
color="#d32f2f"
/>
<MetricCard
title="Total Prayers"
value={data.overview.prayers.total}
change={data.overview.prayers.new}
icon={<FavoriteBorder />}
color="#ed6c02"
/>
<MetricCard
title="Conversations"
value={data.overview.conversations.total}
change={data.overview.conversations.new}
icon={<Chat />}
color="#2e7d32"
/>
<MetricCard
title="Messages"
value={data.overview.messages.total}
change={data.overview.messages.new}
icon={<Chat />}
color="#9c27b0"
/>
<MetricCard
title="Bookmarks"
value={data.overview.bookmarks.total}
change={data.overview.bookmarks.new}
icon={<Bookmarks />}
color="#0288d1"
/>
</Box>
<Box
sx={{
display: 'grid',
gridTemplateColumns: { xs: '1fr', lg: '2fr 1fr' },
gap: 3,
mb: 3
}}
>
{/* Daily Activity Chart */}
<Card>
<CardContent>
<Typography variant="h6" gutterBottom>
Daily Activity Trends
</Typography>
<ResponsiveContainer width="100%" height={300}>
<LineChart data={data.activity.daily}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="date" />
<YAxis />
<Tooltip />
<Legend />
<Line type="monotone" dataKey="newUsers" stroke="#8884d8" name="New Users" />
<Line type="monotone" dataKey="newPrayers" stroke="#82ca9d" name="New Prayers" />
<Line type="monotone" dataKey="newConversations" stroke="#ffc658" name="New Conversations" />
<Line type="monotone" dataKey="newBookmarks" stroke="#ff7300" name="New Bookmarks" />
</LineChart>
</ResponsiveContainer>
</CardContent>
</Card>
{/* User Roles Distribution */}
<Card>
<CardContent>
<Typography variant="h6" gutterBottom>
User Roles Distribution
</Typography>
<ResponsiveContainer width="100%" height={300}>
<PieChart>
<Pie
data={data.distributions.usersByRole.map(item => ({
name: item.role,
value: item._count.role
}))}
cx="50%"
cy="50%"
outerRadius={80}
fill="#8884d8"
dataKey="value"
label
>
{data.distributions.usersByRole.map((entry, index) => (
<Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
))}
</Pie>
<Tooltip />
</PieChart>
</ResponsiveContainer>
</CardContent>
</Card>
</Box>
<Box
sx={{
display: 'grid',
gridTemplateColumns: { xs: '1fr', lg: '1fr 1fr' },
gap: 3
}}
>
{/* Prayer Categories Chart */}
<Card>
<CardContent>
<Typography variant="h6" gutterBottom>
Prayer Requests by Category
</Typography>
<ResponsiveContainer width="100%" height={300}>
<BarChart data={data.distributions.prayersByCategory.map(item => ({
category: item.category,
count: item._count.category
}))}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="category" />
<YAxis />
<Tooltip />
<Bar dataKey="count" fill="#8884d8" />
</BarChart>
</ResponsiveContainer>
</CardContent>
</Card>
{/* Top Prayer Requests */}
<Card>
<CardContent>
<Typography variant="h6" gutterBottom>
Most Prayed For Requests
</Typography>
<TableContainer>
<Table size="small">
<TableHead>
<TableRow>
<TableCell>Title</TableCell>
<TableCell>Category</TableCell>
<TableCell align="right">Prayers</TableCell>
</TableRow>
</TableHead>
<TableBody>
{data.topContent.prayerRequests.map((request) => (
<TableRow key={request.id}>
<TableCell>
<Typography variant="body2" noWrap sx={{ maxWidth: 200 }}>
{request.title}
</Typography>
<Typography variant="caption" color="text.secondary">
by {request.author}
</Typography>
</TableCell>
<TableCell>
<Chip
label={request.category}
size="small"
variant="outlined"
/>
</TableCell>
<TableCell align="right">
<Typography variant="body2" fontWeight="medium">
{request.prayerCount}
</Typography>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</CardContent>
</Card>
</Box>
</Box>
);
}

View File

@@ -0,0 +1,468 @@
'use client';
import { useState, useEffect } from 'react';
import {
Typography,
Box,
Breadcrumbs,
Link,
Card,
CardContent,
Grid,
FormControl,
InputLabel,
Select,
MenuItem,
CircularProgress,
Alert,
Chip,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
Paper,
Avatar
} from '@mui/material';
import {
Home,
Analytics,
People,
TrendingUp,
Schedule,
Assignment
} from '@mui/icons-material';
import {
LineChart,
Line,
AreaChart,
Area,
BarChart,
Bar,
PieChart,
Pie,
Cell,
XAxis,
YAxis,
CartesianGrid,
Tooltip,
Legend,
ResponsiveContainer
} from 'recharts';
interface UserAnalyticsData {
period: number;
timeline: {
registrations: Array<{ date: string; registrations: number }>;
};
activity: {
patterns: Array<{
id: string;
email: string;
name: string | null;
role: string;
createdAt: string;
lastLoginAt: string | null;
_count: {
chatConversations: number;
prayerRequests: number;
bookmarks: number;
notes: number;
};
}>;
mostActive: Array<{
id: string;
email: string;
name: string | null;
role: string;
totalActivity: number;
_count: {
chatConversations: number;
prayerRequests: number;
bookmarks: number;
notes: number;
};
}>;
};
retention: {
rate: number;
newUsers: number;
activeUsers: number;
};
engagement: {
featureUsage: {
chat: number;
prayers: number;
bookmarks: number;
notes: number;
};
avgSessionLength: number;
avgMessagesPerSession: number;
};
demographics: Array<{
role: string;
_count: { role: number };
_min: { createdAt: string };
_max: { createdAt: string };
}>;
}
const COLORS = ['#8884d8', '#82ca9d', '#ffc658', '#ff7300', '#0088fe', '#00c49f'];
export default function UserAnalyticsPage() {
const [data, setData] = useState<UserAnalyticsData | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState('');
const [period, setPeriod] = useState('30');
useEffect(() => {
const fetchUserAnalytics = async () => {
setLoading(true);
try {
const response = await fetch(`/api/admin/analytics/users?period=${period}`, {
credentials: 'include'
});
if (response.ok) {
const analyticsData = await response.json();
setData(analyticsData);
} else {
setError('Failed to load user analytics data');
}
} catch (error) {
setError('Network error loading user analytics');
} finally {
setLoading(false);
}
};
fetchUserAnalytics();
}, [period]);
if (loading) {
return (
<Box sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: 400 }}>
<CircularProgress />
</Box>
);
}
if (error) {
return (
<Alert severity="error" sx={{ mb: 3 }}>
{error}
</Alert>
);
}
if (!data) return null;
const featureUsageData = Object.entries(data.engagement.featureUsage).map(([key, value]) => ({
name: key.charAt(0).toUpperCase() + key.slice(1),
value
}));
return (
<Box>
{/* Breadcrumbs */}
<Breadcrumbs aria-label="breadcrumb" sx={{ mb: 3 }}>
<Link
underline="hover"
sx={{ display: 'flex', alignItems: 'center' }}
color="inherit"
href="/admin"
>
<Home sx={{ mr: 0.5 }} fontSize="inherit" />
Admin
</Link>
<Link
underline="hover"
sx={{ display: 'flex', alignItems: 'center' }}
color="inherit"
href="/admin/analytics"
>
<Analytics sx={{ mr: 0.5 }} fontSize="inherit" />
Analytics
</Link>
<Typography color="text.primary" sx={{ display: 'flex', alignItems: 'center' }}>
<People sx={{ mr: 0.5 }} fontSize="inherit" />
User Analytics
</Typography>
</Breadcrumbs>
{/* Page Header */}
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 4 }}>
<Box>
<Typography variant="h4" component="h1" gutterBottom>
User Analytics
</Typography>
<Typography variant="body1" color="text.secondary">
Detailed insights into user behavior, engagement, and retention
</Typography>
</Box>
<FormControl size="small" sx={{ minWidth: 150 }}>
<InputLabel>Time Period</InputLabel>
<Select
value={period}
label="Time Period"
onChange={(e) => setPeriod(e.target.value)}
>
<MenuItem value="7">Last 7 days</MenuItem>
<MenuItem value="30">Last 30 days</MenuItem>
<MenuItem value="90">Last 90 days</MenuItem>
</Select>
</FormControl>
</Box>
<Box
sx={{
display: 'grid',
gridTemplateColumns: 'repeat(auto-fit, minmax(250px, 1fr))',
gap: 3,
mb: 3
}}
>
{/* Key Metrics */}
<Card>
<CardContent>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<TrendingUp sx={{ fontSize: 40, color: 'primary.main', mr: 2 }} />
<Box>
<Typography color="textSecondary" variant="body2">
Retention Rate
</Typography>
<Typography variant="h5">
{data.retention.rate}%
</Typography>
</Box>
</Box>
</CardContent>
</Card>
<Card>
<CardContent>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Schedule sx={{ fontSize: 40, color: 'warning.main', mr: 2 }} />
<Box>
<Typography color="textSecondary" variant="body2">
Avg Session (min)
</Typography>
<Typography variant="h5">
{data.engagement.avgSessionLength}
</Typography>
</Box>
</Box>
</CardContent>
</Card>
<Card>
<CardContent>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Assignment sx={{ fontSize: 40, color: 'success.main', mr: 2 }} />
<Box>
<Typography color="textSecondary" variant="body2">
Avg Messages/Session
</Typography>
<Typography variant="h5">
{data.engagement.avgMessagesPerSession}
</Typography>
</Box>
</Box>
</CardContent>
</Card>
<Card>
<CardContent>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<People sx={{ fontSize: 40, color: 'info.main', mr: 2 }} />
<Box>
<Typography color="textSecondary" variant="body2">
Active/New Users
</Typography>
<Typography variant="h5">
{data.retention.activeUsers}/{data.retention.newUsers}
</Typography>
</Box>
</Box>
</CardContent>
</Card>
</Box>
<Box
sx={{
display: 'grid',
gridTemplateColumns: { xs: '1fr', lg: '2fr 1fr' },
gap: 3,
mb: 3
}}
>
{/* User Registration Timeline */}
<Card>
<CardContent>
<Typography variant="h6" gutterBottom>
User Registration Timeline
</Typography>
<ResponsiveContainer width="100%" height={300}>
<AreaChart data={data.timeline.registrations}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="date" />
<YAxis />
<Tooltip />
<Area
type="monotone"
dataKey="registrations"
stroke="#8884d8"
fill="#8884d8"
fillOpacity={0.6}
/>
</AreaChart>
</ResponsiveContainer>
</CardContent>
</Card>
{/* Feature Usage Distribution */}
<Card>
<CardContent>
<Typography variant="h6" gutterBottom>
Feature Usage Distribution
</Typography>
<ResponsiveContainer width="100%" height={300}>
<PieChart>
<Pie
data={featureUsageData}
cx="50%"
cy="50%"
outerRadius={80}
fill="#8884d8"
dataKey="value"
label={({ name, percent }: any) => `${name} ${(percent * 100).toFixed(0)}%`}
>
{featureUsageData.map((entry, index) => (
<Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
))}
</Pie>
<Tooltip />
</PieChart>
</ResponsiveContainer>
</CardContent>
</Card>
</Box>
<Box
sx={{
display: 'grid',
gridTemplateColumns: { xs: '1fr', lg: '1fr 1fr' },
gap: 3
}}
>
{/* Most Active Users */}
<Card>
<CardContent>
<Typography variant="h6" gutterBottom>
Most Active Users
</Typography>
<TableContainer>
<Table size="small">
<TableHead>
<TableRow>
<TableCell>User</TableCell>
<TableCell>Role</TableCell>
<TableCell align="right">Total Activity</TableCell>
</TableRow>
</TableHead>
<TableBody>
{data.activity.mostActive.slice(0, 10).map((user) => (
<TableRow key={user.id}>
<TableCell>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
<Avatar sx={{ width: 24, height: 24, fontSize: 12 }}>
{(user.name || user.email)[0].toUpperCase()}
</Avatar>
<Box>
<Typography variant="body2">
{user.name || 'Unknown User'}
</Typography>
<Typography variant="caption" color="text.secondary">
{user.email}
</Typography>
</Box>
</Box>
</TableCell>
<TableCell>
<Chip
label={user.role}
size="small"
color={user.role === 'admin' ? 'error' : user.role === 'moderator' ? 'warning' : 'primary'}
variant="outlined"
/>
</TableCell>
<TableCell align="right">
<Typography variant="body2" fontWeight="medium">
{user.totalActivity}
</Typography>
<Typography variant="caption" color="text.secondary">
{user._count.chatConversations}c {user._count.prayerRequests}p {user._count.bookmarks}b
</Typography>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</CardContent>
</Card>
{/* User Demographics */}
<Card>
<CardContent>
<Typography variant="h6" gutterBottom>
User Demographics by Role
</Typography>
<TableContainer>
<Table size="small">
<TableHead>
<TableRow>
<TableCell>Role</TableCell>
<TableCell align="right">Count</TableCell>
<TableCell>First User</TableCell>
<TableCell>Latest User</TableCell>
</TableRow>
</TableHead>
<TableBody>
{data.demographics.map((demo) => (
<TableRow key={demo.role}>
<TableCell>
<Chip
label={demo.role}
size="small"
color={demo.role === 'admin' ? 'error' : demo.role === 'moderator' ? 'warning' : 'primary'}
variant="outlined"
/>
</TableCell>
<TableCell align="right">
<Typography variant="body2" fontWeight="medium">
{demo._count.role}
</Typography>
</TableCell>
<TableCell>
<Typography variant="caption">
{new Date(demo._min.createdAt).toLocaleDateString()}
</Typography>
</TableCell>
<TableCell>
<Typography variant="caption">
{new Date(demo._max.createdAt).toLocaleDateString()}
</Typography>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</CardContent>
</Card>
</Box>
</Box>
);
}

41
app/admin/chat/page.tsx Normal file
View File

@@ -0,0 +1,41 @@
'use client';
import { Typography, Box, Breadcrumbs, Link } from '@mui/material';
import { Home, Chat } from '@mui/icons-material';
import { ConversationMonitoring } from '@/components/admin/chat/conversation-monitoring';
export default function AdminChatPage() {
return (
<Box>
{/* Breadcrumbs */}
<Breadcrumbs aria-label="breadcrumb" sx={{ mb: 3 }}>
<Link
underline="hover"
sx={{ display: 'flex', alignItems: 'center' }}
color="inherit"
href="/admin"
>
<Home sx={{ mr: 0.5 }} fontSize="inherit" />
Admin
</Link>
<Typography color="text.primary" sx={{ display: 'flex', alignItems: 'center' }}>
<Chat sx={{ mr: 0.5 }} fontSize="inherit" />
Chat Monitoring
</Typography>
</Breadcrumbs>
{/* Page Header */}
<Box sx={{ mb: 4 }}>
<Typography variant="h4" component="h1" gutterBottom>
Chat Monitoring
</Typography>
<Typography variant="body1" color="text.secondary">
Monitor and manage chat conversations, detect inappropriate content, and ensure platform safety
</Typography>
</Box>
{/* Conversation Monitoring */}
<ConversationMonitoring />
</Box>
);
}

View File

@@ -0,0 +1,41 @@
'use client';
import { Typography, Box, Breadcrumbs, Link } from '@mui/material';
import { Home, Gavel } from '@mui/icons-material';
import { PrayerRequestDataGrid } from '@/components/admin/content/prayer-request-data-grid';
export default function AdminContentPage() {
return (
<Box>
{/* Breadcrumbs */}
<Breadcrumbs aria-label="breadcrumb" sx={{ mb: 3 }}>
<Link
underline="hover"
sx={{ display: 'flex', alignItems: 'center' }}
color="inherit"
href="/admin"
>
<Home sx={{ mr: 0.5 }} fontSize="inherit" />
Admin
</Link>
<Typography color="text.primary" sx={{ display: 'flex', alignItems: 'center' }}>
<Gavel sx={{ mr: 0.5 }} fontSize="inherit" />
Content Moderation
</Typography>
</Breadcrumbs>
{/* Page Header */}
<Box sx={{ mb: 4 }}>
<Typography variant="h4" component="h1" gutterBottom>
Content Moderation
</Typography>
<Typography variant="body1" color="text.secondary">
Review and moderate prayer requests and user-generated content
</Typography>
</Box>
{/* Prayer Request Data Grid */}
<PrayerRequestDataGrid />
</Box>
);
}

98
app/admin/layout.tsx Normal file
View File

@@ -0,0 +1,98 @@
'use client';
import { useEffect, useState } from 'react';
import { usePathname, useRouter } from 'next/navigation';
import { ThemeProvider } from '@mui/material/styles';
import { CssBaseline, Box, CircularProgress } from '@mui/material';
import '@fontsource/roboto/300.css';
import '@fontsource/roboto/400.css';
import '@fontsource/roboto/500.css';
import '@fontsource/roboto/700.css';
import { AdminLayout } from '@/components/admin/layout/admin-layout';
import { adminTheme } from '@/lib/admin-theme';
interface AdminUser {
id: string;
email: string;
name: string | null;
role: string;
}
export default function AdminLayoutPage({
children,
}: {
children: React.ReactNode;
}) {
const [admin, setAdmin] = useState<AdminUser | null>(null);
const [loading, setLoading] = useState(true);
const pathname = usePathname();
const router = useRouter();
useEffect(() => {
const checkAuth = async () => {
// Skip auth check if already on login page
if (pathname === '/admin/login') {
setLoading(false);
return;
}
try {
const response = await fetch('/api/admin/auth/me', {
credentials: 'include'
});
if (response.ok) {
const data = await response.json();
setAdmin(data.user);
} else {
// 401 is expected when not logged in - don't log as error
setAdmin(null);
router.push('/admin/login');
}
} catch (error) {
// Only log actual network errors, not auth failures
if (error instanceof TypeError) {
console.error('Network error during auth check:', error);
}
setAdmin(null);
router.push('/admin/login');
} finally {
setLoading(false);
}
};
checkAuth();
}, [pathname, router]);
if (loading) {
return (
<ThemeProvider theme={adminTheme}>
<CssBaseline />
<Box
sx={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
minHeight: '100vh',
}}
>
<CircularProgress />
</Box>
</ThemeProvider>
);
}
return (
<ThemeProvider theme={adminTheme}>
<CssBaseline />
{admin && pathname !== '/admin/login' ? (
<AdminLayout user={admin}>
{children}
</AdminLayout>
) : (
children
)}
</ThemeProvider>
);
}

20
app/admin/login/page.tsx Normal file
View File

@@ -0,0 +1,20 @@
'use client';
import { ThemeProvider } from '@mui/material/styles';
import { CssBaseline } from '@mui/material';
import '@fontsource/roboto/300.css';
import '@fontsource/roboto/400.css';
import '@fontsource/roboto/500.css';
import '@fontsource/roboto/700.css';
import { AdminLoginForm } from '@/components/admin/auth/admin-login-form';
import { adminTheme } from '@/lib/admin-theme';
export default function AdminLoginPage() {
return (
<ThemeProvider theme={adminTheme}>
<CssBaseline />
<AdminLoginForm />
</ThemeProvider>
);
}

46
app/admin/page.tsx Normal file
View File

@@ -0,0 +1,46 @@
import { Typography, Box, Breadcrumbs, Link } from '@mui/material';
import { Home } from '@mui/icons-material';
import { OverviewCards } from '@/components/admin/dashboard/overview-cards';
export default function AdminDashboard() {
return (
<Box>
{/* Breadcrumbs */}
<Breadcrumbs aria-label="breadcrumb" sx={{ mb: 3 }}>
<Link
underline="hover"
sx={{ display: 'flex', alignItems: 'center' }}
color="inherit"
href="/admin"
>
<Home sx={{ mr: 0.5 }} fontSize="inherit" />
Admin
</Link>
<Typography color="text.primary">Dashboard</Typography>
</Breadcrumbs>
{/* Page Header */}
<Box sx={{ mb: 4 }}>
<Typography variant="h4" component="h1" gutterBottom>
Dashboard Overview
</Typography>
<Typography variant="body1" color="text.secondary">
Monitor key metrics and system performance for Biblical Guide
</Typography>
</Box>
{/* Overview Cards */}
<OverviewCards />
{/* Recent Activity Section - Placeholder for future implementation */}
<Box sx={{ mt: 4 }}>
<Typography variant="h6" gutterBottom>
Recent Activity
</Typography>
<Typography variant="body2" color="text.secondary">
Activity feed will be implemented in Phase 2
</Typography>
</Box>
</Box>
);
}

View File

@@ -0,0 +1,41 @@
'use client';
import { Typography, Box, Breadcrumbs, Link } from '@mui/material';
import { Home, Settings } from '@mui/icons-material';
import { SystemDashboard } from '@/components/admin/system/system-dashboard';
export default function AdminSettingsPage() {
return (
<Box>
{/* Breadcrumbs */}
<Breadcrumbs aria-label="breadcrumb" sx={{ mb: 3 }}>
<Link
underline="hover"
sx={{ display: 'flex', alignItems: 'center' }}
color="inherit"
href="/admin"
>
<Home sx={{ mr: 0.5 }} fontSize="inherit" />
Admin
</Link>
<Typography color="text.primary" sx={{ display: 'flex', alignItems: 'center' }}>
<Settings sx={{ mr: 0.5 }} fontSize="inherit" />
System Administration
</Typography>
</Breadcrumbs>
{/* Page Header */}
<Box sx={{ mb: 4 }}>
<Typography variant="h4" component="h1" gutterBottom>
System Administration
</Typography>
<Typography variant="body1" color="text.secondary">
Monitor system health, manage backups, and configure platform settings
</Typography>
</Box>
{/* System Dashboard */}
<SystemDashboard />
</Box>
);
}

41
app/admin/users/page.tsx Normal file
View File

@@ -0,0 +1,41 @@
'use client';
import { Typography, Box, Breadcrumbs, Link } from '@mui/material';
import { Home, People } from '@mui/icons-material';
import { UserDataGrid } from '@/components/admin/users/user-data-grid';
export default function AdminUsersPage() {
return (
<Box>
{/* Breadcrumbs */}
<Breadcrumbs aria-label="breadcrumb" sx={{ mb: 3 }}>
<Link
underline="hover"
sx={{ display: 'flex', alignItems: 'center' }}
color="inherit"
href="/admin"
>
<Home sx={{ mr: 0.5 }} fontSize="inherit" />
Admin
</Link>
<Typography color="text.primary" sx={{ display: 'flex', alignItems: 'center' }}>
<People sx={{ mr: 0.5 }} fontSize="inherit" />
Users
</Typography>
</Breadcrumbs>
{/* Page Header */}
<Box sx={{ mb: 4 }}>
<Typography variant="h4" component="h1" gutterBottom>
User Management
</Typography>
<Typography variant="body1" color="text.secondary">
Manage user accounts, roles, and permissions
</Typography>
</Box>
{/* User Data Grid */}
<UserDataGrid />
</Box>
);
}