From 0945d858382856cf44ef81dfab4b104cf30af858 Mon Sep 17 00:00:00 2001 From: Yared Yemane Date: Wed, 8 Jul 2026 00:00:29 -0700 Subject: [PATCH 1/3] Add video analytics section to the analytics dashboard. Surface watch sessions, completion/replay rates, and checkpoint drop-off charts from the dashboard API. Co-authored-by: Cursor --- src/lib/analytics.ts | 5 + src/pages/analytics/AnalyticsPage.tsx | 175 +++++++++++++++++++++++++- src/types/analytics.types.ts | 19 +++ 3 files changed, 198 insertions(+), 1 deletion(-) diff --git a/src/lib/analytics.ts b/src/lib/analytics.ts index 269ccae..75fb866 100644 --- a/src/lib/analytics.ts +++ b/src/lib/analytics.ts @@ -131,6 +131,11 @@ export function getSeriesPeriodLabel(dateFilter?: DashboardDateFilter): string { } } +export function formatPercentRate(rate: number, fractionDigits = 1): string { + if (!Number.isFinite(rate)) return "0%" + return `${(rate * 100).toFixed(fractionDigits)}%` +} + /** Display label for dashboard breakdown rows (regions, enums, free text). */ export function formatAnalyticsLabel(label: string): string { const text = label?.trim() ?? "" diff --git a/src/pages/analytics/AnalyticsPage.tsx b/src/pages/analytics/AnalyticsPage.tsx index b3b50f5..b178494 100644 --- a/src/pages/analytics/AnalyticsPage.tsx +++ b/src/pages/analytics/AnalyticsPage.tsx @@ -33,6 +33,9 @@ import { FolderOpen, RefreshCw, ChevronDown, + PlayCircle, + RotateCcw, + CheckCircle2, } from "lucide-react" import { Card, CardContent, CardHeader, CardTitle } from "../../components/ui/card" import { Badge } from "../../components/ui/badge" @@ -46,6 +49,7 @@ import { formatAnalyticsLabel, getSubscriptionMetrics, getVideoLessonsSummary, + formatPercentRate, } from "../../lib/analytics" import type { DashboardData, DashboardFilters, LabelCount } from "../../types/analytics.types" @@ -363,7 +367,7 @@ export function AnalyticsPage() { ) } - const { users, subscriptions, payments, courses, content, notifications, issues, team } = dashboard + const { users, subscriptions, payments, courses, content, notifications, issues, team, videos } = dashboard const subscriptionMetrics = getSubscriptionMetrics(subscriptions) const seriesPeriodLabel = getSeriesPeriodLabel(dashboard.date_filter) const lms = courses.lms @@ -402,6 +406,21 @@ export function AnalyticsPage() { color: PIE_COLORS[i % PIE_COLORS.length], })) + const dropOffData = + videos?.drop_off_by_checkpoint.map((d) => ({ + checkpoint: `${d.checkpoint_percent}%`, + checkpointPercent: d.checkpoint_percent, + dropOffRate: Number((d.drop_off_rate * 100).toFixed(1)), + viewersReached: d.viewers_reached, + totalSessions: d.total_sessions, + })) ?? [] + + const retentionData = + videos?.drop_off_by_checkpoint.map((d) => ({ + checkpoint: `${d.checkpoint_percent}%`, + viewers: d.viewers_reached, + })) ?? [] + const generatedAt = new Date(dashboard.generated_at).toLocaleString("en-US", { month: "short", day: "numeric", @@ -880,6 +899,160 @@ export function AnalyticsPage() { + {/* ─── Video Analytics ─── */} + {videos && ( +
+
+ 0 ? "up" : "neutral"} + /> + = 0.25 ? "up" : "neutral"} + /> + 0 ? "up" : "neutral"} + /> + +
+ +
+ + +
+
+ Viewer Retention by Checkpoint +
+ Viewers still watching at each progress milestone +
+
+ {seriesPeriodLabel} +
+
+ + {retentionData.length > 0 ? ( + + + + + + + + + + + + [Number(v).toLocaleString(), "Viewers"]} + contentStyle={{ + borderRadius: 12, + border: "1px solid #E0E0E0", + boxShadow: "0 10px 30px rgba(0,0,0,0.08)", + fontSize: 12, + }} + /> + + + + ) : ( +
+ No checkpoint data available +
+ )} +
+
+ + + +
+
+ Drop-off Rate by Checkpoint +
+ Share of sessions that stopped before each milestone +
+
+ {seriesPeriodLabel} +
+
+ + {dropOffData.length > 0 ? ( + + + + + `${v}%`} + domain={[0, 100]} + /> + { + const row = props?.payload as (typeof dropOffData)[number] | undefined + return [ + `${Number(v).toFixed(1)}% drop-off`, + `${row?.viewersReached?.toLocaleString() ?? 0} viewers reached`, + ] + }} + contentStyle={{ + borderRadius: 12, + border: "1px solid #E0E0E0", + boxShadow: "0 10px 30px rgba(0,0,0,0.08)", + fontSize: 12, + }} + /> + + + + ) : ( +
+ No drop-off data available +
+ )} +
+
+
+ + {dropOffData.length > 0 && ( +
+ ({ + label: `${d.checkpointPercent}% — ${d.viewersReached} viewers (${d.dropOffRate}% drop-off)`, + count: d.viewersReached, + }))} + total={videos.total_watch_sessions} + /> +
+ )} +
+ )} + {/* ─── Team ─── */}
diff --git a/src/types/analytics.types.ts b/src/types/analytics.types.ts index 0e2bd8d..84b5cc2 100644 --- a/src/types/analytics.types.ts +++ b/src/types/analytics.types.ts @@ -117,6 +117,24 @@ export interface DashboardTeam { by_status: LabelCount[] } +export interface VideoDropOffCheckpoint { + checkpoint_percent: number + total_sessions: number + viewers_reached: number + drop_off_rate: number +} + +export interface DashboardVideos { + total_watch_sessions: number + completed_sessions: number + replay_sessions: number + unique_video_starts: number + users_who_replayed: number + completion_rate: number + replay_rate: number + drop_off_by_checkpoint: VideoDropOffCheckpoint[] +} + export type DashboardDateFilterMode = "all_time" | "year" | "year_month" | "custom" export interface DashboardDateFilter { @@ -153,6 +171,7 @@ export interface DashboardData { notifications: DashboardNotifications issues: DashboardIssues team: DashboardTeam + videos?: DashboardVideos } export interface DashboardResponse { From b451f415db9175f9a506bf07e491c29c70ba0e51 Mon Sep 17 00:00:00 2001 From: Yared Yemane Date: Thu, 9 Jul 2026 02:51:45 -0700 Subject: [PATCH 2/3] update subscription plan fix --- .env | 2 +- .../CreateSubscriptionPlanDialog.tsx | 2 +- .../components/EditSubscriptionPlanDialog.tsx | 20 +++++++++++-------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.env b/.env index 4359c69..fa754ed 100644 --- a/.env +++ b/.env @@ -1,3 +1,3 @@ VITE_API_BASE_URL=https://api.yimaruacademy.com/api/v1 # VITE_API_BASE_URL=http://localhost:8432/api/v1 -VITE_GOOGLE_CLIENT_ID= +VITE_GOOGLE_CLIENT_ID= \ No newline at end of file diff --git a/src/pages/settings/components/CreateSubscriptionPlanDialog.tsx b/src/pages/settings/components/CreateSubscriptionPlanDialog.tsx index 8f765f5..695a9cc 100644 --- a/src/pages/settings/components/CreateSubscriptionPlanDialog.tsx +++ b/src/pages/settings/components/CreateSubscriptionPlanDialog.tsx @@ -114,7 +114,7 @@ export function CreateSubscriptionPlanDialog({ toast.success(res.message || "Subscription plan created successfully") onCreated(res.data) onOpenChange(false) - } catch { + } catch (err) { notifyApiError(err, "Failed to create subscription plan.") } finally { setSaving(false) diff --git a/src/pages/settings/components/EditSubscriptionPlanDialog.tsx b/src/pages/settings/components/EditSubscriptionPlanDialog.tsx index d6f37d9..e11e9fb 100644 --- a/src/pages/settings/components/EditSubscriptionPlanDialog.tsx +++ b/src/pages/settings/components/EditSubscriptionPlanDialog.tsx @@ -74,6 +74,13 @@ function draftToPayload(draft: EditDraft): UpdateSubscriptionPlanPayload | null } } +function mergePlanWithPayload( + plan: SubscriptionPlan, + payload: UpdateSubscriptionPlanPayload, +): SubscriptionPlan { + return { ...plan, ...payload } +} + type EditSubscriptionPlanDialogProps = { plan: SubscriptionPlan | null open: boolean @@ -114,18 +121,15 @@ export function EditSubscriptionPlanDialog({ setSaving(true) try { const res = await updateSubscriptionPlan(plan.id, payload) - if (!res.data) { - toast.error("Plan was updated but the response could not be read.") - return - } + const updated = res.data ?? mergePlanWithPayload(plan, payload) toast.success(res.message || "Subscription plan updated successfully") onUpdated({ - ...res.data, - category: res.data.category || plan.category, - created_at: res.data.created_at || plan.created_at, + ...updated, + category: updated.category || plan.category, + created_at: updated.created_at || plan.created_at, }) onOpenChange(false) - } catch { + } catch (err) { notifyApiError(err, "Failed to update subscription plan.") } finally { setSaving(false) From d77d46b549468e4d0838e802bfaf77d3f8a34e37 Mon Sep 17 00:00:00 2001 From: Yared Yemane Date: Thu, 9 Jul 2026 03:26:20 -0700 Subject: [PATCH 3/3] Improve subscription plan management and admin branding. Fetch inactive packages with active_only=false, add in-table status toggles, and replace the default favicon with the Yimaru mascot. Co-authored-by: Cursor --- index.html | 4 +- public/favicon.svg | 8 ++++ src/api/subscription-plans.api.ts | 25 ++++++++---- src/lib/subscriptionPlans.ts | 17 ++++++++ src/pages/DashboardPage.tsx | 2 +- src/pages/settings/SubscriptionPlansTab.tsx | 44 +++++++++++++++++---- 6 files changed, 81 insertions(+), 19 deletions(-) create mode 100644 public/favicon.svg diff --git a/index.html b/index.html index 30949b1..cd76057 100644 --- a/index.html +++ b/index.html @@ -2,9 +2,9 @@ - + - yimaru-admin + Yimaru Admin