Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: add ui for lesson

Brad Barbin05b7ef81b7d8
diff --git a/apps/university/app/components/Share.tsx b/apps/university/app/components/Share.tsx
new file mode 100644
index 0000000000..a100c34ceb
--- /dev/null
+++ b/apps/university/app/components/Share.tsx
@@ -0,0 +1,65 @@
+import {
+ Button,
+ cn,
+ copyToClipboard,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from "@carbon/react";
+import { useState } from "react";
+import { LuCheck, LuCopy } from "react-icons/lu";
+
+const Share = ({
+ text,
+ className,
+ withTextInTooltip = false,
+}: {
+ text: string;
+ className?: string;
+ withTextInTooltip?: boolean;
+}) => {
+ const [isCopied, setIsCopied] = useState(false);
+
+ const handleCopy = () => {
+ copyToClipboard(text);
+ setIsCopied(true);
+ setTimeout(() => setIsCopied(false), 1500);
+ };
+
+ return (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button
+ variant="secondary"
+ aria-label="Copy"
+ size="sm"
+ className={cn(
+ isCopied && "text-emerald-500 hover:text-emerald-500",
+ className
+ )}
+ rightIcon={
+ isCopied ? (
+ <LuCheck className="w-3 h-3" />
+ ) : (
+ <LuCopy className="w-3 h-3" />
+ )
+ }
+ onClick={handleCopy}
+ >
+ Share
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ <span>
+ {isCopied
+ ? "Copied!"
+ : withTextInTooltip
+ ? text
+ : "Copy link to clipboard"}
+ </span>
+ </TooltipContent>
+ </Tooltip>
+ );
+};
+
+export default Share;
diff --git a/apps/university/app/config.tsx b/apps/university/app/config.tsx
index 0a2f2b6e2b..ff103bc03a 100644
--- a/apps/university/app/config.tsx
+++ b/apps/university/app/config.tsx
@@ -30,14 +30,15 @@ type Topic = {
id: string;
description: string;
challenge: Question[];
- videos: Video[];
+ lessons: Lesson[];
};
type Question = any;
-type Video = {
+type Lesson = {
name: string;
id: string;
+ videoId: string;
description: string;
duration: number;
};
@@ -62,21 +63,25 @@ export const sections: Config = [
description:
"This topic covers the basics of Carbon. Here you will learn what it is, how the platform and modules work, and the architecture.",
challenge: [],
- videos: [
+ lessons: [
{
id: "what-is-carbon",
+ videoId: "1234567890",
name: "What is Carbon?",
- description: "",
+ description:
+ "Meet Carbon, the next generation of accessible, scalable, and data-centric ERP/MES/QMS software. Carbon was designed from the ground up to be approachable and easy to get started with, but highly flexible and capable of scaling up to the largest projects.",
duration: 100,
},
{
id: "about-carbon-modules",
+ videoId: "1234567890",
name: "About Carbon's Modules",
description: "",
duration: 100,
},
{
id: "carbon-architecture",
+ videoId: "1234567890",
name: "Carbon's Architecture",
description: "",
duration: 100,
@@ -96,10 +101,11 @@ export const sections: Config = [
description:
"Learn how to setup your company in Carbon. This includes creating your company, adding users, and setting up your company's preferences. This is the first step to getting your organization ready to use Carbon.",
challenge: [],
- videos: [
+ lessons: [
{
id: "company-setup",
name: "Company Setup",
+ videoId: "1234567890",
description:
"Learn how to setup your company in Carbon. This includes creating your company, adding users, and setting up your company's preferences. This is the first step to getting your organization ready to use Carbon.",
duration: 100,
@@ -107,6 +113,7 @@ export const sections: Config = [
{
id: "users-setup",
name: "Users & Permissions",
+ videoId: "1234567890",
description:
"Learn how to setup your users in Carbon. This includes creating your users, adding users, and setting up your users' preferences.",
duration: 100,
@@ -114,6 +121,7 @@ export const sections: Config = [
{
id: "resources-setup",
name: "Resources",
+ videoId: "1234567890",
description:
"Learn how to setup your work centers, machines, and processes in Carbon. This is the first step to getting your organization ready to use Carbon.",
duration: 100,
@@ -121,6 +129,7 @@ export const sections: Config = [
{
id: "integrations-setup",
name: "Integrations",
+ videoId: "1234567890",
description: "Learn how to setup your integrations in Carbon.",
duration: 100,
},
@@ -131,7 +140,7 @@ export const sections: Config = [
],
},
{
- name: "Bill of Materials",
+ name: "Parts & Materials",
background: "#4AA99D",
foreground: "#fff",
id: "bom",
@@ -163,7 +172,7 @@ export const sections: Config = [
courses: [],
},
{
- name: "Quality",
+ name: "Shipping & Receiving",
background: "#EF8729",
foreground: "#fff",
id: "quality",
@@ -171,7 +180,7 @@ export const sections: Config = [
courses: [],
},
{
- name: "Developing",
+ name: "Quality",
background: "#DD6444",
foreground: "#fff",
id: "developing",
@@ -179,19 +188,19 @@ export const sections: Config = [
courses: [],
},
{
- name: "Example",
- background: "#AB7DB3",
+ name: "Developing",
+ background: "#8487C5", // "#AB7DB3",
foreground: "#fff",
id: "example-1",
icon: <LuCrown />,
courses: [],
},
- {
- name: "Example",
- background: "#8487C5",
- foreground: "#fff",
- id: "example-2",
- icon: <LuCrown />,
- courses: [],
- },
+ // {
+ // name: "Example",
+ // background: "#8487C5",
+ // foreground: "#fff",
+ // id: "example-2",
+ // icon: <LuCrown />,
+ // courses: [],
+ // },
];
diff --git a/apps/university/app/root.tsx b/apps/university/app/root.tsx
index 9f59e1f62e..f0b4fca3c3 100644
--- a/apps/university/app/root.tsx
+++ b/apps/university/app/root.tsx
@@ -4,7 +4,14 @@ import {
getSessionFlash,
} from "@carbon/auth/session.server";
import { validator } from "@carbon/form";
-import { Button, Heading, IconButton, toast, Toaster } from "@carbon/react";
+import {
+ Button,
+ Heading,
+ IconButton,
+ toast,
+ Toaster,
+ TooltipProvider,
+} from "@carbon/react";
import {
isRouteErrorResponse,
Link,
@@ -145,7 +152,7 @@ function Document({
<Links />
</head>
<body className="h-full bg-background antialiased selection:bg-primary/10 selection:text-primary">
- {children}
+ <TooltipProvider>{children}</TooltipProvider>
<Toaster position="bottom-right" visibleToasts={5} />
<ScrollRestoration />
<Scripts />
diff --git a/apps/university/app/routes/about.tsx b/apps/university/app/routes/about.tsx
index d1cc2096af..badf4f7d82 100644
--- a/apps/university/app/routes/about.tsx
+++ b/apps/university/app/routes/about.tsx
@@ -74,8 +74,8 @@ export default function AboutRoute() {
asChild
>
<Link
- to={path.to.video(
- sections[0].courses[0].topics[0].videos[0].id
+ to={path.to.lesson(
+ sections[0].courses[0].topics[0].lessons[0].id
)}
>
Begin your first lesson
diff --git a/apps/university/app/routes/test+/_index.tsx b/apps/university/app/routes/challenge+/_index.tsx
similarity index 100%
rename from apps/university/app/routes/test+/_index.tsx
rename to apps/university/app/routes/challenge+/_index.tsx
diff --git a/apps/university/app/routes/test+/_layout.tsx b/apps/university/app/routes/challenge+/_layout.tsx
similarity index 100%
rename from apps/university/app/routes/test+/_layout.tsx
rename to apps/university/app/routes/challenge+/_layout.tsx
diff --git a/apps/university/app/routes/course+/$sectionId.$courseId.tsx b/apps/university/app/routes/course+/$sectionId.$courseId.tsx
index 6c0767b4c6..78d686e627 100644
--- a/apps/university/app/routes/course+/$sectionId.$courseId.tsx
+++ b/apps/university/app/routes/course+/$sectionId.$courseId.tsx
@@ -12,7 +12,9 @@ export default function CourseRoute() {
const totalDuration =
course?.topics.reduce((acc, topic) => {
- return acc + topic.videos.reduce((acc, video) => acc + video.duration, 0);
+ return (
+ acc + topic.lessons.reduce((acc, lesson) => acc + lesson.duration, 0)
+ );
}, 0) ?? 0;
const totalChallenges =
@@ -113,18 +115,18 @@ export default function CourseRoute() {
</div>
<div className="flex flex-col gap-8 py-8 w-full text-sm">
<div className="flex flex-col gap-0">
- {topic.videos.map((video) => (
+ {topic.lessons.map((lesson) => (
<Link
- key={video.id}
- to={path.to.video(video.id)}
+ key={lesson.id}
+ to={path.to.lesson(lesson.id)}
className="flex items-center justify-between gap-2 w-full rounded-md py-1.5 px-3 hover:bg-accent"
>
<div className="flex items-center gap-2">
<LuCirclePlay className="size-4 text-muted-foreground" />
- <span>{video.name}</span>
+ <span>{lesson.name}</span>
</div>
<span className="text-muted-foreground text-xs">
- {formatDuration(video.duration)}
+ {formatDuration(lesson.duration)}
</span>
</Link>
))}
@@ -133,8 +135,11 @@ export default function CourseRoute() {
<Button
leftIcon={<LuFlag className="size-4" />}
variant="secondary"
+ asChild
>
- Take Topic Challenge
+ <Link to={path.to.challenge(topic.id)}>
+ Take Topic Challenge
+ </Link>
</Button>
)}
</div>
diff --git a/apps/university/app/routes/course+/_layout.tsx b/apps/university/app/routes/course+/_layout.tsx
index a1751e6930..09f8c4afdd 100644
--- a/apps/university/app/routes/course+/_layout.tsx
+++ b/apps/university/app/routes/course+/_layout.tsx
@@ -30,8 +30,8 @@ export default function CourseLayout() {
asChild
>
<Link
- to={path.to.video(
- sections[0].courses[0].topics[0].videos[0].id
+ to={path.to.lesson(
+ sections[0].courses[0].topics[0].lessons[0].id
)}
>
Begin your first lesson
diff --git a/apps/university/app/routes/lesson+/$id.tsx b/apps/university/app/routes/lesson+/$id.tsx
new file mode 100644
index 0000000000..f5d7ad38c0
--- /dev/null
+++ b/apps/university/app/routes/lesson+/$id.tsx
@@ -0,0 +1,199 @@
+import { Button } from "@carbon/react";
+import { Link, useParams } from "@remix-run/react";
+import {
+ LuChevronLeft,
+ LuChevronRight,
+ LuCirclePlay,
+ LuFlag,
+} from "react-icons/lu";
+import Share from "~/components/Share";
+import { path } from "~/utils/path";
+import {
+ findLessonContext,
+ findNextLesson,
+ findPreviousLesson,
+ formatDuration,
+} from "~/utils/video";
+
+export default function LessonRoute() {
+ const { id } = useParams();
+
+ if (!id) {
+ throw new Error("Lesson ID is required");
+ }
+
+ const context = findLessonContext(id);
+
+ if (!context) {
+ throw new Error("Lesson not found");
+ }
+
+ const { section, course, topic, lesson } = context;
+ const nextLesson = findNextLesson(id);
+ const previousLesson = findPreviousLesson(id);
+
+ return (
+ <div className="w-full px-4 max-w-6xl mx-auto mt-4 pb-24 flex flex-col gap-8">
+ <div className="flex items-center gap-2">
+ <Button variant="primary" leftIcon={<LuChevronLeft />} asChild>
+ <Link to={path.to.course(section.id, course.id)}>Back to course</Link>
+ </Button>
+
+ <Button
+ variant="link"
+ className="text-sm text-muted-foreground"
+ asChild
+ >
+ <Link to={path.to.course(section.id, course.id)}>{course.name}</Link>
+ </Button>
+
+ <span className="text-muted-foreground text-sm">/</span>
+
+ <span className="text-muted-foreground text-sm font-bold">
+ {topic.name}
+ </span>
+ </div>
+
+ <div className="flex flex-col w-full">
+ <div className="w-full aspect-video bg-black rounded-t-lg overflow-hidden">
+ <iframe
+ src={`https://player.vimeo.com/video/${lesson.videoId}?h=00000000&badge=0&autopause=0&player_id=0&app_id=58479`}
+ allow="autoplay; fullscreen; picture-in-picture"
+ className="w-full h-full"
+ title={lesson.name}
+ />
+ </div>
+ <div
+ className="w-full h-12 rounded-b-lg flex items-center justify-end px-3"
+ style={{
+ backgroundColor: section.background,
+ }}
+ >
+ <Share
+ text={typeof window !== "undefined" ? window.location.href : ""}
+ />
+ </div>
+ </div>
+
+ <div className="grid grid-cols-1 md:grid-cols-[1fr_360px] gap-6">
+ <div className="flex flex-col w-full">
+ <div
+ className="border rounded rounded-b-none p-4"
+ style={{
+ backgroundColor: section?.background,
+ color: section?.foreground,
+ }}
+ >
+ <div className="flex flex-col gap-4">
+ <div className="flex items-start gap-4">
+ <div
+ className="flex-shrink-0 size-12 text-2xl p-3 rounded-full border"
+ style={{
+ backgroundColor: section?.background,
+ borderColor: section?.foreground,
+ color: section?.foreground,
+ }}
+ >
+ {section?.icon}
+ </div>
+ <div className="flex flex-col">
+ <h1 className="uppercase text-[10px] font-display font-bold">
+ Lesson
+ </h1>
+ <h2 className="text-2xl font-display tracking-tight">
+ {lesson.name}
+ </h2>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div className="flex flex-col gap-4 border rounded-b border-t-0 px-6 py-4">
+ <h4 className="text-lg font-display font-bold">Description</h4>
+ <p className="text-base text-muted-foreground">
+ {lesson.description}
+ </p>
+ </div>
+ </div>
+
+ {/* Right Sidebar */}
+ <div className="flex flex-col gap-4">
+ {/* Navigation Buttons */}
+ <div className="flex gap-2">
+ <Button
+ variant="secondary"
+ leftIcon={<LuChevronLeft className="size-4" />}
+ disabled={!previousLesson}
+ asChild={!!previousLesson}
+ className={!previousLesson ? "opacity-50 cursor-not-allowed" : ""}
+ >
+ {previousLesson ? (
+ <Link to={path.to.lesson(previousLesson.id)}>
+ Previous Lesson
+ </Link>
+ ) : (
+ <span>Previous Lesson</span>
+ )}
+ </Button>
+
+ <Button
+ variant={!nextLesson ? "secondary" : "primary"}
+ rightIcon={<LuChevronRight className="size-4" />}
+ disabled={!nextLesson}
+ asChild={!!nextLesson}
+ className={!nextLesson ? "opacity-50 cursor-not-allowed" : ""}
+ >
+ {nextLesson ? (
+ <Link to={path.to.lesson(nextLesson.id)}>Next Lesson</Link>
+ ) : (
+ <span>Next Lesson</span>
+ )}
+ </Button>
+ </div>
+
+ {/* Lesson List */}
+ <div className="border rounded-lg p-4">
+ <h3 className="text-sm font-display font-bold text-muted-foreground mb-3">
+ Lessons in this topic
+ </h3>
+ <div className="flex flex-col gap-1">
+ {topic.lessons.map((topicLesson) => (
+ <Link
+ key={topicLesson.id}
+ to={path.to.lesson(topicLesson.id)}
+ className={`flex items-center justify-between gap-2 w-full rounded-md py-2 px-3 text-sm transition-colors ${
+ topicLesson.id === lesson.id
+ ? "bg-accent text-accent-foreground"
+ : "hover:bg-accent"
+ }`}
+ >
+ <div className="flex items-center gap-2">
+ <LuCirclePlay className="size-4 text-muted-foreground" />
+ <span
+ className={
+ topicLesson.id === lesson.id ? "font-medium" : ""
+ }
+ >
+ {topicLesson.name}
+ </span>
+ </div>
+ <span className="text-muted-foreground text-xs">
+ {formatDuration(topicLesson.duration)}
+ </span>
+ </Link>
+ ))}
+ </div>
+ </div>
+ {topic.challenge && (
+ <Button
+ variant={!nextLesson ? "primary" : "secondary"}
+ leftIcon={<LuFlag className="size-4" />}
+ asChild
+ >
+ <Link to={path.to.challenge(topic.id)}>Take Topic Challenge</Link>
+ </Button>
+ )}
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/university/app/utils/path.ts b/apps/university/app/utils/path.ts
index 44a9806b22..039facb392 100644
--- a/apps/university/app/utils/path.ts
+++ b/apps/university/app/utils/path.ts
@@ -1,8 +1,9 @@
import { getAppUrl, SUPABASE_URL } from "@carbon/auth";
import { generatePath } from "@remix-run/react";
+const challenge = "/challenge"; // from ~/routes/challenge+ folder
const course = "/course"; // from ~/routes/course+ folder
-const video = "/video"; // from ~/routes/video+ folder
+const lesson = "/lesson"; // from ~/routes/lesson+ folder
const ERP_URL = getAppUrl();
@@ -11,6 +12,7 @@ export const path = {
about: "/about",
accountSettings: `${ERP_URL}/x/account`,
callback: "/callback",
+ challenge: (topicId: string) => generatePath(`${challenge}/${topicId}`),
course: (sectionId: string, courseId: string) =>
generatePath(`${course}/${sectionId}/${courseId}`),
dashboard: `${ERP_URL}/x`,
@@ -19,7 +21,7 @@ export const path = {
logout: "/logout",
refreshSession: "/refresh-session",
root: "/",
- video: (id: string) => generatePath(`${video}/${id}`),
+ lesson: (id: string) => generatePath(`${lesson}/${id}`),
},
} as const;
diff --git a/apps/university/app/utils/video.ts b/apps/university/app/utils/video.ts
index 0bc542d808..44fa7e5b8e 100644
--- a/apps/university/app/utils/video.ts
+++ b/apps/university/app/utils/video.ts
@@ -1,5 +1,60 @@
+import { sections } from "~/config";
+
export function formatDuration(duration: number) {
const minutes = Math.floor(duration / 60);
const seconds = duration % 60;
return `${minutes}:${seconds.toString().padStart(2, "0")}`;
}
+
+export function findLessonContext(lessonId: string) {
+ for (const section of sections) {
+ for (const course of section.courses) {
+ for (const topic of course.topics) {
+ const lesson = topic.lessons.find(
+ (lesson: { id: string }) => lesson.id === lessonId
+ );
+ if (lesson) {
+ return {
+ section,
+ course,
+ topic,
+ lesson,
+ };
+ }
+ }
+ }
+ }
+ return null;
+}
+
+export function findNextLesson(lessonId: string) {
+ const context = findLessonContext(lessonId);
+ if (!context) return null;
+
+ const { topic } = context;
+ const currentIndex = topic.lessons.findIndex(
+ (lesson) => lesson.id === lessonId
+ );
+
+ if (currentIndex === -1 || currentIndex === topic.lessons.length - 1) {
+ return null;
+ }
+
+ return topic.lessons[currentIndex + 1];
+}
+
+export function findPreviousLesson(lessonId: string) {
+ const context = findLessonContext(lessonId);
+ if (!context) return null;
+
+ const { topic } = context;
+ const currentIndex = topic.lessons.findIndex(
+ (lesson) => lesson.id === lessonId
+ );
+
+ if (currentIndex <= 0) {
+ return null;
+ }
+
+ return topic.lessons[currentIndex - 1];
+}
diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx
index e7a6b5a469..bf0ee2e1bc 100644
--- a/packages/react/src/index.tsx
+++ b/packages/react/src/index.tsx
@@ -295,6 +295,7 @@ import type {
ShortcutDefinition,
} from "./hooks/useShortcutKeys";
import { cn } from "./utils/cn";
+import { copyToClipboard } from "./utils/dom";
import { getValidChildren, reactNodeToString } from "./utils/react";
export * from "./hooks";
@@ -551,6 +552,7 @@ export {
VStack,
buttonVariants,
cn,
+ copyToClipboard,
getValidChildren,
multiSelectTriggerVariants,
reactNodeToString,