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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
/* eslint-disable max-statements */
import type { GetStaticProps } from 'next';
import Head from 'next/head';
import { useRouter } from 'next/router';
import Script from 'next/script';
import { useCallback, type ReactNode } from 'react';
import { useIntl } from 'react-intl';
import {
getLayout,
Heading,
Link,
LinksWidget,
Page,
PageBody,
PageHeader,
PageSidebar,
SearchForm,
type SearchFormSubmit,
} from '../components';
import {
getThematicsPreview,
getTopicsPreview,
getTotalThematics,
getTotalTopics,
} from '../services/graphql';
import type {
NextPageWithLayout,
RawThematicPreview,
RawTopicPreview,
} from '../types';
import { CONFIG } from '../utils/config';
import { ROUTES } from '../utils/constants';
import { getLinksItemData, getPageLinkFromRawData } from '../utils/helpers';
import { loadTranslation, type Messages } from '../utils/helpers/server';
import { useBreadcrumb } from '../utils/hooks';
type Error404PageProps = {
thematicsList: RawThematicPreview[];
topicsList: RawTopicPreview[];
translation: Messages;
};
/**
* Error 404 page.
*/
const Error404Page: NextPageWithLayout<Error404PageProps> = ({
thematicsList,
topicsList,
}) => {
const router = useRouter();
const intl = useIntl();
const title = intl.formatMessage({
defaultMessage: 'Page not found',
description: 'Error404Page: page title',
id: 'KnWeKh',
});
const body = intl.formatMessage(
{
defaultMessage:
'Sorry, it seems that the page your are looking for does not exist. If you think this path should work, feel free to <link>contact me</link> with the necessary information so that I can fix the problem.',
id: '9sGNKq',
description: 'Error404Page: page body',
},
{
link: (chunks: ReactNode) => <Link href={ROUTES.CONTACT}>{chunks}</Link>,
}
);
const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumb({
title,
url: ROUTES.NOT_FOUND,
});
const pageTitle = intl.formatMessage(
{
defaultMessage: 'Error 404: Page not found - {websiteName}',
description: '404Page: SEO - Page title',
id: '310o3F',
},
{ websiteName: CONFIG.name }
);
const pageDescription = intl.formatMessage({
defaultMessage: 'Page not found.',
description: '404Page: SEO - Meta description',
id: '48Ww//',
});
const thematicsListTitle = intl.formatMessage({
defaultMessage: 'Thematics',
description: 'Error404Page: thematics list widget title',
id: 'HohQPh',
});
const topicsListTitle = intl.formatMessage({
defaultMessage: 'Topics',
description: 'Error404Page: topics list widget title',
id: 'GVpTIl',
});
const searchSubmitHandler: SearchFormSubmit = useCallback(
({ query }) => {
if (!query)
return {
messages: {
error: intl.formatMessage({
defaultMessage: 'Query must be longer than one character.',
description: '404Page: invalid query message',
id: 'C6oK7h',
}),
},
validator: (value) => value.query.length > 1,
};
router.push({ pathname: ROUTES.SEARCH, query: { s: query } });
return undefined;
},
[intl, router]
);
return (
<Page breadcrumbs={breadcrumbItems}>
<Head>
<title>{pageTitle}</title>
{/*eslint-disable-next-line react/jsx-no-literals -- Name allowed */}
<meta name="description" content={pageDescription} />
</Head>
<Script
dangerouslySetInnerHTML={{ __html: JSON.stringify(breadcrumbSchema) }}
// eslint-disable-next-line react/jsx-no-literals -- Id allowed
id="schema-breadcrumb"
type="application/ld+json"
/>
<PageHeader heading={title} />
<PageBody>
{body}
<p>
{intl.formatMessage({
defaultMessage: 'You can also try a search:',
description: 'Error404Page: try a search message',
id: 'XKy7rx',
})}
</p>
<SearchForm isLabelHidden onSubmit={searchSubmitHandler} />
</PageBody>
<PageSidebar>
<LinksWidget
heading={
<Heading isFake level={3}>
{thematicsListTitle}
</Heading>
}
items={getLinksItemData(
thematicsList.map((thematic) =>
getPageLinkFromRawData(thematic, 'thematic')
)
)}
/>
<LinksWidget
heading={
<Heading isFake level={3}>
{topicsListTitle}
</Heading>
}
items={getLinksItemData(
topicsList.map((topic) => getPageLinkFromRawData(topic, 'topic'))
)}
/>
</PageSidebar>
</Page>
);
};
Error404Page.getLayout = (page) => getLayout(page);
export const getStaticProps: GetStaticProps<Error404PageProps> = async ({
locale,
}) => {
const totalThematics = await getTotalThematics();
const thematics = await getThematicsPreview({ first: totalThematics });
const totalTopics = await getTotalTopics();
const topics = await getTopicsPreview({ first: totalTopics });
const translation = await loadTranslation(locale);
return {
props: {
thematicsList: thematics.edges.map((edge) => edge.node),
topicsList: topics.edges.map((edge) => edge.node),
translation,
},
};
};
export default Error404Page;
|