@influenzanet/participant-webapp-kit 0.1.0 → 0.1.1

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.
package/README.md CHANGED
@@ -56,6 +56,14 @@ export default defineConfig(influenzanetVite({
56
56
  Env vars keep the CRA names (`REACT_APP_*`) because case-web-app-core reads them; they're
57
57
  available as `process.env.REACT_APP_X` in code and `%REACT_APP_X%` in `index.html`.
58
58
 
59
+ ## Default texts
60
+
61
+ Texts of the pages every country has (for now the newsletter and weekly reminder unsubscribe
62
+ pages) ship with the kit, in `src/locales/<language>/<namespace>.json` (`en` and `it`), and are
63
+ added under the country's own locale files when the app starts. A country does not copy them:
64
+ to change one, put the same key in its own `public/assets/locales/<language>/<namespace>.json`,
65
+ which always wins. Other languages fall back to the fallback language for the keys they lack.
66
+
59
67
  ## Extensions
60
68
 
61
69
  Used from `pages.json` items (case-web-app-core 2.7.x matches on `config.type`):
@@ -0,0 +1,16 @@
1
+ import { i18n as I18n } from "i18next";
2
+ /** Texts by language, then namespace: `{ it: { linkresolvers: { ... } } }`. */
3
+ export type DefaultTexts = Record<string, Record<string, object>>;
4
+ /**
5
+ * The texts of the pages every country app has (src/locales/<language>/<namespace>.json). A
6
+ * country gets them without copying them into its public/ folder, and replaces any of them by
7
+ * putting the same key in its own locale file.
8
+ */
9
+ export declare const kitTexts: DefaultTexts;
10
+ /**
11
+ * Fills the keys a country's locale files lack with the given texts, once i18n has loaded each
12
+ * namespace, or failed to (the country has no file for it). The country's own keys are never
13
+ * replaced. The texts are added while i18n records the load, before the components waiting
14
+ * for the namespace render. Call it right after i18n is initialised.
15
+ */
16
+ export declare function addDefaultTexts(defaults: DefaultTexts, instance?: I18n): void;
@@ -0,0 +1,38 @@
1
+ import i18n from "i18next";
2
+ import enLinkResolvers from "./locales/en/linkresolvers.json";
3
+ import itLinkResolvers from "./locales/it/linkresolvers.json";
4
+ /**
5
+ * The texts of the pages every country app has (src/locales/<language>/<namespace>.json). A
6
+ * country gets them without copying them into its public/ folder, and replaces any of them by
7
+ * putting the same key in its own locale file.
8
+ */
9
+ export const kitTexts = {
10
+ en: { linkresolvers: enLinkResolvers },
11
+ it: { linkresolvers: itLinkResolvers },
12
+ };
13
+ /**
14
+ * Fills the keys a country's locale files lack with the given texts, once i18n has loaded each
15
+ * namespace, or failed to (the country has no file for it). The country's own keys are never
16
+ * replaced. The texts are added while i18n records the load, before the components waiting
17
+ * for the namespace render. Call it right after i18n is initialised.
18
+ */
19
+ export function addDefaultTexts(defaults, instance = i18n) {
20
+ let adding = false;
21
+ const fill = (lng, ns) => {
22
+ var _a;
23
+ const texts = (_a = defaults[lng]) === null || _a === void 0 ? void 0 : _a[ns];
24
+ // addResourceBundle announces itself as "added" too: ignore our own addition.
25
+ if (!texts || adding)
26
+ return;
27
+ adding = true;
28
+ try {
29
+ // A copy: i18n keeps the objects it is given, and a later load merges into them.
30
+ instance.addResourceBundle(lng, ns, JSON.parse(JSON.stringify(texts)), true, false);
31
+ }
32
+ finally {
33
+ adding = false;
34
+ }
35
+ };
36
+ instance.store.on("added", fill);
37
+ instance.on("failedLoading", fill);
38
+ }
package/dist/index.d.ts CHANGED
@@ -5,3 +5,5 @@ export type { ParticipantAppProps, Extension, DateLocale } from "./ParticipantAp
5
5
  export { defaultExtensions, IframeEmbed, BlogPosts } from "./extensions";
6
6
  export type { IframeEmbedProps } from "./extensions/IframeEmbed";
7
7
  export type { BlogPostsProps } from "./extensions/BlogPosts/BlogPosts";
8
+ export { kitTexts, addDefaultTexts } from "./defaultTexts";
9
+ export type { DefaultTexts } from "./defaultTexts";
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { renderParticipantApp } from "./render";
2
2
  export { default as ParticipantApp } from "./ParticipantApp";
3
3
  export { defaultExtensions, IframeEmbed, BlogPosts } from "./extensions";
4
+ export { kitTexts, addDefaultTexts } from "./defaultTexts";
@@ -0,0 +1,19 @@
1
+ {
2
+ "unsubscribe": {
3
+ "newsletter": {
4
+ "title": "Unsubscribe from the newsletter",
5
+ "info": "Confirm to stop receiving the newsletter.",
6
+ "success": "Done: you will no longer receive the newsletter. You can subscribe again at any time in your account settings."
7
+ },
8
+ "weekly": {
9
+ "title": "Stop the weekly reminder",
10
+ "info": "Confirm to stop receiving the weekly reminder. You can still fill in the questionnaire whenever you like.",
11
+ "success": "Done: you will no longer receive the weekly reminder. You can turn it back on at any time in your account settings."
12
+ },
13
+ "confirmBtn": "Confirm",
14
+ "retryBtn": "Try again",
15
+ "homeBtn": "Go to the home page",
16
+ "invalidLink": "This link is not valid or has expired. You can change your subscriptions in your account settings after logging in.",
17
+ "error": "Something went wrong and nothing was changed. Please try again in a few minutes."
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "unsubscribe": {
3
+ "newsletter": {
4
+ "title": "Disiscriviti dalla newsletter",
5
+ "info": "Conferma per non ricevere più la newsletter.",
6
+ "success": "Fatto: non riceverai più la newsletter. Puoi iscriverti di nuovo in qualsiasi momento dalle impostazioni del tuo account."
7
+ },
8
+ "weekly": {
9
+ "title": "Disattiva il promemoria settimanale",
10
+ "info": "Conferma per non ricevere più il promemoria settimanale. Potrai comunque compilare il questionario quando vuoi.",
11
+ "success": "Fatto: non riceverai più il promemoria settimanale. Puoi riattivarlo in qualsiasi momento dalle impostazioni del tuo account."
12
+ },
13
+ "confirmBtn": "Conferma",
14
+ "retryBtn": "Riprova",
15
+ "homeBtn": "Vai alla pagina iniziale",
16
+ "invalidLink": "Il link non è valido o è scaduto. Puoi modificare le tue iscrizioni dalle impostazioni del tuo account, dopo aver effettuato l'accesso.",
17
+ "error": "Si è verificato un errore e non è stato modificato nulla. Riprova tra qualche minuto."
18
+ }
19
+ }
package/dist/render.d.ts CHANGED
@@ -11,7 +11,7 @@ export interface RenderOptions extends ParticipantAppProps {
11
11
  rootId?: string;
12
12
  }
13
13
  /**
14
- * Boots a participant web app: i18n, redux store, Suspense fallback, and the
15
- * ParticipantApp (AppCore + kit extensions + country extensions).
14
+ * Boots a participant web app: i18n (with the kit's default texts under the country's), redux
15
+ * store, Suspense fallback, and the ParticipantApp (AppCore + kit extensions + country extensions).
16
16
  */
17
17
  export declare function renderParticipantApp(options: RenderOptions): void;
package/dist/render.js CHANGED
@@ -7,15 +7,17 @@ import { LoadingPlaceholder } from "@influenzanet/case-web-ui";
7
7
  import "./runtime";
8
8
  import { env } from "./env";
9
9
  import ParticipantApp from "./ParticipantApp";
10
+ import { addDefaultTexts, kitTexts } from "./defaultTexts";
10
11
  /**
11
- * Boots a participant web app: i18n, redux store, Suspense fallback, and the
12
- * ParticipantApp (AppCore + kit extensions + country extensions).
12
+ * Boots a participant web app: i18n (with the kit's default texts under the country's), redux
13
+ * store, Suspense fallback, and the ParticipantApp (AppCore + kit extensions + country extensions).
13
14
  */
14
15
  export function renderParticipantApp(options) {
15
16
  var _a, _b, _c, _d;
16
17
  const { fallbackLanguage, localeUrl, beforeRender, rootId, ...appProps } = options;
17
18
  const defaultLanguage = (_b = (_a = appProps.defaultLanguage) !== null && _a !== void 0 ? _a : env.defaultLanguage) !== null && _b !== void 0 ? _b : "en";
18
19
  initI18n(defaultLanguage, (_c = fallbackLanguage !== null && fallbackLanguage !== void 0 ? fallbackLanguage : env.fallbackLanguage) !== null && _c !== void 0 ? _c : "en", localeUrl !== null && localeUrl !== void 0 ? localeUrl : `${(_d = env.contentUrl) !== null && _d !== void 0 ? _d : "/assets"}/locales`);
20
+ addDefaultTexts(kitTexts);
19
21
  beforeRender === null || beforeRender === void 0 ? void 0 : beforeRender();
20
22
  ReactDOM.render(_jsx(React.StrictMode, { children: _jsx(Provider, { store: store, children: _jsx(Suspense, { fallback: _jsx(LoadingPlaceholder, { color: "secondary", minHeight: "100vh" }), children: _jsx(ParticipantApp, { ...appProps, defaultLanguage: defaultLanguage }) }) }) }), document.getElementById(rootId !== null && rootId !== void 0 ? rootId : "root"));
21
23
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@influenzanet/participant-webapp-kit",
3
- "version": "0.1.0",
4
- "description": "Shared shell for Influenzanet participant web apps: bootstrap, Vite preset and generic page extensions on top of case-web-app-core",
3
+ "version": "0.1.1",
4
+ "description": "Shared code for Influenzanet participant web apps: bootstrap, Vite preset and generic page extensions on top of case-web-app-core",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
@@ -32,6 +32,7 @@
32
32
  "clean": "rm -rf dist",
33
33
  "build": "yarn clean && tsc -p tsconfig.json && tsc -p tsconfig.vite.json && node scripts/copy-css.mjs",
34
34
  "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.vite.json --noEmit",
35
+ "test": "vitest run",
35
36
  "prepublishOnly": "yarn build"
36
37
  },
37
38
  "dependencies": {
@@ -75,7 +76,8 @@
75
76
  "redux": "^4.2.0",
76
77
  "survey-engine": "1.2.1",
77
78
  "typescript": "^5.6.0",
78
- "vite": "^6.4.2"
79
+ "vite": "^6.4.2",
80
+ "vitest": "^3.2.0"
79
81
  },
80
82
  "resolutions": {
81
83
  "@types/react": "^17.0.2"