diff --git a/src/components/course-card/CourseCard.styles.ts b/src/components/course-card/CourseCard.styles.ts new file mode 100644 index 000000000..b46517dd8 --- /dev/null +++ b/src/components/course-card/CourseCard.styles.ts @@ -0,0 +1,43 @@ +import { TypographyVariantEnum } from '~/types' +import { ellipsisTextStyle } from '~/utils/helper-functions' + +export const styles = { + card: { + display: 'flex', + flexDirection: 'column', + justifyContent: 'space-between', + maxWidth: '312px', + minHeight: '245px', + backgroundColor: 'basic.white', + borderRadius: '6px', + p: '24px 24px 16px' + }, + title: { + typography: TypographyVariantEnum.H5, + ...ellipsisTextStyle(2), + fontWeight: '600', + lineHeight: '24px', + letterSpacing: '0.15px' + }, + description: { + typography: TypographyVariantEnum.Body1, + ...ellipsisTextStyle(2), + m: '8px 0px' + }, + secondaryText: { + typography: TypographyVariantEnum.Body2, + color: 'basic.turquoiseDark', + m: '8px 0px' + }, + dateContainer: { + display: 'flex', + justifyContent: 'space-between', + alignItems: 'center' + }, + line: { + m: '16px 0' + }, + chipContainer: { + position: 'relative' + } +} diff --git a/src/components/course-card/CourseCard.tsx b/src/components/course-card/CourseCard.tsx new file mode 100644 index 000000000..aab190731 --- /dev/null +++ b/src/components/course-card/CourseCard.tsx @@ -0,0 +1,64 @@ +import { FC } from 'react' +import Box from '@mui/material/Box' +import Typography from '@mui/material/Typography' +import IconButton from '@mui/material/IconButton' +import MoreVertIcon from '@mui/icons-material/MoreVert' +import Divider from '@mui/material/Divider' + +import SubjectLevelChips from '~/components/subject-level-chips/SubjectLevelChips' + +import { styles } from '~/components/course-card/CourseCard.styles' +import { getFormattedDate } from '~/utils/helper-functions' +import { Course } from '~/types' +import { useTranslation } from 'react-i18next' + +interface CourseCardProps { + course: Course +} + +const CourseCard: FC = ({ course }) => { + const { t } = useTranslation() + + const { + title, + description, + category, + subject, + proficiencyLevel, + sections = [{}], + createdAt + } = course + + const date = getFormattedDate({ date: createdAt }) + + return ( + + + {title} + {description} + + + {`${sections.length} ${ + sections.length > 1 ? t('course.sections') : t('course.section') + }`} + + + + + + {date} + + + + + + + ) +} + +export default CourseCard diff --git a/src/constants/translations/en/course.json b/src/constants/translations/en/course.json index cfa4e7b44..6f368d0d6 100644 --- a/src/constants/translations/en/course.json +++ b/src/constants/translations/en/course.json @@ -1,5 +1,7 @@ { "addSectionBtn": "Add Section", + "section": "section", + "sections": "sections", "courseSection": { "defaultNewTitle": "Section 1", "defaultNewDescription": "Description...", diff --git a/src/constants/translations/ua/course.json b/src/constants/translations/ua/course.json index 1c44bc8f8..47ce21fae 100644 --- a/src/constants/translations/ua/course.json +++ b/src/constants/translations/ua/course.json @@ -1,5 +1,7 @@ { "addSectionBtn": "Новий курс", + "section": "Розділ", + "sections": "Розділи", "courseSection": { "defaultNewTitle": "Розділ 1", "defaultNewDescription": "Опис ...", diff --git a/src/types/course/interfaces/course.interface.ts b/src/types/course/interfaces/course.interface.ts index f16a426e8..a97483817 100644 --- a/src/types/course/interfaces/course.interface.ts +++ b/src/types/course/interfaces/course.interface.ts @@ -1,10 +1,20 @@ -import { CommonEntityFields, Lesson, Quiz, Attachment, Category } from '~/types' +import { + CommonEntityFields, + Lesson, + Quiz, + Attachment, + CategoryInterface, + SubjectNameInterface, + ProficiencyLevelEnum +} from '~/types' export interface Course extends CommonEntityFields { title: string description: string sections?: CourseSection[] - category: Category | null + category: CategoryInterface + subject: SubjectNameInterface + proficiencyLevel: ProficiencyLevelEnum[] } export interface CourseSection { diff --git a/tests/unit/components/course-card/CourseCard.spec.jsx b/tests/unit/components/course-card/CourseCard.spec.jsx new file mode 100644 index 000000000..f7109a5b8 --- /dev/null +++ b/tests/unit/components/course-card/CourseCard.spec.jsx @@ -0,0 +1,45 @@ +import { render, screen } from '@testing-library/react' +import CourseCard from '~/components/course-card/CourseCard' + +describe('CourseCard', () => { + const mockCourse = { + proficiencyLevel: ['Beginner'], + title: 'Advanced Lineal Math: Theoretical Concepts', + description: 'The mathematical language of quantum mechanics', + languages: ['English'], + subject: { + _id: '648850c4fdc2d1a130c24aea', + name: 'Quantum Mechanics' + }, + category: { + _id: '64884f21fdc2d1a130c24ac0', + appearance: { + icon: 'mocked-path-to-icon', + color: '#66C42C' + } + }, + sections: [{}, {}, {}], + createdAt: '2023-09-19T12:12:25.098Z', + updatedAt: '2023-09-19T12:17:10.447Z' + } + + beforeEach(() => { + render() + }) + + it('Should render title and description of component ', () => { + const title = screen.getByText('Advanced Lineal Math: Theoretical Concepts') + const description = screen.getByText( + 'The mathematical language of quantum mechanics' + ) + + expect(title).toBeInTheDocument() + expect(description).toBeInTheDocument() + }) + + it('Should render sum of sections', () => { + const sections = screen.getByText('3 course.sections') + + expect(sections).toBeInTheDocument() + }) +})