diff --git a/app/[locale]/bible/reader.tsx b/app/[locale]/bible/reader.tsx index 6edc054..f54a1ce 100644 --- a/app/[locale]/bible/reader.tsx +++ b/app/[locale]/bible/reader.tsx @@ -214,9 +214,9 @@ export default function BibleReaderNew() { const verseParam = searchParams.get('verse') if (bookParam) { - const book = books.find(b => b.id === bookParam) + const book = books.find(b => b.id === bookParam) || books.find(b => b.bookKey === bookParam) if (book) { - setSelectedBook(bookParam) + setSelectedBook(book.id) if (chapterParam) { const chapter = parseInt(chapterParam) if (chapter > 0) { diff --git a/app/[locale]/search/page.tsx b/app/[locale]/search/page.tsx index a7a0b09..cee22d4 100644 --- a/app/[locale]/search/page.tsx +++ b/app/[locale]/search/page.tsx @@ -17,6 +17,7 @@ import { Chip, List, ListItem, + ListItemButton, ListItemText, IconButton, Tooltip, @@ -366,7 +367,8 @@ export default function SearchPage() { }, []) const handleNavigateToVerse = useCallback((result: SearchResult) => { - router.push(`/${locale}/bible?book=${result.bookId}&chapter=${result.chapter}&verse=${result.verse}`) + const bookIdentifier = result.bookId || result.bookKey || result.book + router.push(`/${locale}/bible?book=${bookIdentifier}&chapter=${result.chapter}&verse=${result.verse}`) }, [router, locale]) const clearFilters = useCallback(() => { @@ -493,14 +495,13 @@ export default function SearchPage() { > {suggestions.map((suggestion, index) => ( - { - setSearchQuery(suggestion.text) - handleSearch(suggestion.text) - }} - > + + { + setSearchQuery(suggestion.text) + handleSearch(suggestion.text) + }} + > @@ -520,6 +521,7 @@ export default function SearchPage() { } /> + ))} diff --git a/app/api/search/verses/route.ts b/app/api/search/verses/route.ts index 21b497f..f8a8af8 100644 --- a/app/api/search/verses/route.ts +++ b/app/api/search/verses/route.ts @@ -171,7 +171,10 @@ export async function GET(request: NextRequest) { return { id: verse.id.toString(), + verseId: verse.id.toString(), book: verse.chapter.book.name, + bookId: verse.chapter.book.id, + bookKey: verse.chapter.book.bookKey, chapter: verse.chapter.chapterNum, verse: verse.verseNum, text: verse.text, diff --git a/temp/admin-dashboard-mvp.md b/temp/admin-dashboard-mvp.md new file mode 100644 index 0000000..c99c468 --- /dev/null +++ b/temp/admin-dashboard-mvp.md @@ -0,0 +1,347 @@ +# BiblicalGuide Admin Dashboard - MVP Features + +## 1. Dashboard Overview (Home) + +### Key Metrics Cards +- **Total Users** (number + % change from last week) +- **Daily Active Users** (DAU - real-time count) +- **AI Conversations Today** (count + cost estimate) +- **Active Now** (users currently online) + +### Quick Stats +- **New signups** (last 24 hours) +- **Total bookmarks created** (all-time) +- **Prayer requests** (last 24 hours) +- **Server status** (API health, response time) + +### Activity Feed (Live) +- New user registrations +- Prayer wall posts +- High-engagement AI conversations +- Error alerts +- System notifications + +## 2. User Management + +### User List View +``` +Search: [_________] Filter: [All Users ▼] + +| Email | Name | Joined | Last Active | AI Chats | Status | Actions | +|-------|------|--------|-------------|----------|--------|---------| +| user@example.com | John D. | 2024-01-15 | 2 hrs ago | 45 | Active | [View] [Ban] | +``` + +### User Actions +- **View Profile** (see detailed user activity) +- **Send Email** (direct communication) +- **Reset Password** (force password reset) +- **Suspend/Ban** (temporary or permanent) +- **Delete Account** (GDPR compliance) + +### User Details Modal +- Registration date and method +- Total AI conversations +- Bookmarks count +- Last 10 chat topics +- Prayer requests posted +- Account status history + +## 3. AI Chat Monitoring + +### Conversations Overview +- **Total conversations** (today/week/month) +- **Average response time** (target: <5 seconds) +- **Error rate** (failed responses %) +- **Cost tracking** (OpenAI API spend) + +### Live Chat Monitor +``` +Recent Conversations (Auto-refresh every 30s) + +User: "What does the Bible say about forgiveness?" +AI: "The Bible speaks extensively about forgiveness..." +[View Full] [Flag] [Quality: ⭐⭐⭐⭐⭐] + +User: "Help me understand Romans 8" +AI: "Romans 8 is one of the most powerful chapters..." +[View Full] [Flag] [Quality: ⭐⭐⭐⭐⭐] +``` + +### Quality Control +- **Flag inappropriate requests** +- **Review AI responses** for theological accuracy +- **Common questions** (FAQ generation) +- **Failed responses** log +- **Response ratings** (if users rate them) + +### Cost Management +- Daily API usage ($X.XX) +- Projection for current month +- Per-user average cost +- High-usage user alerts + +## 4. Content Moderation + +### Prayer Wall Moderation +``` +Pending Review (3) + +"Please pray for my family..." +[Approve] [Edit] [Reject] [Ban User] + +"Spam content here..." +[Approve] [Edit] [Reject] [Ban User] +``` + +### Moderation Queue +- **Prayer requests** (pending approval) +- **Reported content** (user flags) +- **AI conversation flags** (inappropriate) +- **Bulk actions** (approve/reject all) + +### Auto-Moderation Settings +- Profanity filter (on/off) +- Spam detection threshold +- Auto-approve trusted users +- Keyword blacklist management + +## 5. Analytics Dashboard + +### User Analytics +- **Growth Chart** (daily new users - line graph) +- **Retention Funnel** + - Day 1: 100% + - Day 7: 45% + - Day 30: 30% +- **User Segments** + - Power users (>10 chats/week) + - Regular (3-10 chats/week) + - Casual (<3 chats/week) + - Dormant (no activity 7+ days) + +### Engagement Metrics +- **Most Read Bible Books** (top 10 bar chart) +- **Popular Chat Topics** (word cloud) +- **Peak Usage Hours** (heatmap) +- **Feature Usage** (bookmarks vs chat vs prayer wall) + +### Simple Conversion Tracking +- Sign-up to first chat +- First chat to bookmark +- Single to returning user +- Free to premium (when implemented) + +## 6. System Administration + +### Quick Actions +- **Broadcast Message** (banner to all users) +- **Maintenance Mode** (on/off toggle) +- **Clear Cache** (Redis flush) +- **Backup Database** (manual trigger) + +### API Management +- **OpenAI API Status** + - Current balance + - Rate limit status + - Error rate + - Switch API keys +- **Bible API Status** + - Response time + - Cache hit rate + - Error logs + +### Error Monitoring +``` +Recent Errors (Last 24 hours) + +Type | Count | Last Occurred | Status +-----|-------|---------------|-------- +API Timeout | 12 | 10 min ago | [View] [Resolve] +Login Failed | 45 | 2 min ago | [View] [Ignore] +DB Connection | 0 | - | OK +``` + +### Server Health +- CPU usage (%) +- Memory usage (%) +- Database connections +- API response times +- Disk space remaining + +## 7. Communications + +### Email Templates (Basic) +- Welcome email +- Password reset +- Daily verse (if enabled) +- Account suspended +- System announcements + +### Bulk Email +- **Send to**: All users / Active last 7 days / Segment +- **Subject**: [_________] +- **Message**: [Rich text editor] +- **Schedule**: Now / Later +- [Send Test] [Schedule] [Send Now] + +### In-App Notifications +- Create announcement banner +- Target specific user segments +- Set expiration time +- Track dismissal rate + +## 8. Settings & Configuration + +### App Settings +- **Site name**: BiblicalGuide +- **Support email**: support@biblical-guide.com +- **Daily verse**: Enabled/Disabled +- **Prayer wall**: Public/Moderated/Disabled +- **AI model**: GPT-4/GPT-3.5 +- **Rate limits**: X chats per user per day + +### Feature Toggles +- [ ] AI Chat enabled +- [ ] Prayer Wall enabled +- [ ] User registration open +- [ ] Daily verse emails +- [ ] Social sharing +- [ ] Maintenance mode + +### Admin Users +``` +Admin Users (3) + +Email | Role | Last Login | Actions +------|------|------------|-------- +admin@site.com | Super Admin | 1 hr ago | [Edit] [Remove] +support@site.com | Moderator | 2 days ago | [Edit] [Remove] +[+ Add Admin] +``` + +## 9. Simple Reporting + +### Daily Report Email +- New users count +- Total AI conversations +- API costs +- Error summary +- Top chat topics +- System health status + +### Export Data +- **User list** (CSV) +- **Chat logs** (last 30 days) +- **Prayer requests** (CSV) +- **Analytics summary** (PDF) + +## 10. Security Section + +### Security Log +``` +Recent Security Events + +Time | User | Event | IP Address | Action +-----|------|-------|------------|-------- +10:23 AM | john@... | Failed login (3x) | 192.168.1.1 | [Block IP] +09:45 AM | Admin login | Success | 10.0.0.1 | - +``` + +### Security Actions +- View failed login attempts +- IP blocking/allowlisting +- Force logout all users +- Require password reset (bulk) +- 2FA enforcement settings + +## Implementation Priority + +### Phase 1 - Critical (Week 1) +1. **Login/Authentication** for admins +2. **Dashboard overview** (basic metrics) +3. **User list** with basic actions +4. **AI conversation monitoring** (view only) + +### Phase 2 - Essential (Week 2) +1. **Prayer wall moderation** +2. **User management** (suspend/ban) +3. **Basic analytics** (users, engagement) +4. **Error monitoring** + +### Phase 3 - Important (Week 3) +1. **Email communications** +2. **System settings** +3. **Export functionality** +4. **Cost tracking** + +## Tech Stack for Admin + +### Frontend +- **React** with **Recharts** for graphs +- **Tailwind CSS** with **shadcn/ui** components +- **React Table** for data tables +- **React Query** for data fetching + +### Backend Additions +- **Admin authentication** (separate from users) +- **Role-based access** (admin, moderator) +- **Audit logging** (track all admin actions) +- **Scheduled jobs** (daily reports) + +### Database Schema Additions +```sql +-- Admin users table +admin_users ( + id, email, password_hash, role, + last_login, created_at +) + +-- Audit log table +audit_logs ( + id, admin_id, action, target_user_id, + details, ip_address, timestamp +) + +-- System settings table +settings ( + key, value, updated_at, updated_by +) +``` + +## Access Control Levels + +### Super Admin +- Full access to everything +- Can manage other admins +- System configuration +- Database operations + +### Moderator +- Content moderation +- User management (not deletion) +- View analytics +- Cannot change system settings + +### Support +- View user details +- Reset passwords +- View chat logs +- Cannot ban/delete users + +## Security Considerations + +1. **Separate admin authentication** (not regular user accounts) +2. **IP allowlisting** for admin access +3. **Audit log** all admin actions +4. **Session timeout** after 30 min inactive +5. **2FA required** for all admin accounts +6. **Read-only mode** for most views (explicit edit mode) + +## Success Metrics for Admin + +- **Response time** to user issues < 1 hour +- **Moderation queue** cleared daily +- **System uptime** > 99.9% +- **API costs** within budget +- **User complaints** resolved < 24 hours \ No newline at end of file