1 "use client"
2
3 import clsx from "clsx"
4 import React from "react"
5 import { LearningPathIcon } from "./Icon"
6 import { getLearningPath } from "@/utils"
7 import { useLearningPath } from "@/providers/LearningPath"
8 import { Button } from "@/components/Button"
9 import { Link } from "@/components/Link"
10 import { useNotifications } from "@/providers/Notification"
11 import { CircleMiniSolid } from "@medusajs/icons"
12
13 type LearningPathProps = {
14 pathName: string
15 className?: string
16 } & React.AllHTMLAttributes<HTMLDivElement>
17
18 export const LearningPath = ({
19 pathName,
20 className = "",
21 }: LearningPathProps) => {
22 const path = getLearningPath(pathName)
23 if (!path) {
24 throw new Error(`Learning path ${pathName} does not exist.`)
25 }
26 const { startPath, path: currentPath } = useLearningPath()
27 const notificationContext = useNotifications()
28
29 const handleClick = () => {
30 if (notificationContext && currentPath?.notificationId) {
31 notificationContext.removeNotification(currentPath.notificationId)
32 }
33 startPath(path)
34 }
35
36 return (
37 <div
38 className={clsx(
39 "rounded shadow-elevation-card-rest dark:shadow-elevation-card-rest-dark bg-medusa-bg-subtle mt-docs_1.5 mb-docs_4",
40 className
41 )}
42 >
43 <div
44 className={clsx(
45 "flex items-center gap-docs_1 p-docs_1 border-0 border-b border-solid border-medusa-border-base"
46 )}
47 >
48 <LearningPathIcon />
49 <div className={clsx("basis-3/4")}>
50 <span
51 className={clsx(
52 "text-medusa-fg-base text-compact-large-plus block"
53 )}
54 >
55 {path.label}
56 </span>
57 {path.description && (
58 <span
59 className={clsx(
60 "text-medusa-fg-subtle text-compact-medium mt-docs_0.25 inline-block"
61 )}
62 >
63 {path.description}
64 </span>
65 )}
66 </div>
67 <Button onClick={handleClick} className={clsx("basis-1/4 max-w-fit")}>
68 Start Path
69 </Button>
70 </div>
71 {path.steps.map((step, index) => (
72 <div
73 className={clsx(
74 "flex items-center p-docs_1 gap-docs_1 relative",
75 index !== path.steps.length - 1 &&
76 "border-0 border-b border-solid border-medusa-border-base"
77 )}
78 key={index}
79 >
80 <div className={clsx("w-docs_3 flex items-center justify-center")}>
81 <CircleMiniSolid className="text-medusa-fg-muted" />
82 </div>
83 <span
84 className={clsx("text-medusa-fg-base text-compact-medium-plus")}
85 >
86 {step.title}
87 </span>
88 <Link
89 href={step.path}
90 className={clsx("absolute top-0 left-0 w-full h-full")}
91 />
92 </div>
93 ))}
94 </div>
95 )
96 }