@newskit-render/standalone-components 0.28.1-alpha.0 → 0.28.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +192 -25
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -16,15 +16,17 @@ For npm:
16
16
 
17
17
  ## Components
18
18
 
19
- 1. Article recommendations
19
+ ## 1. Article recommendations
20
20
 
21
- - Endpoint `/api/recommendations` is used in the `core` package which returns a list on recommendations articles.
21
+ - Endpoint `/api/recommendations` is used in the `core` package which returns a list of recommendations articles.
22
22
 
23
23
  - Endpoint accepts the following params
24
+
24
25
  - `articleId`
25
26
  - `userId`
26
27
 
27
28
  - Endpoint used in the following files in the `core` package
29
+
28
30
  - `packages/core/pages/[section]/[articleId]/[articleSlug].tsx`
29
31
  - `packages/core/pages/[section]/[articleId]/relatedArticles.tsx`
30
32
 
@@ -71,19 +73,9 @@ For npm:
71
73
  }
72
74
  ```
73
75
 
74
- 2. Help-hub pages: the package provides 2 pages:
75
-
76
- - Search page: where the user is able to search their queries and see the most common questions.
77
- - Result page: displaying the relevant results based on the user query. To facilitate the search we are using Algolia.
78
-
79
- The Help-hub pages will work independent of other components and customized using the context.
76
+ ### How to use
80
77
 
81
- # How to use
82
-
83
- 1. Article recommendations:
84
- First, you need to fetch some article recommendations with the recommendationsProvider function, then iterate over the returned array and use the ArticleRecommendation component to display them.
85
-
86
- Example of use:
78
+ First, you need to fetch some article recommendations with the recommendationsProvider function, then iterate over the returned array and use the ArticleRecommendation component to display them.
87
79
 
88
80
  ```typescript
89
81
  import React from 'react'
@@ -131,22 +123,197 @@ export async function getServerSideProps(context) {
131
123
  }
132
124
  ```
133
125
 
134
- 2. Help-hub pages:
126
+ ## 2. Help-hub:
127
+
128
+ Help - hub is a section of a website on which your customers can search for a specific problem and find some help to resolve it. It consists of three parts:
129
+
130
+ 1. Landing page: Where the user is able to search their queries and see the most common questions.
131
+ 2. Search results page: Displaying the relevant results based on the user query. To facilitate the search we are using Algolia.
132
+ 3. Help article page: Page displaying a specific search result.
135
133
 
136
- Example of use:
134
+ The Help-hub pages will work independent of other components and are customized using the context.
135
+
136
+ ### Prerequisite
137
+
138
+ Help-hub is designed to work only with Next.js, so make sure that your app is running with Next.js
139
+ Before integrating Help-hub, you must ensure that you have an Algolia (Search API) account. If you don't have an account, please create one. After you have obtained an Algolia account, you need to insert the data in it (see docs: https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/#pushing-your-data-to-an-algolia-index). The data must follow the following format:
137
140
 
138
141
  ```typescript
