Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add all-day prop to event-card #161

Merged
merged 1 commit into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/components/EventCard/EventCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ describe('The EventCard component', () => {
expect(normalizedText).toBe('02/12/2024 | 08:30 - 03/12/2024 | 09:30');
});

it('does not display start and end time if allDay property set "true"', () => {
setup({
event: {
...defaultProps.event,
allDay: true,
},
});

const textContent = screen.getByText(
/02\/12\/2024\s*-\s*03\/12\/2024/i
).textContent;

const normalizedText = textContent?.replace(/\s+/g, ' ').trim();

expect(normalizedText).toBe('02/12/2024 - 03/12/2024');
});

it('displays the speakers', async () => {
setup();

Expand Down
50 changes: 37 additions & 13 deletions src/components/EventCard/EventCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { BREAKPOINT_MD_QUERY } from '../../constants/breakpoints';
import StrapiEvent, { EventType } from '../../models/strapi/StrapiEvent';
import { IntlContext } from '../ContextProvider';
import strapiMediaUrl from '../../utils/strapiMediaUrl';
import convertStrapiTime from '../../utils/convertStrapiTime';
import isSameDate from '../../utils/isSameDate';

export interface EventCardProps {
event: StrapiEvent;
Expand Down Expand Up @@ -209,22 +209,46 @@ export const EventCard = ({ event }: EventCardProps): JSX.Element => {
color={'var(--boemly-colors-primary-700)'}
/>
<Text size={['xsLowBold', null, null, 'smLowBold']}>
{formatDate(event.startDate, {
{formatDate(event.start, {
year: 'numeric',
month: '2-digit',
day: '2-digit',
})}
{event.startTime &&
` | ${convertStrapiTime(event.startTime, formatNumber)} `}
{(event.endDate || event.endTime) && ' - '}
{event.endDate &&
formatDate(event.endDate, {
year: 'numeric',
month: '2-digit',
day: '2-digit',
})}
{event.endTime && event.endDate && ' | '}
{event.endTime && convertStrapiTime(event.endTime, formatNumber)}

{!event.allDay &&
` | ${formatNumber(new Date(event.start).getUTCHours(), {
minimumIntegerDigits: 2,
})}:${formatNumber(new Date(event.start).getUTCMinutes(), {
minimumIntegerDigits: 2,
})}`}

{event.end &&
!isSameDate(new Date(event.start), new Date(event.end)) && (
<>
{' - '}
{formatDate(event.end, {
year: 'numeric',
month: '2-digit',
day: '2-digit',
})}

{!event.allDay &&
` | ${formatNumber(new Date(event.end).getUTCHours(), {
minimumIntegerDigits: 2,
})}:${formatNumber(new Date(event.end).getUTCMinutes(), {
minimumIntegerDigits: 2,
})}`}
</>
)}

{event.end &&
!event.allDay &&
isSameDate(new Date(event.start), new Date(event.end)) &&
` - ${formatNumber(new Date(event.end).getUTCHours(), {
minimumIntegerDigits: 2,
})}:${formatNumber(new Date(event.end).getUTCMinutes(), {
minimumIntegerDigits: 2,
})}`}
</Text>
</Flex>
</Flex>
Expand Down
7 changes: 3 additions & 4 deletions src/models/strapi/StrapiEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ interface StrapiEvent {
location?: string;
locale: Locale;
online?: boolean;
startDate: Date;
startTime?: string;
endDate?: Date;
endTime?: string;
start: Date;
end?: Date;
allDay?: boolean;
slices: any[];
localizations: StrapiLocalization[];
topBanner?: StrapiTopBanner;
Expand Down
20 changes: 9 additions & 11 deletions src/slices/Events/Events.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const pastEventMock = {
attributes: {
...strapiEventMock.attributes,
title: 'Past Event',
startDate: '2024-12-01',
start: '2024-12-01T10:00:00.000Z',
eventTypes: [{ id: 1, eventType: EventType.MEET_UP }],
languages: [{ id: 1, language: 'English', countryCode: 'GB' }],
},
Expand All @@ -30,7 +30,7 @@ const upcomingEventMock = {
attributes: {
...strapiEventMock.attributes,
title: 'Upcoming Event',
startDate: '2025-02-01',
start: '2024-12-01T10:00:00.000Z',
eventTypes: [{ id: 1, eventType: EventType.CONFERENCE }],
languages: [{ id: 1, language: 'German', countryCode: 'DE' }],
},
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('The Events slice', () => {
const key = getKey(0, null);
getKeyCalls.push(key.toString());

if (getKey.toString().includes('filters[startDate][$gte]')) {
if (getKey.toString().includes('filters[start][$gte]')) {
return {
data: [{ body: { data: [upcomingEventMock] } }],
isLoading: false,
Expand All @@ -77,7 +77,7 @@ describe('The Events slice', () => {
loadMore: jest.fn(),
};
}
if (getKey.toString().includes('filters[startDate][$lt]')) {
if (getKey.toString().includes('filters[start][$lt]')) {
return {
data: [{ body: { data: [pastEventMock] } }],
isLoading: false,
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('The Events slice', () => {
// Use past events for the testing, because the batch for past events is defined as 2 and
// the "Load button" will be shown when there are more then 2 past events
(useEvents as jest.Mock).mockImplementation(({ getKey }) => {
if (getKey.toString().includes('filters[startDate][$lt]')) {
if (getKey.toString().includes('filters[start][$lt]')) {
return {
data: [
{
Expand Down Expand Up @@ -243,7 +243,7 @@ describe('The Events slice', () => {
await waitFor(() => {
expect(getKeyCalls.map(decodeURIComponent)).toEqual(
expect.arrayContaining([
expect.stringContaining('filters[startDate][$gte]'),
expect.stringContaining('filters[start][$gte]'),
expect.stringContaining(
'filters[$or][0][eventTypes][eventType]=Conference'
),
Expand Down Expand Up @@ -278,7 +278,7 @@ describe('The Events slice', () => {
await waitFor(() => {
expect(getKeyCalls.map(decodeURIComponent)).toEqual(
expect.arrayContaining([
expect.stringContaining('filters[startDate][$gte]'),
expect.stringContaining('filters[start][$gte]'),
expect.stringContaining(
'filters[$or][0][languages][language]=German'
),
Expand All @@ -303,7 +303,7 @@ describe('The Events slice', () => {
expect(getKeyCalls.map(decodeURIComponent)).toEqual(
expect.arrayContaining([
expect.stringContaining(
`filters[startDate][$gte]=${NOW.toISOString()}`
`filters[start][$gte]=${NOW.toISOString()}`
),
])
);
Expand Down Expand Up @@ -341,9 +341,7 @@ describe('The Events slice', () => {
await waitFor(() => {
expect(getKeyCalls.map(decodeURIComponent)).toEqual(
expect.arrayContaining([
expect.stringContaining(
`filters[startDate][$lt]=${NOW.toISOString()}`
),
expect.stringContaining(`filters[start][$lt]=${NOW.toISOString()}`),
])
);
});
Expand Down
9 changes: 4 additions & 5 deletions src/slices/Events/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ export const Events: React.FC<EventsProps> = ({ slice }: EventsProps) => {
url.searchParams.append('pLevel', STRAPI_DEFAULT_POPULATE_DEPTH);

if (sort[0] === Sort.OLDEST_FIRST) {
url.searchParams.append('sort', 'startDate:asc');
url.searchParams.append('sort', 'start:asc');
} else {
url.searchParams.append('sort', 'startDate:desc');
url.searchParams.append('sort', 'start:desc');
}

if (eventTypeFilter.length) {
Expand All @@ -123,13 +123,12 @@ export const Events: React.FC<EventsProps> = ({ slice }: EventsProps) => {

const getUpcomingKey: SWRInfiniteKeyLoader = useCallback(
(index) =>
buildEventsUrl(index, UPCOMING_BATCH_SIZE, 'filters[startDate][$gte]'),
buildEventsUrl(index, UPCOMING_BATCH_SIZE, 'filters[start][$gte]'),
[eventTypeFilter, languageFilter, sort]
);

const getPastKey: SWRInfiniteKeyLoader = useCallback(
(index) =>
buildEventsUrl(index, PAST_BATCH_SIZE, 'filters[startDate][$lt]'),
(index) => buildEventsUrl(index, PAST_BATCH_SIZE, 'filters[start][$lt]'),
[eventTypeFilter, languageFilter, sort]
);

Expand Down
7 changes: 3 additions & 4 deletions src/test/strapiMocks/strapiEventMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ export const strapiEventMock: IStrapiData<StrapiEvent> = {
logo: { id: 1, alt: 'Logo alt text 1', img: { data: strapiMediaMock } },
eventTypes: [{ id: 1, eventType: EventType.MEET_UP }],
languages: [{ id: 1, language: 'English', countryCode: 'GB' }],
startDate: new Date('2024-02-12'),
startTime: '08:30:00.000',
endDate: new Date('2024-03-12'),
endTime: '09:30:00.000',
start: new Date('2024-02-12T08:30:00Z'),
end: new Date('2024-03-12T09:30:00Z'),
allDay: false,
title: 'Event Title',
description: 'Event Description',
button: { id: 1, text: 'Button text', url: 'https://tree.ly' },
Expand Down
21 changes: 0 additions & 21 deletions src/utils/convertStrapiTime.test.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/utils/convertStrapiTime.ts

This file was deleted.

18 changes: 18 additions & 0 deletions src/utils/isSameDate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import isSameDate from './isSameDate';

describe('The getCountryFlag util', () => {
it('returns flag icon', () => {
expect(
isSameDate(
new Date('2024-02-12T08:30:00Z'),
new Date('2024-02-12T08:30:00Z')
)
).toEqual(true);
expect(
isSameDate(
new Date('2025-02-12T08:30:00Z'),
new Date('2024-02-10T08:30:00Z')
)
).toEqual(false);
});
});
9 changes: 9 additions & 0 deletions src/utils/isSameDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const isSameDate = (date1: Date, date2: Date): boolean => {
return (
date1.getFullYear() === date2.getFullYear() &&
date1.getMonth() === date2.getMonth() &&
date1.getDate() === date2.getDate()
);
};

export default isSameDate;