Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MT-5280] Feature - Implement banner on preview newsrooms #93

Merged
merged 5 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.14.2
v16
72 changes: 22 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"react-dom": "^17.x || ^18.x"
},
"dependencies": {
"@prezly/sdk": "^6.24.0",
"@prezly/sdk": "^7.3.0",
"@react-hookz/web": "^14.2.2",
"next-seo": "^5.4.0",
"parse-data-url": "^4.0.1"
Expand Down
9 changes: 9 additions & 0 deletions src/__mocks__/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const LANGUAGES: Record<string, NewsroomLanguageSettings> = {
subscribe_disclaimer:
'<p>Door uw abonnement te bevestigen, bevestigt u dat u begrijpt dat u zich registreert om materiaal te ontvangen en dat uw gegevens veilig worden verwerkt en opgeslagen.</p>',
},
notifications: [],
},
nl_NL: {
code: 'nl_NL',
Expand Down Expand Up @@ -88,6 +89,7 @@ export const LANGUAGES: Record<string, NewsroomLanguageSettings> = {
cookie_statement: '',
subscribe_disclaimer: '',
},
notifications: [],
},
en: {
code: 'en',
Expand Down Expand Up @@ -134,6 +136,7 @@ export const LANGUAGES: Record<string, NewsroomLanguageSettings> = {
subscribe_disclaimer:
'<p>By confirming your subscription you are confirming you understand that you are registering to receive content and consent to your information being securely processed and stored.</p>',
},
notifications: [],
},
en_US: {
code: 'en_US',
Expand Down Expand Up @@ -180,6 +183,7 @@ export const LANGUAGES: Record<string, NewsroomLanguageSettings> = {
subscribe_disclaimer:
'<p>By confirming your subscription you are confirming you understand that you are registering to receive content and consent to your information being securely processed and stored.</p>',
},
notifications: [],
},
en_GB: {
code: 'en_GB',
Expand Down Expand Up @@ -226,6 +230,7 @@ export const LANGUAGES: Record<string, NewsroomLanguageSettings> = {
subscribe_disclaimer:
'<p>By confirming your subscription you are confirming you understand that you are registering to receive content and consent to your information being securely processed and stored.</p>',
},
notifications: [],
},
fr: {
code: 'fr',
Expand Down Expand Up @@ -272,6 +277,7 @@ export const LANGUAGES: Record<string, NewsroomLanguageSettings> = {
subscribe_disclaimer:
'<p>En confirmant votre inscription, vous confirmez que vous comprenez que vous vous inscrivez pour recevoir du contenu, et consentez à ce que vos données personnelles soient traitées et stockées en toute sécurité.</p>',
},
notifications: [],
},
fr_BE: {
code: 'fr_BE',
Expand Down Expand Up @@ -318,6 +324,7 @@ export const LANGUAGES: Record<string, NewsroomLanguageSettings> = {
subscribe_disclaimer:
'<p>En confirmant votre inscription, vous confirmez que vous comprenez que vous vous inscrivez pour recevoir du contenu, et consentez à ce que vos données personnelles soient traitées et stockées en toute sécurité.</p>',
},
notifications: [],
},
es_ES: {
code: 'es_ES',
Expand Down Expand Up @@ -361,6 +368,7 @@ export const LANGUAGES: Record<string, NewsroomLanguageSettings> = {
subscribe_disclaimer:
'<p>Al confirmar su suscripción, confirma que entiende que se está registrando para recibir contenido y accede a que su información se procese y guarde de manera segura.</p>',
},
notifications: [],
},
es_419: {
code: 'es_419',
Expand Down Expand Up @@ -404,5 +412,6 @@ export const LANGUAGES: Record<string, NewsroomLanguageSettings> = {
subscribe_disclaimer:
'<p>Al confirmar su suscripción, confirma que entiende que se está registrando para recibir contenido y accede a que su información se procese y guarde de manera segura.</p>',
},
notifications: [],
},
};
7 changes: 4 additions & 3 deletions src/__mocks__/story.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ExtendedStory } from '@prezly/sdk';
import {
NewsroomStatus,
StoryLifecycleStatus,
StoryPublicationStatus,
StoryVisibility,
Expand Down Expand Up @@ -68,6 +69,7 @@ export const STORY: ExtendedStory = {
thumbnail_url:
'https://avatars-cdn.prezly.com/newsroom/12698/e4939974b7781d4c61e282713116690387e9b7b1f6302478b13b68e18e0d3055?t=1648556918&v=1',
timezone: 'europe/london',
status: NewsroomStatus.ACTIVE,
is_active: true,
is_archived: false,
is_online: true,
Expand All @@ -77,7 +79,6 @@ export const STORY: ExtendedStory = {
url: 'https://the-good-news-room.prezly.com/',
links: {
media_gallery_api: 'https://api.prezly.com/v1/rooms/12698/media',
room_contacts_api: 'https://api.prezly.com/v1/rooms/12698/contacts',
analytics_and_visibility_settings:
'https://rock.prezly.com/pressroom/the-good-news-room/ga',
categories_management:
Expand Down Expand Up @@ -178,6 +179,7 @@ export const STORY: ExtendedStory = {
thumbnail_url:
'https://avatars-cdn.prezly.com/newsroom/12698/e4939974b7781d4c61e282713116690387e9b7b1f6302478b13b68e18e0d3055?t=1648556918&v=1',
timezone: 'europe/london',
status: NewsroomStatus.ACTIVE,
is_active: true,
is_archived: false,
is_online: true,
Expand All @@ -187,7 +189,6 @@ export const STORY: ExtendedStory = {
url: 'https://the-good-news-room.prezly.com/',
links: {
media_gallery_api: 'https://api.prezly.com/v1/rooms/12698/media',
room_contacts_api: 'https://api.prezly.com/v1/rooms/12698/contacts',
analytics_and_visibility_settings:
'https://rock.prezly.com/pressroom/the-good-news-room/ga',
categories_management:
Expand Down Expand Up @@ -277,6 +278,7 @@ export const STORY: ExtendedStory = {
thumbnail_url:
'https://avatars-cdn.prezly.com/newsroom/12698/e4939974b7781d4c61e282713116690387e9b7b1f6302478b13b68e18e0d3055?t=1648556918&v=1',
timezone: 'europe/london',
status: NewsroomStatus.ACTIVE,
is_active: true,
is_archived: false,
is_online: true,
Expand All @@ -286,7 +288,6 @@ export const STORY: ExtendedStory = {
url: 'https://the-good-news-room.prezly.com/',
links: {
media_gallery_api: 'https://api.prezly.com/v1/rooms/12698/media',
room_contacts_api: 'https://api.prezly.com/v1/rooms/12698/contacts',
analytics_and_visibility_settings:
'https://rock.prezly.com/pressroom/the-good-news-room/ga',
categories_management:
Expand Down
3 changes: 3 additions & 0 deletions src/data-fetching/api/PrezlyApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getDefaultLanguage,
getLanguageFromNextLocaleIsoCode,
getLanguageFromStory,
getNotifications,
LocaleObject,
} from '../../intl';
import type { PageProps, ServerSidePageProps } from '../../types';
Expand Down Expand Up @@ -273,6 +274,7 @@ export class PrezlyApi {
// TODO: if no information given for current language, show boilerplate from default language
const companyInformation = getCompanyInformation(languages, locale);

const notifications = getNotifications(languages, locale);
const algoliaSettings = getAlgoliaSettings(request);

return {
Expand All @@ -282,6 +284,7 @@ export class PrezlyApi {
categories,
languages,
localeCode,
notifications,
themePreset,
algoliaSettings,
},
Expand Down
12 changes: 11 additions & 1 deletion src/intl/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,17 @@ export function getCompanyInformation(languages: NewsroomLanguageSettings[], loc
}

/**
* Get shortest locale code possible from full locale code
* Get newsroom notifications for the selected locale
*/
export function getNotifications(languages: NewsroomLanguageSettings[], locale: LocaleObject) {
const currentLanguage =
getLanguageByExactLocaleCode(languages, locale) || getDefaultLanguage(languages);

return currentLanguage.notifications;
}

/**
* Get the shortest locale code possible from full locale code
* First: try shorting to neutral language code (there should be no locales with the same language code)
* Then: try shorting to region code (there should be no locales with the same region code)
* Finally: return the original locale code (shorting is not possible)
Expand Down
7 changes: 7 additions & 0 deletions src/newsroom-context/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
NewsroomContact,
NewsroomLanguageSettings,
NewsroomThemePreset,
Notification,
} from '@prezly/sdk';
import type { PropsWithChildren } from 'react';
import { createContext, useMemo } from 'react';
Expand Down Expand Up @@ -47,6 +48,10 @@ export interface NewsroomContextType {
* Currently chosen locale
*/
locale: LocaleObject;
/**
* Newsroom user-facing notifications (usually displayed as top-edge banners)
*/
notifications: Notification[];
/**
* Theme settings as set in the Prezly app.
* You need to provide `PREZLY_THEME_UUID` in environment variables in order for the preset to be loaded.
Expand Down Expand Up @@ -78,6 +83,7 @@ export function NewsroomContextProvider({
companyInformation,
languages,
localeCode,
notifications,
themePreset,
algoliaSettings,
children,
Expand All @@ -98,6 +104,7 @@ export function NewsroomContextProvider({
companyInformation,
languages,
locale,
notifications,
themePreset,
algoliaSettings,
}}
Expand Down