139
- import React from 'react'
140
- import { SearchPage } from '@newskit-render/standalone-components'
141
- import Layout from '../../components/layout'
142
+ {
143
+ title: string
144
+ objectID: string
145
+ content: string
146
+ }
147
+ ```
142
148
 
143
- const HelpHub = () => (
144
- <Layout>
145
- <SearchPage />
146
- </Layout>
147
- )
149
+ ### How to use
150
+
151
+ #### 1. Credentials
152
+
153
+ You need to have Algolia credentials as enviromnent variables:
154
+
155
+ - ALGOLIA_API_KEY
156
+ - ALGOLIA_APP_ID
157
+ - ALGOLIA_INDEX
158
+
159
+ #### 2. Implementation
160
+
161
+ As said above, help hub consists of three pages and we will take a look on how to add each one of them individually. Standalone-components package exports page components and a provider function for each page.
162
+
163
+ 1. Help-Hub Landing page. As stated above, landing page will display the most read articles. For now these articles are hardcoded and need to be passed to the Landing page (see example below). These articles must be already imported in Algolia in order for them to work.
164
+
165
+ ```typescript
166
+ import React, { useContext } from 'react'
167
+ import newrelic from 'newrelic'
168
+ import {
169
+ HelpHubLandingPage,
170
+ helpHubLandingPageProvider,
171
+ } from '@newskit-render/standalone-components'
172
+ import { createThemeDropdownObject } from '../../helpers/createThemeDropdownObject'
173
+ import { AppContext } from '../../context'
174
+ import { addCacheHeaders } from '../../helpers/addCacheHeaders'
175
+
176
+ const mostReadArticles = [
177
+ {
178
+ title: 'Sign-in with Google',
179
+ objectID: 'sign-with-google',
180
+ },
181
+ {
182
+ title:
183
+ 'I am trying to share an article via Google+ but an error message keeps appearing',
184
+ objectID:
185
+ 'i-am-trying-to-share-an-article-via-google-but-an-error-message-keeps-appearing',
186
+ },
187
+ {
188
+ title: 'How will I find out if I have won a competition?',
189
+ objectID: 'how-will-i-find-out-if-i-have-won-a-competition',
190
+ },
191
+ {
192
+ title: 'How do I login/reset my password?',
193
+ objectID: 'how-do-i-login-reset-my-password',
194
+ },
195
+ {
196
+ title: 'How do I cancel or change my pack?',
197
+ objectID: 'how-do-i-cancel-or-change-my-pack',
198
+ },
199
+ {
200
+ title: 'Can I share my Times & Sunday Times iPad subscription access?',
201
+ objectID: 'can-i-share-my-times-sunday-times-ipad-subscription-access',
202
+ },
203
+ ]
204
+
205
+ const LandingPage = (props) => {
206
+ const { theme, setTheme } = useContext(AppContext)
207
+ const themeDropdownObject = createThemeDropdownObject(setTheme)
208
+
209
+ return (
210
+ <HelpHubLandingPage
211
+ {...props}
212
+ context={{ mostReadArticles }}
213
+ customTheme={theme}
214
+ themeDropdownObject={themeDropdownObject}
215
+ />
216
+ )
217
+ }
218
+
219
+ export default LandingPage
220
+
221
+ export const getServerSideProps = async (context) => {
222
+ newrelic.setTransactionName('HelpHubLandingPage')
223
+ console.warn('context:')
224
+ console.warn(context.req && context.req.headers)
225
+ addCacheHeaders(context.res)
148
226
 
149
- export default HelpHub
227
+ return helpHubLandingPageProvider()
228
+ }
229
+ ```
230
+
231
+ 2. Help-hub Search Results page.
232
+
233
+ example usage:
234
+
235
+ ```typescript
236
+ import React, { useContext } from 'react'
237
+ import newrelic from 'newrelic'
238
+ import {
239
+ HelpHubResultsPage,
240
+ AlgoliaCredentials,
241
+ Hit,
242
+ helpHubResultsProvider,
243
+ } from '@newskit-render/standalone-components'
244
+ import { createThemeDropdownObject } from '../../helpers/createThemeDropdownObject'
245
+ import { AppContext } from '../../context'
246
+ import { addCacheHeaders } from '../../helpers/addCacheHeaders'
247
+
248
+ const ResultsPage: React.FC<{
249
+ credentilas: AlgoliaCredentials
250
+ hits: Hit[]
251
+ }> = (props) => {
252
+ const { theme, setTheme } = useContext(AppContext)
253
+ const themeDropdownObject = createThemeDropdownObject(setTheme)
254
+
255
+ return (
256
+ <HelpHubResultsPage
257
+ {...props}
258
+ customTheme={theme}
259
+ themeDropdownObject={themeDropdownObject}
260
+ />
261
+ )
262
+ }
263
+
264
+ export default ResultsPage
265
+
266
+ export const getServerSideProps = async (context) => {
267
+ newrelic.setTransactionName('HelpHubResultsPage')
268
+ console.warn('context:')
269
+ console.warn(context.req && context.req.headers)
270
+
271
+ addCacheHeaders(context.res)
272
+
273
+ const results = await helpHubResultsProvider({ ...context })
274
+ return results
275
+ }
276
+ ```
277
+
278
+ 3. Help-hub Help Article page. Article page uses next.js router to get the article parameter in order to fetch the article. The parameter is called title. That means that your path in Next routing system should look like this:
279
+
280
+ `help-hub/article/[title]/index.tsx`
281
+
282
+ Example use:
283
+
284
+ ```typescript
285
+ import React, { useContext } from 'react'
286
+ import newrelic from 'newrelic'
287
+ import {
288
+ HelpHubArticlePage,
289
+ helpHubArticleProvider,
290
+ } from '@newskit-render/standalone-components'
291
+ import { createThemeDropdownObject } from '../../../../helpers/createThemeDropdownObject'
292
+ import { AppContext } from '../../../../context'
293
+ import { addCacheHeaders } from '../../../../helpers/addCacheHeaders'
294
+
295
+ const ArticlePage = (props) => {
296
+ const { theme, setTheme } = useContext(AppContext)
297
+ const themeDropdownObject = createThemeDropdownObject(setTheme)
298
+
299
+ return (
300
+ <HelpHubArticlePage
301
+ {...props}
302
+ customTheme={theme}
303
+ themeDropdownObject={themeDropdownObject}
304
+ />
305
+ )
306
+ }
307
+
308
+ export const getServerSideProps = async (context) => {
309
+ newrelic.setTransactionName('HelpHubArticlePage')
310
+ console.warn('context:')
311
+ console.warn(context.req && context.req.headers)
312
+
313
+ addCacheHeaders(context.res)
314
+ return helpHubArticleProvider({ ...context })
315
+ }
316
+ export default ArticlePage
150
317
  ```
151
318
 
152
319
  .
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newskit-render/standalone-components",
3
- "version": "0.28.1-alpha.0",
3
+ "version": "0.28.2",
4
4
  "description": "Newskit Render Standalone Components",
5
5
  "author": "",
6
6
  "license": "UNLICENSED",
@@ -81,7 +81,7 @@
81
81
  "@algolia/autocomplete-preset-algolia": "1.6.3",
82
82
  "@apollo/client": "3.4.16",
83
83
  "@newskit-render/api": "^0.36.0",
84
- "@newskit-render/shared-components": "^0.66.1-alpha.0",
84
+ "@newskit-render/shared-components": "^0.66.1",
85
85
  "algoliasearch": "4.13.1",
86
86
  "cross-fetch": "3.1.5",
87
87
  "graphql": "15.6.0",