import { For, Show } from "solid-js"; import { Link } from "@tanstack/solid-router"; import { createResource } from "@/lib/create-resource"; import { getAcademicYears } from "@/api/academic-years"; import { getClasses } from "@/api/classes"; import { getCourses } from "@/api/courses"; import { getUserSearch } from "@/api/users"; import { IconCheck, IconChevronRight } from "@/components/ui/icons"; import { cn } from "@/lib/cn"; import type { MessageKey } from "@/i18n/messages"; import { useT } from "@/stores/preferences-context"; type Step = { id: string; labelKey: MessageKey; to: string; module?: string; /** How many exist now; the step is done at one or more. */ count: () => Promise; }; const STEPS: Step[] = [ { id: "year", labelKey: "setup.academicYear", to: "/management/academic-years", count: async () => (await getAcademicYears({ limit: 1 })).total }, { id: "teachers", labelKey: "setup.teachers", to: "/management/teachers", count: async () => (await getUserSearch("", undefined, "teacher", { limit: 1 })).total }, { id: "students", labelKey: "setup.students", to: "/management/students", count: async () => (await getUserSearch("", undefined, "student", { limit: 1 })).total }, { id: "classes", labelKey: "setup.classes", to: "/management/classes", module: "classes", count: async () => (await getClasses({ limit: 1 })).total }, { id: "courses", labelKey: "setup.courses", to: "/courses", module: "courses", count: async () => (await getCourses({ limit: 1 })).total }, ]; /** * ADM "school setup": the five things a new school needs before the rest of * the app has anything to show, each ticked by a real count (at least one * exists) and linking to where it is added. A read that fails leaves its step * unknown rather than claiming it done or missing. Once every step is done * the panel steps aside. */ export function SetupChecklistPanel(props: { moduleOn: (module: string) => boolean }) { const t = useT(); const [status] = createResource(async () => { const steps = STEPS.filter((step) => !step.module || props.moduleOn(step.module)); return Promise.all( steps.map(async (step) => ({ step, done: await step.count().then((total) => total > 0).catch(() => null) })), ); }); const doneCount = () => (status() ?? []).filter((row) => row.done === true).length; const allDone = () => (status() ?? []).length > 0 && doneCount() === status()!.length; return (

{t("setup.title")}

{t("setup.progress", { done: doneCount(), total: status()!.length })}
    {(row) => (
  1. {t(row.step.labelKey)} {row.done === true ? t("setup.done") : row.done === false ? t("setup.todo") : t("setup.unknown")}
  2. )}
); }