-
-
Notifications
You must be signed in to change notification settings - Fork 580
Expand file tree
/
Copy pathindex.tsx
More file actions
72 lines (66 loc) · 2.3 KB
/
index.tsx
File metadata and controls
72 lines (66 loc) · 2.3 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
import { NextPage, GetStaticProps } from 'next';
import useTranslation from 'next-translate/useTranslation';
import { fetcher } from '@/api';
import CoursesPageLayout from '@/components/Course/CoursesPageLayout';
import NextSeoWrapper from '@/components/NextSeoWrapper';
import { getLearningPlansImageUrl } from '@/lib/og';
import { logErrorToSentry } from '@/lib/sentry';
import { Course } from '@/types/auth/Course';
import { makeGetCoursesUrl } from '@/utils/auth/apiPaths';
import { getAllChaptersData } from '@/utils/chapter';
import { getLanguageAlternates } from '@/utils/locale';
import { getCanonicalUrl, getCoursesNavigationUrl } from '@/utils/navigation';
import { REVALIDATION_PERIOD_ON_ERROR_SECONDS } from '@/utils/staticPageGeneration';
import { getBasePath } from '@/utils/url';
type LearningPlansPageProps = {
courses?: Course[];
};
const LearningPlansPage: NextPage<LearningPlansPageProps> = ({ courses }) => {
const { t, lang } = useTranslation('learn');
const initialCourses = courses && courses.length > 0 ? courses : undefined;
return (
<>
<NextSeoWrapper
title={t('common:learning-plans')}
canonical={getCanonicalUrl(lang, getCoursesNavigationUrl())}
languageAlternates={getLanguageAlternates(getCoursesNavigationUrl())}
description={t('learning-plans-meta-desc')}
image={getLearningPlansImageUrl({
locale: lang,
})}
imageWidth={1200}
imageHeight={630}
/>
<CoursesPageLayout initialCourses={initialCourses} />
</>
);
};
export const getStaticProps: GetStaticProps = async ({ locale }) => {
const allChaptersData = await getAllChaptersData(locale);
try {
const response = await fetcher<{ data?: Course[] }>(makeGetCoursesUrl({ myCourses: false }), {
headers: {
origin: getBasePath(),
},
});
return {
props: {
courses: response?.data ?? [],
chaptersData: allChaptersData,
},
revalidate: REVALIDATION_PERIOD_ON_ERROR_SECONDS,
};
} catch (error) {
logErrorToSentry(error, {
transactionName: 'getStaticProps-LearningPlansPage',
});
return {
props: {
courses: [],
chaptersData: allChaptersData,
},
revalidate: REVALIDATION_PERIOD_ON_ERROR_SECONDS,
};
}
};
export default LearningPlansPage;