|
| 1 | +import { Fragment, useMemo } from "react"; |
| 2 | +import ArrowButton from "@/components/ui/button/Arrow"; |
| 3 | +import Link from "next/link"; |
| 4 | +import { useTranslation } from "next-i18next"; |
| 5 | +import Tag from "../ui/Tag"; |
| 6 | +import { DurationBadge } from "@/components/badges/Duration"; |
| 7 | +import { useMultiSelector } from "@/hooks/useTypedSelector"; |
| 8 | +import { IRootState } from "@/store"; |
| 9 | +import { LearningModule } from "@/types/course"; |
| 10 | + |
| 11 | +/** |
| 12 | + * Props for the RelatedLearning component. |
| 13 | + */ |
| 14 | + |
| 15 | +/** |
| 16 | + * Component that displays related learning material with a title, description, and "Start now" button. |
| 17 | + */ |
| 18 | +export function LearningModuleCard({ data }: { data: LearningModule }): JSX.Element { |
| 19 | + const { t } = useTranslation() |
| 20 | + const { challenge, community, colors } = useMultiSelector<any, any>({ |
| 21 | + challenge: (state: IRootState) => state.challenges.current, |
| 22 | + community: (state: IRootState) => state.communities.current, |
| 23 | + colors: (state: IRootState) => state.ui.colors |
| 24 | + }) |
| 25 | + |
| 26 | + const level = useMemo(() => { |
| 27 | + const value = challenge?.level; |
| 28 | + return t((value === 0 || value === 1) ? "course.challenge.level-0" : "course.challenge.level-2"); |
| 29 | + }, [challenge?.level]); |
| 30 | + |
| 31 | + const courses = data?.courses.map(course => ({ name: course.name, slug: course.slug })) |
| 32 | + |
| 33 | + return ( |
| 34 | + <div className="flex flex-col content-start w-full p-8 rounded-3xl group text-gray-700 border-solid border border-gray-200 gap-8"> |
| 35 | + <div className="flex flex-wrap gap-2 text-xs items-center justify-between"> |
| 36 | + <div className="gap-2 flex items-center"> |
| 37 | + <div className="h-4.5 w-4.5 rounded-sm" style={{ backgroundColor: colors?.primary }} /> |
| 38 | + <span className="uppercase font-semibold">{t("communities.card.module")}</span> |
| 39 | + </div> |
| 40 | + <div className="gap-2 flex items-center"> |
| 41 | + {challenge.level && <Tag className="uppercase">{level}</Tag>} |
| 42 | + <DurationBadge value={data.duration} type="bordered" /> |
| 43 | + </div> |
| 44 | + </div> |
| 45 | + |
| 46 | + <div className="flex-grow flex flex-col gap-6"> |
| 47 | + <div className="text-base font-medium leading-normal text-gray-900">{data.title}</div> |
| 48 | + <div className="text-sm font-normal text-gray-700 max-w-xxs">{data.description}</div> |
| 49 | + </div> |
| 50 | + |
| 51 | + {courses.length ? |
| 52 | + <p className="font-medium text-gray text-tertiary text-sm"> |
| 53 | + {t('learning-module.course.other.appearances')} |
| 54 | + {courses.map((course, index) => |
| 55 | + <Fragment key={`related-course-${index}`}> |
| 56 | + <Link |
| 57 | + key={`other-appearance-course-${index}`} |
| 58 | + href={`/communities/${community.slug}/courses/${course?.slug}`} |
| 59 | + className="hover:underline ml-1">{course.name} |
| 60 | + </Link> |
| 61 | + {index !== courses.length - 1 && ","} |
| 62 | + </Fragment> |
| 63 | + )} |
| 64 | + </p> |
| 65 | + : |
| 66 | + <></>} |
| 67 | + |
| 68 | + <div className="w-full mb-0 justify-self-end"> |
| 69 | + <Link href={`/communities/${community.slug}/challenges/${challenge?.id}/learning-modules/${data.id}`}> |
| 70 | + <ArrowButton communityStyles={true} variant="outline-primary"> |
| 71 | + {t("communities.overview.challenge.learning.start")} |
| 72 | + </ArrowButton> |
| 73 | + </Link> |
| 74 | + </div> |
| 75 | + </div> |
| 76 | + ); |
| 77 | +}; |
| 78 | + |
0 commit comments