Skip to content

Commit 7cd14fa

Browse files
Merge branch 'dev' into ft/learning-module-card
2 parents 115e9ef + 7874f9b commit 7cd14fa

File tree

12 files changed

+143
-59
lines changed

12 files changed

+143
-59
lines changed

public/locales/bg/common.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@
122122
"communities.overview.challenge.learning.modules.included": "Включени образователни модули",
123123
"communities.overview.challenge.no.learning.modules": "Без включени образователни модули",
124124
"communities.overview.challenge.learning.title": "Следните учебни материали ще ви осигурят техническите умения, необходими за успешното справяне с предизвикателството.",
125+
"communities.overview.challenge.course": "КУРС",
126+
"communities.overview.challenge.course.learningModule": "{{count}} един учебен материал включен",
127+
"communities.overview.challenge.course.learningModules": "{{count}} единични учебни материали включени",
125128
"communities.overview.challenge.learning.start": "започнете сега",
126129
"communities.overview.challenge.team.setup.title": "Създайте вашия екип",
127130
"communities.overview.challenge.team.setup.description": "Изберете от 1 до 3 члена, които да се присъединят към предизвикателството.",

public/locales/en/common.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@
128128
"communities.overview.challenge.learning.modules.included": "Learning modules included",
129129
"communities.overview.challenge.no.learning.modules": "No learning modules included",
130130
"communities.overview.challenge.learning.title": "The following learning materials will equip you with the technical expertise required to successfully address the challenge.",
131+
"communities.overview.challenge.course": "COURSE",
132+
"communities.overview.challenge.course.learningModule": "{{count}} Single learning module included",
133+
"communities.overview.challenge.course.learningModules": "{{count}} Single learning modules included",
131134
"communities.overview.challenge.learning.start": "Start now",
132135
"communities.overview.challenge.team.setup.title": "Form your team",
133136
"communities.overview.challenge.team.setup.description": "Select from 1 to 3 members to join you in the challenge.",

public/locales/es/common.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@
127127
"communities.overview.challenge.learning.modules.included": "Módulos de aprendizaje incluidos",
128128
"communities.overview.challenge.no.learning.modules": "No se incluyen módulos de aprendizaje",
129129
"communities.overview.challenge.learning.title": "Los siguientes materiales de aprendizaje le proporcionarán la experiencia técnica necesaria para abordar con éxito el desafío.",
130+
"communities.overview.challenge.course": "CURSO",
131+
"communities.overview.challenge.course.learningModule": "{{count}} Módulo de aprendizaje único incluido",
132+
"communities.overview.challenge.course.learningModules": "{{count}} Módulos de aprendizaje únicos incluidos",
130133
"communities.overview.challenge.learning.start": "Comenzar ahora",
131134
"communities.overview.challenge.team.setup.title": "Forma tu equipo",
132135
"communities.overview.challenge.team.setup.description": "Selecciona de 1 a 3 miembros para que se unan a ti en el desafío.",

public/locales/hr/common.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@
176176
"communities.overview.challenge.learning.modules.included": "Uključeni moduli učenja",
177177
"communities.overview.challenge.no.learning.modules": "Nema uključenih modula učenja",
178178
"communities.overview.challenge.learning.title": "Sljedeći materijali za učenje opskrbit će vas tehničkim stručnostima potrebnim za uspješno rješavanje izazova.",
179+
"communities.overview.challenge.course": "TEČAJ",
180+
"communities.overview.challenge.course.learningModule": "{{count}} pojedini učeni materijal uključen",
181+
"communities.overview.challenge.course.learningModules": "{{count}} pojedinih učeni materijala uključeni",
179182
"communities.overview.challenge.learning.start": "Počnite sada",
180183
"communities.overview.challenge.team.setup.title": "Sastavite svoj tim",
181184
"communities.overview.challenge.team.setup.description": "Odaberite između 1 do 3 člana koji će vam se pridružiti u izazovu.",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import DateManager from "@/utilities/DateManager";
2+
import classNames from "classnames";
3+
import { useRouter } from "next/router";
4+
import React, { useCallback } from "react";
5+
6+
interface DurationBadgeProps {
7+
value: number;
8+
type?: string;
9+
}
10+
11+
export default function DurationBadge({ value, type = "gray" }: DurationBadgeProps) {
12+
const router = useRouter();
13+
const getDuration = useCallback((value: number, locale: string) => {
14+
if (!value) return 0;
15+
return DateManager.humanize(value, locale);
16+
}, []);
17+
return (
18+
<div
19+
className={classNames("text-xxs uppercase font-semibold px-2 rounded-3xl inline-block text-gray-500 text-nowrap", {
20+
"bg-gray-200": type === "gray",
21+
"border border-gray-200": type === "bordered",
22+
})}
23+
>
24+
{getDuration(value, router.locale as string)}
25+
</div>
26+
);
27+
}

