Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

HeaderNotifications.tsx 3.2 KB

You have to be logged in to leave a comment. Sign In
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
  1. import { useRouter } from 'next/router'
  2. import cx from 'classnames'
  3. import { useMainContext } from 'components/context/MainContext'
  4. import { useTranslation } from 'components/hooks/useTranslation'
  5. import { ExcludesNull } from 'components/lib/ExcludesNull'
  6. import { useVersion } from './hooks/useVersion'
  7. enum NotificationType {
  8. RELEASE = 'RELEASE',
  9. TRANSLATION = 'TRANSLATION',
  10. EARLY_ACCESS = 'EARLY_ACCESS',
  11. }
  12. type Notif = {
  13. content: string
  14. type: NotificationType
  15. }
  16. export const HeaderNotifications = () => {
  17. const router = useRouter()
  18. const { currentVersion } = useVersion()
  19. const { relativePath, allVersions, data, languages, currentLanguage, userLanguage, currentPathWithoutLanguage } = useMainContext()
  20. const { t } = useTranslation('header')
  21. const translationNotices: Array<Notif> = []
  22. if (router.locale !== 'en') {
  23. if (relativePath?.includes('/site-policy')) {
  24. translationNotices.push({
  25. type: NotificationType.TRANSLATION,
  26. content: data.reusables.policies.translation,
  27. })
  28. } else if (languages[currentLanguage].wip !== true) {
  29. translationNotices.push({
  30. type: NotificationType.TRANSLATION,
  31. content: t('notices.localization_complete'),
  32. })
  33. } else if (languages[currentLanguage].wip) {
  34. translationNotices.push({
  35. type: NotificationType.TRANSLATION,
  36. content: t('notices.localization_in_progress'),
  37. })
  38. }
  39. } else {
  40. if (userLanguage && userLanguage !== 'en' && languages[userLanguage]?.wip === false) {
  41. translationNotices.push({
  42. type: NotificationType.TRANSLATION,
  43. content:
  44. `This article is also available in your language of choice. Click <a href="/${userLanguage}${currentPathWithoutLanguage}">here</a>`
  45. })
  46. }
  47. }
  48. const releaseNotices: Array<Notif> = []
  49. if (currentVersion === 'github-ae@latest') {
  50. releaseNotices.push({
  51. type: NotificationType.RELEASE,
  52. content: t('notices.ghae_silent_launch'),
  53. })
  54. } else if (currentVersion === data.variables.release_candidate.version) {
  55. releaseNotices.push({
  56. type: NotificationType.RELEASE,
  57. content: `${allVersions[currentVersion].versionTitle}${t('notices.release_candidate')}`,
  58. })
  59. }
  60. const allNotifications: Array<Notif> = [
  61. ...translationNotices,
  62. ...releaseNotices,
  63. // ONEOFF EARLY ACCESS NOTICE
  64. (relativePath || '').includes('early-access/')
  65. ? {
  66. type: NotificationType.EARLY_ACCESS,
  67. content: t('notices.early_access'),
  68. }
  69. : null,
  70. ].filter(ExcludesNull)
  71. return (
  72. <>
  73. {allNotifications.map(({ type, content }, i) => {
  74. const isLast = i === allNotifications.length - 1
  75. return (
  76. <div
  77. className={cx(
  78. 'header-notifications text-center f5 color-text-primary py-4 px-6',
  79. type === NotificationType.TRANSLATION && 'translation_notice color-bg-info',
  80. type === NotificationType.RELEASE && 'release_notice color-bg-info',
  81. type === NotificationType.EARLY_ACCESS && 'early_access color-bg-danger',
  82. !isLast && 'border-bottom color-border-tertiary'
  83. )}
  84. dangerouslySetInnerHTML={{ __html: content }}
  85. />
  86. )
  87. })}
  88. </>
  89. )
  90. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...