-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathuseEventsRHHCConfig.tsx
More file actions
135 lines (133 loc) · 4.79 KB
/
Copy pathuseEventsRHHCConfig.tsx
File metadata and controls
135 lines (133 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import type {
ApolloClient,
NormalizedCacheObject,
} from '@apollo/client/core/index.js';
import type {
CardProps,
Config,
} from '@city-of-helsinki/react-helsinki-headless-cms';
import {
defaultConfig as rhhcDefaultConfig,
ModuleItemTypeEnum,
} from '@city-of-helsinki/react-helsinki-headless-cms';
import type { EventFieldsFragment } from '@events-helsinki/components';
import {
useResilientTranslation,
getLanguageCode,
useLocale,
MAIN_CONTENT_ID,
useCommonCmsConfig,
HelsinkiCityOwnedIcon,
CITY_OF_HELSINKI_LINKED_EVENTS_ORGANIZATION_PREFIXES,
} from '@events-helsinki/components';
import { ButtonVariant } from 'hds-react';
import Head from 'next/head';
import Link from 'next/link';
import React from 'react';
import { ROUTES } from '../constants';
import AppConfig from '../domain/app/AppConfig';
import routerHelper from '../domain/app/routerHelper';
import type { ArticleDetailsProps } from '../domain/article/articleDetails/ArticleDetails';
import ArticleDetails from '../domain/article/articleDetails/ArticleDetails';
import type { EventDetailsProps } from '../domain/event/eventDetails/EventDetails';
import EventDetails from '../domain/event/eventDetails/EventDetails';
import getVenueSourceId from '../domain/venue/utils/getVenueSourceId';
import type { VenueDetailsProps } from '../domain/venue/venueDetails/VenueDetails';
import VenueDetails from '../domain/venue/venueDetails/VenueDetails';
const APP_DOMAIN = new URL(AppConfig.origin).origin;
const CMS_API_DOMAIN = new URL(AppConfig.cmsOrigin).origin;
const LINKEDEVENTS_API_EVENT_ENDPOINT = new URL(
AppConfig.linkedEventsEventEndpoint
).href;
export default function useEventsRHHCConfig(args: {
apolloClient: ApolloClient<NormalizedCacheObject>;
}): Config {
const { apolloClient } = args;
const { resilientT } = useResilientTranslation();
const locale = useLocale();
const commonConfig = useCommonCmsConfig();
return React.useMemo(() => {
const internalHrefOrigins = [
APP_DOMAIN,
CMS_API_DOMAIN,
LINKEDEVENTS_API_EVENT_ENDPOINT,
];
const getIsHrefExternal = (href: string) => {
if (href?.startsWith('/')) return false;
return !internalHrefOrigins.some((origin) => href?.includes(origin));
};
return {
...rhhcDefaultConfig,
...commonConfig,
mainContentId: MAIN_CONTENT_ID,
organisationPrefixes:
CITY_OF_HELSINKI_LINKED_EVENTS_ORGANIZATION_PREFIXES,
components: {
...rhhcDefaultConfig.components,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Head: (props: any) => <Head {...props} />,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Link: ({ href, ...props }: any) => (
<Link legacyBehavior href={href || ''} {...props} />
),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
EventCardContent: (props: any) => (
<EventDetails {...(props as EventDetailsProps)} />
),
ArticleCardContent: (props: ArticleDetailsProps) => (
<ArticleDetails {...props} />
),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
VenueCardContent: (props: any) => (
<VenueDetails {...(props as VenueDetailsProps)} />
),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
HelsinkiCityOwnedIcon: (props: any) => (
<HelsinkiCityOwnedIcon {...props} />
),
},
customCopy: {
loadMoreButtonVariant: ButtonVariant.Success,
},
siteName: resilientT('appEvents:appName'),
currentLanguageCode: getLanguageCode(locale),
apolloClient,
eventsApolloClient: apolloClient,
venuesApolloClient: apolloClient,
utils: {
...rhhcDefaultConfig.utils,
getEventCardProps: AppConfig.showEnrolmentStatusInCardDetails
? (
item: EventFieldsFragment,
organisationPrefixes: string[],
locale: string
): CardProps => ({
...rhhcDefaultConfig.utils.getEventCardProps(
item,
organisationPrefixes,
locale
),
})
: rhhcDefaultConfig.utils.getEventCardProps,
getRoutedInternalHref: (
link?: string | null,
type?: ModuleItemTypeEnum
): string => {
if (type === ModuleItemTypeEnum.Venue) {
// quick fix for venue url rewrites
return routerHelper.getLocalizedCmsItemUrl(
ROUTES.VENUES,
{
venueId: getVenueSourceId(link ?? ''),
},
locale
);
}
return link || '#';
},
getIsHrefExternal,
},
internalHrefOrigins,
};
}, [commonConfig, resilientT, locale, apolloClient]);
}