src/components/cards/challenge/Badges.tsx renamed to src/components/badges/index.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Tag from "@/components/ui/Tag";
22
import { Challenge } from "@/types/course";
3-
import { useEffect, useState } from "react";
4-
import { useTranslation } from "react-i18next";
3+
import { useMemo } from "react";
4+
import { useTranslation } from "next-i18next";
55

66
/**
77
* this component is for the badges indicating if the course has a team challenge and the course level
@@ -13,23 +13,22 @@ import { useTranslation } from "react-i18next";
1313
* @returns {*}
1414
*/
1515
interface BadgeProps {
16-
challenge: Challenge;
16+
challenge?: Challenge;
1717
className?: string;
18+
courseLevel?: number;
1819
}
19-
export default function Badges({ challenge, className }: BadgeProps) {
20+
export default function Badges({ challenge, className, courseLevel }: BadgeProps) {
2021
const { t } = useTranslation();
21-
const [challengeLevel, setChallengeLevel] = useState("");
2222

23-
useEffect(() => {
24-
if (challenge.level === 0 || challenge.level === 1) return setChallengeLevel("course.challenge.level-0");
25-
return setChallengeLevel("course.challenge.level-2");
26-
}, [challenge.level]);
27-
28-
if (!challenge?.level && !challenge?.isTeamChallenge) return <></>;
23+
const level = useMemo(() => {
24+
const value = challenge?.level || courseLevel;
25+
return (value === 0 || value === 1) ? "course.challenge.level-0" : "course.challenge.level-2";
26+
}, [challenge?.level, courseLevel]);
2927

28+
if (!level && !challenge?.isTeamChallenge) return <></>;
3029
return (
3130
<div className={`uppercase flex flex-wrap gap-2 mb-3 ${className}`}>
32-
{challenge?.level && <Tag>{t(challengeLevel)}</Tag>}
31+
{level && <Tag>{t(level)}</Tag>}
3332
{challenge?.isTeamChallenge && <Tag type="light">{challenge?.isHackathon ? "Hackathon" : "Team"} challenge</Tag>}
3433
</div>
3534
);

src/components/cards/challenge/Challenge.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import ArrowButton from "@/components/ui/button/Arrow";
22
import { Community } from "@/types/community";
33
import { Challenge } from "@/types/course";
44
import Link from "next/link";
5-
import Badges from "./Badges";
65
import { useMemo } from "react";
76
import { useTranslation } from "next-i18next";
87
import Image from "next/image";
98
import RewardCertificate from "./RewardCertificate";
9+
import Badges from "@/components/badges";
1010

1111
/**
1212
* `ChallengeCard` is a function component that renders a card

src/components/cards/challenge/_partials/Learning.tsx

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React from "react";
2+
import ArrowButton from "@/components/ui/button/Arrow";
3+
import Link from "next/link";
4+
import { useTranslation } from "next-i18next";
5+
import { useSelector } from "react-redux";
6+
import { IRootState } from "@/store";
7+
import Badges from "@/components/badges";
8+
import DurationBadge from "@/components/badges/DurationBadge";
9+
10+
interface CourseMaterialProps {
11+
title: string;
12+
description: string;
13+
link: string;
14+
level: number;
15+
learningModulesCount: number;
16+
duration: number;
17+
}
18+
19+
/**
20+
* CourseMaterial component.
21+
*
22+
* @param {CourseMaterial} { title, description, link, level, learningModulesCount, duration }.
23+
* @returns {JSX.Element}
24+
*/
25+
export default function CourseMaterial({ title, description, link, level, learningModulesCount, duration }: CourseMaterialProps): JSX.Element {
26+
const { t } = useTranslation();
27+
const colors = useSelector((state: IRootState) => state.ui.colors);
28+
29+
return (
30+
<div className="flex flex-col gap-3 relative p-6 divide-y sm:divide-y-0 sm:divide-x divide-gray-200 rounded-3xl group text-gray-700 sm:p-8 border-solid border border-gray-200">
31+
<div className="flex flex-col w-full">
32+
<div className="flex items-center justify-between mb-6 flex-wrap gap-2">
33+
<div className="flex gap-2 items-center">
34+
<div className="h-5.5 w-5.5 rounded-sm clip-hexagon" style={{ backgroundColor: colors?.primary }} />
35+
<span className="capitalize font-semibold text-[#4B5563] text-sm">COURSE</span>
36+
</div>
37+
<div className="flex items-center gap-2">
38+
<Badges courseLevel={level} className="!mb-0" />
39+
<DurationBadge value={duration} type="bordered" />
40+
</div>
41+
</div>
42+
<div className="flex flex-col gap-6">
43+
<div className="text-lg font-medium leading-normal text-gray-900">{title}</div>
44+
<div className="text-sm font-normal text-gray-700 max-w-xxs">{description}</div>
45+
{learningModulesCount && (
46+
<p className="text-sm pb-6 font-medium text-gray-400 border-b-2 border-gray-200 border-dotted">
47+
{t(learningModulesCount === 1 ? "communities.overview.challenge.course.learningModule" : "communities.overview.challenge.course.learningModules", {
48+
count: learningModulesCount,
49+
})}
50+
</p>
51+
)}
52+
</div>
53+
<div className="bottom-0 mt-6">
54+
<Link href={link}>
55+
<ArrowButton communityStyles={true} variant="outline-primary">
56+
{t("communities.overview.challenge.learning.start")}
57+
</ArrowButton>
58+
</Link>
59+
</div>
60+
</div>
61+
</div>
62+
);
63+
}

src/components/sections/challenges/Learning.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Accordion from "@/components/ui/accordion/Accordion";
22
import Section from "@/components/sections/communities/_partials/Section";
3-
import LearningCard from "@/components/cards/challenge/_partials/Learning";
43
import { LearningModuleCard } from "@/components/cards/LearningModule";
4+
import CourseMaterial from "@/components/cards/course/CourseMaterial";
55
import { Course, LearningModule } from "@/types/course";
66
import { Community } from "@/types/community";
77
import { useTranslation } from "next-i18next";
@@ -22,13 +22,16 @@ export default function Learning({ courses, learningModules, community }: { cour
2222
content={
2323
<>
2424
<div className="text-base font-normal text-primary py-6">{t("communities.overview.challenge.learning.title")}</div>
25-
<div className="grid grid-cols-1 md:grid-cols-2 gap-3 mb-3">
25+
<div className={`grid grid-cols-1 gap-3 mb-3 ${courses?.length > 1 && "md:grid-cols-2"}`}>
2626
{courses?.map((course) => (
27-
<LearningCard
27+
<CourseMaterial
2828
key={`learning-card-data-${course.id}`}
2929
title={course.name}
3030
description={course.description}
3131
link={`/communities/${community.slug}/courses/${course.slug}`}
32+
duration={course.duration}
33+
level={course.level}
34+
learningModulesCount={course.learningModules?.length}
3235
/>
3336
))}
3437
</div>

0 commit comments

Comments
 (0)