From 15e7e96fee8912216e548efed168db4340dc913e Mon Sep 17 00:00:00 2001 From: Yared Yemane Date: Sun, 1 Nov 2026 14:09:46 +0300 Subject: [PATCH] Remove customer catalog from staff admin panel --- scripts/learning-integration.test.mjs | 24 ------- src/api/publicCatalog.api.ts | 38 ----------- src/app/AppRoutes.tsx | 5 +- src/lib/publicApiBase.ts | 4 -- src/pages/auth/LoginPage.tsx | 1 - src/pages/catalog/PublicCatalogPage.tsx | 85 ------------------------- 6 files changed, 1 insertion(+), 156 deletions(-) delete mode 100644 src/api/publicCatalog.api.ts delete mode 100644 src/lib/publicApiBase.ts delete mode 100644 src/pages/catalog/PublicCatalogPage.tsx diff --git a/scripts/learning-integration.test.mjs b/scripts/learning-integration.test.mjs index e295a2c..79176d4 100644 --- a/scripts/learning-integration.test.mjs +++ b/scripts/learning-integration.test.mjs @@ -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 } -}) diff --git a/src/api/publicCatalog.api.ts b/src/api/publicCatalog.api.ts deleted file mode 100644 index 39f912d..0000000 --- a/src/api/publicCatalog.api.ts +++ /dev/null @@ -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(path: string, signal?: AbortSignal): Promise { - 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(`/catalog/courses?${params}`, signal) -} -export function getPublicCourse(id: number, signal?: AbortSignal) { - return read(`/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 -} diff --git a/src/app/AppRoutes.tsx b/src/app/AppRoutes.tsx index 8d56ede..ecb0785 100644 --- a/src/app/AppRoutes.tsx +++ b/src/app/AppRoutes.tsx @@ -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 ( - : } /> - } /> - } /> + : } /> } /> } /> } /> diff --git a/src/lib/publicApiBase.ts b/src/lib/publicApiBase.ts deleted file mode 100644 index 6fd0bc1..0000000 --- a/src/lib/publicApiBase.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** Public discovery must never inherit the staff /admin scope. */ -export function publicApiBase(value: string): string { - return value.replace(/\/+$/, "").replace(/\/admin$/, "") -} diff --git a/src/pages/auth/LoginPage.tsx b/src/pages/auth/LoginPage.tsx index 4b07215..b727870 100644 --- a/src/pages/auth/LoginPage.tsx +++ b/src/pages/auth/LoginPage.tsx @@ -234,7 +234,6 @@ export function LoginPage() { return (
- Explore courses without signing in {/* Decorative left panel */}
{/* Abstract decorative shapes */} diff --git a/src/pages/catalog/PublicCatalogPage.tsx b/src/pages/catalog/PublicCatalogPage.tsx deleted file mode 100644 index 0a5fb5f..0000000 --- a/src/pages/catalog/PublicCatalogPage.tsx +++ /dev/null @@ -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(null) - const [course, setCourse] = useState(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
-
- - -
-
- {courseId ? All courses :
-

Your next chapter starts here

-

Build skills.
Open new possibilities.

-

Explore our courses, discover what you will learn, and find the right place to begin. Browse every published course without an account.

-
{ 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"> - - -
-
} - {loading ?

Loading courses...

: error ?

{error}

: course ? <> -
-

{course.access_tier === "PREMIUM" ? "Premium course" : "Free course"}

{course.name}

{course.description}

-

{course.chapter_count} chapters · {course.lesson_count} lessons · {course.quiz_count} quizzes

- {learnerApp ? Sign in to learn :

Sign in through your learning app to watch lessons and take quizzes.

} -
{course.thumbnail ? : }
-
-

What you will learn

- {course.chapters.map((chapter, index) =>
- {index + 1}. {chapter.name}{chapter.lessons.length} lessons -

{chapter.description}

-
    {chapter.lessons.map(lesson =>
  • {lesson.title}

    {lesson.description}

    {lesson.access_tier === "PREMIUM" ? "Premium lesson" : "Free lesson"}
  • )} - {chapter.quizzes.map(quiz =>
  • {quiz.title}

    Chapter quiz · {quiz.question_count} questions

  • )}
-
)} - {!course.chapters.length &&

The course outline will be available soon.

} -
- :
-

{search ? `Results for “${search}”` : "Explore our courses"}

{catalog?.total_count ?? 0} courses
-
{catalog?.courses.map(item => -
{item.thumbnail ? : }
-
{item.access_tier === "PREMIUM" ? "Premium" : "Free"}

{item.name}

{item.description}

{item.chapter_count} chapters · {item.lesson_count} lessons · {item.quiz_count} quizzes

View course
- )}
- {!catalog?.courses.length &&

{search ? "No courses match your search. Try another topic." : "New courses are on their way. Check back soon."}

} - {!!catalog?.total_count && } -
} -
-
-}