@aarhus-university/au-lib-react-components 10.13.0 → 10.15.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.
@@ -0,0 +1,25 @@
1
+ import { getPortalByName } from '../../src/lib/portals';
2
+
3
+ describe('Context', () => {
4
+ test('Mitstudie findes som portal', () => {
5
+ const portal = getPortalByName('da', 'mitstudie');
6
+ expect(portal?.name).toBe('mitstudie');
7
+ });
8
+
9
+ test('Mitstudie portalcontexten indeholder én impersonation option', () => {
10
+ const portal = getPortalByName('da', 'mitstudie');
11
+ expect(portal?.impersonationOptions.length).toBe(1);
12
+ });
13
+
14
+ test('Mitstudie portalcontextens ene impersonation option hedder "AU-id" på dansk og "AU ID" på engelsk', () => {
15
+ const danish = getPortalByName('da', 'mitstudie');
16
+ expect(danish?.impersonationOptions[0].label).toBe('AU-id');
17
+ const english = getPortalByName('en', 'mitstudie');
18
+ expect(english?.impersonationOptions[0].label).toBe('AU ID');
19
+ });
20
+
21
+ test('Portalcontexten "sfgsdfsdfsdf" findes ikke', () => {
22
+ const portal = getPortalByName('da', 'sfgsdfsdfsdf');
23
+ expect(portal).toBe(null);
24
+ });
25
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "@aarhus-university/au-lib-react-components",
4
- "version": "10.13.0",
4
+ "version": "10.15.1",
5
5
  "description": "Library for shared React components for various applications on au.dk",
6
6
  "scripts": {
7
7
  "test": "jest",
@@ -70,8 +70,8 @@
70
70
  "webpack-cli": "^4.9.2"
71
71
  },
72
72
  "dependencies": {
73
- "@aarhus-university/au-designsystem-delphinus": "0.29.0",
74
- "@aarhus-university/types": "0.9.0",
73
+ "@aarhus-university/au-designsystem-delphinus": "0.30.1",
74
+ "@aarhus-university/types": "0.10.1",
75
75
  "@reduxjs/toolkit": "^1.8.3",
76
76
  "@types/google.analytics": "^0.0.42",
77
77
  "@types/history": "^5.0.0",
@@ -0,0 +1,38 @@
1
+ import React, { createContext, useContext } from 'react';
2
+ import { setLocale } from './dates';
3
+ import { getPortalByName } from './portals';
4
+
5
+ export const LangContext = createContext<string>('da');
6
+ export const useLangContext = (): string => {
7
+ const lang = useContext(LangContext);
8
+ setLocale(lang);
9
+ return lang;
10
+ };
11
+
12
+ export const UserContext = createContext<AU.IUserContext | null>(null);
13
+ export const useUserContext = (): AU.IUserContext | null => {
14
+ const user = useContext(UserContext);
15
+ return user;
16
+ };
17
+
18
+ export const PortalContext = createContext<AU.IPortalContext | null>(null);
19
+
20
+ export const AUPortal = {
21
+ Provider: ({
22
+ name,
23
+ children,
24
+ }: PortalContextProviderProps) => {
25
+ const lang = useLangContext();
26
+ const portal = getPortalByName(lang || 'da', name);
27
+ return (
28
+ <PortalContext.Provider value={portal}>
29
+ {children}
30
+ </PortalContext.Provider>
31
+ );
32
+ },
33
+ };
34
+
35
+ export const usePortalContext = (): AU.IPortalContext | null => {
36
+ const portal = useContext(PortalContext);
37
+ return portal;
38
+ };
@@ -0,0 +1,23 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ const impersonationLabels = {
3
+ IMPERSONATION_SELECT_OPTION_CPR: { da: 'CPR-nr.', en: 'CPR no.' },
4
+ IMPERSONATION_SELECT_OPTION_EMAIL: { da: 'E-mail', en: 'Email' },
5
+ IMPERSONATION_SELECT_OPTION_AUID: { da: 'AU-id', en: 'AU ID' },
6
+ };
7
+
8
+ const portals: (lang: string) => AU.IPortalContext[] = (lang: string) => [
9
+ {
10
+ name: 'mitstudie',
11
+ impersonationOptions: [
12
+ {
13
+ value: 'auid',
14
+ label: impersonationLabels.IMPERSONATION_SELECT_OPTION_AUID[lang],
15
+ },
16
+ ],
17
+ },
18
+ ];
19
+
20
+ export const getPortalByName = (
21
+ lang: string,
22
+ name: string,
23
+ ): AU.IPortalContext | null => portals(lang).find((portal) => portal.name === name) ?? null;
@@ -1,13 +0,0 @@
1
- import { createContext, useContext } from 'react';
2
-
3
- export const LangContext = createContext<string>('da');
4
- export const useLangContext = (): string => {
5
- const lang = useContext(LangContext);
6
- return lang;
7
- };
8
-
9
- export const UserContext = createContext<AU.IUserContext | null>(null);
10
- export const useUserContext = (): AU.IUserContext | null => {
11
- const user = useContext(UserContext);
12
- return user;
13
- };