Remove customer catalog from staff admin panel

This commit is contained in:
Yared Yemane 2026-11-01 14:09:46 +03:00
parent b9d221024e
commit 15e7e96fee
6 changed files with 1 additions and 156 deletions

View File

@ -83,27 +83,3 @@ test("user learning activity preserves the course chapter lesson tree", async ()
assert.equal(activity.learning.completions.courses.length, 1)
assert.equal("modules" in chapter, false)
})
test("public catalog base strips the admin suffix", async () => {
const { publicApiBase } = await loadModule("src/lib/publicApiBase.ts")
assert.equal(publicApiBase("https://api.example.test/api/v1/admin/"), "https://api.example.test/api/v1")
assert.equal(publicApiBase("/api/v1"), "/api/v1")
})
test("catalog browsing does not send a staff token or cookies", async () => {
const original = globalThis.fetch
const calls = []
globalThis.fetch = async (url, options) => {
calls.push([url, options])
return { ok: true, json: async () => ({ data: { courses: [], total_count: 0 } }) }
}
try {
const api = await loadModule("src/api/publicCatalog.api.ts")
await api.getPublicCourses("hello world", 12)
await api.getPublicCourse(3)
assert.equal(calls[0][0], "/api/v1/catalog/courses?q=hello+world&limit=12&offset=12")
assert.equal(calls[1][0], "/api/v1/catalog/courses/3")
assert.ok(calls.every(([,options]) => options.credentials === "omit" && options.headers === undefined))
} finally { globalThis.fetch = original }
})

View File

