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
|
- import { useRouter } from 'next/router'
- import cx from 'classnames'
- import { useMainContext } from 'components/context/MainContext'
- import { useTranslation } from 'components/hooks/useTranslation'
- import { ExcludesNull } from 'components/lib/ExcludesNull'
- import { useVersion } from './hooks/useVersion'
- enum NotificationType {
- RELEASE = 'RELEASE',
- TRANSLATION = 'TRANSLATION',
- EARLY_ACCESS = 'EARLY_ACCESS',
- }
- type Notif = {
- content: string
- type: NotificationType
- }
- export const HeaderNotifications = () => {
- const router = useRouter()
- const { currentVersion } = useVersion()
- const { relativePath, allVersions, data, languages, currentLanguage, userLanguage, currentPathWithoutLanguage } = useMainContext()
- const { t } = useTranslation('header')
- const translationNotices: Array<Notif> = []
- if (router.locale !== 'en') {
- if (relativePath?.includes('/site-policy')) {
- translationNotices.push({
- type: NotificationType.TRANSLATION,
- content: data.reusables.policies.translation,
- })
- } else if (languages[currentLanguage].wip !== true) {
- translationNotices.push({
- type: NotificationType.TRANSLATION,
- content: t('notices.localization_complete'),
- })
- } else if (languages[currentLanguage].wip) {
- translationNotices.push({
- type: NotificationType.TRANSLATION,
- content: t('notices.localization_in_progress'),
- })
- }
- } else {
- if (userLanguage && userLanguage !== 'en' && languages[userLanguage]?.wip === false) {
- translationNotices.push({
- type: NotificationType.TRANSLATION,
- content:
- `This article is also available in your language of choice. Click <a href="/${userLanguage}${currentPathWithoutLanguage}">here</a>`
- })
- }
- }
- const releaseNotices: Array<Notif> = []
- if (currentVersion === 'github-ae@latest') {
- releaseNotices.push({
- type: NotificationType.RELEASE,
- content: t('notices.ghae_silent_launch'),
- })
- } else if (currentVersion === data.variables.release_candidate.version) {
- releaseNotices.push({
- type: NotificationType.RELEASE,
- content: `${allVersions[currentVersion].versionTitle}${t('notices.release_candidate')}`,
- })
- }
- const allNotifications: Array<Notif> = [
- ...translationNotices,
- ...releaseNotices,
- // ONEOFF EARLY ACCESS NOTICE
- (relativePath || '').includes('early-access/')
- ? {
- type: NotificationType.EARLY_ACCESS,
- content: t('notices.early_access'),
- }
- : null,
- ].filter(ExcludesNull)
- return (
- <>
- {allNotifications.map(({ type, content }, i) => {
- const isLast = i === allNotifications.length - 1
- return (
- <div
- className={cx(
- 'header-notifications text-center f5 color-text-primary py-4 px-6',
- type === NotificationType.TRANSLATION && 'translation_notice color-bg-info',
- type === NotificationType.RELEASE && 'release_notice color-bg-info',
- type === NotificationType.EARLY_ACCESS && 'early_access color-bg-danger',
- !isLast && 'border-bottom color-border-tertiary'
- )}
- dangerouslySetInnerHTML={{ __html: content }}
- />
- )
- })}
- </>
- )
- }
|