@aarhus-university/au-lib-react-components 10.19.0 → 10.19.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.
- package/package.json +3 -3
- package/src/components/AUButtonComponent.tsx +3 -1
- package/src/components/AUSubmitButtonContainerComponent.tsx +12 -14
- package/src/components/AUToastComponent.tsx +8 -7
- package/src/lib/helpers.ts +1 -1
- package/stories/lib/helpers.tsx +6 -10
- package/src/components/profile/AUProfileActions.js +0 -128
- package/src/components/profile/AUProfileAvatarComponent.js +0 -83
- package/src/components/profile/AUProfileAvatarV2Component.js +0 -91
- package/src/components/profile/AUProfileAvatarV3Component.tsx +0 -42
- package/src/components/profile/AUProfileContainerComponent.js +0 -283
- package/src/components/profile/AUProfileHooks.js +0 -30
- package/src/components/profile/AUProfileItemComponent.js +0 -54
- package/src/components/profile/AUProfileLanguageComponent.js +0 -131
- package/src/components/profile/AUProfileLoginComponent.tsx +0 -26
- package/src/components/profile/AUProfileMailComponent.js +0 -307
- package/src/components/profile/AUProfileMobileComponent.js +0 -164
- package/src/components/profile/AUProfileNameComponent.js +0 -253
- package/src/components/profile/AUProfileNextOfKinComponent.js +0 -216
- package/src/components/profile/AUProfileReducer.js +0 -230
- package/src/components/profile/AUProfileWidgetComponent.js +0 -95
- package/src/components/profile/AUProfileWidgetV2Component.js +0 -116
- package/src/components/profile/AUProfileWidgetV3Component.tsx +0 -122
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
/* eslint-env browser */
|
|
2
|
-
/* eslint-disable jsx-a11y/label-has-associated-control */
|
|
3
|
-
/* eslint-disable jsx-a11y/label-has-for */
|
|
4
|
-
/* eslint-disable max-len */
|
|
5
|
-
import React, { useState, useEffect } from 'react';
|
|
6
|
-
import PropTypes from 'prop-types';
|
|
7
|
-
import { Link } from 'react-router-dom';
|
|
8
|
-
import AUSubmitButtonContainerComponent from '../form/AUSubmitButtonContainerComponent';
|
|
9
|
-
import { useProfileForm } from './AUProfileHooks';
|
|
10
|
-
import { scrollTo } from '../../lib/helpers';
|
|
11
|
-
import { profileLabels } from '../../lib/i18n';
|
|
12
|
-
import { renderValidation, validateForm } from '../../lib/validation';
|
|
13
|
-
|
|
14
|
-
const AUProfileNameComponent = ({
|
|
15
|
-
lang,
|
|
16
|
-
routeProps: { history },
|
|
17
|
-
path,
|
|
18
|
-
firstNames,
|
|
19
|
-
lastName,
|
|
20
|
-
hasChosenName: pHasChosenName,
|
|
21
|
-
chosenFirstNames: pChosenFirstNames,
|
|
22
|
-
chosenLastName: pChosenLastName,
|
|
23
|
-
onSave,
|
|
24
|
-
onSaveAction,
|
|
25
|
-
saving,
|
|
26
|
-
saved,
|
|
27
|
-
dismissMessages,
|
|
28
|
-
clear,
|
|
29
|
-
}) => {
|
|
30
|
-
const validationRules = [{
|
|
31
|
-
message: profileLabels[lang].validFirstName,
|
|
32
|
-
rule: (fieldValue) => fieldValue.trim().length > 0,
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
message: profileLabels[lang].validLastName,
|
|
36
|
-
rule: (fieldValue) => fieldValue.trim().length > 0,
|
|
37
|
-
}];
|
|
38
|
-
|
|
39
|
-
const [hasChosenName, setHasChosenName] = useState(pHasChosenName);
|
|
40
|
-
const [chosenFirstNames, setChosenFirstNames] = useState(pChosenFirstNames);
|
|
41
|
-
const [chosenLastName, setChosenLastName] = useState(pChosenLastName);
|
|
42
|
-
const [firstNameValidationMessages, setFirstNameValidationMessages] = useState([]);
|
|
43
|
-
const [lastNameValidationMessages, setLastNameValidationMessages] = useState([]);
|
|
44
|
-
const [isFirstNameValid, setIsFirstNameValid] = useState(!pHasChosenName || (!!pChosenFirstNames));
|
|
45
|
-
const [isLastNameValid, setIsLastNameValid] = useState(!pHasChosenName || (!!pChosenLastName));
|
|
46
|
-
const [onCancel] = useProfileForm(saved, history, lang, clear);
|
|
47
|
-
|
|
48
|
-
const validateFirstName = (value, alert = true) => {
|
|
49
|
-
const [valid, messages] = validateForm(lang, value, [validationRules[0]]);
|
|
50
|
-
setChosenFirstNames(value);
|
|
51
|
-
setFirstNameValidationMessages(alert ? messages : []);
|
|
52
|
-
setIsFirstNameValid(!hasChosenName || valid);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const validateLastName = (value, alert = true) => {
|
|
56
|
-
const [valid, messages] = validateForm(lang, value, [validationRules[1]]);
|
|
57
|
-
setChosenLastName(value);
|
|
58
|
-
setLastNameValidationMessages(alert ? messages : []);
|
|
59
|
-
setIsLastNameValid(!hasChosenName || valid);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const submit = (e) => {
|
|
63
|
-
e.preventDefault();
|
|
64
|
-
validateFirstName(chosenFirstNames, !isFirstNameValid);
|
|
65
|
-
validateLastName(chosenLastName, !isLastNameValid);
|
|
66
|
-
if (isFirstNameValid && isLastNameValid) {
|
|
67
|
-
onSave({
|
|
68
|
-
hasChosenName,
|
|
69
|
-
chosenFirstNames: chosenFirstNames.trim(),
|
|
70
|
-
chosenLastName: chosenLastName.trim(),
|
|
71
|
-
}, onSaveAction);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
let firstNameValidationClassName = '';
|
|
76
|
-
if (!isFirstNameValid && firstNameValidationMessages.length) {
|
|
77
|
-
firstNameValidationClassName = ' form-info--error';
|
|
78
|
-
} else if (isFirstNameValid) {
|
|
79
|
-
firstNameValidationClassName = ' form-info--confirmed';
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
let lastNameValidationClassName = '';
|
|
83
|
-
if (!isLastNameValid && lastNameValidationMessages.length) {
|
|
84
|
-
lastNameValidationClassName = ' form-info--error';
|
|
85
|
-
} else if (isLastNameValid) {
|
|
86
|
-
lastNameValidationClassName = ' form-info--confirmed';
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
useEffect(() => {
|
|
90
|
-
dismissMessages();
|
|
91
|
-
scrollTo();
|
|
92
|
-
const firstName = document.getElementById('first-name');
|
|
93
|
-
if (firstName) {
|
|
94
|
-
firstName.focus();
|
|
95
|
-
}
|
|
96
|
-
}, []);
|
|
97
|
-
|
|
98
|
-
return [
|
|
99
|
-
<div key="header" className="list-navigator">
|
|
100
|
-
<h1 className="list-navigator__header">{profileLabels[lang].headerName}</h1>
|
|
101
|
-
<Link className="list-navigator__list-name" to={path}>{profileLabels[lang].headerContainer}</Link>
|
|
102
|
-
</div>,
|
|
103
|
-
<form key="form" className="form" noValidate="novalidate">
|
|
104
|
-
<fieldset>
|
|
105
|
-
<legend>
|
|
106
|
-
<div className="fieldset__legend-wrapper">
|
|
107
|
-
{profileLabels[lang].legendName}
|
|
108
|
-
<div className="form-info__hint">
|
|
109
|
-
{profileLabels[lang].legendNameHint}
|
|
110
|
-
</div>
|
|
111
|
-
</div>
|
|
112
|
-
</legend>
|
|
113
|
-
<div className="form__field form__field--horizontal">
|
|
114
|
-
<label htmlFor="default-display-name">
|
|
115
|
-
{`${firstNames} ${lastName}`}
|
|
116
|
-
<div className="form-info__hint">
|
|
117
|
-
{profileLabels[lang].formNameHint}
|
|
118
|
-
</div>
|
|
119
|
-
</label>
|
|
120
|
-
<input
|
|
121
|
-
type="radio"
|
|
122
|
-
id="default-display-name"
|
|
123
|
-
checked={!hasChosenName}
|
|
124
|
-
onChange={() => {
|
|
125
|
-
setHasChosenName(false);
|
|
126
|
-
setChosenFirstNames(firstNames);
|
|
127
|
-
setChosenLastName(lastName);
|
|
128
|
-
setIsFirstNameValid(true);
|
|
129
|
-
setIsLastNameValid(true);
|
|
130
|
-
}}
|
|
131
|
-
disabled={saving}
|
|
132
|
-
/>
|
|
133
|
-
</div>
|
|
134
|
-
<div className="form__field form__field--horizontal">
|
|
135
|
-
<label htmlFor="custom-display-name">
|
|
136
|
-
{profileLabels[lang].formNameDisplayName}
|
|
137
|
-
</label>
|
|
138
|
-
<input
|
|
139
|
-
type="radio"
|
|
140
|
-
id="custom-display-name"
|
|
141
|
-
checked={hasChosenName}
|
|
142
|
-
onChange={() => {
|
|
143
|
-
setHasChosenName(true);
|
|
144
|
-
}}
|
|
145
|
-
disabled={saving}
|
|
146
|
-
/>
|
|
147
|
-
</div>
|
|
148
|
-
</fieldset>
|
|
149
|
-
{(() => {
|
|
150
|
-
if (hasChosenName) {
|
|
151
|
-
return [
|
|
152
|
-
<div key="fn" className={`form__field${firstNameValidationClassName}`}>
|
|
153
|
-
<label htmlFor="first-name">
|
|
154
|
-
{profileLabels[lang].firstName}
|
|
155
|
-
<div className="form-info__hint">
|
|
156
|
-
{profileLabels[lang].firstNameHint}
|
|
157
|
-
</div>
|
|
158
|
-
{renderValidation(firstNameValidationMessages)}
|
|
159
|
-
</label>
|
|
160
|
-
<input
|
|
161
|
-
type="text"
|
|
162
|
-
id="first-name"
|
|
163
|
-
value={chosenFirstNames}
|
|
164
|
-
onChange={(e) => {
|
|
165
|
-
validateFirstName(e.target.value, firstNameValidationMessages.length);
|
|
166
|
-
}}
|
|
167
|
-
onKeyUp={(e) => {
|
|
168
|
-
if (e.key === 'Enter') {
|
|
169
|
-
validateFirstName(e.target.value);
|
|
170
|
-
}
|
|
171
|
-
}}
|
|
172
|
-
disabled={saving}
|
|
173
|
-
/>
|
|
174
|
-
</div>,
|
|
175
|
-
<div key="ln" className={`form__field${lastNameValidationClassName}`}>
|
|
176
|
-
<label htmlFor="last-name">
|
|
177
|
-
{profileLabels[lang].lastName}
|
|
178
|
-
{renderValidation(lastNameValidationMessages)}
|
|
179
|
-
</label>
|
|
180
|
-
<input
|
|
181
|
-
type="text"
|
|
182
|
-
id="last-name"
|
|
183
|
-
value={chosenLastName}
|
|
184
|
-
onChange={(e) => {
|
|
185
|
-
validateLastName(e.target.value, lastNameValidationMessages.length);
|
|
186
|
-
}}
|
|
187
|
-
onKeyUp={(e) => {
|
|
188
|
-
if (e.key === 'Enter') {
|
|
189
|
-
validateLastName(e.target.value);
|
|
190
|
-
}
|
|
191
|
-
}}
|
|
192
|
-
disabled={saving}
|
|
193
|
-
/>
|
|
194
|
-
</div>,
|
|
195
|
-
];
|
|
196
|
-
}
|
|
197
|
-
return null;
|
|
198
|
-
})()}
|
|
199
|
-
<AUSubmitButtonContainerComponent
|
|
200
|
-
lang={lang}
|
|
201
|
-
disabled={saving}
|
|
202
|
-
onSubmit={submit}
|
|
203
|
-
onCancel={onCancel}
|
|
204
|
-
/>
|
|
205
|
-
</form>,
|
|
206
|
-
];
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
AUProfileNameComponent.defaultProps = {
|
|
210
|
-
onSaveAction: (data, callback) => {
|
|
211
|
-
const putData = async () => {
|
|
212
|
-
let url = `${window.profileApiUri}/UpdatePersonNames`;
|
|
213
|
-
if (typeof window.API_AUID !== 'undefined') {
|
|
214
|
-
url = `${url}?auid=${window.API_AUID}`;
|
|
215
|
-
}
|
|
216
|
-
const response = await fetch(url, {
|
|
217
|
-
method: 'PUT',
|
|
218
|
-
credentials: 'include',
|
|
219
|
-
headers: {
|
|
220
|
-
'Content-Type': 'application/json',
|
|
221
|
-
},
|
|
222
|
-
body: JSON.stringify(data),
|
|
223
|
-
});
|
|
224
|
-
const json = await response.json();
|
|
225
|
-
callback(response.ok, response.status, json);
|
|
226
|
-
|
|
227
|
-
// clear context cache
|
|
228
|
-
window.auAuth.setUserContext(window.API_AUID || 0, 'profile-clear-cache', true, () => {}, () => {}, true, window.authenticated);
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
putData();
|
|
232
|
-
},
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
AUProfileNameComponent.propTypes = {
|
|
236
|
-
lang: PropTypes.string.isRequired,
|
|
237
|
-
routeProps: PropTypes.shape({}).isRequired,
|
|
238
|
-
path: PropTypes.string.isRequired,
|
|
239
|
-
firstNames: PropTypes.string.isRequired,
|
|
240
|
-
lastName: PropTypes.string.isRequired,
|
|
241
|
-
hasChosenName: PropTypes.bool.isRequired,
|
|
242
|
-
chosenFirstNames: PropTypes.string.isRequired,
|
|
243
|
-
chosenLastName: PropTypes.string.isRequired,
|
|
244
|
-
onSave: PropTypes.func.isRequired,
|
|
245
|
-
onSaveAction: PropTypes.func,
|
|
246
|
-
saving: PropTypes.bool.isRequired,
|
|
247
|
-
saved: PropTypes.bool.isRequired,
|
|
248
|
-
dismissMessages: PropTypes.func.isRequired,
|
|
249
|
-
clear: PropTypes.func.isRequired,
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
AUProfileNameComponent.displayName = 'AUProfileNameComponent';
|
|
253
|
-
export default AUProfileNameComponent;
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
/* eslint-env browser */
|
|
2
|
-
/* eslint-disable jsx-a11y/label-has-associated-control */
|
|
3
|
-
/* eslint-disable jsx-a11y/label-has-for */
|
|
4
|
-
/* eslint-disable max-len */
|
|
5
|
-
import React, { useState, useEffect } from 'react';
|
|
6
|
-
import PropTypes from 'prop-types';
|
|
7
|
-
import { Link } from 'react-router-dom';
|
|
8
|
-
import AUSubmitButtonContainerComponent from '../form/AUSubmitButtonContainerComponent';
|
|
9
|
-
import AUMobilePrefixComponent from '../form/AUMobilePrefixComponent';
|
|
10
|
-
import { useProfileForm, useMobilePrefix } from './AUProfileHooks';
|
|
11
|
-
import {
|
|
12
|
-
splitPhoneNumber,
|
|
13
|
-
scrollTo,
|
|
14
|
-
} from '../../lib/helpers';
|
|
15
|
-
import { profileLabels } from '../../lib/i18n';
|
|
16
|
-
import { renderValidation, validateForm } from '../../lib/validation';
|
|
17
|
-
|
|
18
|
-
const AUProfileNextOfKinComponent = ({
|
|
19
|
-
lang,
|
|
20
|
-
routeProps: { history },
|
|
21
|
-
path,
|
|
22
|
-
countryCodes,
|
|
23
|
-
nextOfKinName: pNextOfKinName,
|
|
24
|
-
nextOfKinPhoneNumber,
|
|
25
|
-
onSave,
|
|
26
|
-
onSaveAction,
|
|
27
|
-
saving,
|
|
28
|
-
saved,
|
|
29
|
-
dismissMessages,
|
|
30
|
-
clear,
|
|
31
|
-
}) => {
|
|
32
|
-
const validationRules = [{
|
|
33
|
-
message: profileLabels[lang].validName,
|
|
34
|
-
rule: (fieldValue) => fieldValue.trim().length > 0,
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
message: profileLabels[lang].validMobile,
|
|
38
|
-
rule: (fieldValue) => fieldValue.trim().match(/^\+[1-9][0-9]{5,14}$/),
|
|
39
|
-
}];
|
|
40
|
-
|
|
41
|
-
const [nextOfKinName, setNextOfKinName] = useState(pNextOfKinName);
|
|
42
|
-
const [prefix, mobile, setPrefix, setMobile] = useMobilePrefix(splitPhoneNumber, countryCodes, nextOfKinPhoneNumber);
|
|
43
|
-
const [onCancel] = useProfileForm(saved, history, lang, clear);
|
|
44
|
-
const [nokNameValidationMessages, setNokNameValidationMessages] = useState([]);
|
|
45
|
-
const [nokMobileValidationMessages, setNokMobileValidationMessages] = useState([]);
|
|
46
|
-
const [isNokNameValid, setIsNokNameValid] = useState(!!pNextOfKinName);
|
|
47
|
-
const [isNokMobileValid, setIsNokMobileValid] = useState(!!nextOfKinPhoneNumber);
|
|
48
|
-
|
|
49
|
-
const validateName = (value, alert = true) => {
|
|
50
|
-
const [valid, messages] = validateForm(lang, value, [validationRules[0]]);
|
|
51
|
-
setNextOfKinName(value);
|
|
52
|
-
setNokNameValidationMessages(alert ? messages : []);
|
|
53
|
-
setIsNokNameValid(valid);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const validateMobile = (value, alert = true) => {
|
|
57
|
-
const [valid, messages] = validateForm(lang, prefix + value, [validationRules[1]]);
|
|
58
|
-
setMobile(value);
|
|
59
|
-
setNokMobileValidationMessages(alert ? messages : []);
|
|
60
|
-
setIsNokMobileValid(valid);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const submit = (e) => {
|
|
64
|
-
e.preventDefault();
|
|
65
|
-
validateName(nextOfKinName, !isNokNameValid);
|
|
66
|
-
validateMobile(mobile, !isNokMobileValid);
|
|
67
|
-
if (isNokNameValid && isNokMobileValid) {
|
|
68
|
-
onSave({
|
|
69
|
-
nextOfKinName: nextOfKinName.trim(),
|
|
70
|
-
nextOfKinPhoneNumber: prefix + mobile,
|
|
71
|
-
}, onSaveAction);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
let nokNameValidationClassName = '';
|
|
76
|
-
if (!isNokNameValid && nokNameValidationMessages.length) {
|
|
77
|
-
nokNameValidationClassName = ' form-info--error';
|
|
78
|
-
} else if (isNokNameValid) {
|
|
79
|
-
nokNameValidationClassName = ' form-info--confirmed';
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
let nokMobileValidationClassName = '';
|
|
83
|
-
if (!isNokMobileValid && nokMobileValidationMessages.length) {
|
|
84
|
-
nokMobileValidationClassName = ' form-info--error';
|
|
85
|
-
} else if (isNokMobileValid) {
|
|
86
|
-
nokMobileValidationClassName = ' form-info--confirmed';
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
useEffect(() => {
|
|
90
|
-
dismissMessages();
|
|
91
|
-
scrollTo();
|
|
92
|
-
document.getElementById('contact-name').focus();
|
|
93
|
-
}, []);
|
|
94
|
-
|
|
95
|
-
return [
|
|
96
|
-
<div key="header" className="list-navigator">
|
|
97
|
-
<h1 className="list-navigator__header">{profileLabels[lang].headerNextOfKin}</h1>
|
|
98
|
-
<Link className="list-navigator__list-name" to={path}>{profileLabels[lang].headerContainer}</Link>
|
|
99
|
-
</div>,
|
|
100
|
-
<p key="paragraph">
|
|
101
|
-
{profileLabels[lang].nextOfKinParagraph}
|
|
102
|
-
</p>,
|
|
103
|
-
<form key="form" className="form" noValidate="novalidate">
|
|
104
|
-
<div className={`form__field${nokNameValidationClassName}`}>
|
|
105
|
-
<label htmlFor="contact-name">
|
|
106
|
-
{profileLabels[lang].nextOfKinName}
|
|
107
|
-
{renderValidation(nokNameValidationMessages)}
|
|
108
|
-
</label>
|
|
109
|
-
<input
|
|
110
|
-
type="text"
|
|
111
|
-
id="contact-name"
|
|
112
|
-
value={nextOfKinName}
|
|
113
|
-
onChange={(e) => {
|
|
114
|
-
validateName(e.target.value, nokNameValidationMessages.length);
|
|
115
|
-
}}
|
|
116
|
-
onKeyUp={(e) => {
|
|
117
|
-
if (e.key === 'Enter') {
|
|
118
|
-
validateName(e.target.value);
|
|
119
|
-
}
|
|
120
|
-
}}
|
|
121
|
-
disabled={saving}
|
|
122
|
-
/>
|
|
123
|
-
</div>
|
|
124
|
-
<fieldset className="fieldset--not-radio-checkbox">
|
|
125
|
-
<legend>
|
|
126
|
-
<div className="fieldset__legend-wrapper">{profileLabels[lang].nextOfKinTelephone}</div>
|
|
127
|
-
</legend>
|
|
128
|
-
<div className="form__field">
|
|
129
|
-
<label htmlFor="contact-country-code">{profileLabels[lang].countryCode}</label>
|
|
130
|
-
<select
|
|
131
|
-
id="contact-country-code"
|
|
132
|
-
value={prefix}
|
|
133
|
-
onChange={(e) => {
|
|
134
|
-
setPrefix(e.target.value);
|
|
135
|
-
}}
|
|
136
|
-
>
|
|
137
|
-
<AUMobilePrefixComponent countryCodes={countryCodes} important />
|
|
138
|
-
<optgroup label="Alle lande">
|
|
139
|
-
<AUMobilePrefixComponent countryCodes={countryCodes} />
|
|
140
|
-
</optgroup>
|
|
141
|
-
</select>
|
|
142
|
-
</div>
|
|
143
|
-
<div className={`form__field${nokMobileValidationClassName}`}>
|
|
144
|
-
<label htmlFor="contact-phone">
|
|
145
|
-
{profileLabels[lang].number}
|
|
146
|
-
{renderValidation(nokMobileValidationMessages)}
|
|
147
|
-
</label>
|
|
148
|
-
<input
|
|
149
|
-
type="tel"
|
|
150
|
-
id="contact-phone"
|
|
151
|
-
value={mobile}
|
|
152
|
-
onChange={(e) => {
|
|
153
|
-
validateMobile(e.target.value, nokMobileValidationMessages.length);
|
|
154
|
-
}}
|
|
155
|
-
onKeyUp={(e) => {
|
|
156
|
-
if (e.key === 'Enter') {
|
|
157
|
-
validateMobile(e.target.value);
|
|
158
|
-
}
|
|
159
|
-
}}
|
|
160
|
-
disabled={saving}
|
|
161
|
-
/>
|
|
162
|
-
</div>
|
|
163
|
-
</fieldset>
|
|
164
|
-
<AUSubmitButtonContainerComponent
|
|
165
|
-
lang={lang}
|
|
166
|
-
disabled={saving}
|
|
167
|
-
onSubmit={submit}
|
|
168
|
-
onCancel={onCancel}
|
|
169
|
-
/>
|
|
170
|
-
</form>,
|
|
171
|
-
];
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
AUProfileNextOfKinComponent.defaultProps = {
|
|
175
|
-
onSaveAction: (data, callback) => {
|
|
176
|
-
const putData = async () => {
|
|
177
|
-
let url = `${window.profileApiUri}/UpdateNextOfKin`;
|
|
178
|
-
if (typeof window.API_AUID !== 'undefined') {
|
|
179
|
-
url = `${url}?auid=${window.API_AUID}`;
|
|
180
|
-
}
|
|
181
|
-
const response = await fetch(url, {
|
|
182
|
-
method: 'PUT',
|
|
183
|
-
credentials: 'include',
|
|
184
|
-
headers: {
|
|
185
|
-
'Content-Type': 'application/json',
|
|
186
|
-
},
|
|
187
|
-
body: JSON.stringify(data),
|
|
188
|
-
});
|
|
189
|
-
const json = await response.json();
|
|
190
|
-
callback(response.ok, response.status, json);
|
|
191
|
-
|
|
192
|
-
// clear context cache
|
|
193
|
-
window.auAuth.setUserContext(window.API_AUID || 0, 'profile-clear-cache', true, () => {}, () => {}, true, window.authenticated);
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
putData();
|
|
197
|
-
},
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
AUProfileNextOfKinComponent.propTypes = {
|
|
201
|
-
lang: PropTypes.string.isRequired,
|
|
202
|
-
routeProps: PropTypes.shape({}).isRequired,
|
|
203
|
-
path: PropTypes.string.isRequired,
|
|
204
|
-
countryCodes: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
|
|
205
|
-
nextOfKinName: PropTypes.string.isRequired,
|
|
206
|
-
nextOfKinPhoneNumber: PropTypes.string.isRequired,
|
|
207
|
-
onSave: PropTypes.func.isRequired,
|
|
208
|
-
onSaveAction: PropTypes.func,
|
|
209
|
-
saving: PropTypes.bool.isRequired,
|
|
210
|
-
saved: PropTypes.bool.isRequired,
|
|
211
|
-
dismissMessages: PropTypes.func.isRequired,
|
|
212
|
-
clear: PropTypes.func.isRequired,
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
AUProfileNextOfKinComponent.displayName = 'AUProfileNextOfKinComponent';
|
|
216
|
-
export default AUProfileNextOfKinComponent;
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import { profileLabels } from '../../lib/i18n';
|
|
2
|
-
import {
|
|
3
|
-
GET_BASIC_USER,
|
|
4
|
-
SAVING_USER,
|
|
5
|
-
PATCH_NAME,
|
|
6
|
-
PATCH_MAIL,
|
|
7
|
-
PATCH_MOBILE,
|
|
8
|
-
PATCH_LANGUAGE,
|
|
9
|
-
PATCH_NEXTOFKIN,
|
|
10
|
-
DISMISS_MESSAGES,
|
|
11
|
-
SET_SAVED,
|
|
12
|
-
GET_WORKMAIL_DOMAIN,
|
|
13
|
-
} from './AUProfileActions';
|
|
14
|
-
|
|
15
|
-
export const initialState = {
|
|
16
|
-
user: {
|
|
17
|
-
auId: 0,
|
|
18
|
-
firstNames: '',
|
|
19
|
-
lastName: '',
|
|
20
|
-
hasChosenName: false,
|
|
21
|
-
chosenFirstNames: '',
|
|
22
|
-
chosenLastName: '',
|
|
23
|
-
name: '',
|
|
24
|
-
privateMailAddress: '',
|
|
25
|
-
privatePhoneNumber: '',
|
|
26
|
-
privateMobileNumber: '',
|
|
27
|
-
nextOfKinName: '',
|
|
28
|
-
nextOfKinPhoneNumber: '',
|
|
29
|
-
preferredLanguage: 'da',
|
|
30
|
-
studentNumber: null,
|
|
31
|
-
educations: [],
|
|
32
|
-
isStudentImpersonator: false,
|
|
33
|
-
timelineAllowed: false,
|
|
34
|
-
isActiveStudent: false,
|
|
35
|
-
suCandidate: false,
|
|
36
|
-
studentMailAddress: null,
|
|
37
|
-
studentChosenMailAddress: null,
|
|
38
|
-
workMailAddress: '',
|
|
39
|
-
workMailDomain: '',
|
|
40
|
-
saving: false,
|
|
41
|
-
saved: false,
|
|
42
|
-
loaded: false,
|
|
43
|
-
},
|
|
44
|
-
messages: [],
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const reducer = (state, action) => {
|
|
48
|
-
const nextState = { ...state };
|
|
49
|
-
|
|
50
|
-
switch (action.type) {
|
|
51
|
-
case GET_BASIC_USER: { // Tror ikke det her i brug...
|
|
52
|
-
const { result } = action;
|
|
53
|
-
if (result.user) {
|
|
54
|
-
const prevUser = { ...nextState.user };
|
|
55
|
-
const newUser = Object.assign(prevUser, result.user);
|
|
56
|
-
nextState.user = newUser;
|
|
57
|
-
} else if (result.error) {
|
|
58
|
-
nextState.messages = [{
|
|
59
|
-
type: 'warning',
|
|
60
|
-
message: result.error.Message,
|
|
61
|
-
}];
|
|
62
|
-
}
|
|
63
|
-
return nextState;
|
|
64
|
-
}
|
|
65
|
-
case GET_WORKMAIL_DOMAIN: {
|
|
66
|
-
const { result } = action;
|
|
67
|
-
if (result.user) {
|
|
68
|
-
const prevUser = { ...nextState.user };
|
|
69
|
-
const newUser = Object.assign(prevUser, result.user);
|
|
70
|
-
nextState.user = newUser;
|
|
71
|
-
} else if (result.error) {
|
|
72
|
-
nextState.messages = [{
|
|
73
|
-
type: 'warning',
|
|
74
|
-
message: nextState.user.preferredLanguage === 'da' ? result.error.errorMessageDa : result.error.errorMessageEn,
|
|
75
|
-
// Skal bruges i de andre profilePatch også?
|
|
76
|
-
}];
|
|
77
|
-
}
|
|
78
|
-
return nextState;
|
|
79
|
-
}
|
|
80
|
-
case DISMISS_MESSAGES: {
|
|
81
|
-
nextState.messages = [];
|
|
82
|
-
return nextState;
|
|
83
|
-
}
|
|
84
|
-
case SET_SAVED: {
|
|
85
|
-
const prevUser = { ...nextState.user };
|
|
86
|
-
nextState.user = Object.assign(prevUser, {
|
|
87
|
-
saved: false,
|
|
88
|
-
});
|
|
89
|
-
return nextState;
|
|
90
|
-
}
|
|
91
|
-
case SAVING_USER: {
|
|
92
|
-
const prevUser = { ...nextState.user };
|
|
93
|
-
nextState.user = Object.assign(prevUser, { saving: true, saved: false });
|
|
94
|
-
return nextState;
|
|
95
|
-
}
|
|
96
|
-
case PATCH_NAME: {
|
|
97
|
-
const { result } = action;
|
|
98
|
-
const prevUser = { ...nextState.user };
|
|
99
|
-
if (result.user) {
|
|
100
|
-
const { user: { hasChosenName, chosenFirstNames, chosenLastName } } = result;
|
|
101
|
-
nextState.user = Object.assign(prevUser, {
|
|
102
|
-
hasChosenName,
|
|
103
|
-
chosenFirstNames,
|
|
104
|
-
chosenLastName,
|
|
105
|
-
saving: false,
|
|
106
|
-
saved: true,
|
|
107
|
-
});
|
|
108
|
-
nextState.messages = [{
|
|
109
|
-
type: 'confirm',
|
|
110
|
-
message: profileLabels[nextState.user.preferredLanguage].saved,
|
|
111
|
-
}];
|
|
112
|
-
} else if (result.error) {
|
|
113
|
-
nextState.messages = [{
|
|
114
|
-
type: 'warning',
|
|
115
|
-
message: result.error.Message,
|
|
116
|
-
}];
|
|
117
|
-
nextState.user = Object.assign(prevUser, { saving: false });
|
|
118
|
-
}
|
|
119
|
-
return nextState;
|
|
120
|
-
}
|
|
121
|
-
case PATCH_MAIL: {
|
|
122
|
-
const { result } = action;
|
|
123
|
-
const prevUser = { ...nextState.user };
|
|
124
|
-
if (result.user) {
|
|
125
|
-
const { user: { privateMailAddress, workMailAddress, studentChosenMailAddress } } = result;
|
|
126
|
-
nextState.user = Object.assign(prevUser, {
|
|
127
|
-
workMailAddress,
|
|
128
|
-
studentChosenMailAddress,
|
|
129
|
-
privateMailAddress,
|
|
130
|
-
saving: false,
|
|
131
|
-
saved: true,
|
|
132
|
-
});
|
|
133
|
-
nextState.messages = [{
|
|
134
|
-
type: 'confirm',
|
|
135
|
-
message: `${profileLabels[nextState.user.preferredLanguage].saved} ${profileLabels[nextState.user.preferredLanguage].mailNotice}`,
|
|
136
|
-
}];
|
|
137
|
-
} else if (result.error) {
|
|
138
|
-
nextState.messages = [{
|
|
139
|
-
type: 'warning',
|
|
140
|
-
message: nextState.user.preferredLanguage === 'da' ? result.error.errorMessageDa : result.error.errorMessageEn,
|
|
141
|
-
// Skal bruges i de andre profilePatch også?
|
|
142
|
-
}];
|
|
143
|
-
nextState.user = Object.assign(prevUser, { saving: false });
|
|
144
|
-
}
|
|
145
|
-
return nextState;
|
|
146
|
-
}
|
|
147
|
-
case PATCH_MOBILE: {
|
|
148
|
-
const { result } = action;
|
|
149
|
-
const prevUser = { ...nextState.user };
|
|
150
|
-
if (result.user) {
|
|
151
|
-
const { user: { privatePhoneNumber, privateMobileNumber } } = result;
|
|
152
|
-
nextState.user = Object.assign(prevUser, {
|
|
153
|
-
privatePhoneNumber,
|
|
154
|
-
privateMobileNumber,
|
|
155
|
-
saving: false,
|
|
156
|
-
saved: true,
|
|
157
|
-
});
|
|
158
|
-
nextState.messages = [{
|
|
159
|
-
type: 'confirm',
|
|
160
|
-
message: profileLabels[nextState.user.preferredLanguage].saved,
|
|
161
|
-
}];
|
|
162
|
-
} else if (result.error) {
|
|
163
|
-
if (result.error.Message) {
|
|
164
|
-
nextState.messages = [{
|
|
165
|
-
type: 'warning',
|
|
166
|
-
message: result.error.Message,
|
|
167
|
-
}];
|
|
168
|
-
} else {
|
|
169
|
-
nextState.messages = result.error.map((e) => ({
|
|
170
|
-
type: 'warning',
|
|
171
|
-
message: e.errorMessage,
|
|
172
|
-
}));
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
nextState.user = Object.assign(prevUser, { saving: false });
|
|
176
|
-
}
|
|
177
|
-
return nextState;
|
|
178
|
-
}
|
|
179
|
-
case PATCH_LANGUAGE: {
|
|
180
|
-
const { result } = action;
|
|
181
|
-
const prevUser = { ...nextState.user };
|
|
182
|
-
if (result.user) {
|
|
183
|
-
const { user: { preferredLanguage } } = result;
|
|
184
|
-
nextState.user = Object.assign(prevUser, {
|
|
185
|
-
preferredLanguage,
|
|
186
|
-
saving: false,
|
|
187
|
-
saved: true,
|
|
188
|
-
});
|
|
189
|
-
nextState.messages = [{
|
|
190
|
-
type: 'confirm',
|
|
191
|
-
message: profileLabels[nextState.user.preferredLanguage].saved,
|
|
192
|
-
}];
|
|
193
|
-
} else if (result.error) {
|
|
194
|
-
nextState.messages = [{
|
|
195
|
-
type: 'warning',
|
|
196
|
-
message: result.error.Message,
|
|
197
|
-
}];
|
|
198
|
-
nextState.user = Object.assign(prevUser, { saving: false });
|
|
199
|
-
}
|
|
200
|
-
return nextState;
|
|
201
|
-
}
|
|
202
|
-
case PATCH_NEXTOFKIN: {
|
|
203
|
-
const { result } = action;
|
|
204
|
-
const prevUser = { ...nextState.user };
|
|
205
|
-
if (result.user) {
|
|
206
|
-
const { user: { nextOfKinName, nextOfKinPhoneNumber } } = result;
|
|
207
|
-
nextState.user = Object.assign(prevUser, {
|
|
208
|
-
nextOfKinName,
|
|
209
|
-
nextOfKinPhoneNumber,
|
|
210
|
-
saving: false,
|
|
211
|
-
saved: true,
|
|
212
|
-
});
|
|
213
|
-
nextState.messages = [{
|
|
214
|
-
type: 'confirm',
|
|
215
|
-
message: profileLabels[nextState.user.preferredLanguage].saved,
|
|
216
|
-
}];
|
|
217
|
-
} else if (result.error) {
|
|
218
|
-
nextState.messages = [{
|
|
219
|
-
type: 'warning',
|
|
220
|
-
message: result.error.Message,
|
|
221
|
-
}];
|
|
222
|
-
nextState.user = Object.assign(prevUser, { saving: false });
|
|
223
|
-
}
|
|
224
|
-
return nextState;
|
|
225
|
-
}
|
|
226
|
-
default: {
|
|
227
|
-
return null;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
};
|