@ -1,38 +0,0 @@
import { publicApiBase } from "../lib/publicApiBase"
export type PublicCourse = {
id: number; name: string; description: string; thumbnail: string; access_tier: "FREE" | "PREMIUM"
chapter_count: number; lesson_count: number; quiz_count: number
}
export type PublicCourseOutline = PublicCourse & { chapters: {
id: number; name: string; description: string
lessons: { id: number; title: string; description: string; thumbnail: string; access_tier: "FREE" | "PREMIUM" }[]
quizzes: { id: number; title: string; question_count: number }[]
}[] }
export type PublicCatalogPage = { courses: PublicCourse[]; total_count: number; limit: number; offset: number }
const base = publicApiBase(import.meta.env.VITE_API_BASE_URL ?? "/api/v1")
// Use a separate anonymous client: staff tokens, refresh and login redirects do
// not belong in public discovery, even when a staff session exists in this tab.
async function read<T>(path: string, signal?: AbortSignal): Promise<T> {
const response = await fetch(`${base}${path}`, { signal, credentials: "omit" })
if (!response.ok) throw new Error(response.status === 404 ? "This course is not available." : "Unable to load the course catalog. Please try again.")
const result = await response.json()
return result.data as T
}
export function getPublicCourses(search: string, offset: number, signal?: AbortSignal) {
const params = new URLSearchParams({ q: search, limit: "12", offset: String(offset) })
return read<PublicCatalogPage>(`/catalog/courses?${params}`, signal)
}
export function getPublicCourse(id: number, signal?: AbortSignal) {
return read<PublicCourseOutline>(`/catalog/courses/${id}`, signal)
}
export function catalogThumbnail(value: string): string {
if (!value.startsWith("/static/")) return value
// Static uploads live on the API origin when the UI and API use different hosts.
if (/^https?:\/\//.test(base)) return `${new URL(base).origin}${value}`
return value
}

View File

@ -1,4 +1,3 @@
import { PublicCatalogPage } from "../pages/catalog/PublicCatalogPage";
import { getAccessToken } from "../lib/teamAuthStorage";
import { Navigate, Route, Routes } from "react-router-dom";
import { LearningHierarchyPage } from "../pages/content-management/LearningHierarchyPage";
@ -52,9 +51,7 @@ import { PersonasPage } from "../pages/personas/PersonasPage";
export function AppRoutes() {
return (
<Routes>
<Route path="/" element={getAccessToken() ? <Navigate to={getDefaultAppHome(getNormalizedSessionTeamRole())} replace /> : <PublicCatalogPage />} />
<Route path="/catalog" element={<PublicCatalogPage />} />
<Route path="/catalog/courses/:courseId" element={<PublicCatalogPage />} />
<Route path="/" element={getAccessToken() ? <Navigate to={getDefaultAppHome(getNormalizedSessionTeamRole())} replace /> : <Navigate to="/login" replace />} />
<Route path="/login" element={<LoginPage />} />
<Route path="/forgot-password" element={<ForgotPasswordPage />} />
<Route path="/reset-password" element={<ResetPasswordPage />} />

View File

@ -1,4 +0,0 @@
/** Public discovery must never inherit the staff /admin scope. */
export function publicApiBase(value: string): string {
return value.replace(/\/+$/, "").replace(/\/admin$/, "")
}

View File

@ -234,7 +234,6 @@ export function LoginPage() {
return (
<div className="relative flex min-h-dvh overflow-y-auto bg-[#f4f2ec]">
<Link to="/catalog" className="absolute right-5 top-5 z-10 text-sm font-medium text-[#163d35] underline">Explore courses without signing in</Link>
{/* Decorative left panel */}
<div className="hidden lg:flex lg:w-1/2 xl:w-[55%] items-center justify-center bg-[#163d35] relative">
{/* Abstract decorative shapes */}

View File

@ -1,85 +0,0 @@
import { useEffect, useState } from "react"
import { Link, useParams, useSearchParams } from "react-router-dom"
import { ArrowLeft, ArrowRight, BookOpen, CheckCircle2, LockKeyhole, Search } from "lucide-react"
import { BrandLogo } from "../../components/brand/BrandLogo"
import { catalogThumbnail, getPublicCourse, getPublicCourses, type PublicCatalogPage as Catalog, type PublicCourseOutline } from "../../api/publicCatalog.api"
const learnerApp = import.meta.env.VITE_LEARNER_APP_URL as string | undefined
export function PublicCatalogPage() {
const { courseId } = useParams<{ courseId: string }>()
const [params, setParams] = useSearchParams()
const search = params.get("q") ?? ""
const offset = Math.max(0, Number(params.get("offset")) || 0)
const [draftSearch, setDraftSearch] = useState(search)
const [catalog, setCatalog] = useState<Catalog | null>(null)
const [course, setCourse] = useState<PublicCourseOutline | null>(null)
const [loading, setLoading] = useState(true)
const [error, setError] = useState("")
const [retry, setRetry] = useState(0)
useEffect(() => {
const controller = new AbortController()
async function load() {
setLoading(true); setError(""); setCourse(null)
try {
if (courseId) {
const id = Number(courseId)
if (!Number.isSafeInteger(id) || id < 1) throw new Error("This course is not available.")
const outline = await getPublicCourse(id, controller.signal)
if (!controller.signal.aborted) setCourse(outline)
} else {
const page = await getPublicCourses(search, offset, controller.signal)
if (!controller.signal.aborted) setCatalog(page)
}
} catch (problem) {
if (!controller.signal.aborted) setError(problem instanceof Error ? problem.message : "Unable to load courses.")
} finally { if (!controller.signal.aborted) setLoading(false) }
}
void load()
return () => controller.abort()
}, [courseId, search, offset, retry])
return <div className="min-h-screen bg-[#f7f6f2] text-[#163d35]">
<header className="border-b border-[#163d35]/10 bg-white"><div className="mx-auto flex max-w-6xl items-center justify-between gap-4 px-5 py-5">
<Link to="/catalog" aria-label="Rezina course catalog"><BrandLogo className="h-10" /></Link>
<nav className="flex items-center gap-5 text-sm"><Link to="/catalog" className="font-semibold">Explore courses</Link><Link to="/login" className="rounded-full border border-[#163d35]/20 px-4 py-2">Staff sign in</Link></nav>
</div></header>
<main className="mx-auto max-w-6xl px-5 py-10 sm:py-16">
{courseId ? <Link to={`/catalog${params.size ? `?${params}` : ""}`} className="mb-8 inline-flex items-center gap-2 text-sm"><ArrowLeft size={16} />All courses</Link> : <section className="mb-10 max-w-3xl">
<p className="mb-4 text-xs font-semibold uppercase tracking-[.24em] text-[#987343]">Your next chapter starts here</p>
<h1 className="text-4xl font-semibold leading-tight tracking-tight sm:text-6xl">Build skills.<br />Open new possibilities.</h1>
<p className="mt-5 max-w-xl text-lg leading-relaxed text-[#163d35]/70">Explore our courses, discover what you will learn, and find the right place to begin. Browse every published course without an account.</p>
<form onSubmit={event => { event.preventDefault(); setParams(draftSearch.trim() ? { q: draftSearch.trim() } : {}) }} className="mt-7 flex max-w-xl gap-2 rounded-xl border border-[#163d35]/15 bg-white p-2">
<label className="flex flex-1 items-center gap-3 px-2"><Search size={20} /><input aria-label="Search courses" className="min-w-0 flex-1 bg-transparent py-2 outline-none" placeholder="What would you like to learn?" maxLength={200} value={draftSearch} onChange={event => setDraftSearch(event.target.value)} /></label>
<button className="rounded-lg bg-[#163d35] px-5 text-sm font-semibold text-white">Search</button>
</form>
</section>}
{loading ? <p role="status" className="py-16 text-center">Loading courses...</p> : error ? <div role="alert" className="rounded-2xl border bg-white p-8"><p>{error}</p><button className="mt-4 underline" onClick={() => setRetry(value => value + 1)}>Try again</button></div> : course ? <>
<section className="grid gap-8 rounded-3xl bg-[#163d35] p-7 text-white sm:p-10 md:grid-cols-[1fr_280px]">
<div><p className="mb-3 text-sm text-[#e4c28f]">{course.access_tier === "PREMIUM" ? "Premium course" : "Free course"}</p><h1 className="text-3xl font-semibold sm:text-5xl">{course.name}</h1><p className="mt-5 leading-relaxed text-white/75">{course.description}</p>
<p className="mt-5 text-sm text-white/70">{course.chapter_count} chapters · {course.lesson_count} lessons · {course.quiz_count} quizzes</p>
{learnerApp ? <a href={learnerApp} className="mt-7 inline-flex rounded-full bg-[#e4c28f] px-6 py-3 font-semibold text-[#163d35]">Sign in to learn<ArrowRight className="ml-2" size={18} /></a> : <p className="mt-7 flex items-center gap-2 text-sm"><LockKeyhole size={17} />Sign in through your learning app to watch lessons and take quizzes.</p>}
</div><div className="flex items-center justify-center overflow-hidden rounded-xl bg-white/5">{course.thumbnail ? <img className="h-full max-h-64 w-full object-cover" src={catalogThumbnail(course.thumbnail)} alt="" /> : <BookOpen size={80} className="text-[#e4c28f]" />}</div>
</section>
<section className="mt-12 max-w-4xl"><h2 className="mb-6 text-2xl font-semibold">What you will learn</h2><div className="space-y-4">
{course.chapters.map((chapter, index) => <details key={chapter.id} className="rounded-2xl border border-[#163d35]/10 bg-white p-5" open={index === 0}>
<summary className="cursor-pointer text-lg font-semibold">{index + 1}. {chapter.name}<span className="ml-3 text-sm font-normal text-[#163d35]/60">{chapter.lessons.length} lessons</span></summary>
<p className="mt-3 text-sm text-[#163d35]/70">{chapter.description}</p>
<ul className="mt-4 divide-y divide-[#163d35]/10">{chapter.lessons.map(lesson => <li key={lesson.id} className="flex gap-3 py-4"><BookOpen size={18} className="mt-1 shrink-0" /><div><h3 className="font-medium">{lesson.title}</h3><p className="mt-1 text-sm leading-relaxed text-[#163d35]/65">{lesson.description}</p><span className="mt-2 inline-block text-xs text-[#163d35]/60">{lesson.access_tier === "PREMIUM" ? "Premium lesson" : "Free lesson"}</span></div></li>)}
{chapter.quizzes.map(quiz => <li key={`quiz-${quiz.id}`} className="flex gap-3 py-4"><CheckCircle2 size={18} className="mt-1 shrink-0" /><div><h3 className="font-medium">{quiz.title}</h3><p className="mt-1 text-sm text-[#163d35]/65">Chapter quiz · {quiz.question_count} questions</p></div></li>)}</ul>
</details>)}
{!course.chapters.length && <p>The course outline will be available soon.</p>}
</div></section>
</> : <section aria-label="Course highlights">
<div className="mb-6 flex items-center justify-between"><h2 className="text-2xl font-semibold">{search ? `Results for “${search}”` : "Explore our courses"}</h2><span className="text-sm text-[#163d35]/65">{catalog?.total_count ?? 0} courses</span></div>
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">{catalog?.courses.map(item => <Link key={item.id} to={`/catalog/courses/${item.id}${params.size ? `?${params}` : ""}`} className="group overflow-hidden rounded-2xl border border-[#163d35]/10 bg-white transition hover:-translate-y-1 hover:shadow-lg">
<div className="flex h-44 items-center justify-center overflow-hidden bg-[#163d35]">{item.thumbnail ? <img src={catalogThumbnail(item.thumbnail)} alt="" className="h-full w-full object-cover" loading="lazy" /> : <BookOpen size={55} className="text-[#e4c28f]" />}</div>
<div className="p-6"><span className="text-xs font-semibold uppercase tracking-wide text-[#987343]">{item.access_tier === "PREMIUM" ? "Premium" : "Free"}</span><h3 className="mt-2 text-xl font-semibold">{item.name}</h3><p className="mt-3 line-clamp-3 text-sm leading-relaxed text-[#163d35]/65">{item.description}</p><p className="mt-5 text-xs text-[#163d35]/65">{item.chapter_count} chapters · {item.lesson_count} lessons · {item.quiz_count} quizzes</p><span className="mt-5 inline-flex items-center gap-2 text-sm font-semibold">View course<ArrowRight size={16} /></span></div>
</Link>)}</div>
{!catalog?.courses.length && <p className="rounded-2xl border border-dashed p-12 text-center">{search ? "No courses match your search. Try another topic." : "New courses are on their way. Check back soon."}</p>}
{!!catalog?.total_count && <nav aria-label="Catalog pages" className="mt-8 flex justify-center gap-5"><button className="rounded-full border px-5 py-2 disabled:opacity-40" disabled={offset === 0} onClick={() => setParams({ q: search, offset: String(Math.max(0, offset - 12)) })}>Previous</button><button className="rounded-full border px-5 py-2 disabled:opacity-40" disabled={offset + 12 >= catalog.total_count} onClick={() => setParams({ q: search, offset: String(offset + 12) })}>Next</button></nav>}
</section>}
</main><footer className="mx-auto max-w-6xl px-5 pb-10 text-sm text-[#163d35]/60">Rezina · Learn at your own pace.</footer>
</div>
}