Compare commits
No commits in common. "a61008f71aae4fec8a4e8c4b4e8f1798565b3b6e" and "44c7fce2b743720469092b7f080fb2da26ad89a5" have entirely different histories.
a61008f71a
...
44c7fce2b7
11 changed files with 236 additions and 488 deletions
|
|
@ -7,8 +7,7 @@
|
||||||
"Bash(npx prisma generate:*)",
|
"Bash(npx prisma generate:*)",
|
||||||
"Bash(npm run build:*)",
|
"Bash(npm run build:*)",
|
||||||
"Bash(docker-compose up:*)",
|
"Bash(docker-compose up:*)",
|
||||||
"Bash(npx prisma migrate:*)",
|
"Bash(npx prisma migrate:*)"
|
||||||
"Bash(tree:*)"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,55 @@
|
||||||
import { adminApiClient } from './client'
|
import { adminApiClient } from './client'
|
||||||
|
|
||||||
// Dashboard stats from backend /api/admin/analytics/dashboard
|
|
||||||
export interface DashboardStats {
|
export interface DashboardStats {
|
||||||
users: number
|
users: number
|
||||||
activeUsers: number
|
cards: number
|
||||||
rooms: number
|
packs: number
|
||||||
activeRooms: number
|
enabledPacks: number
|
||||||
questionPacks: number
|
payments: number
|
||||||
publicPacks: number
|
}
|
||||||
gamesPlayed: number
|
|
||||||
gamesToday: number
|
export interface RecentUser {
|
||||||
|
id: number
|
||||||
|
name?: string
|
||||||
|
email?: string
|
||||||
|
createdAt?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TopPack {
|
||||||
|
id: number
|
||||||
|
title: string
|
||||||
|
cards: number
|
||||||
|
enabled: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChartDataPoint {
|
||||||
|
date: string
|
||||||
|
registrations?: number
|
||||||
|
revenue?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DashboardData {
|
||||||
|
stats: DashboardStats
|
||||||
|
recentUsers: RecentUser[]
|
||||||
|
topPacks: TopPack[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const analyticsApi = {
|
export const analyticsApi = {
|
||||||
// Get dashboard analytics
|
// Get dashboard analytics
|
||||||
getDashboard: async (): Promise<DashboardStats> => {
|
getDashboard: async (): Promise<DashboardData> => {
|
||||||
const response = await adminApiClient.get('/api/admin/analytics/dashboard')
|
const response = await adminApiClient.get('/api/v2/admin/analytics/dashboard')
|
||||||
|
return response.data
|
||||||
|
},
|
||||||
|
|
||||||
|
// Get user registration chart data
|
||||||
|
getUsersChart: async (): Promise<{ data: ChartDataPoint[]; period: string }> => {
|
||||||
|
const response = await adminApiClient.get('/api/v2/admin/analytics/users/chart')
|
||||||
|
return response.data
|
||||||
|
},
|
||||||
|
|
||||||
|
// Get revenue chart data
|
||||||
|
getRevenueChart: async (): Promise<{ data: ChartDataPoint[]; period: string; currency: string }> => {
|
||||||
|
const response = await adminApiClient.get('/api/v2/admin/analytics/revenue/chart')
|
||||||
return response.data
|
return response.data
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ export const packsApi = {
|
||||||
showDisabled?: boolean
|
showDisabled?: boolean
|
||||||
}): Promise<PaginatedResponse<CardPackPreviewDto>> => {
|
}): Promise<PaginatedResponse<CardPackPreviewDto>> => {
|
||||||
try {
|
try {
|
||||||
const response = await adminApiClient.get('/api/admin/packs', {
|
const response = await adminApiClient.get('/api/v2/admin/packs', {
|
||||||
params: {
|
params: {
|
||||||
page: params?.page || 1,
|
page: params?.page || 1,
|
||||||
limit: params?.limit || 20,
|
limit: params?.limit || 20,
|
||||||
|
|
@ -82,7 +82,7 @@ export const packsApi = {
|
||||||
// Get pack details by ID for editing
|
// Get pack details by ID for editing
|
||||||
getPack: async (packId: string): Promise<EditCardPackDto> => {
|
getPack: async (packId: string): Promise<EditCardPackDto> => {
|
||||||
try {
|
try {
|
||||||
const response = await adminApiClient.get(`/api/admin/packs/${packId}`)
|
const response = await adminApiClient.get(`/api/v2/admin/packs/${packId}`)
|
||||||
return response.data
|
return response.data
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const axiosError = error as AxiosError<{ error?: string; message?: string }>
|
const axiosError = error as AxiosError<{ error?: string; message?: string }>
|
||||||
|
|
@ -110,7 +110,7 @@ export const packsApi = {
|
||||||
// Create or update pack
|
// Create or update pack
|
||||||
upsertPack: async (pack: EditCardPackDto): Promise<{ success: boolean; pack: EditCardPackDto }> => {
|
upsertPack: async (pack: EditCardPackDto): Promise<{ success: boolean; pack: EditCardPackDto }> => {
|
||||||
try {
|
try {
|
||||||
const response = await adminApiClient.post('/api/admin/packs', pack)
|
const response = await adminApiClient.post('/api/v2/admin/packs', pack)
|
||||||
return response.data
|
return response.data
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const axiosError = error as AxiosError<{ error?: string; message?: string; field?: string; details?: string }>
|
const axiosError = error as AxiosError<{ error?: string; message?: string; field?: string; details?: string }>
|
||||||
|
|
@ -146,7 +146,7 @@ export const packsApi = {
|
||||||
// Delete pack
|
// Delete pack
|
||||||
deletePack: async (packId: string): Promise<{ success: boolean; message: string }> => {
|
deletePack: async (packId: string): Promise<{ success: boolean; message: string }> => {
|
||||||
try {
|
try {
|
||||||
const response = await adminApiClient.delete(`/api/admin/packs/${packId}`)
|
const response = await adminApiClient.delete(`/api/v2/admin/packs/${packId}`)
|
||||||
return response.data
|
return response.data
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const axiosError = error as AxiosError<{ error?: string; message?: string }>
|
const axiosError = error as AxiosError<{ error?: string; message?: string }>
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,44 @@
|
||||||
import { adminApiClient } from './client'
|
import { adminApiClient } from './client'
|
||||||
import type { UserDto, PaginatedResponse } from '@/types/models'
|
import type { UserDto, PaginatedResponse, PaymentDto } from '@/types/models'
|
||||||
|
|
||||||
export const usersApi = {
|
export const usersApi = {
|
||||||
// Get all users with pagination
|
// Get all users with pagination
|
||||||
getUsers: async (params?: {
|
getUsers: async (params?: {
|
||||||
page?: number
|
page?: number
|
||||||
limit?: number
|
limit?: number
|
||||||
|
ids?: string[]
|
||||||
}): Promise<PaginatedResponse<UserDto>> => {
|
}): Promise<PaginatedResponse<UserDto>> => {
|
||||||
const response = await adminApiClient.get('/api/admin/users', {
|
const response = await adminApiClient.get('/api/v2/admin/users', {
|
||||||
params: {
|
params: {
|
||||||
page: params?.page || 1,
|
page: params?.page || 1,
|
||||||
limit: params?.limit || 20,
|
limit: params?.limit || 20,
|
||||||
|
ids: params?.ids?.join(','),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return response.data
|
return response.data
|
||||||
},
|
},
|
||||||
|
|
||||||
// Get single user by ID
|
// Get user IDs list
|
||||||
getUser: async (userId: string): Promise<UserDto> => {
|
getUserIds: async (): Promise<string[]> => {
|
||||||
const response = await adminApiClient.get(`/api/admin/users/${userId}`)
|
const response = await adminApiClient.get('/api/v2/admin/users/ids')
|
||||||
return response.data
|
return response.data.ids
|
||||||
},
|
},
|
||||||
|
|
||||||
// Update user
|
// Get user purchases
|
||||||
updateUser: async (userId: string, user: Partial<UserDto>): Promise<UserDto> => {
|
getUserPurchases: async (userId: string): Promise<PaymentDto[]> => {
|
||||||
const response = await adminApiClient.patch(`/api/admin/users/${userId}`, user)
|
const response = await adminApiClient.get(`/api/v2/admin/users/${userId}/purchases`)
|
||||||
|
return response.data.payments
|
||||||
|
},
|
||||||
|
|
||||||
|
// Create or update user
|
||||||
|
upsertUser: async (user: UserDto): Promise<{ result: boolean }> => {
|
||||||
|
const response = await adminApiClient.post('/api/v2/admin/users', user)
|
||||||
return response.data
|
return response.data
|
||||||
},
|
},
|
||||||
|
|
||||||
// Delete user
|
// Delete user
|
||||||
deleteUser: async (userId: string): Promise<{ message: string }> => {
|
deleteUser: async (userId: string): Promise<{ result: boolean }> => {
|
||||||
const response = await adminApiClient.delete(`/api/admin/users/${userId}`)
|
const response = await adminApiClient.delete(`/api/v2/admin/users/${userId}`)
|
||||||
return response.data
|
return response.data
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import { useQuery } from '@tanstack/react-query'
|
import { useQuery } from '@tanstack/react-query'
|
||||||
import { Users, Package, TrendingUp, Activity } from 'lucide-react'
|
import { Users, FileText, Package, DollarSign, TrendingUp, Clock } from 'lucide-react'
|
||||||
|
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, BarChart, Bar } from 'recharts'
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||||
import { analyticsApi, type DashboardStats } from '@/api/analytics'
|
import { Badge } from '@/components/ui/badge'
|
||||||
|
import { analyticsApi, type DashboardData, type ChartDataPoint } from '@/api/analytics'
|
||||||
import { useAuthStore } from '@/stores/authStore'
|
import { useAuthStore } from '@/stores/authStore'
|
||||||
|
|
||||||
export default function DashboardPage() {
|
export default function DashboardPage() {
|
||||||
|
|
@ -10,12 +12,24 @@ export default function DashboardPage() {
|
||||||
// Only make requests if authenticated and token exists
|
// Only make requests if authenticated and token exists
|
||||||
const isReady = isAuthenticated && !!token && !!localStorage.getItem('admin_token')
|
const isReady = isAuthenticated && !!token && !!localStorage.getItem('admin_token')
|
||||||
|
|
||||||
const { data: dashboardData, isLoading: dashboardLoading } = useQuery<DashboardStats>({
|
const { data: dashboardData, isLoading: dashboardLoading } = useQuery<DashboardData>({
|
||||||
queryKey: ['dashboard'],
|
queryKey: ['dashboard'],
|
||||||
queryFn: analyticsApi.getDashboard,
|
queryFn: analyticsApi.getDashboard,
|
||||||
enabled: isReady,
|
enabled: isReady,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const { data: usersChartData } = useQuery<{ data: ChartDataPoint[] }>({
|
||||||
|
queryKey: ['users-chart'],
|
||||||
|
queryFn: analyticsApi.getUsersChart,
|
||||||
|
enabled: isReady,
|
||||||
|
})
|
||||||
|
|
||||||
|
const { data: revenueChartData } = useQuery<{ data: ChartDataPoint[] }>({
|
||||||
|
queryKey: ['revenue-chart'],
|
||||||
|
queryFn: analyticsApi.getRevenueChart,
|
||||||
|
enabled: isReady,
|
||||||
|
})
|
||||||
|
|
||||||
if (dashboardLoading) {
|
if (dashboardLoading) {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
|
@ -58,7 +72,7 @@ export default function DashboardPage() {
|
||||||
<Users className="h-4 w-4 text-muted-foreground" />
|
<Users className="h-4 w-4 text-muted-foreground" />
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="text-2xl font-bold">{dashboardData?.users || 0}</div>
|
<div className="text-2xl font-bold">{dashboardData?.stats.users || 0}</div>
|
||||||
<p className="text-xs text-muted-foreground">
|
<p className="text-xs text-muted-foreground">
|
||||||
Registered users
|
Registered users
|
||||||
</p>
|
</p>
|
||||||
|
|
@ -67,96 +81,165 @@ export default function DashboardPage() {
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
<CardTitle className="text-sm font-medium">Active Users</CardTitle>
|
<CardTitle className="text-sm font-medium">Total Cards</CardTitle>
|
||||||
<Activity className="h-4 w-4 text-muted-foreground" />
|
<FileText className="h-4 w-4 text-muted-foreground" />
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="text-2xl font-bold">{dashboardData?.activeUsers || 0}</div>
|
<div className="text-2xl font-bold">{dashboardData?.stats.cards || 0}</div>
|
||||||
<p className="text-xs text-muted-foreground">
|
<p className="text-xs text-muted-foreground">
|
||||||
Active in last 7 days
|
Game cards created
|
||||||
</p>
|
</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
<CardTitle className="text-sm font-medium">Question Packs</CardTitle>
|
<CardTitle className="text-sm font-medium">Active Packs</CardTitle>
|
||||||
<Package className="h-4 w-4 text-muted-foreground" />
|
<Package className="h-4 w-4 text-muted-foreground" />
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="text-2xl font-bold">{dashboardData?.publicPacks || 0}</div>
|
<div className="text-2xl font-bold">{dashboardData?.stats.enabledPacks || 0}</div>
|
||||||
<p className="text-xs text-muted-foreground">
|
<p className="text-xs text-muted-foreground">
|
||||||
of {dashboardData?.questionPacks || 0} total packs
|
of {dashboardData?.stats.packs || 0} total packs
|
||||||
</p>
|
</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
<CardTitle className="text-sm font-medium">Games Today</CardTitle>
|
<CardTitle className="text-sm font-medium">Total Payments</CardTitle>
|
||||||
<TrendingUp className="h-4 w-4 text-muted-foreground" />
|
<DollarSign className="h-4 w-4 text-muted-foreground" />
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="text-2xl font-bold">{dashboardData?.gamesToday || 0}</div>
|
<div className="text-2xl font-bold">{dashboardData?.stats.payments || 0}</div>
|
||||||
<p className="text-xs text-muted-foreground">
|
<p className="text-xs text-muted-foreground">
|
||||||
of {dashboardData?.gamesPlayed || 0} total games
|
Successful transactions
|
||||||
</p>
|
</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Rooms Stats */}
|
{/* Charts */}
|
||||||
<div className="grid gap-4 md:grid-cols-2">
|
<div className="grid gap-4 md:grid-cols-2">
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Room Statistics</CardTitle>
|
<CardTitle>User Registrations</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
Current room status overview
|
Daily user registrations for the last 30 days
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
{usersChartData?.data && (
|
||||||
|
<ResponsiveContainer width="100%" height={300}>
|
||||||
|
<LineChart data={usersChartData.data}>
|
||||||
|
<CartesianGrid strokeDasharray="3 3" />
|
||||||
|
<XAxis
|
||||||
|
dataKey="date"
|
||||||
|
tickFormatter={(value) => new Date(value).toLocaleDateString('en-US', { month: 'short', day: 'numeric' })}
|
||||||
|
/>
|
||||||
|
<YAxis />
|
||||||
|
<Tooltip
|
||||||
|
labelFormatter={(value) => new Date(value).toLocaleDateString()}
|
||||||
|
formatter={(value: number | undefined) => [value ?? 0, 'Registrations']}
|
||||||
|
/>
|
||||||
|
<Line
|
||||||
|
type="monotone"
|
||||||
|
dataKey="registrations"
|
||||||
|
stroke="#8884d8"
|
||||||
|
strokeWidth={2}
|
||||||
|
dot={{ fill: '#8884d8' }}
|
||||||
|
/>
|
||||||
|
</LineChart>
|
||||||
|
</ResponsiveContainer>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Revenue Trend</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Daily revenue for the last 30 days
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
{revenueChartData?.data && (
|
||||||
|
<ResponsiveContainer width="100%" height={300}>
|
||||||
|
<BarChart data={revenueChartData.data}>
|
||||||
|
<CartesianGrid strokeDasharray="3 3" />
|
||||||
|
<XAxis
|
||||||
|
dataKey="date"
|
||||||
|
tickFormatter={(value) => new Date(value).toLocaleDateString('en-US', { month: 'short', day: 'numeric' })}
|
||||||
|
/>
|
||||||
|
<YAxis />
|
||||||
|
<Tooltip
|
||||||
|
labelFormatter={(value) => new Date(value).toLocaleDateString()}
|
||||||
|
formatter={(value: number | undefined) => [`$${value ?? 0}`, 'Revenue']}
|
||||||
|
/>
|
||||||
|
<Bar dataKey="revenue" fill="#82ca9d" />
|
||||||
|
</BarChart>
|
||||||
|
</ResponsiveContainer>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Recent Users and Top Packs */}
|
||||||
|
<div className="grid gap-4 md:grid-cols-2">
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="flex items-center gap-2">
|
||||||
|
<Clock className="h-5 w-5" />
|
||||||
|
Recent Users
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Latest user registrations
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="flex items-center justify-between">
|
{dashboardData?.recentUsers.slice(0, 5).map((user) => (
|
||||||
<div>
|
<div key={user.id} className="flex items-center justify-between">
|
||||||
<p className="font-medium">Total Rooms</p>
|
<div>
|
||||||
<p className="text-sm text-muted-foreground">All time</p>
|
<p className="font-medium">{user.name || 'No name'}</p>
|
||||||
|
<p className="text-sm text-muted-foreground">{user.email || 'No email'}</p>
|
||||||
|
</div>
|
||||||
|
<div className="text-sm text-muted-foreground">
|
||||||
|
{user.createdAt ? new Date(user.createdAt).toLocaleDateString() : 'N/A'}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-2xl font-bold">{dashboardData?.rooms || 0}</div>
|
)) || (
|
||||||
</div>
|
<p className="text-muted-foreground">No recent users</p>
|
||||||
<div className="flex items-center justify-between">
|
)}
|
||||||
<div>
|
|
||||||
<p className="font-medium">Active Rooms</p>
|
|
||||||
<p className="text-sm text-muted-foreground">Currently playing or waiting</p>
|
|
||||||
</div>
|
|
||||||
<div className="text-2xl font-bold text-green-600">{dashboardData?.activeRooms || 0}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Game Statistics</CardTitle>
|
<CardTitle className="flex items-center gap-2">
|
||||||
|
<TrendingUp className="h-5 w-5" />
|
||||||
|
Popular Packs
|
||||||
|
</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
Overall game activity
|
Most popular card packs
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="flex items-center justify-between">
|
{dashboardData?.topPacks.map((pack) => (
|
||||||
<div>
|
<div key={pack.id} className="flex items-center justify-between">
|
||||||
<p className="font-medium">Total Games</p>
|
<div>
|
||||||
<p className="text-sm text-muted-foreground">All time completed games</p>
|
<p className="font-medium">{pack.title}</p>
|
||||||
|
<p className="text-sm text-muted-foreground">{pack.cards} cards</p>
|
||||||
|
</div>
|
||||||
|
<Badge variant={pack.enabled ? "default" : "secondary"}>
|
||||||
|
{pack.enabled ? 'Active' : 'Disabled'}
|
||||||
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-2xl font-bold">{dashboardData?.gamesPlayed || 0}</div>
|
)) || (
|
||||||
</div>
|
<p className="text-muted-foreground">No packs available</p>
|
||||||
<div className="flex items-center justify-between">
|
)}
|
||||||
<div>
|
|
||||||
<p className="font-medium">Today's Games</p>
|
|
||||||
<p className="text-sm text-muted-foreground">Completed today</p>
|
|
||||||
</div>
|
|
||||||
<div className="text-2xl font-bold text-blue-600">{dashboardData?.gamesToday || 0}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
|
||||||
|
|
@ -29,20 +29,28 @@ export interface CardPackPreviewDto {
|
||||||
order?: number
|
order?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
// User model matching backend Prisma schema
|
|
||||||
export interface UserDto {
|
export interface UserDto {
|
||||||
id: string
|
id?: number
|
||||||
email?: string
|
|
||||||
name?: string
|
name?: string
|
||||||
role: 'USER' | 'ADMIN'
|
email?: string
|
||||||
telegramId?: string
|
admin: boolean
|
||||||
createdAt: string
|
packs: string[]
|
||||||
gamesPlayed: number
|
purchases: string[]
|
||||||
gamesWon: number
|
subscription?: boolean
|
||||||
totalPoints: number
|
subscriptionFeatures: string[]
|
||||||
|
userDataDto?: unknown
|
||||||
|
userSettingsDto?: unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: PaymentDto removed - no payment system exists in the backend
|
export interface PaymentDto {
|
||||||
|
id: string
|
||||||
|
userId: string
|
||||||
|
amount: number
|
||||||
|
currency: string
|
||||||
|
status: string
|
||||||
|
createdAt: string
|
||||||
|
updatedAt: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface SubscriptionPlanAdminDto {
|
export interface SubscriptionPlanAdminDto {
|
||||||
id: string
|
id: string
|
||||||
|
|
|
||||||
|
|
@ -362,46 +362,22 @@ export class AdminAuthService implements OnModuleInit {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
// Check if email is already taken by another user
|
// Create admin user for password login
|
||||||
const existingUserWithEmail = await this.prisma.user.findUnique({
|
user = await this.prisma.user.create({
|
||||||
where: { email: adminUsername },
|
data: {
|
||||||
|
telegramId: passwordAdminTelegramId,
|
||||||
|
role: 'ADMIN',
|
||||||
|
name: 'Admin',
|
||||||
|
email: adminUsername,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
email: true,
|
||||||
|
name: true,
|
||||||
|
role: true,
|
||||||
|
telegramId: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (existingUserWithEmail) {
|
|
||||||
// If email exists but with different telegramId, update it
|
|
||||||
user = await this.prisma.user.update({
|
|
||||||
where: { id: existingUserWithEmail.id },
|
|
||||||
data: {
|
|
||||||
telegramId: passwordAdminTelegramId,
|
|
||||||
role: 'ADMIN',
|
|
||||||
name: 'Admin',
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
email: true,
|
|
||||||
name: true,
|
|
||||||
role: true,
|
|
||||||
telegramId: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Create new admin user for password login
|
|
||||||
user = await this.prisma.user.create({
|
|
||||||
data: {
|
|
||||||
telegramId: passwordAdminTelegramId,
|
|
||||||
role: 'ADMIN',
|
|
||||||
name: 'Admin',
|
|
||||||
email: adminUsername,
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
email: true,
|
|
||||||
name: true,
|
|
||||||
role: true,
|
|
||||||
telegramId: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if (user.role !== 'ADMIN') {
|
} else if (user.role !== 'ADMIN') {
|
||||||
// Upgrade to admin if needed
|
// Upgrade to admin if needed
|
||||||
await this.prisma.user.update({
|
await this.prisma.user.update({
|
||||||
|
|
|
||||||
|
|
@ -1,191 +0,0 @@
|
||||||
.name-input-modal-backdrop {
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
background: rgba(0, 0, 0, 0.7);
|
|
||||||
backdrop-filter: blur(5px);
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
z-index: 1000;
|
|
||||||
padding: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-modal-content {
|
|
||||||
background: rgba(20, 20, 30, 0.95);
|
|
||||||
backdrop-filter: blur(20px);
|
|
||||||
border-radius: 20px;
|
|
||||||
padding: clamp(20px, 3vh, 30px);
|
|
||||||
max-width: 450px;
|
|
||||||
width: 100%;
|
|
||||||
border: 2px solid rgba(255, 215, 0, 0.3);
|
|
||||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-modal-header {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
margin-bottom: clamp(15px, 2vh, 20px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-modal-title {
|
|
||||||
color: #ffd700;
|
|
||||||
font-size: clamp(1.3rem, 2.5vw, 1.8rem);
|
|
||||||
margin: 0;
|
|
||||||
text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-modal-close {
|
|
||||||
background: rgba(255, 107, 107, 0.2);
|
|
||||||
color: #ff6b6b;
|
|
||||||
border: 2px solid rgba(255, 107, 107, 0.5);
|
|
||||||
border-radius: 50%;
|
|
||||||
width: 40px;
|
|
||||||
height: 40px;
|
|
||||||
font-size: 2rem;
|
|
||||||
line-height: 1;
|
|
||||||
cursor: pointer;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-modal-close:hover {
|
|
||||||
background: rgba(255, 107, 107, 0.4);
|
|
||||||
border-color: #ff6b6b;
|
|
||||||
transform: scale(1.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-modal-form {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-modal-body {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 20px;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-modal-description {
|
|
||||||
color: rgba(255, 255, 255, 0.9);
|
|
||||||
text-align: center;
|
|
||||||
font-size: clamp(0.95rem, 2vw, 1.1rem);
|
|
||||||
line-height: 1.6;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-group {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-field {
|
|
||||||
width: 100%;
|
|
||||||
padding: 15px 20px;
|
|
||||||
background: rgba(255, 255, 255, 0.1);
|
|
||||||
border: 2px solid rgba(255, 215, 0, 0.3);
|
|
||||||
border-radius: 12px;
|
|
||||||
color: #ffffff;
|
|
||||||
font-size: 1.1rem;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-field:focus {
|
|
||||||
outline: none;
|
|
||||||
border-color: #ffd700;
|
|
||||||
background: rgba(255, 255, 255, 0.15);
|
|
||||||
box-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-field::placeholder {
|
|
||||||
color: rgba(255, 255, 255, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-error {
|
|
||||||
color: #ff6b6b;
|
|
||||||
font-size: 0.9rem;
|
|
||||||
margin: 0;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-modal-footer {
|
|
||||||
display: flex;
|
|
||||||
gap: 10px;
|
|
||||||
justify-content: flex-end;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-submit-button,
|
|
||||||
.name-input-cancel-button {
|
|
||||||
padding: 12px 24px;
|
|
||||||
border-radius: 10px;
|
|
||||||
font-size: 1rem;
|
|
||||||
font-weight: 600;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
border: 2px solid transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-submit-button {
|
|
||||||
background: rgba(255, 215, 0, 0.2);
|
|
||||||
color: #ffd700;
|
|
||||||
border-color: rgba(255, 215, 0, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-submit-button:hover:not(:disabled) {
|
|
||||||
background: rgba(255, 215, 0, 0.3);
|
|
||||||
border-color: #ffd700;
|
|
||||||
transform: translateY(-2px);
|
|
||||||
box-shadow: 0 4px 12px rgba(255, 215, 0, 0.3);
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-submit-button:disabled {
|
|
||||||
opacity: 0.5;
|
|
||||||
cursor: not-allowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-cancel-button {
|
|
||||||
background: rgba(255, 255, 255, 0.1);
|
|
||||||
color: rgba(255, 255, 255, 0.8);
|
|
||||||
border-color: rgba(255, 255, 255, 0.3);
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-cancel-button:hover {
|
|
||||||
background: rgba(255, 255, 255, 0.2);
|
|
||||||
border-color: rgba(255, 255, 255, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
.name-input-modal-content {
|
|
||||||
padding: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-modal-title {
|
|
||||||
font-size: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-modal-close {
|
|
||||||
width: 35px;
|
|
||||||
height: 35px;
|
|
||||||
font-size: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-modal-footer {
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.name-input-submit-button,
|
|
||||||
.name-input-cancel-button {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,109 +0,0 @@
|
||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
import './NameInputModal.css';
|
|
||||||
|
|
||||||
const NameInputModal = ({ isOpen, onSubmit, onCancel }) => {
|
|
||||||
const [name, setName] = useState('');
|
|
||||||
const [error, setError] = useState('');
|
|
||||||
|
|
||||||
// Сброс формы при открытии модального окна
|
|
||||||
useEffect(() => {
|
|
||||||
if (isOpen) {
|
|
||||||
setName('');
|
|
||||||
setError('');
|
|
||||||
}
|
|
||||||
}, [isOpen]);
|
|
||||||
|
|
||||||
if (!isOpen) return null;
|
|
||||||
|
|
||||||
const handleSubmit = (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
const trimmedName = name.trim();
|
|
||||||
|
|
||||||
if (!trimmedName) {
|
|
||||||
setError('Введите имя');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (trimmedName.length > 50) {
|
|
||||||
setError('Имя слишком длинное (максимум 50 символов)');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setError('');
|
|
||||||
onSubmit(trimmedName);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleBackdropClick = (e) => {
|
|
||||||
if (e.target === e.currentTarget && onCancel) {
|
|
||||||
onCancel();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="name-input-modal-backdrop" onClick={handleBackdropClick}>
|
|
||||||
<div className="name-input-modal-content">
|
|
||||||
<div className="name-input-modal-header">
|
|
||||||
<h2 className="name-input-modal-title">Введите ваше имя</h2>
|
|
||||||
{onCancel && (
|
|
||||||
<button className="name-input-modal-close" onClick={onCancel}>
|
|
||||||
×
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<form className="name-input-modal-form" onSubmit={handleSubmit}>
|
|
||||||
<div className="name-input-modal-body">
|
|
||||||
<p className="name-input-modal-description">
|
|
||||||
Чтобы присоединиться к комнате, введите ваше имя
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div className="name-input-group">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
value={name}
|
|
||||||
onChange={(e) => {
|
|
||||||
setName(e.target.value);
|
|
||||||
setError('');
|
|
||||||
}}
|
|
||||||
onKeyPress={(e) => {
|
|
||||||
if (e.key === 'Enter') {
|
|
||||||
handleSubmit(e);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
placeholder="Ваше имя"
|
|
||||||
className="name-input-field"
|
|
||||||
autoFocus
|
|
||||||
maxLength={50}
|
|
||||||
/>
|
|
||||||
{error && (
|
|
||||||
<p className="name-input-error">{error}</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="name-input-modal-footer">
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
className="name-input-submit-button primary"
|
|
||||||
disabled={!name.trim()}
|
|
||||||
>
|
|
||||||
Продолжить
|
|
||||||
</button>
|
|
||||||
{onCancel && (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={onCancel}
|
|
||||||
className="name-input-cancel-button secondary"
|
|
||||||
>
|
|
||||||
Отмена
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default NameInputModal;
|
|
||||||
|
|
||||||
|
|
@ -3,11 +3,10 @@ import { useNavigate } from 'react-router-dom';
|
||||||
import { useAuth } from '../context/AuthContext';
|
import { useAuth } from '../context/AuthContext';
|
||||||
import { useRoom } from '../hooks/useRoom';
|
import { useRoom } from '../hooks/useRoom';
|
||||||
import { questionsApi } from '../services/api';
|
import { questionsApi } from '../services/api';
|
||||||
import NameInputModal from '../components/NameInputModal';
|
|
||||||
|
|
||||||
const CreateRoom = () => {
|
const CreateRoom = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { user, loginAnonymous, loading: authLoading } = useAuth();
|
const { user } = useAuth();
|
||||||
const { createRoom, loading: roomLoading } = useRoom();
|
const { createRoom, loading: roomLoading } = useRoom();
|
||||||
|
|
||||||
const [questionPacks, setQuestionPacks] = useState([]);
|
const [questionPacks, setQuestionPacks] = useState([]);
|
||||||
|
|
@ -19,27 +18,6 @@ const CreateRoom = () => {
|
||||||
timerDuration: 30,
|
timerDuration: 30,
|
||||||
});
|
});
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [isNameModalOpen, setIsNameModalOpen] = useState(false);
|
|
||||||
|
|
||||||
// Проверка авторизации и показ модального окна для ввода имени
|
|
||||||
useEffect(() => {
|
|
||||||
if (!authLoading && !user) {
|
|
||||||
setIsNameModalOpen(true);
|
|
||||||
} else if (user) {
|
|
||||||
setIsNameModalOpen(false);
|
|
||||||
}
|
|
||||||
}, [authLoading, user]);
|
|
||||||
|
|
||||||
// Обработка ввода имени и авторизация
|
|
||||||
const handleNameSubmit = async (name) => {
|
|
||||||
try {
|
|
||||||
await loginAnonymous(name);
|
|
||||||
setIsNameModalOpen(false);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Login error:', error);
|
|
||||||
alert('Ошибка при авторизации. Попробуйте еще раз.');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchPacks = async () => {
|
const fetchPacks = async () => {
|
||||||
|
|
@ -53,16 +31,12 @@ const CreateRoom = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (user) {
|
fetchPacks();
|
||||||
fetchPacks();
|
|
||||||
} else {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
const handleCreateRoom = async () => {
|
const handleCreateRoom = async () => {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
setIsNameModalOpen(true);
|
alert('Войдите в систему для создания комнаты');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -168,12 +142,6 @@ const CreateRoom = () => {
|
||||||
<button onClick={() => navigate('/')}>Назад</button>
|
<button onClick={() => navigate('/')}>Назад</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<NameInputModal
|
|
||||||
isOpen={isNameModalOpen}
|
|
||||||
onSubmit={handleNameSubmit}
|
|
||||||
onCancel={null}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,11 @@ import { useRoom } from '../hooks/useRoom';
|
||||||
import { questionsApi } from '../services/api';
|
import { questionsApi } from '../services/api';
|
||||||
import QRCode from 'qrcode';
|
import QRCode from 'qrcode';
|
||||||
import QRModal from '../components/QRModal';
|
import QRModal from '../components/QRModal';
|
||||||
import NameInputModal from '../components/NameInputModal';
|
|
||||||
|
|
||||||
const RoomPage = () => {
|
const RoomPage = () => {
|
||||||
const { roomCode } = useParams();
|
const { roomCode } = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { user, loginAnonymous, loading: authLoading } = useAuth();
|
const { user } = useAuth();
|
||||||
const {
|
const {
|
||||||
room,
|
room,
|
||||||
participants,
|
participants,
|
||||||
|
|
@ -23,7 +22,6 @@ const RoomPage = () => {
|
||||||
const [qrCode, setQrCode] = useState('');
|
const [qrCode, setQrCode] = useState('');
|
||||||
const [joined, setJoined] = useState(false);
|
const [joined, setJoined] = useState(false);
|
||||||
const [isQRModalOpen, setIsQRModalOpen] = useState(false);
|
const [isQRModalOpen, setIsQRModalOpen] = useState(false);
|
||||||
const [isNameModalOpen, setIsNameModalOpen] = useState(false);
|
|
||||||
const [questionPacks, setQuestionPacks] = useState([]);
|
const [questionPacks, setQuestionPacks] = useState([]);
|
||||||
const [selectedPackId, setSelectedPackId] = useState('');
|
const [selectedPackId, setSelectedPackId] = useState('');
|
||||||
const [loadingPacks, setLoadingPacks] = useState(false);
|
const [loadingPacks, setLoadingPacks] = useState(false);
|
||||||
|
|
@ -53,26 +51,6 @@ const RoomPage = () => {
|
||||||
}
|
}
|
||||||
}, [roomCode]);
|
}, [roomCode]);
|
||||||
|
|
||||||
// Проверка авторизации и показ модального окна для ввода имени
|
|
||||||
useEffect(() => {
|
|
||||||
if (!authLoading && !user && room && !loading) {
|
|
||||||
setIsNameModalOpen(true);
|
|
||||||
} else if (user) {
|
|
||||||
setIsNameModalOpen(false);
|
|
||||||
}
|
|
||||||
}, [authLoading, user, room, loading]);
|
|
||||||
|
|
||||||
// Обработка ввода имени и авторизация
|
|
||||||
const handleNameSubmit = async (name) => {
|
|
||||||
try {
|
|
||||||
await loginAnonymous(name);
|
|
||||||
setIsNameModalOpen(false);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Login error:', error);
|
|
||||||
alert('Ошибка при авторизации. Попробуйте еще раз.');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleJoin = async () => {
|
const handleJoin = async () => {
|
||||||
if (room && user && !joined) {
|
if (room && user && !joined) {
|
||||||
|
|
@ -269,12 +247,6 @@ const RoomPage = () => {
|
||||||
qrCode={qrCode}
|
qrCode={qrCode}
|
||||||
roomCode={roomCode}
|
roomCode={roomCode}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<NameInputModal
|
|
||||||
isOpen={isNameModalOpen}
|
|
||||||
onSubmit={handleNameSubmit}
|
|
||||||
onCancel={null}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue