import { For, Show, createMemo, createSignal, onMount } from "solid-js"; import { HelpCircle } from "lucide-solid"; import { BTN_GHOST, CARD, INPUT } from "~/components/DashboardShell"; import { type RoleKey } from "./RoleDashboardShared"; const API = ""; const NAVY = "#0D0D2A"; const ORANGE = "#FF5E13"; type Props = { roleKey: RoleKey }; type Category = { id: string; name: string; slug: string; description?: string }; type Article = { id: string; title: string; slug: string; summary?: string; category?: string; updatedAt?: string; }; async function apiFetch(path: string, opts?: RequestInit) { const token = typeof window !== "undefined" ? window.sessionStorage.getItem("nxtgauge_access_token") || "" : ""; return fetch(`${API}${path}`, { ...opts, credentials: "include", headers: { "Content-Type": "application/json", ...(token ? { Authorization: `Bearer ${token}` } : {}), ...(opts?.headers ?? {}), }, }); } function normalizeArticle(raw: any): Article { return { id: String(raw?.id || ""), title: String(raw?.title || ""), slug: String(raw?.slug || ""), summary: raw?.summary ? String(raw.summary) : "", category: String(raw?.category || raw?.category_name || ""), updatedAt: String(raw?.updatedAt || raw?.updated_at || ""), }; } export default function HelpCenterDashboardPage(props: Props) { const [categories, setCategories] = createSignal([]); const [articles, setArticles] = createSignal([]); const [loading, setLoading] = createSignal(true); const [search, setSearch] = createSignal(""); const [err, setErr] = createSignal(""); const loadData = async () => { setLoading(true); setErr(""); try { const [catRes, artRes] = await Promise.all([ apiFetch("/api/kb/categories"), apiFetch(`/api/kb/articles?role=${encodeURIComponent(props.roleKey)}&page=1&limit=200`), ]); const catJson = await catRes.json().catch(() => ({})); const artJson = await artRes.json().catch(() => ({})); if (catRes.ok) { const catList = Array.isArray(catJson?.categories) ? catJson.categories : Array.isArray(catJson) ? catJson : []; setCategories(catList); } if (artRes.ok) { const rawArticles = Array.isArray(artJson?.articles) ? artJson.articles : Array.isArray(artJson) ? artJson : []; setArticles( rawArticles .map(normalizeArticle) .filter((a: Article) => Boolean(a.id && a.slug && a.title)) ); } if (!catRes.ok && !artRes.ok) setErr("Failed to load help center resources."); } catch { setErr("Network error while loading help center."); } finally { setLoading(false); } }; onMount(loadData); const filtered = createMemo(() => { const q = search().trim().toLowerCase(); if (!q) return articles(); return articles().filter( (a) => String(a.title || "") .toLowerCase() .includes(q) || String(a.summary || "") .toLowerCase() .includes(q) || String(a.category || "") .toLowerCase() .includes(q) ); }); return (

Help Center

Find guides and articles for your role.

{err()}
setSearch(e.currentTarget.value)} style={INPUT} placeholder="Search help articles" />

Loading help center...

0}>

Categories

{(cat) => (

{cat.name}

{cat.description || "Knowledge base category"}

)}

Articles

No articles found.

0}>
); }