|
| 1 | +import { useEffect, useState } 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 { DurationCard } from "../ui/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 [level, setLevel] = useState(""); |
| 20 | + const { t } = useTranslation() |
| 21 | + const { challenge, community, colors } = useMultiSelector<any, any>({ |
| 22 | + challenge: (state: IRootState) => state.challenges.current, |
| 23 | + community: (state: IRootState) => state.communities.current, |
| 24 | + colors: (state: IRootState) => state.ui.colors |
| 25 | + }) |
| 26 | + |
| 27 | + useEffect(() => { |
| 28 | + if (!challenge?.level) return |
| 29 | + if (challenge.level === 0 || challenge.level === 1) return setLevel("course.challenge.level-0"); |
| 30 | + return setLevel("course.challenge.level-2"); |
| 31 | + }, [challenge.level]); |
| 32 | + |
| 33 | + const courses = data?.courses.map(course => course.name) |
| 34 | + |
| 35 | + return ( |
| 36 | + <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"> |
| 37 | + <div className="flex text-xs items-center justify-between"> |
| 38 | + <div className="gap-2 flex items-center"> |
| 39 | + <div className="h-4.5 w-4.5 rounded-sm" style={{ backgroundColor: colors?.primary }} /> |
| 40 | + <span className="uppercase">{t("communities.card.module")}</span> |
| 41 | + </div> |
| 42 | + <div className="gap-2 flex items-center"> |
| 43 | + <Tag className="uppercase">{t(level)}</Tag> |
| 44 | + <DurationCard value={data.duration} type="bordered" /> |
| 45 | + </div> |
| 46 | + </div> |
| 47 | + |
| 48 | + <div className="flex-grow flex flex-col gap-6"> |
| 49 | + <div className="text-base font-medium leading-normal text-gray-900">{data.title}</div> |
| 50 | + <div className="text-sm font-normal text-gray-700 max-w-xxs">{data.description}</div> |
| 51 | + </div> |
| 52 | + |
| 53 | + {courses.length ? <p className="font-medium text-gray text-tertiary text-sm">{t('learning-module.course.other.appearances')}: {courses.map((course, index) => <Link href={`/communities/${community.slug}/challenges/${challenge?.id}/learning-modules/${data.id}`} key={`other-appearance-counse-${index}`} className="underline ml-1">{course}{index !== courses.length - 1 && ","} </Link>)} </p> : <></>} |
| 54 | + |
| 55 | + <div className="w-full mb-0 justify-self-end"> |
| 56 | + <Link href={"#"}> |
| 57 | + <ArrowButton communityStyles={true} variant="outline-primary"> |
| 58 | + Start now |
| 59 | + </ArrowButton> |
| 60 | + </Link> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + ); |
| 64 | +}; |
| 65 | + |
0 commit comments