615 lines
27 KiB
TypeScript
615 lines
27 KiB
TypeScript
import {
|
|
// Activity,
|
|
BadgeCheck,
|
|
Bell,
|
|
CreditCard,
|
|
// Coins,
|
|
DollarSign,
|
|
HelpCircle,
|
|
MessageSquare,
|
|
Star,
|
|
// TrendingUp,
|
|
Users,
|
|
UsersRound,
|
|
UserX,
|
|
Video,
|
|
} from "lucide-react"
|
|
import {
|
|
Bar,
|
|
BarChart,
|
|
Cell,
|
|
CartesianGrid,
|
|
ResponsiveContainer,
|
|
Tooltip,
|
|
XAxis,
|
|
YAxis,
|
|
} from "recharts"
|
|
import spinnerSrc from "../assets/05d37a91-04f9-41d8-99a2-b11bf20a6af2.png"
|
|
import { ActivePlansBreakdownCard, analyticsSoftCardClass, BreakdownBarCard, RenewalRateCard } from "../components/analytics/SubscriptionRevenueVisuals"
|
|
import { labelCountsToPieSlices, SUBSCRIPTION_CHART_COLORS } from "../components/analytics/SubscriptionRevenueVisuals.shared"
|
|
import { RevenueTrendCard } from "../components/dashboard/RevenueTrendCard"
|
|
import { DashboardProfileRail } from "../components/dashboard/DashboardProfileRail"
|
|
import { StatCard } from "../components/dashboard/StatCard"
|
|
|
|
import { useEffect, useState, type ReactNode } from "react"
|
|
import { Link } from "react-router-dom"
|
|
import { getDashboard } from "../api/analytics.api"
|
|
import { getRatingSummary, listRatingsByTarget } from "../api/ratings.api"
|
|
import { getSubscriptionPlans } from "../api/subscription-plans.api"
|
|
import { getTeamMemberById } from "../api/team.api"
|
|
import alertSrc from "../assets/Alert.svg"
|
|
import { AnalyticsTimeRangeFilter } from "../components/analytics/AnalyticsTimeRangeFilter"
|
|
import { getDashboardFilterLabel } from "../components/analytics/AnalyticsTimeRangeFilter.shared"
|
|
import { Badge } from "../components/ui/badge"
|
|
import { Card, CardContent, CardHeader, CardTitle } from "../components/ui/card"
|
|
import { SensitiveRevealProvider, SensitiveValue } from "../components/ui/sensitive-value"
|
|
import { cn } from "../lib/utils"
|
|
|
|
import {
|
|
buildSubscriptionStatusPie,
|
|
formatAnalyticsSeriesDate,
|
|
getPrimaryQuestionTypeSummary,
|
|
getSeriesPeriodLabel,
|
|
getSubscriptionMetrics,
|
|
getVideoLessonsSummary,
|
|
} from "../lib/analytics"
|
|
import { formatAppDateTime } from "../lib/datetime"
|
|
import { formatAverageStars } from "../lib/ratingsDisplay"
|
|
import { formatPlanDuration } from "../lib/subscriptionPlans"
|
|
import type { DashboardData, DashboardFilters } from "../types/analytics.types"
|
|
import type { Rating, RatingSummary } from "../types/ratings.types"
|
|
import type { SubscriptionPlan } from "../types/subscription.types"
|
|
|
|
const PIE_COLORS = SUBSCRIPTION_CHART_COLORS
|
|
const chartTooltipStyle = {
|
|
borderRadius: 10,
|
|
border: "1px solid hsl(var(--border))",
|
|
backgroundColor: "hsl(var(--popover))",
|
|
color: "hsl(var(--popover-foreground))",
|
|
boxShadow: "0 8px 24px rgba(0,0,0,0.08)",
|
|
fontSize: 12,
|
|
}
|
|
|
|
function DashboardSectionTitle({ children }: { children: ReactNode }) {
|
|
return (
|
|
<h2 className="flex items-center gap-3 text-base font-semibold tracking-tight text-grayScale-600">{children}</h2>
|
|
)
|
|
}
|
|
|
|
function formatDate(dateStr: string) {
|
|
return formatAnalyticsSeriesDate(dateStr)
|
|
}
|
|
|
|
const DEFAULT_FILTERS: DashboardFilters = { mode: "all_time" }
|
|
|
|
export function DashboardPage() {
|
|
const [userFirstName, setUserFirstName] = useState<string>("")
|
|
const [dashboard, setDashboard] = useState<DashboardData | null>(null)
|
|
const [loading, setLoading] = useState(true)
|
|
const [activeStatTab, setActiveStatTab] = useState<"primary" | "secondary">("primary")
|
|
const [appRatings, setAppRatings] = useState<Rating[]>([])
|
|
const [appRatingsSummary, setAppRatingsSummary] = useState<RatingSummary>({
|
|
total_count: 0,
|
|
average_stars: 0,
|
|
})
|
|
const [appRatingsLoading, setAppRatingsLoading] = useState(true)
|
|
const [filters, setFilters] = useState<DashboardFilters>(DEFAULT_FILTERS)
|
|
const [subscriptionPlans, setSubscriptionPlans] = useState<SubscriptionPlan[]>([])
|
|
const [subscriptionPlansLoading, setSubscriptionPlansLoading] = useState(true)
|
|
|
|
useEffect(() => {
|
|
const fetchUser = async () => {
|
|
try {
|
|
const memberId = Number(localStorage.getItem("member_id"))
|
|
const res = await getTeamMemberById(memberId)
|
|
const member = res.data.data
|
|
|
|
setUserFirstName(member.first_name)
|
|
localStorage.setItem("user_first_name", member.first_name)
|
|
localStorage.setItem("user_last_name", member.last_name)
|
|
window.dispatchEvent(new Event("user-profile-updated"))
|
|
} catch (err) {
|
|
console.error(err)
|
|
}
|
|
}
|
|
|
|
fetchUser()
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
const fetchAppRatings = async () => {
|
|
try {
|
|
const [summary, reviews] = await Promise.all([
|
|
getRatingSummary({ target_type: "app", target_id: 0 }),
|
|
listRatingsByTarget({ target_type: "app", target_id: 0, limit: 5, offset: 0 }),
|
|
])
|
|
setAppRatingsSummary(summary)
|
|
setAppRatings(reviews)
|
|
} catch (err) {
|
|
console.error(err)
|
|
} finally {
|
|
setAppRatingsLoading(false)
|
|
}
|
|
}
|
|
|
|
fetchAppRatings()
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
const fetchPlans = async () => {
|
|
setSubscriptionPlansLoading(true)
|
|
try {
|
|
const res = await getSubscriptionPlans({ active_only: false })
|
|
setSubscriptionPlans(res.data)
|
|
} catch (err) {
|
|
console.error(err)
|
|
setSubscriptionPlans([])
|
|
} finally {
|
|
setSubscriptionPlansLoading(false)
|
|
}
|
|
}
|
|
|
|
fetchPlans()
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
const fetchDashboard = async () => {
|
|
setLoading(true)
|
|
try {
|
|
const res = await getDashboard(filters)
|
|
setDashboard(res.data)
|
|
} catch (err) {
|
|
console.error(err)
|
|
setDashboard(null)
|
|
} finally {
|
|
setLoading(false)
|
|
}
|
|
}
|
|
|
|
fetchDashboard()
|
|
}, [filters])
|
|
|
|
const registrationData =
|
|
dashboard?.users.registrations_last_30_days.map((d) => ({
|
|
date: formatDate(d.date),
|
|
count: d.count,
|
|
})) ?? []
|
|
|
|
const subscriptionStatusData = buildSubscriptionStatusPie(
|
|
dashboard?.subscriptions.by_status,
|
|
PIE_COLORS,
|
|
)
|
|
|
|
const seriesPeriodLabel = dashboard ? getSeriesPeriodLabel(dashboard.date_filter) : "Last 30 Days"
|
|
const subscriptionMetrics = dashboard
|
|
? getSubscriptionMetrics(dashboard.subscriptions)
|
|
: null
|
|
|
|
const generatedAt = dashboard ? formatAppDateTime(dashboard.generated_at) : ""
|
|
const peakRegistrations = Math.max(0, ...registrationData.map(row => row.count))
|
|
|
|
return (
|
|
<SensitiveRevealProvider>
|
|
<div className="dashboard-layout mx-auto w-full min-w-0 max-w-[1800px] pb-6"
|
|
>
|
|
<div className="dashboard-workspace min-w-0">
|
|
<div className="dashboard-greeting relative mb-7 flex flex-wrap items-center justify-between gap-4">
|
|
<div className="pointer-events-none absolute -right-12 -top-24 h-64 w-64 rounded-full bg-brand-100/40 blur-3xl" />
|
|
<div className="relative min-w-0">
|
|
<div className="mb-1.5 flex items-center gap-2 text-[11px] font-bold uppercase tracking-[0.18em] text-brand-600">
|
|
<span className="h-1.5 w-1.5 rounded-full bg-brand-500" />
|
|
Dashboard
|
|
</div>
|
|
<h1 className="text-2xl font-semibold tracking-tight text-grayScale-600">
|
|
Hello {userFirstName || localStorage.getItem("user_first_name") || "there"}
|
|
</h1>
|
|
<p className="mt-1.5 text-sm text-grayScale-500">
|
|
Snapshot for {getDashboardFilterLabel(filters)}
|
|
{dashboard ? ` · Updated ${generatedAt}` : ""}
|
|
</p>
|
|
</div>
|
|
<div className="relative flex flex-wrap items-center gap-3">
|
|
<Link
|
|
to="/analytics"
|
|
className="text-xs font-semibold text-brand-600 transition-colors hover:text-brand-500"
|
|
>
|
|
Full analytics →
|
|
</Link>
|
|
<AnalyticsTimeRangeFilter value={filters} onChange={setFilters} />
|
|
</div>
|
|
</div>
|
|
|
|
{loading ? (
|
|
<div className="flex flex-col items-center justify-center gap-3 rounded-2xl border border-grayScale-100 bg-white py-24 shadow-sm">
|
|
<img src={spinnerSrc} alt="" className="h-10 w-10 animate-spin" />
|
|
<span className="text-sm font-medium text-grayScale-400">Loading dashboard…</span>
|
|
</div>
|
|
) : !dashboard ? (
|
|
<div className="flex flex-col items-center justify-center gap-3 rounded-2xl border border-red-100 bg-red-50/40 py-24">
|
|
<img src={alertSrc} alt="" className="h-12 w-12" />
|
|
<span className="text-sm font-medium text-destructive">Failed to load dashboard data.</span>
|
|
</div>
|
|
) : (
|
|
<>
|
|
<div className="mb-5 flex flex-wrap items-center justify-between gap-3 rounded-2xl border border-grayScale-100 bg-white px-4 pt-3 shadow-sm sm:px-5">
|
|
<div className="-mb-px flex gap-6">
|
|
<button
|
|
type="button"
|
|
onClick={() => setActiveStatTab("primary")}
|
|
className={cn(
|
|
"relative px-1 pb-3.5 pt-1 text-sm font-semibold transition-all",
|
|
activeStatTab === "primary"
|
|
? "text-brand-600"
|
|
: "text-grayScale-400 hover:text-grayScale-700",
|
|
)}
|
|
>
|
|
Overview
|
|
{activeStatTab === "primary" && (
|
|
<span className="absolute inset-x-0 bottom-0 h-0.5 rounded-full bg-brand-500" />
|
|
)}
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => setActiveStatTab("secondary")}
|
|
className={cn(
|
|
"relative px-1 pb-3.5 pt-1 text-sm font-semibold transition-all",
|
|
activeStatTab === "secondary"
|
|
? "text-brand-600"
|
|
: "text-grayScale-400 hover:text-grayScale-700",
|
|
)}
|
|
>
|
|
More metrics
|
|
{activeStatTab === "secondary" && (
|
|
<span className="absolute inset-x-0 bottom-0 h-0.5 rounded-full bg-brand-500" />
|
|
)}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Stat Cards */}
|
|
{activeStatTab === "primary" && (
|
|
<div className="mb-6 grid gap-3 sm:grid-cols-2 md:grid-cols-3">
|
|
<StatCard
|
|
icon={Users}
|
|
label="Total Users"
|
|
value={dashboard.users.total_users.toLocaleString()}
|
|
deltaLabel={`+${dashboard.users.new_month} this month`}
|
|
deltaPositive={dashboard.users.new_month > 0}
|
|
/>
|
|
<StatCard
|
|
icon={CreditCard}
|
|
label="Payments"
|
|
value={dashboard.payments.total_payments.toLocaleString()}
|
|
deltaLabel={`${dashboard.payments.successful_payments} successful`}
|
|
deltaPositive={dashboard.payments.successful_payments > 0}
|
|
/>
|
|
<StatCard
|
|
icon={DollarSign}
|
|
label="Total Revenue (ETB)"
|
|
value={
|
|
<SensitiveValue>
|
|
{dashboard.payments.total_revenue.toLocaleString()}
|
|
</SensitiveValue>
|
|
}
|
|
deltaLabel={`${dashboard.payments.total_payments} payments`}
|
|
deltaPositive={dashboard.payments.total_revenue > 0}
|
|
/>
|
|
</div>
|
|
)}
|
|
|
|
{/* Secondary Stats */}
|
|
{activeStatTab === "secondary" && subscriptionMetrics && (
|
|
<div className="mb-6 grid gap-3 sm:grid-cols-2 xl:grid-cols-4">
|
|
<StatCard
|
|
icon={CreditCard}
|
|
label="Total Subscriptions"
|
|
value={subscriptionMetrics.total.toLocaleString()}
|
|
deltaLabel={`+${dashboard.subscriptions.new_month} this month`}
|
|
deltaPositive={dashboard.subscriptions.new_month > 0}
|
|
/>
|
|
<StatCard
|
|
icon={BadgeCheck}
|
|
label="Active Subscriptions"
|
|
value={subscriptionMetrics.active.toLocaleString()}
|
|
deltaLabel={`+${dashboard.subscriptions.new_today} today · +${dashboard.subscriptions.new_week} this week`}
|
|
deltaPositive={subscriptionMetrics.active > 0}
|
|
/>
|
|
<StatCard
|
|
icon={UserX}
|
|
label="Inactive Subscriptions"
|
|
value={subscriptionMetrics.inactive.toLocaleString()}
|
|
deltaLabel={
|
|
dashboard.subscriptions.by_status.length > 0
|
|
? "From subscription status breakdown"
|
|
: "Total minus active"
|
|
}
|
|
deltaPositive={subscriptionMetrics.inactive === 0}
|
|
trend="neutral"
|
|
/>
|
|
<StatCard
|
|
icon={Video}
|
|
label="Videos"
|
|
value={dashboard.courses.total_videos.toLocaleString()}
|
|
deltaLabel={getVideoLessonsSummary(
|
|
dashboard.courses.exam_prep?.lessons_with_video,
|
|
)}
|
|
deltaPositive={dashboard.courses.total_videos > 0}
|
|
/>
|
|
<StatCard
|
|
icon={HelpCircle}
|
|
label="Questions"
|
|
value={dashboard.content.total_questions.toLocaleString()}
|
|
deltaLabel={getPrimaryQuestionTypeSummary(dashboard.content.questions_by_type)}
|
|
deltaPositive={dashboard.content.total_questions > 0}
|
|
/>
|
|
<StatCard
|
|
icon={Bell}
|
|
label="Notifications"
|
|
value={dashboard.notifications.total_sent.toLocaleString()}
|
|
deltaLabel={`${dashboard.notifications.unread_count} unread`}
|
|
deltaPositive={dashboard.notifications.unread_count === 0}
|
|
trend={dashboard.notifications.unread_count > 0 ? "neutral" : "up"}
|
|
/>
|
|
<StatCard
|
|
icon={UsersRound}
|
|
label="Team Members"
|
|
value={dashboard.team.total_members.toLocaleString()}
|
|
deltaLabel={`${dashboard.team.by_role.length} roles`}
|
|
deltaPositive
|
|
trend="neutral"
|
|
/>
|
|
</div>
|
|
)}
|
|
|
|
<div className="space-y-6">
|
|
<div className="grid items-start gap-6 xl:grid-cols-2">
|
|
<section className="min-w-0 space-y-3">
|
|
<DashboardSectionTitle>Growth</DashboardSectionTitle>
|
|
<Card className={cn(analyticsSoftCardClass)}>
|
|
<CardHeader className="pb-2 pt-5">
|
|
<div className="flex items-start justify-between gap-3">
|
|
<div>
|
|
<CardTitle className="text-base font-bold text-grayScale-900">
|
|
User Registrations
|
|
</CardTitle>
|
|
<p className="mt-1 text-xs text-grayScale-400">
|
|
New sign-ups over {seriesPeriodLabel.toLowerCase()}
|
|
</p>
|
|
<div className="mt-3 text-2xl font-bold tracking-tight text-grayScale-900">
|
|
{dashboard.users.total_users.toLocaleString()}
|
|
</div>
|
|
<div className="mt-1 text-xs font-medium text-mint-500">
|
|
+{dashboard.users.new_today} today · +{dashboard.users.new_week} this week
|
|
</div>
|
|
</div>
|
|
<Badge variant="secondary" className="shrink-0 font-semibold">
|
|
{seriesPeriodLabel}
|
|
</Badge>
|
|
</div>
|
|
</CardHeader>
|
|
<CardContent className="h-[280px] px-5 pb-5 pt-2">
|
|
<ResponsiveContainer width="100%" height="100%" minWidth={0}>
|
|
<BarChart data={registrationData} margin={{ left: 0, right: 8, top: 16, bottom: 4 }} barCategoryGap="25%">
|
|
<CartesianGrid vertical={false} stroke="var(--gs-200)" strokeDasharray="3 5" strokeOpacity={0.5} />
|
|
<XAxis dataKey="date" tickLine={false} axisLine={false} fontSize={10} minTickGap={20} tick={{ fill: "var(--gs-500)" }} />
|
|
<YAxis tickLine={false} axisLine={false} fontSize={10} width={36} allowDecimals={false} tick={{ fill: "var(--gs-500)" }} />
|
|
<Tooltip cursor={{ fill: "var(--gs-100)" }} contentStyle={chartTooltipStyle} />
|
|
<Bar dataKey="count" name="Registrations" radius={[5, 5, 0, 0]} maxBarSize={24} isAnimationActive={false}>
|
|
{registrationData.map(row => <Cell key={row.date} fill={row.count === peakRegistrations && peakRegistrations > 0 ? "#27685F" : "#79AAA0"} />)}
|
|
</Bar>
|
|
</BarChart>
|
|
</ResponsiveContainer>
|
|
</CardContent>
|
|
</Card>
|
|
</section>
|
|
|
|
<section className="min-w-0 space-y-3">
|
|
<DashboardSectionTitle>Revenue & subscriptions</DashboardSectionTitle>
|
|
<div className="grid gap-4">
|
|
<RevenueTrendCard paymentMethod={filters.payment_method} />
|
|
</div>
|
|
</section>
|
|
</div>
|
|
|
|
<section className="space-y-3">
|
|
<DashboardSectionTitle>Subscription health</DashboardSectionTitle>
|
|
<div className="grid min-w-0 items-stretch gap-4 md:grid-cols-2 2xl:grid-cols-3">
|
|
<ActivePlansBreakdownCard
|
|
data={labelCountsToPieSlices(
|
|
(dashboard.subscriptions.active_by_plan?.length
|
|
? dashboard.subscriptions.active_by_plan
|
|
: dashboard.subscriptions.by_status
|
|
).map((row) => ({
|
|
label: row.label,
|
|
count: row.count,
|
|
})),
|
|
)}
|
|
/>
|
|
<RenewalRateCard
|
|
renewalRate={dashboard.subscriptions.renewal?.renewal_rate ?? 0}
|
|
autoRenewCount={dashboard.subscriptions.snapshot?.auto_renew_enabled ?? 0}
|
|
cancelledCount={dashboard.subscriptions.snapshot?.cancelled_now ?? 0}
|
|
/>
|
|
{subscriptionStatusData.length > 0 ? (
|
|
<BreakdownBarCard
|
|
title="Subscription Status"
|
|
data={subscriptionStatusData}
|
|
countSuffix="Subscriptions"
|
|
/>
|
|
) : null}
|
|
</div>
|
|
</section>
|
|
|
|
<section className="space-y-3">
|
|
<DashboardSectionTitle>Catalog & feedback</DashboardSectionTitle>
|
|
<div className="grid grid-cols-1 items-start gap-4">
|
|
<Card className={cn(analyticsSoftCardClass)}>
|
|
<CardHeader className="pb-2 pt-5">
|
|
<div className="flex items-center gap-2">
|
|
<div className="grid h-9 w-9 place-items-center rounded-lg bg-brand-100/60 text-brand-600">
|
|
<CreditCard className="h-4 w-4" />
|
|
</div>
|
|
<div>
|
|
<CardTitle className="text-base font-bold text-grayScale-900">
|
|
Subscription plans
|
|
</CardTitle>
|
|
<p className="text-sm text-grayScale-500">Available billing plans for learners.</p>
|
|
</div>
|
|
</div>
|
|
</CardHeader>
|
|
<CardContent className="px-5 pb-5 pt-2">
|
|
{subscriptionPlansLoading ? (
|
|
<div className="flex items-center justify-center py-10">
|
|
<img src={spinnerSrc} alt="" className="h-8 w-8 animate-spin" />
|
|
</div>
|
|
) : subscriptionPlans.length === 0 ? (
|
|
<div className="flex items-center justify-center py-10 text-sm text-grayScale-400">
|
|
No subscription plans found
|
|
</div>
|
|
) : (
|
|
<div className="grid gap-3 sm:grid-cols-2">
|
|
{subscriptionPlans.map((plan) => (
|
|
<div
|
|
key={plan.id}
|
|
className="flex flex-col rounded-xl border border-grayScale-200/80 bg-white p-4 shadow-sm transition-all duration-200 hover:-translate-y-0.5 hover:border-brand-200/60 hover:shadow-md"
|
|
>
|
|
<div className="flex items-start justify-between gap-2">
|
|
<h3 className="font-semibold text-grayScale-700">{plan.name}</h3>
|
|
<Badge variant={plan.is_active ? "success" : "secondary"}>
|
|
{plan.is_active ? "Active" : "Inactive"}
|
|
</Badge>
|
|
</div>
|
|
{plan.description ? (
|
|
<p className="mt-2 line-clamp-2 text-sm text-grayScale-500">{plan.description}</p>
|
|
) : null}
|
|
<div className="mt-4 flex flex-wrap items-end justify-between gap-2 border-t border-grayScale-200 pt-4">
|
|
<div>
|
|
<div className="text-xs font-medium uppercase tracking-wide text-grayScale-400">Price</div>
|
|
<div className="text-lg font-semibold text-brand-600">
|
|
{plan.currency}{" "}
|
|
{Number.isInteger(plan.price)
|
|
? plan.price.toLocaleString()
|
|
: plan.price.toLocaleString(undefined, {
|
|
minimumFractionDigits: 0,
|
|
maximumFractionDigits: 2,
|
|
})}
|
|
</div>
|
|
</div>
|
|
<div className="text-right">
|
|
<div className="text-xs font-medium uppercase tracking-wide text-grayScale-400">
|
|
Billing
|
|
</div>
|
|
<div className="text-sm font-semibold text-grayScale-600">{formatPlanDuration(plan)}</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
|
|
<Card className={cn(analyticsSoftCardClass)}>
|
|
<CardHeader className="pb-2 pt-5">
|
|
<div className="flex items-center justify-between gap-2">
|
|
<div className="flex items-center gap-2">
|
|
<div className="grid h-9 w-9 place-items-center rounded-lg bg-brand-100/60 text-brand-600">
|
|
<MessageSquare className="h-4 w-4" />
|
|
</div>
|
|
<CardTitle className="text-base font-bold text-grayScale-900">
|
|
Recent App Reviews
|
|
</CardTitle>
|
|
</div>
|
|
<Link
|
|
to="/app-reviews"
|
|
className="rounded-lg px-2.5 py-1 text-xs font-semibold text-brand-600 transition-colors hover:bg-brand-100/40"
|
|
>
|
|
View all
|
|
</Link>
|
|
</div>
|
|
</CardHeader>
|
|
<CardContent className="px-5 pb-5 pt-2">
|
|
{appRatingsLoading ? (
|
|
<div className="flex items-center justify-center py-10">
|
|
<img src={spinnerSrc} alt="" className="h-8 w-8 animate-spin" />
|
|
</div>
|
|
) : appRatingsSummary.total_count === 0 ? (
|
|
<div className="flex items-center justify-center py-10 text-sm text-grayScale-400">
|
|
No app reviews yet
|
|
</div>
|
|
) : (
|
|
<>
|
|
<div className="mb-4 flex items-center gap-3 rounded-xl border border-grayScale-100 bg-gradient-to-r from-amber-50/80 to-white px-4 py-3">
|
|
<div className="flex items-center gap-1">
|
|
{Array.from({ length: 5 }).map((_, i) => (
|
|
<Star
|
|
key={i}
|
|
className={cn(
|
|
"h-4 w-4",
|
|
i < Math.round(appRatingsSummary.average_stars)
|
|
? "fill-amber-400 text-amber-400"
|
|
: "fill-grayScale-200 text-grayScale-200",
|
|
)}
|
|
/>
|
|
))}
|
|
</div>
|
|
<span className="text-sm font-semibold text-grayScale-600">
|
|
{formatAverageStars(appRatingsSummary.average_stars)}
|
|
</span>
|
|
<span className="text-xs text-grayScale-400">
|
|
({appRatingsSummary.total_count}{" "}
|
|
{appRatingsSummary.total_count === 1 ? "review" : "reviews"})
|
|
</span>
|
|
</div>
|
|
|
|
<div className="divide-y divide-grayScale-100">
|
|
{appRatings.map((rating) => (
|
|
<div key={rating.id} className="flex gap-3 py-4 first:pt-0 last:pb-0">
|
|
<div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-brand-50 text-xs font-semibold text-brand-600">
|
|
U{rating.user_id}
|
|
</div>
|
|
<div className="min-w-0 flex-1">
|
|
<div className="flex items-center justify-between gap-2">
|
|
<span className="text-sm font-semibold text-grayScale-600">
|
|
User #{rating.user_id}
|
|
</span>
|
|
<span className="shrink-0 text-xs text-grayScale-400">
|
|
{formatDate(rating.created_at)}
|
|
</span>
|
|
</div>
|
|
<div className="mt-0.5 flex items-center gap-0.5">
|
|
{Array.from({ length: 5 }).map((_, i) => (
|
|
<Star
|
|
key={i}
|
|
className={cn(
|
|
"h-3.5 w-3.5",
|
|
i < rating.stars
|
|
? "fill-amber-400 text-amber-400"
|
|
: "fill-grayScale-200 text-grayScale-200",
|
|
)}
|
|
/>
|
|
))}
|
|
</div>
|
|
{rating.review && (
|
|
<p className="mt-1 text-sm text-grayScale-500">{rating.review}</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</>
|
|
)}
|
|
</div>
|
|
<DashboardProfileRail firstName={userFirstName} dashboard={dashboard} />
|
|
</div>
|
|
</SensitiveRevealProvider>
|
|
)
|
|
}
|