Skip to content

Commit 265acea

Browse files
authored
638-feat: Add registration end date to the course pages (#828)
* feat: 638 - add ending of register date * feat: 638 - add end registration date * fix: 638 - fix unnecessary conditional rendering * feat: 638 - add reg date in upcoming courses * fix: 638 - fix component * fix: 638 - Fixed files * refactor: 638 - Refactor short-info-panel * refactor: 638 - Refactor variables * refactor: 638 - Refactor short-info-panel tests * fix: 638 - Fix styles in mentoring course-card * fix: 638 - Delete isCompactView variable * refactor: 638 - Refactor shortInfoPanel * fix: 638 - Add .env.example * fix: 638 - fix bags * fix: 638 - Fix short-infp-panel tests * fix: 638 - Fix start date * fix: 638 - Fix data-simple component * fix: 638 - Fix tests course-item * fix: 638 - fix the name of .env.example
1 parent 9edc92c commit 265acea

File tree

8 files changed

+222
-142
lines changed

8 files changed

+222
-142
lines changed

src/entities/course/ui/course-card/course-card.tsx

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import classNames from 'classnames/bind';
33
import Image from 'next/image';
44

55
import type { Course } from '../../types';
6-
import { LABELS, TO_BE_DETERMINED } from '@/shared/constants';
7-
import { DateSimple } from '@/shared/ui/date-simple';
6+
import { LABELS } from '@/shared/constants';
87
import { LinkCustom } from '@/shared/ui/link-custom';
98
import { ShortInfoPanel } from '@/shared/ui/short-info-panel';
109
import { Subtitle } from '@/shared/ui/subtitle';
@@ -25,7 +24,8 @@ export type CourseCardProps = Pick<
2524
| 'registrationEndDate'
2625
| 'personalMentoringStartDate'
2726
| 'personalMentoringEndDate'
28-
> & Pick<HTMLProps<HTMLDivElement>, 'className'> & {
27+
> &
28+
Pick<HTMLProps<HTMLDivElement>, 'className'> & {
2929
size?: 'sm' | 'md';
3030
showMentoringStartDate?: boolean;
3131
};
@@ -40,7 +40,7 @@ export const CourseCard = ({
4040
backgroundStyle,
4141
personalMentoringStartDate,
4242
personalMentoringEndDate,
43-
showMentoringStartDate = false,
43+
showMentoringStartDate,
4444
className = '',
4545
size = 'md',
4646
}: CourseCardProps) => {
@@ -63,33 +63,22 @@ export const CourseCard = ({
6363
<article className={cx('course-card', classes)} data-testid="course-card">
6464
<div className={cx('card-header')} style={cardStyle} data-testid="card-header">
6565
<Image src={iconSrc} alt={title} />
66-
<Subtitle className={cx('course-title')} fontSize={fontSize}>{title}</Subtitle>
66+
<Subtitle className={cx('course-title')} fontSize={fontSize}>
67+
{title}
68+
</Subtitle>
6769
</div>
6870
<div className={cx('course-info')}>
69-
{!showMentoringStartDate && (
70-
<ShortInfoPanel
71-
label={dateLabel}
72-
startDate={startDate}
73-
registrationEndDate={registrationEndDate}
74-
language={language}
75-
>
76-
</ShortInfoPanel>
77-
)}
78-
{showMentoringStartDate && (
79-
<div>
80-
<DateSimple
81-
label={LABELS.MENTOR_ACTIVITIES}
82-
startDate={personalMentoringStartDate || TO_BE_DETERMINED}
83-
endDate={personalMentoringStartDate ? personalMentoringEndDate : null}
84-
labelSeparator={LABELS.MENTOR_ACTIVITIES_SEPARATOR}
85-
/>
86-
<ShortInfoPanel
87-
startDate={null}
88-
registrationEndDate={null}
89-
language={language}
90-
/>
91-
</div>
92-
)}
71+
<ShortInfoPanel
72+
showMentoringStartDate={showMentoringStartDate}
73+
label={dateLabel}
74+
startDate={startDate}
75+
registrationEndDate={registrationEndDate}
76+
language={language}
77+
personalMentoringStartDate={personalMentoringStartDate}
78+
personalMentoringEndDate={personalMentoringEndDate}
79+
>
80+
</ShortInfoPanel>
81+
9382
<LinkCustom
9483
className={cx('course-link')}
9584
href={detailsUrl}

src/entities/course/ui/course-item/course-item.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,11 @@ export const CourseItem = ({
3030
/>
3131
</figure>
3232
<article className={cx('course-info')}>
33-
<Subtitle fontSize="extra-small">
34-
{title}
35-
</Subtitle>
33+
<Subtitle fontSize="extra-small">{title}</Subtitle>
3634
<ShortInfoPanel
3735
startDate={startDate}
3836
registrationEndDate={registrationEndDate}
3937
language={language}
40-
onlyLanguage={true}
4138
/>
4239
</article>
4340
<LinkCustom

src/shared/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const API_MAX_INCLUDE_DEPTH = 10;
1616
export const LABELS = {
1717
START_DATE: 'Course starts on:',
1818
START_DATE_SHORT: 'Start:',
19+
REGISTRATION_END: 'Enroll untill:',
1920
COURSE_LANGUAGE_EN: 'English',
2021
COURSE_LANGUAGE_RU: 'Russian',
2122
MENTOR_ACTIVITIES: 'Mentorship starts on:',

src/shared/ui/date-simple/date-simple.test.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import { dayJS } from '@/shared/helpers/day-js';
99
describe('DateSimple', () => {
1010
it('renders UI correctly having only start date', () => {
1111
const startDate = '2088-01-01';
12+
const showMentoringStartDate = false;
1213

13-
render(<DateSimple startDate={startDate} />);
14+
render(<DateSimple startDate={startDate} showMentoringStartDate={showMentoringStartDate} />);
1415
expect(screen.queryByText(LABELS.START_DATE)).toBeNull();
1516
expect(screen.getByText(`${startDate}`)).toBeInTheDocument();
1617
expect(screen.queryByAltText('note-icon')).toBeNull();
@@ -21,13 +22,15 @@ describe('DateSimple', () => {
2122
const startDate = '2088-01-01';
2223
const endDate = '2088-06-30';
2324
const labelSeparator = 'test-separator';
25+
const showMentoringStartDate = true;
2426

2527
render(
2628
<DateSimple
2729
label={label}
2830
startDate={startDate}
2931
endDate={endDate}
3032
labelSeparator={labelSeparator}
33+
showMentoringStartDate={showMentoringStartDate}
3134
/>,
3235
);
3336
expect(screen.getByAltText('note-icon')).toHaveAttribute('src', noteIcon.src);
@@ -40,8 +43,15 @@ describe('DateSimple', () => {
4043
it('displays dates and date attributes correctly including endDate TBD case', () => {
4144
const startDate = '2088-01-01';
4245
const endDate = TO_BE_DETERMINED;
46+
const showMentoringStartDate = true;
4347

44-
render(<DateSimple startDate={startDate} endDate={endDate} />);
48+
render(
49+
<DateSimple
50+
startDate={startDate}
51+
endDate={endDate}
52+
showMentoringStartDate={showMentoringStartDate}
53+
/>,
54+
);
4555
const startDateElement = screen.getByTestId('date-time-start');
4656
const endDateElement = screen.getByTestId('date-time-end');
4757

@@ -54,13 +64,15 @@ describe('DateSimple', () => {
5464
it('displays dates and date attributes correctly when start and end dates are TBD', () => {
5565
const startDate = TO_BE_DETERMINED;
5666
const endDate = TO_BE_DETERMINED;
67+
const showMentoringStartDate = true;
5768

5869
render(
5970
<DateSimple
6071
label={LABELS.START_DATE}
6172
startDate={startDate}
6273
labelSeparator={LABELS.MENTOR_ACTIVITIES_SEPARATOR}
6374
endDate={endDate}
75+
showMentoringStartDate={showMentoringStartDate}
6476
/>,
6577
);
6678
const startDateElement = screen.getByTestId('date-time-start');
@@ -77,12 +89,14 @@ describe('DateSimple', () => {
7789
it('displays correctly when endDate is undefined but label separator not', () => {
7890
const startDate = '2088-01-01';
7991
const labelSeparator = 'test-separator';
92+
const showMentoringStartDate = true;
8093

8194
render(
8295
<DateSimple
8396
label={LABELS.START_DATE}
8497
startDate={startDate}
8598
labelSeparator={labelSeparator}
99+
showMentoringStartDate={showMentoringStartDate}
86100
/>,
87101
);
88102
const labelSeparatorElement = screen.queryByText(`${labelSeparator}`);
@@ -93,9 +107,10 @@ describe('DateSimple', () => {
93107
it('displays start date and additional info passed as children', () => {
94108
const startDate = '2088-01-01';
95109
const additionalInfoText = 'Test additional info element';
110+
const showMentoringStartDate = true;
96111

97112
render(
98-
<DateSimple startDate={startDate}>
113+
<DateSimple startDate={startDate} showMentoringStartDate={showMentoringStartDate}>
99114
<span>{additionalInfoText}</span>
100115
</DateSimple>,
101116
);
Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,66 @@
1-
import React from 'react';
2-
import classNames from 'classnames/bind';
3-
import Image from 'next/image';
4-
5-
import noteIcon from '@/shared/assets/icons/note-icon.svg';
6-
import { TO_BE_DETERMINED } from '@/shared/constants';
7-
import { dayJS } from '@/shared/helpers/day-js';
8-
9-
import styles from './date-simple.module.scss';
10-
11-
const cx = classNames.bind(styles);
12-
13-
type DateStartProps = {
14-
startDate: string | null;
15-
endDate?: string | null;
16-
label?: string;
17-
labelSeparator?: string;
18-
children?: React.ReactNode;
19-
};
20-
21-
const formatDateAttr = (date: string | null | undefined): string | undefined => {
22-
if (!date || date === TO_BE_DETERMINED) {
23-
return undefined;
24-
}
25-
26-
return dayJS(date).toISOString();
27-
};
28-
29-
export const DateSimple = ({
30-
startDate,
31-
endDate,
32-
label,
33-
labelSeparator,
34-
children,
35-
}: DateStartProps) => {
36-
const startDateAttr = formatDateAttr(startDate);
37-
const endDateAttr = formatDateAttr(endDate);
38-
39-
return (
40-
<p className={cx('date')}>
41-
{label && (
42-
<>
43-
<Image className={cx('icon')} src={noteIcon} alt="note-icon" />
44-
<span className={cx('bold')}>{label}</span>
45-
</>
46-
)}
47-
{startDate && (
48-
<time dateTime={startDateAttr} data-testid="date-time-start">
49-
{startDate}
50-
</time>
51-
)}
52-
{labelSeparator && endDate && <span>{labelSeparator}</span>}
53-
{endDate && (
54-
<time dateTime={endDateAttr} data-testid="date-time-end">
55-
{endDate}
56-
</time>
57-
)}
58-
{children}
59-
</p>
60-
);
61-
};
1+
import React from 'react';
2+
import classNames from 'classnames/bind';
3+
import Image from 'next/image';
4+
5+
import noteIcon from '@/shared/assets/icons/note-icon.svg';
6+
import { TO_BE_DETERMINED } from '@/shared/constants';
7+
import { dayJS } from '@/shared/helpers/day-js';
8+
9+
import styles from './date-simple.module.scss';
10+
11+
const cx = classNames.bind(styles);
12+
13+
type DateStartProps = {
14+
startDate: string | null;
15+
endDate?: string | null;
16+
label?: string;
17+
labelSeparator?: string;
18+
children?: React.ReactNode;
19+
showMentoringStartDate: boolean;
20+
};
21+
22+
const formatDateAttr = (date: string | null | undefined): string | undefined => {
23+
if (!date || date === TO_BE_DETERMINED) {
24+
return undefined;
25+
}
26+
27+
return dayJS(date).toISOString();
28+
};
29+
30+
export const DateSimple = ({
31+
startDate,
32+
endDate,
33+
label,
34+
labelSeparator,
35+
children,
36+
showMentoringStartDate,
37+
}: DateStartProps) => {
38+
const startDateAttr = formatDateAttr(startDate);
39+
const endDateAttr = formatDateAttr(endDate);
40+
41+
const startDateFormat = startDate && endDate ? dayJS(startDate).format('MMM D') : startDate;
42+
43+
return (
44+
<p className={cx('date')}>
45+
{label && (
46+
<>
47+
<Image className={cx('icon')} src={noteIcon} alt="note-icon" />
48+
<span className={cx('bold')}>{label}</span>
49+
</>
50+
)}
51+
{startDate && (
52+
<time dateTime={startDateAttr} data-testid="date-time-start">
53+
{showMentoringStartDate ? startDate : startDateFormat}
54+
</time>
55+
)}
56+
57+
{labelSeparator && endDate && <span>{labelSeparator}</span>}
58+
{endDate && (
59+
<time dateTime={endDateAttr} data-testid="date-time-end">
60+
{endDate}
61+
</time>
62+
)}
63+
{children}
64+
</p>
65+
);
66+
};

src/shared/ui/short-info-panel/short-info-panel.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
margin: 0;
1919

2020
font-size: 14px;
21-
color: $color-gray-600;
21+
color: $color-gray-900;
2222
}
2323

2424
.icon {

0 commit comments

Comments
 (0)