@aarhus-university/au-lib-react-components 8.80.0 → 8.81.0
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/package.json +1 -1
- package/src/components/profile/AUProfileAvatarV3Component.tsx +42 -0
- package/src/components/profile/{AUProfileWidgetV3Component.js → AUProfileWidgetV3Component.tsx} +24 -36
- package/src/lib/helpers.ts +4 -3
- package/types/common/interfaces.d.ts +19 -0
- package/types/common/props.d.ts +20 -0
- package/src/components/profile/AUProfileAvatarV3Component.js +0 -80
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": "8.
|
|
4
|
+
"version": "8.81.0",
|
|
5
5
|
"description": "Library for shared React components for various applications on au.dk",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "webpack --config ./webpack.config.js"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* eslint-env browser */
|
|
2
|
+
import React, { FC, memo } from 'react';
|
|
3
|
+
import AUProfileWidgetComponent from './AUProfileWidgetV3Component';
|
|
4
|
+
import AUSubNavComponent from '../AUSubNavComponent';
|
|
5
|
+
|
|
6
|
+
const AUProfileAvatarComponent: FC<AUProfileAvatarComponentProps> = memo(({
|
|
7
|
+
user,
|
|
8
|
+
settings,
|
|
9
|
+
profileLabels,
|
|
10
|
+
logoutUri,
|
|
11
|
+
changeLanguageUri,
|
|
12
|
+
lang,
|
|
13
|
+
}: AUProfileAvatarComponentProps) => {
|
|
14
|
+
const {
|
|
15
|
+
auId,
|
|
16
|
+
firstNames,
|
|
17
|
+
lastName,
|
|
18
|
+
} = user;
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<AUSubNavComponent
|
|
22
|
+
id="profile-menu-toggle"
|
|
23
|
+
className="nav__item nav__item--icon nav__item--icon--right"
|
|
24
|
+
dataIcon=""
|
|
25
|
+
text={firstNames}
|
|
26
|
+
ariaLabel={`${profileLabels[lang].profileFor} ${firstNames} ${lastName}`}
|
|
27
|
+
>
|
|
28
|
+
<AUProfileWidgetComponent
|
|
29
|
+
lang={lang}
|
|
30
|
+
name={`${firstNames} ${lastName}`}
|
|
31
|
+
auId={auId}
|
|
32
|
+
settings={settings}
|
|
33
|
+
profileLabels={profileLabels}
|
|
34
|
+
changeLanguageUri={changeLanguageUri}
|
|
35
|
+
logoutUri={logoutUri}
|
|
36
|
+
/>
|
|
37
|
+
</AUSubNavComponent>
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
AUProfileAvatarComponent.displayName = 'AUProfileAvatarComponent';
|
|
42
|
+
export default AUProfileAvatarComponent;
|
package/src/components/profile/{AUProfileWidgetV3Component.js → AUProfileWidgetV3Component.tsx}
RENAMED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
/* eslint-env browser */
|
|
2
|
-
import React, {
|
|
3
|
-
|
|
2
|
+
import React, {
|
|
3
|
+
FC, useEffect, useState, useRef, memo,
|
|
4
|
+
} from 'react';
|
|
4
5
|
import { setCopyToClipboard } from '@aarhus-university/au-designsystem-delphinus/source/js/components/nav';
|
|
5
6
|
|
|
6
|
-
const AUProfileWidgetComponent =
|
|
7
|
+
const AUProfileWidgetComponent: FC<AUProfileWidgetComponentProps> = memo(({
|
|
7
8
|
lang,
|
|
8
9
|
name,
|
|
9
|
-
|
|
10
|
+
auId,
|
|
10
11
|
studentNumber,
|
|
11
12
|
settings,
|
|
12
|
-
|
|
13
|
+
changeLanguageUri,
|
|
13
14
|
logoutUri,
|
|
14
15
|
profileLabels,
|
|
15
|
-
}) => {
|
|
16
|
-
const [ctcSet, setCtcSet] = useState(false);
|
|
17
|
-
const
|
|
18
|
-
|
|
16
|
+
}: AUProfileWidgetComponentProps) => {
|
|
17
|
+
const [ctcSet, setCtcSet] = useState<boolean>(false);
|
|
18
|
+
const btnRefs = useRef<HTMLButtonElement[]>([]);
|
|
19
|
+
btnRefs.current = [];
|
|
20
|
+
const addToRefs = (el: HTMLButtonElement) => {
|
|
21
|
+
if (el && !btnRefs.current.includes(el)) {
|
|
22
|
+
btnRefs.current.push(el);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const renderSettings = settings.map((s, i) => {
|
|
19
26
|
if (s.type === 'anchor') {
|
|
20
27
|
return (
|
|
21
28
|
<a
|
|
@@ -32,11 +39,11 @@ const AUProfileWidgetComponent = React.memo(({
|
|
|
32
39
|
return (
|
|
33
40
|
<button
|
|
34
41
|
key={s.text}
|
|
35
|
-
ref={
|
|
42
|
+
ref={addToRefs}
|
|
36
43
|
type="button"
|
|
37
44
|
disabled={s.disabled}
|
|
38
45
|
className={`sub-nav__item ${s.classNames}`}
|
|
39
|
-
onClick={() => s.onClick(
|
|
46
|
+
onClick={() => s.onClick(btnRefs.current[i])}
|
|
40
47
|
data-icon={s.icon}
|
|
41
48
|
data-gtm={s.dataGtm}
|
|
42
49
|
>
|
|
@@ -46,7 +53,7 @@ const AUProfileWidgetComponent = React.memo(({
|
|
|
46
53
|
});
|
|
47
54
|
|
|
48
55
|
useEffect(() => {
|
|
49
|
-
if (
|
|
56
|
+
if (auId > 0 && !ctcSet) {
|
|
50
57
|
setCopyToClipboard(lang);
|
|
51
58
|
setCtcSet(true);
|
|
52
59
|
}
|
|
@@ -60,11 +67,11 @@ const AUProfileWidgetComponent = React.memo(({
|
|
|
60
67
|
type="button"
|
|
61
68
|
className="copy-to-clipboard"
|
|
62
69
|
title={profileLabels[lang].copyAuid}
|
|
63
|
-
aria-label={`${profileLabels[lang].auId}: AU${
|
|
70
|
+
aria-label={`${profileLabels[lang].auId}: AU${auId}`}
|
|
64
71
|
data-gtm="au-btn-header-copy-auid"
|
|
65
72
|
>
|
|
66
73
|
{`${profileLabels[lang].auId}: `}
|
|
67
|
-
<span className="copy-to-clipboard__this">{`AU${
|
|
74
|
+
<span className="copy-to-clipboard__this">{`AU${auId}`}</span>
|
|
68
75
|
</button>
|
|
69
76
|
{
|
|
70
77
|
studentNumber && (
|
|
@@ -84,9 +91,9 @@ const AUProfileWidgetComponent = React.memo(({
|
|
|
84
91
|
{renderSettings}
|
|
85
92
|
<hr />
|
|
86
93
|
{
|
|
87
|
-
|
|
94
|
+
changeLanguageUri && (
|
|
88
95
|
<>
|
|
89
|
-
<a className="sub-nav__item sub-nav__item--icon" href={
|
|
96
|
+
<a className="sub-nav__item sub-nav__item--icon" href={changeLanguageUri} data-icon="" data-gtm="au-btn-header-profile-changelanguage">{profileLabels[lang].changeLanguage}</a>
|
|
90
97
|
<hr />
|
|
91
98
|
</>
|
|
92
99
|
)
|
|
@@ -104,26 +111,7 @@ const AUProfileWidgetComponent = React.memo(({
|
|
|
104
111
|
});
|
|
105
112
|
|
|
106
113
|
AUProfileWidgetComponent.defaultProps = {
|
|
107
|
-
studentNumber:
|
|
108
|
-
changeLanguageUrl: '',
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
AUProfileWidgetComponent.propTypes = {
|
|
112
|
-
lang: PropTypes.string.isRequired,
|
|
113
|
-
name: PropTypes.string.isRequired,
|
|
114
|
-
auid: PropTypes.number.isRequired,
|
|
115
|
-
studentNumber: PropTypes.string,
|
|
116
|
-
settings: PropTypes.arrayOf(PropTypes.shape({
|
|
117
|
-
type: PropTypes.string.isRequired,
|
|
118
|
-
url: PropTypes.string,
|
|
119
|
-
text: PropTypes.string.isRequired,
|
|
120
|
-
onClick: PropTypes.func,
|
|
121
|
-
classNames: PropTypes.string,
|
|
122
|
-
icon: PropTypes.string,
|
|
123
|
-
})).isRequired,
|
|
124
|
-
profileLabels: PropTypes.shape({}).isRequired,
|
|
125
|
-
changeLanguageUrl: PropTypes.string,
|
|
126
|
-
logoutUri: PropTypes.string.isRequired,
|
|
114
|
+
studentNumber: '',
|
|
127
115
|
};
|
|
128
116
|
|
|
129
117
|
AUProfileWidgetComponent.displayName = 'AUProfileWidgetComponent';
|
package/src/lib/helpers.ts
CHANGED
|
@@ -47,7 +47,8 @@ const isElementPartlyInViewport = (element: HTMLElement): boolean => {
|
|
|
47
47
|
|
|
48
48
|
const setCookie = (
|
|
49
49
|
cookieName: string,
|
|
50
|
-
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
value: any,
|
|
51
52
|
maxAge: number | null = null,
|
|
52
53
|
exdays: number | null = null,
|
|
53
54
|
path = ';path=/;domain=au.dk',
|
|
@@ -139,11 +140,11 @@ const splitPhoneNumber = (countryCodes: ICountryCode[], phoneNumber: string): IP
|
|
|
139
140
|
if (countryCodes.length > 0) {
|
|
140
141
|
const skip = '';
|
|
141
142
|
let count = 1;
|
|
142
|
-
let prefix = countryCodes.find((x) => x.important)?.code
|
|
143
|
+
let prefix = `${countryCodes.find((x) => x.important)?.code}`;
|
|
143
144
|
while (count < phoneNumber.length) {
|
|
144
145
|
const split = phoneNumber.substring(skip.length, skip.length + count);
|
|
145
146
|
if (countryCodeFound(split)) {
|
|
146
|
-
prefix =
|
|
147
|
+
prefix = split;
|
|
147
148
|
}
|
|
148
149
|
count += 1;
|
|
149
150
|
}
|
|
@@ -62,3 +62,22 @@ interface ITrackers {
|
|
|
62
62
|
account: string,
|
|
63
63
|
name: string,
|
|
64
64
|
}
|
|
65
|
+
|
|
66
|
+
interface IProfileSettings {
|
|
67
|
+
type: string,
|
|
68
|
+
url: string,
|
|
69
|
+
classNames: string,
|
|
70
|
+
icon: string,
|
|
71
|
+
dataGtm: string,
|
|
72
|
+
text: string,
|
|
73
|
+
disabled: boolean,
|
|
74
|
+
onClick: (el: Element) => void,
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
interface IProfileUser {
|
|
78
|
+
auId: number,
|
|
79
|
+
firstNames: string,
|
|
80
|
+
lastName: string,
|
|
81
|
+
preferredLanguage: string,
|
|
82
|
+
studentNumber: string,
|
|
83
|
+
}
|
package/types/common/props.d.ts
CHANGED
|
@@ -136,3 +136,23 @@ interface AUReceiptComponentProps {
|
|
|
136
136
|
showGoTo: boolean,
|
|
137
137
|
buttons: IReceiptButton[],
|
|
138
138
|
}
|
|
139
|
+
|
|
140
|
+
interface AUProfileWidgetComponentProps {
|
|
141
|
+
lang: string,
|
|
142
|
+
name: string,
|
|
143
|
+
auId: number,
|
|
144
|
+
studentNumber?: string,
|
|
145
|
+
settings: IProfileSettings[],
|
|
146
|
+
changeLanguageUri: string,
|
|
147
|
+
logoutUri: string,
|
|
148
|
+
profileLabels: any, // Noget med labels her?
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
interface AUProfileAvatarComponentProps {
|
|
152
|
+
user: IProfileUser,
|
|
153
|
+
settings: IProfileSettings[],
|
|
154
|
+
profileLabels: any, // Noget med labels her?
|
|
155
|
+
logoutUri: string,
|
|
156
|
+
changeLanguageUri: string,
|
|
157
|
+
lang: string,
|
|
158
|
+
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/* eslint-env browser */
|
|
2
|
-
import React, { useEffect } from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import AUProfileWidgetComponent from './AUProfileWidgetV3Component';
|
|
5
|
-
import AUSubNavComponent from '../delphinus/AUSubNavComponent';
|
|
6
|
-
|
|
7
|
-
const AUProfileAvatarComponent = React.memo(({
|
|
8
|
-
user,
|
|
9
|
-
settings,
|
|
10
|
-
onLoad,
|
|
11
|
-
onLoadAction,
|
|
12
|
-
profileLabels,
|
|
13
|
-
logoutUri,
|
|
14
|
-
changeLanguageUrl,
|
|
15
|
-
lang,
|
|
16
|
-
}) => {
|
|
17
|
-
const {
|
|
18
|
-
auId,
|
|
19
|
-
firstNames,
|
|
20
|
-
lastName,
|
|
21
|
-
} = user;
|
|
22
|
-
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (typeof onLoad === 'function') {
|
|
25
|
-
onLoad(onLoadAction);
|
|
26
|
-
}
|
|
27
|
-
}, []);
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<AUSubNavComponent
|
|
31
|
-
id="profile-menu-toggle"
|
|
32
|
-
className="nav__item nav__item--icon nav__item--icon--right"
|
|
33
|
-
dataIcon=""
|
|
34
|
-
text={firstNames}
|
|
35
|
-
ariaLabel={`${profileLabels[lang].profileFor} ${firstNames} ${lastName}`}
|
|
36
|
-
>
|
|
37
|
-
<AUProfileWidgetComponent
|
|
38
|
-
lang={lang}
|
|
39
|
-
name={`${firstNames} ${lastName}`}
|
|
40
|
-
auid={auId}
|
|
41
|
-
settings={settings}
|
|
42
|
-
profileLabels={profileLabels}
|
|
43
|
-
changeLanguageUrl={changeLanguageUrl}
|
|
44
|
-
logoutUri={logoutUri}
|
|
45
|
-
/>
|
|
46
|
-
</AUSubNavComponent>
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
AUProfileAvatarComponent.defaultProps = {
|
|
51
|
-
onLoad: null,
|
|
52
|
-
onLoadAction: () => {
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
changeLanguageUrl: '',
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
AUProfileAvatarComponent.propTypes = {
|
|
59
|
-
user: PropTypes.shape({
|
|
60
|
-
auId: PropTypes.number.isRequired,
|
|
61
|
-
firstNames: PropTypes.string.isRequired,
|
|
62
|
-
lastName: PropTypes.string.isRequired,
|
|
63
|
-
preferredLanguage: PropTypes.string.isRequired,
|
|
64
|
-
}).isRequired,
|
|
65
|
-
settings: PropTypes.arrayOf(PropTypes.shape({
|
|
66
|
-
type: PropTypes.string.isRequired,
|
|
67
|
-
url: PropTypes.string,
|
|
68
|
-
text: PropTypes.string.isRequired,
|
|
69
|
-
onClick: PropTypes.func,
|
|
70
|
-
})).isRequired,
|
|
71
|
-
onLoad: PropTypes.func,
|
|
72
|
-
onLoadAction: PropTypes.func,
|
|
73
|
-
profileLabels: PropTypes.shape({}).isRequired,
|
|
74
|
-
logoutUri: PropTypes.string.isRequired,
|
|
75
|
-
changeLanguageUrl: PropTypes.string,
|
|
76
|
-
lang: PropTypes.string.isRequired,
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
AUProfileAvatarComponent.displayName = 'AUProfileAvatarComponent';
|
|
80
|
-
export default AUProfileAvatarComponent;
|