@stssocialst-stp/fe-admin 1.3.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.
@@ -0,0 +1,3514 @@
1
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
+ import React, { Component, useState, useEffect } from 'react';
3
+ import { Person, LocationCity, Tune, LocalHospital, HealingOutlined, LocalPharmacyOutlined, Healing, LocalPharmacy, PinDrop, Tab, Delete } from '@material-ui/icons';
4
+ import { withModulesManager, formatMessage, MainMenuContribution, decodeId, formatPageQuery, graphql, formatPageQueryWithCount, graphqlWithVariables, prepareMutation, formatMutation, fetchMutation, ControlledField, PublishedComponent, TextInput, ConfirmDialog, Searcher, formatMessageWithValues, formatDateFromISO, withHistory, withTooltip, clearCurrentPaginationPage, historyPush, combine, useTranslations, ProgressOrError, useGraphqlQuery, ValidatedTextInput, validatePassword, passwordGenerator, Helmet, Form, journalize, coreConfirm, parseData, useDebounceCb, Autocomplete as Autocomplete$1, dispatchMutationResp, dispatchMutationErr, dispatchMutationReq, formatServerError, formatGraphQLError, pageInfo, FormattedMessage } from '@openimis/fe-core';
5
+ import _extends from '@babel/runtime/helpers/extends';
6
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
7
+ import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
8
+ import _createClass from '@babel/runtime/helpers/createClass';
9
+ import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
10
+ import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
11
+ import _inherits from '@babel/runtime/helpers/inherits';
12
+ import { injectIntl, useIntl } from 'react-intl';
13
+ import { connect, useDispatch, useSelector } from 'react-redux';
14
+ import { bindActionCreators } from 'redux';
15
+ import { Grid, FormControlLabel, Checkbox, Tooltip, IconButton, Fab, TableContainer, Paper, Table, TableHead, TableRow, TableCell, TableBody, TableFooter, Button, Typography, Switch, Divider, InputAdornment, TextField } from '@material-ui/core';
16
+ import AddIcon from '@material-ui/icons/Add';
17
+ import { withTheme, withStyles } from '@material-ui/core/styles';
18
+ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
19
+ import _regeneratorRuntime from '@babel/runtime/regenerator';
20
+ import _debounce from 'lodash/debounce';
21
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
22
+ import ReplayIcon from '@material-ui/icons/Replay';
23
+ import DeleteIcon from '@material-ui/icons/Delete';
24
+ import VisibilityIcon from '@material-ui/icons/Visibility';
25
+ import VisibilityOffIcon from '@material-ui/icons/VisibilityOff';
26
+ import { Autocomplete } from '@material-ui/lab';
27
+ import Autocomplete$2 from '@material-ui/lab/Autocomplete';
28
+ import TextField$1 from '@material-ui/core/TextField';
29
+
30
+ var RIGHT_PRODUCTS = 121001;
31
+ var RIGHT_HEALTHFACILITIES = 121101;
32
+ var RIGHT_PRICELISTMS = 121201;
33
+ var RIGHT_PRICELISTMI = 121301;
34
+ var RIGHT_MEDICALSERVICES = 121401;
35
+ var RIGHT_MEDICALITEMS = 122101;
36
+ var RIGHT_ENROLMENTOFFICER = 121501;
37
+ var RIGHT_CLAIMADMINISTRATOR = 121601;
38
+ var RIGHT_LOCATIONS = 121901;
39
+ var RIGHT_USERS = 121701;
40
+ var RIGHT_USER_ADD = 121702;
41
+ var RIGHT_USER_EDIT = 121703;
42
+ var RIGHT_USER_DELETE = 121704;
43
+ var INTERACTIVE_USER_TYPE = "INTERACTIVE";
44
+ var ENROLMENT_OFFICER_USER_TYPE = "OFFICER";
45
+ var OFFICER_ROLE_IS_SYSTEM = 1;
46
+ var CLAIM_ADMIN_USER_TYPE = "CLAIM_ADMIN";
47
+ var CLAIM_ADMIN_IS_SYSTEM = 256;
48
+ var MODULE_NAME = "user";
49
+ var DEFAULT = {
50
+ RENDER_LAST_NAME_FIRST: true
51
+ };
52
+
53
+ // https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
54
+ var EMAIL_REGEX_PATTERN = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
55
+ var USER_TYPES = function USER_TYPES(rights) {
56
+ var baseTypes = [INTERACTIVE_USER_TYPE];
57
+ if (rights.includes(RIGHT_ENROLMENTOFFICER)) {
58
+ baseTypes.push(ENROLMENT_OFFICER_USER_TYPE);
59
+ if (rights.includes(RIGHT_CLAIMADMINISTRATOR)) {
60
+ baseTypes.push(CLAIM_ADMIN_USER_TYPE);
61
+ }
62
+ }
63
+ return baseTypes;
64
+ };
65
+
66
+ function _callSuper$4(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$4() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
67
+ function _isNativeReflectConstruct$4() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$4 = function _isNativeReflectConstruct() { return !!t; })(); }
68
+ var ADMIN_MAIN_MENU_CONTRIBUTION_KEY = "admin.MainMenu";
69
+ var ADMIN_VOUCHER_MAIN_MENU_CONTRIBUTION_KEY = "admin.voucher.MainMenu";
70
+ var AdminMainMenu = /*#__PURE__*/function (_Component) {
71
+ function AdminMainMenu(props) {
72
+ var _this;
73
+ _classCallCheck(this, AdminMainMenu);
74
+ _this = _callSuper$4(this, AdminMainMenu, [props]);
75
+ _this.isWorker = props.modulesManager.getConf("fe-core", "isWorker", false);
76
+ return _this;
77
+ }
78
+ _inherits(AdminMainMenu, _Component);
79
+ return _createClass(AdminMainMenu, [{
80
+ key: "render",
81
+ value: function render() {
82
+ var rights = this.props.rights;
83
+ var entries = [];
84
+ if (this.isWorker) {
85
+ if (rights.includes(RIGHT_USERS)) {
86
+ entries.push({
87
+ text: formatMessage(this.props.intl, "admin", "menu.users"),
88
+ icon: /*#__PURE__*/React.createElement(Person, null),
89
+ route: "/admin/users",
90
+ id: "admin.users"
91
+ });
92
+ }
93
+ entries.push.apply(entries, _toConsumableArray(this.props.modulesManager.getContribs(ADMIN_VOUCHER_MAIN_MENU_CONTRIBUTION_KEY).filter(function (c) {
94
+ return !c.filter || c.filter(rights);
95
+ })));
96
+ if (!entries.length) return null;
97
+ return /*#__PURE__*/React.createElement(MainMenuContribution, _extends({}, this.props, {
98
+ header: formatMessage(this.props.intl, "admin", "mainMenu"),
99
+ icon: /*#__PURE__*/React.createElement(LocationCity, null),
100
+ entries: entries,
101
+ menuId: "AdminMainMenu"
102
+ }));
103
+ }
104
+ if (rights.includes(RIGHT_PRODUCTS)) {
105
+ entries.push({
106
+ text: formatMessage(this.props.intl, "admin", "menu.products"),
107
+ icon: /*#__PURE__*/React.createElement(Tune, null),
108
+ route: "/admin/products",
109
+ id: "admin.products"
110
+ });
111
+ }
112
+ if (rights.includes(RIGHT_HEALTHFACILITIES)) {
113
+ entries.push({
114
+ text: formatMessage(this.props.intl, "admin", "menu.healthFacilities"),
115
+ icon: /*#__PURE__*/React.createElement(LocalHospital, null),
116
+ route: "/location/healthFacilities",
117
+ withDivider: true,
118
+ id: "admin.healthFacilities"
119
+ });
120
+ }
121
+ if (rights.includes(RIGHT_PRICELISTMS)) {
122
+ entries.push({
123
+ text: formatMessage(this.props.intl, "admin", "menu.medicalServicesPrices"),
124
+ icon: /*#__PURE__*/React.createElement(HealingOutlined, null),
125
+ route: "/medical/pricelists/services",
126
+ id: "admin.services"
127
+ });
128
+ }
129
+ if (rights.includes(RIGHT_PRICELISTMI)) {
130
+ entries.push({
131
+ text: formatMessage(this.props.intl, "admin", "menu.medicalItemsPrices"),
132
+ icon: /*#__PURE__*/React.createElement(LocalPharmacyOutlined, null),
133
+ route: "/medical/pricelists/items",
134
+ id: "admin.items",
135
+ withDivider: true
136
+ });
137
+ }
138
+ if (rights.includes(RIGHT_MEDICALSERVICES)) {
139
+ entries.push({
140
+ text: formatMessage(this.props.intl, "admin", "menu.medicalServices"),
141
+ icon: /*#__PURE__*/React.createElement(Healing, null),
142
+ route: "/medical/medicalServices",
143
+ id: "admin.medicalServices"
144
+ });
145
+ }
146
+ if (rights.includes(RIGHT_MEDICALITEMS)) {
147
+ entries.push({
148
+ text: formatMessage(this.props.intl, "admin", "menu.medicalItems"),
149
+ icon: /*#__PURE__*/React.createElement(LocalPharmacy, null),
150
+ route: "/medical/medicalItems",
151
+ withDivider: true,
152
+ id: "admin.medicalItems"
153
+ });
154
+ }
155
+ if (rights.includes(RIGHT_USERS)) {
156
+ entries.push({
157
+ text: formatMessage(this.props.intl, "admin", "menu.users"),
158
+ icon: /*#__PURE__*/React.createElement(Person, null),
159
+ route: "/admin/users",
160
+ id: "admin.users"
161
+ });
162
+ }
163
+ if (rights.includes(RIGHT_LOCATIONS)) {
164
+ entries.push({
165
+ text: formatMessage(this.props.intl, "admin", "menu.locations"),
166
+ icon: /*#__PURE__*/React.createElement(PinDrop, null),
167
+ route: "/location/locations",
168
+ id: "admin.locations"
169
+ });
170
+ }
171
+ entries.push.apply(entries, _toConsumableArray(this.props.modulesManager.getContribs(ADMIN_MAIN_MENU_CONTRIBUTION_KEY).filter(function (c) {
172
+ return !c.filter || c.filter(rights);
173
+ })));
174
+ if (!entries.length) return null;
175
+ return /*#__PURE__*/React.createElement(MainMenuContribution, _extends({}, this.props, {
176
+ header: formatMessage(this.props.intl, "admin", "mainMenu"),
177
+ icon: /*#__PURE__*/React.createElement(LocationCity, null),
178
+ entries: entries,
179
+ menuId: "AdminMainMenu"
180
+ }));
181
+ }
182
+ }]);
183
+ }(Component);
184
+ var mapStateToProps$5 = function mapStateToProps(state) {
185
+ return {
186
+ rights: !!state.core && !!state.core.user && !!state.core.user.i_user ? state.core.user.i_user.rights : []
187
+ };
188
+ };
189
+ var AdminMainMenu$1 = withModulesManager(injectIntl(connect(mapStateToProps$5)(AdminMainMenu)));
190
+
191
+ function ownKeys$7(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
192
+ function _objectSpread$7(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$7(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$7(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
193
+ var addUserType = function addUserType(user, userType) {
194
+ if (!user.userTypes.includes(userType)) {
195
+ user.userTypes = [].concat(_toConsumableArray(user.userTypes), [userType]);
196
+ }
197
+ };
198
+ function checkRolesAndGetUserTypes(user) {
199
+ var _tempUser$roles, _tempUser$roles2;
200
+ if (!user) return console.warn("User not provided in checkRolesAndGetUserTypes function!");
201
+ var tempUser = user;
202
+ var initialUserTypes = [INTERACTIVE_USER_TYPE];
203
+ if (!tempUser.roles) {
204
+ tempUser.userTypes = initialUserTypes;
205
+ }
206
+ if ((_tempUser$roles = tempUser.roles) !== null && _tempUser$roles !== void 0 && _tempUser$roles.some(function (role) {
207
+ return role.isSystem === CLAIM_ADMIN_IS_SYSTEM;
208
+ })) {
209
+ addUserType(tempUser, CLAIM_ADMIN_USER_TYPE);
210
+ }
211
+ if ((_tempUser$roles2 = tempUser.roles) !== null && _tempUser$roles2 !== void 0 && _tempUser$roles2.some(function (role) {
212
+ return role.isSystem === OFFICER_ROLE_IS_SYSTEM;
213
+ })) {
214
+ addUserType(tempUser, ENROLMENT_OFFICER_USER_TYPE);
215
+ }
216
+ return tempUser.userTypes;
217
+ }
218
+ var mapQueriesUserToStore = function mapQueriesUserToStore(u) {
219
+ // TODO: make this more generic
220
+ u.hasLogin = false;
221
+ u.userTypes = checkRolesAndGetUserTypes(u);
222
+ if (u.iUser) {
223
+ u.hasLogin = true;
224
+ u.lastName = u.iUser.lastName;
225
+ u.otherNames = u.iUser.otherNames;
226
+ u.email = u.iUser.email;
227
+ u.phoneNumber = u.iUser.phone;
228
+ u.healthFacility = u.iUser.healthFacility;
229
+ u.language = u.iUser.languageId;
230
+ u.roles = u.iUser.roles;
231
+ u.districts = u.iUser.districts.map(function (d) {
232
+ return d.location;
233
+ });
234
+ }
235
+ if (u.claimAdmin) {
236
+ var _u$email;
237
+ u.hasLogin = u.hasLogin || u.claimAdmin.hasLogin;
238
+ u.lastName = u.claimAdmin.lastName;
239
+ u.otherNames = u.claimAdmin.otherNames;
240
+ u.email = (_u$email = u.email) !== null && _u$email !== void 0 ? _u$email : u.claimAdmin.emailId;
241
+ u.phoneNumber = u.claimAdmin.phone;
242
+ u.birthDate = u.claimAdmin.dob;
243
+ u.healthFacility = u.claimAdmin.healthFacility;
244
+ }
245
+ if (u.officer) {
246
+ var _u$email2;
247
+ u.hasLogin = u.hasLogin || u.officer.hasLogin;
248
+ u.lastName = u.officer.lastName;
249
+ u.otherNames = u.officer.otherNames;
250
+ u.email = (_u$email2 = u.email) !== null && _u$email2 !== void 0 ? _u$email2 : u.officer.email;
251
+ u.phoneNumber = u.officer.phone;
252
+ u.birthDate = u.officer.dob;
253
+ u.address = u.officer.address;
254
+ u.substitutionOfficer = u.officer.substitutionOfficer;
255
+ // substitutionOfficer is user.officer so it cannot be retrieved using the UserPicker
256
+ u.worksTo = u.officer.worksTo;
257
+ u.location = u.officer.location;
258
+ u.officerVillages = u.officer.officerVillages.map(function (x) {
259
+ return x.location;
260
+ });
261
+ }
262
+ return u;
263
+ };
264
+ var mapUserValuesToInput = function mapUserValuesToInput(values) {
265
+ var _values$substitutionO, _values$officerVillag;
266
+ var input = {
267
+ uuid: values.id ? decodeId(values.id) : null,
268
+ username: values.username,
269
+ userTypes: values.userTypes,
270
+ lastName: values.lastName,
271
+ otherNames: values.otherNames,
272
+ phone: values.phoneNumber,
273
+ email: values.email,
274
+ password: values.password,
275
+ healthFacilityId: values.healthFacility ? decodeId(values.healthFacility.id) : null,
276
+ districts: values.districts.map(function (d) {
277
+ return decodeId(d.id);
278
+ }),
279
+ locationId: values.location ? decodeId(values.location.id) : null,
280
+ language: values.language,
281
+ roles: values.roles.map(function (r) {
282
+ return decodeId(r.id);
283
+ }),
284
+ birthDate: values.birthDate,
285
+ address: values.address,
286
+ substitutionOfficerId: (_values$substitutionO = values.substitutionOfficer) !== null && _values$substitutionO !== void 0 && _values$substitutionO.id ? decodeId(values.substitutionOfficer.id) : null,
287
+ worksTo: values.worksTo,
288
+ villageIds: (_values$officerVillag = values.officerVillages) === null || _values$officerVillag === void 0 ? void 0 : _values$officerVillag.map(function (location) {
289
+ return decodeId(location.id);
290
+ })
291
+ };
292
+ return input;
293
+ };
294
+ var toggleUserType = function toggleUserType(user, type) {
295
+ if (!user.userTypes) {
296
+ user.userTypes = [];
297
+ }
298
+ if (user.userTypes.includes(type)) {
299
+ user.userTypes = user.userTypes.filter(function (x) {
300
+ return x !== type;
301
+ });
302
+ } else {
303
+ user.userTypes.push(type);
304
+ }
305
+ return user;
306
+ };
307
+ var toggleUserRoles = function toggleUserRoles(edited, data, isValid, isEnabled, hasRole, onEditedChanged, roleIsSystem) {
308
+ var _edited$roles, _data$role$edges;
309
+ var roles = (_edited$roles = edited === null || edited === void 0 ? void 0 : edited.roles) !== null && _edited$roles !== void 0 ? _edited$roles : [];
310
+ var role = data === null || data === void 0 || (_data$role$edges = data.role.edges) === null || _data$role$edges === void 0 ? void 0 : _data$role$edges[0].node;
311
+ if (isValid && isEnabled && !hasRole) {
312
+ roles.push(role);
313
+ edited.roles = roles;
314
+ onEditedChanged(_objectSpread$7({}, edited));
315
+ } else if (isValid && !isEnabled) {
316
+ var filteredRoles = roles.filter(function (tempRole) {
317
+ return tempRole.isSystem !== roleIsSystem;
318
+ });
319
+ edited.roles = filteredRoles;
320
+ onEditedChanged(_objectSpread$7({}, edited));
321
+ }
322
+ };
323
+ var toggleSwitchButton = function toggleSwitchButton(edited, hasRole, hasUserType, setIsEnabled, onEditedChanged, userType) {
324
+ if (hasRole) {
325
+ setIsEnabled(function () {
326
+ return true;
327
+ });
328
+ onEditedChanged(toggleUserType(edited, userType));
329
+ } else {
330
+ setIsEnabled(function () {
331
+ return false;
332
+ });
333
+ if (hasUserType) {
334
+ onEditedChanged(toggleUserType(edited, userType));
335
+ }
336
+ }
337
+ };
338
+ var fetchSubstitutionEOs = function fetchSubstitutionEOs(dispatch, mm, officerUuid, searchString, villages) {
339
+ dispatch(fetchSubstitutionEnrolmentOfficers(mm, {
340
+ officerUuid: officerUuid,
341
+ first: searchString ? undefined : 15,
342
+ villagesUuids: villages === null || villages === void 0 ? void 0 : villages.map(function (village) {
343
+ return village.uuid;
344
+ }),
345
+ str: searchString
346
+ }));
347
+ };
348
+
349
+ var USER_SUMMARY_PROJECTION = ["id", "username", "officer{id,dob,phone,lastName,otherNames,email}", "iUser{id,phone,lastName,otherNames,email,roles{id,name}}", "claimAdmin{id,phone,lastName,otherNames,emailId,dob}", "validityTo", "clientMutationId"];
350
+ var DISTRICT_DATA_FETCH_PARAMS = "id, uuid, code, name, parent { id, uuid, name, code }";
351
+ var USER_PICKER_PROJECTION = ["id", "username", "iUser{id otherNames lastName}"];
352
+ function fetchUsers(mm) {
353
+ var filters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
354
+ var restrictHealthFacility = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
355
+ return function (dispatch, getState) {
356
+ if (restrictHealthFacility) {
357
+ var state = getState();
358
+ var hf = state.loc.userHealthFacilityFullPath;
359
+ if (hf) {
360
+ filters.push("healthFacilityId: ".concat(decodeId(hf.id)));
361
+ }
362
+ }
363
+ var payload = formatPageQuery("users", filters, mm.getRef("admin.UserPicker.projection"));
364
+ return dispatch(graphql(payload, "ADMIN_USERS", filters));
365
+ };
366
+ }
367
+ function fetchUsersSummaries(mm, filters) {
368
+ var payload = formatPageQueryWithCount("users", filters, USER_SUMMARY_PROJECTION);
369
+ return graphql(payload, "ADMIN_USERS_SUMMARIES");
370
+ }
371
+ function fetchEnrolmentOfficers(mm, variables) {
372
+ return graphqlWithVariables("\n query ($searchString: String, $first: Int) {\n enrolmentOfficers(str: $searchString, first: $first) {\n edges {\n node {\n id\n code\n lastName\n otherNames\n\n }\n }\n pageInfo {\n hasNextPage\n }\n }\n }\n ", variables, "ADMIN_ENROLMENT_OFFICERS");
373
+ }
374
+ function fetchSubstitutionEnrolmentOfficers(mm, variables) {
375
+ return graphqlWithVariables("\n query SubstitutionEnrolmentOfficers ($str: String, $villagesUuids: [String!], $officerUuid: String) {\n substitutionEnrolmentOfficers(str: $str, villagesUuids: $villagesUuids, officerUuid: $officerUuid) {\n edges {\n node {\n id\n uuid\n code\n lastName\n otherNames\n }\n }\n }\n }\n ", variables, "ADMIN_SUBSTITUTION_ENROLMENT_OFFICERS");
376
+ }
377
+ function createUser(mm, user, clientMutationLabel) {
378
+ var mutation = prepareMutation("\n mutation ($input: CreateUserMutationInput!) {\n createUser(input: $input) {\n clientMutationId\n internalId\n }\n }\n ", mapUserValuesToInput(user), {
379
+ clientMutationLabel: clientMutationLabel
380
+ });
381
+
382
+ // eslint-disable-next-line no-param-reassign
383
+ user.clientMutationId = mutation.clientMutationId;
384
+ return graphqlWithVariables(mutation.operation, mutation.variables, ["ADMIN_USER_MUTATION_REQ", "ADMIN_USER_CREATE_RESP", "ADMIN_USER_MUTATION_ERR"], {
385
+ clientMutationId: mutation.clientMutationId,
386
+ clientMutationLabel: clientMutationLabel
387
+ });
388
+ }
389
+ function updateUser(mm, user, clientMutationLabel) {
390
+ var mutation = prepareMutation("\n mutation ($input: UpdateUserMutationInput!) {\n updateUser(input: $input) {\n clientMutationId\n internalId\n }\n }\n ", mapUserValuesToInput(user), {
391
+ clientMutationLabel: clientMutationLabel
392
+ });
393
+
394
+ // eslint-disable-next-line no-param-reassign
395
+ user.clientMutationId = mutation.clientMutationId;
396
+ return graphqlWithVariables(mutation.operation, mutation.variables, ["ADMIN_USER_MUTATION_REQ", "ADMIN_USER_UPDATE_RESP", "ADMIN_USER_MUTATION_ERR"], {
397
+ clientMutationId: mutation.clientMutationId,
398
+ clientMutationLabel: clientMutationLabel,
399
+ userId: user.id
400
+ });
401
+ }
402
+ function deleteUser(mm, user, clientMutationLabel) {
403
+ var mutation = formatMutation("deleteUser", "uuids: [\"".concat(decodeId(user.id), "\"]"), clientMutationLabel);
404
+ // eslint-disable-next-line no-param-reassign
405
+ user.clientMutationId = mutation.clientMutationId;
406
+ return function (dispatch) {
407
+ dispatch(graphql(mutation.payload, ["ADMIN_USER_MUTATION_REQ", "ADMIN_USER_DELETE_RESP", "ADMIN_USER_MUTATION_ERR"], {
408
+ clientMutationId: mutation.clientMutationId,
409
+ clientMutationLabel: clientMutationLabel,
410
+ userId: user.id
411
+ }));
412
+ dispatch(fetchMutation(mutation.clientMutationId));
413
+ };
414
+ }
415
+ function fetchUser(mm, userId, clientMutationId) {
416
+ var filters = [];
417
+ if (userId) {
418
+ filters.push("id: \"".concat(decodeId(userId), "\""));
419
+ filters.push("showDeleted: true");
420
+ } else if (clientMutationId) {
421
+ filters.push("clientMutationId: \"".concat(clientMutationId, "\""));
422
+ }
423
+ return graphql("\n {\n users(".concat(filters.join(" "), ") {\n pageInfo { hasNextPage, hasPreviousPage, startCursor, endCursor}\n edges {\n node {\n clientMutationId\n id\n username\n validityTo\n officer {\n id\n uuid\n hasLogin\n phone\n dob\n lastName\n otherNames\n address\n substitutionOfficer { id lastName otherNames code }\n worksTo\n officerVillages {\n id\n location {\n id\n name\n code\n uuid\n parent {\n id\n name\n code\n uuid\n }\n }\n }\n location {\n id\n name\n uuid\n code\n parent {\n id\n name\n uuid\n code\n }\n }\n }\n iUser {\n id\n phone\n languageId\n lastName\n otherNames\n roles { id name isSystem}\n healthFacility ").concat(mm.getProjection("location.HealthFacilityPicker.projection"), "\n validityFrom\n validityTo\n email\n districts: userdistrictSet { location { id name code uuid parent { id code uuid name }}}\n }\n claimAdmin{\n id\n hasLogin\n emailId\n phone\n dob\n lastName\n otherNames\n healthFacility ").concat(mm.getProjection("location.HealthFacilityPicker.projection"), "\n\n }\n }\n }\n }\n }\n "), "ADMIN_USER_OVERVIEW");
424
+ }
425
+ function fetchUserMutation(mm, clientMutationId) {
426
+ var payload = formatPageQuery("mutationLogs", ["clientMutationId:\"".concat(clientMutationId, "\"")], ["id", "status", "users{coreUser{id}}"]);
427
+ return graphql(payload, "ADMIN_USER");
428
+ }
429
+ function fetchRegionDistricts(parent) {
430
+ var filters = ["type: \"D\""];
431
+ if (parent) {
432
+ filters.push("parent_Uuid: \"".concat(parent.uuid, "\""));
433
+ }
434
+ var payload = formatPageQuery("locations", filters, ["id", "uuid", "type", "code", "name", "malePopulation", "femalePopulation", "otherPopulation", "families", "clientMutationId"]);
435
+ return graphql(payload, "LOCATION_REGION_DISTRICTS");
436
+ }
437
+ function fetchDataFromDistrict(districtUuids) {
438
+ var filters = [];
439
+ if (districtUuids) {
440
+ filters.push("parent_Uuid_In: [\"".concat(districtUuids.join('", "'), "\"]"));
441
+ }
442
+ var payload = formatPageQuery("locations", filters, ["".concat(DISTRICT_DATA_FETCH_PARAMS, ", children { edges {node {").concat(DISTRICT_DATA_FETCH_PARAMS, "}}}")]);
443
+ return graphql(payload, "LOCATION_DISTRICT_DATA");
444
+ }
445
+ function fetchObligatoryUserFields() {
446
+ var payload = "query userObligatoryFields {userObligatoryFields}";
447
+ return graphql(payload, "OBLIGTORY_USER_FIELDS");
448
+ }
449
+ function fetchObligatoryEnrolmentOfficerFields() {
450
+ var payload = "query userObligatoryFields {eoObligatoryFields}";
451
+ return graphql(payload, "OBLIGTORY_EO_FIELDS");
452
+ }
453
+ function clearDistrictData() {
454
+ return function (dispatch) {
455
+ dispatch({
456
+ type: "LOCATION_DISTRICT_DATA_CLEAR"
457
+ });
458
+ };
459
+ }
460
+ function usernameValidationCheck(mm, variables) {
461
+ return graphqlWithVariables("\n query ($username: String!) {\n isValid: validateUsername(username: $username)\n }\n ", variables, "USERNAME_FIELDS_VALIDATION");
462
+ }
463
+ function fetchUsernameLength() {
464
+ var payload = "query {usernameLength}";
465
+ return graphql(payload, "USERNAME_LENGTH_FIELDS");
466
+ }
467
+ function fetchPasswordPolicy() {
468
+ var payload = "query {\n passwordPolicy\n }";
469
+ return graphql(payload, "PASSWORD_POLICY_FIELDS");
470
+ }
471
+ function usernameValidationClear() {
472
+ return function (dispatch) {
473
+ dispatch({
474
+ type: "USERNAME_FIELDS_VALIDATION_CLEAR"
475
+ });
476
+ };
477
+ }
478
+ function setUsernameValid() {
479
+ return function (dispatch) {
480
+ dispatch({
481
+ type: "USERNAME_FIELDS_VALIDATION_SET_VALID"
482
+ });
483
+ };
484
+ }
485
+ function clearUser() {
486
+ return function (dispatch) {
487
+ dispatch({
488
+ type: "ADMIN_USER_OVERVIEW_CLEAR"
489
+ });
490
+ };
491
+ }
492
+ function userEmailValidationCheck(mm, variables) {
493
+ return graphqlWithVariables("\n query ($userEmail: String!) {\n isValid: validateUserEmail(userEmail: $userEmail)\n }\n ", variables, "USER_EMAIL_FIELDS_VALIDATION");
494
+ }
495
+ function userEmailValidationClear() {
496
+ return function (dispatch) {
497
+ dispatch({
498
+ type: "USER_EMAIL_FIELDS_VALIDATION_CLEAR"
499
+ });
500
+ };
501
+ }
502
+ function setUserEmailValid() {
503
+ return function (dispatch) {
504
+ dispatch({
505
+ type: "USER_EMAIL_FIELDS_VALIDATION_SET_VALID"
506
+ });
507
+ };
508
+ }
509
+ function saveEmailFormatValidity(isFormatInvalid) {
510
+ return function (dispatch) {
511
+ dispatch({
512
+ type: "USER_EMAIL_FORMAT_VALIDATION_CHECK",
513
+ payload: {
514
+ data: {
515
+ isFormatInvalid: isFormatInvalid
516
+ }
517
+ }
518
+ });
519
+ };
520
+ }
521
+
522
+ function ownKeys$6(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
523
+ function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$6(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$6(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
524
+ function _callSuper$3(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$3() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
525
+ function _isNativeReflectConstruct$3() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$3 = function _isNativeReflectConstruct() { return !!t; })(); }
526
+ var styles$9 = function styles(theme) {
527
+ return {
528
+ dialogTitle: theme.dialog.title,
529
+ dialogContent: theme.dialog.content,
530
+ form: {
531
+ padding: "0 0 10px 0",
532
+ width: "100%"
533
+ },
534
+ item: {
535
+ padding: theme.spacing(1)
536
+ },
537
+ paperDivider: theme.paper.divider
538
+ };
539
+ };
540
+ var extractLocations = function extractLocations(locations) {
541
+ var locationsArray = Object.values(locations).map(function (l) {
542
+ return l.value;
543
+ });
544
+ var region = locationsArray.find(function (l) {
545
+ return !l.parent;
546
+ });
547
+ var district = region && locationsArray.find(function (l) {
548
+ return l.parent && l.parent.id === region.id;
549
+ });
550
+ var municipality = district && locationsArray.find(function (l) {
551
+ return l.parent && l.parent.id === district.id;
552
+ });
553
+ var village = municipality && locationsArray.find(function (l) {
554
+ return l.parent && l.parent.id === municipality.id;
555
+ });
556
+ return {
557
+ region: region,
558
+ district: district,
559
+ municipality: municipality,
560
+ village: village
561
+ };
562
+ };
563
+ var getParentLocation = function getParentLocation(locations) {
564
+ var extractedLocations = extractLocations(locations);
565
+ var region = extractedLocations.region,
566
+ district = extractedLocations.district,
567
+ municipality = extractedLocations.municipality,
568
+ village = extractedLocations.village;
569
+ if (!region) {
570
+ return null;
571
+ }
572
+ var newLocation = {
573
+ key: "regionId",
574
+ id: decodeId(region.id),
575
+ value: region
576
+ };
577
+ if (district) {
578
+ newLocation = {
579
+ key: "districtId",
580
+ id: decodeId(district.id),
581
+ value: district
582
+ };
583
+ }
584
+ if (municipality) {
585
+ newLocation = {
586
+ key: "municipalityId",
587
+ id: decodeId(municipality.id),
588
+ value: municipality
589
+ };
590
+ }
591
+ if (village) {
592
+ newLocation = {
593
+ key: "villageId",
594
+ id: decodeId(village.id),
595
+ value: village
596
+ };
597
+ }
598
+ return newLocation;
599
+ };
600
+ var UserFilter = /*#__PURE__*/function (_Component) {
601
+ function UserFilter(props) {
602
+ var _this;
603
+ _classCallCheck(this, UserFilter);
604
+ _this = _callSuper$3(this, UserFilter, [props]);
605
+ _defineProperty(_this, "state", {
606
+ locationFilters: {},
607
+ selectedDistrict: {}
608
+ });
609
+ _defineProperty(_this, "debouncedOnChangeFilter", _debounce(_this.props.onChangeFilters, _this.props.modulesManager.getConf("fe-admin", "debounceTime", 200)));
610
+ _defineProperty(_this, "filterValue", function (k) {
611
+ var filters = _this.props.filters;
612
+ return !!filters && !!filters[k] ? filters[k].value : null;
613
+ });
614
+ _defineProperty(_this, "filterTextFieldValue", function (k) {
615
+ var filters = _this.props.filters;
616
+ return !!filters && !!filters[k] ? filters[k].value : "";
617
+ });
618
+ _defineProperty(_this, "filterDistrict", function (locations) {
619
+ var extractedLocations = extractLocations(locations);
620
+ var district = extractedLocations.district;
621
+ return district;
622
+ });
623
+ _defineProperty(_this, "onChangeCheckbox", function (key, value) {
624
+ var filters = [{
625
+ id: key,
626
+ value: value,
627
+ filter: "".concat(key, ": ").concat(value)
628
+ }];
629
+ _this.props.onChangeFilters(filters);
630
+ });
631
+ _defineProperty(_this, "onChangeUserTypes", function (currentUserType) {
632
+ var onChangeFilters = _this.props.onChangeFilters;
633
+ onChangeFilters([{
634
+ id: "userTypes",
635
+ value: currentUserType,
636
+ filter: currentUserType ? "userTypes: [".concat(currentUserType, "]") : []
637
+ }]);
638
+ });
639
+ _defineProperty(_this, "onChangeUserRoles", function (currentUserRoles) {
640
+ var onChangeFilters = _this.props.onChangeFilters;
641
+ _this.setState({
642
+ currentUserRoles: currentUserRoles
643
+ });
644
+ onChangeFilters([{
645
+ id: "roles",
646
+ value: currentUserRoles,
647
+ filter: currentUserRoles ? "roles: [".concat(currentUserRoles.map(function (ur) {
648
+ return decodeId(ur.id);
649
+ }).join(","), "]") : []
650
+ }]);
651
+ });
652
+ _defineProperty(_this, "onChangeLocation", function (newLocationFilters) {
653
+ var onChangeFilters = _this.props.onChangeFilters;
654
+ var locationFilters = _objectSpread$6({}, _this.state.locationFilters);
655
+ newLocationFilters.forEach(function (filter) {
656
+ if (filter.value === null) {
657
+ delete locationFilters[filter.id];
658
+ } else {
659
+ locationFilters[filter.id] = {
660
+ value: filter.value,
661
+ filter: filter.filter
662
+ };
663
+ }
664
+ });
665
+ var selectedDistrict = _this.filterDistrict(locationFilters);
666
+ _this.setState({
667
+ locationFilters: locationFilters,
668
+ selectedDistrict: selectedDistrict
669
+ });
670
+ var parentLocation = getParentLocation(locationFilters);
671
+ var filters = [{
672
+ id: "parentLocation",
673
+ filter: parentLocation && "".concat(parentLocation.key, ": ").concat(parentLocation.id)
674
+ }];
675
+ onChangeFilters(filters);
676
+ });
677
+ _defineProperty(_this, "renderLastNameField", function (classes) {
678
+ return /*#__PURE__*/React.createElement(ControlledField, {
679
+ module: "admin",
680
+ id: "userFilter.LastName",
681
+ field: /*#__PURE__*/React.createElement(Grid, {
682
+ item: true,
683
+ xs: 3,
684
+ className: classes.item
685
+ }, /*#__PURE__*/React.createElement(TextInput, {
686
+ module: "user",
687
+ label: "admin.user.lastName",
688
+ name: "lastName",
689
+ value: _this.filterTextFieldValue("lastName"),
690
+ onChange: function onChange(v) {
691
+ return _this.debouncedOnChangeFilter([{
692
+ id: "lastName",
693
+ value: v,
694
+ filter: "lastName: \"".concat(v, "\"")
695
+ }]);
696
+ }
697
+ }))
698
+ });
699
+ });
700
+ _defineProperty(_this, "renderGivenNameField", function (classes) {
701
+ return /*#__PURE__*/React.createElement(ControlledField, {
702
+ module: "admin",
703
+ id: "userFilter.OtherNames",
704
+ field: /*#__PURE__*/React.createElement(Grid, {
705
+ item: true,
706
+ xs: 3,
707
+ className: classes.item
708
+ }, /*#__PURE__*/React.createElement(TextInput, {
709
+ module: "user",
710
+ label: "admin.user.otherNames",
711
+ name: "otherNames",
712
+ value: _this.filterTextFieldValue("otherNames"),
713
+ onChange: function onChange(v) {
714
+ return _this.debouncedOnChangeFilter([{
715
+ id: "otherNames",
716
+ value: v,
717
+ filter: "otherNames: \"".concat(v, "\"")
718
+ }]);
719
+ }
720
+ }))
721
+ });
722
+ });
723
+ _this.renderLastNameFirst = props.modulesManager.getConf("fe-insuree", "renderLastNameFirst", DEFAULT.RENDER_LAST_NAME_FIRST);
724
+ return _this;
725
+ }
726
+ _inherits(UserFilter, _Component);
727
+ return _createClass(UserFilter, [{
728
+ key: "render",
729
+ value: function render() {
730
+ var _this2 = this;
731
+ var _this$props = this.props,
732
+ classes = _this$props.classes;
733
+ _this$props.filters;
734
+ var onChangeFilters = _this$props.onChangeFilters,
735
+ intl = _this$props.intl;
736
+ _this$props.rights;
737
+ var _this$state = this.state;
738
+ _this$state.locationFilters;
739
+ _this$state.currentUserType;
740
+ _this$state.currentUserRoles;
741
+ _this$state.selectedDistrict;
742
+ return /*#__PURE__*/React.createElement("section", {
743
+ className: classes.form
744
+ }, /*#__PURE__*/React.createElement(Grid, {
745
+ container: true
746
+ }, /*#__PURE__*/React.createElement(ControlledField, {
747
+ module: "admin",
748
+ id: "userFilter.userRoles",
749
+ field: /*#__PURE__*/React.createElement(Grid, {
750
+ item: true,
751
+ xs: 3,
752
+ className: classes.item
753
+ }, /*#__PURE__*/React.createElement(PublishedComponent, {
754
+ pubRef: "admin.UserRolesPicker",
755
+ value: this.filterValue("roles"),
756
+ onChange: function onChange(v) {
757
+ return _this2.onChangeUserRoles(v);
758
+ }
759
+ }))
760
+ }), /*#__PURE__*/React.createElement(ControlledField, {
761
+ module: "admin",
762
+ id: "userFilter.username",
763
+ field: /*#__PURE__*/React.createElement(Grid, {
764
+ item: true,
765
+ xs: 3,
766
+ className: classes.item
767
+ }, /*#__PURE__*/React.createElement(TextInput, {
768
+ module: "user",
769
+ label: "admin.user.username",
770
+ name: "username",
771
+ value: this.filterTextFieldValue("username"),
772
+ onChange: function onChange(v) {
773
+ return _this2.debouncedOnChangeFilter([{
774
+ id: "username",
775
+ value: v,
776
+ filter: "username_Icontains: \"".concat(v, "\"")
777
+ }]);
778
+ }
779
+ }))
780
+ }), this.renderLastNameFirst ? /*#__PURE__*/React.createElement(React.Fragment, null, this.renderLastNameField(classes), this.renderGivenNameField(classes)) : /*#__PURE__*/React.createElement(React.Fragment, null, this.renderGivenNameField(classes), this.renderLastNameField(classes)), /*#__PURE__*/React.createElement(ControlledField, {
781
+ module: "admin",
782
+ id: "userFilter.Email",
783
+ field: /*#__PURE__*/React.createElement(Grid, {
784
+ item: true,
785
+ xs: 3,
786
+ className: classes.item
787
+ }, /*#__PURE__*/React.createElement(TextInput, {
788
+ module: "user",
789
+ label: "admin.user.email",
790
+ name: "email",
791
+ value: this.filterTextFieldValue("email"),
792
+ onChange: function onChange(v) {
793
+ return _this2.debouncedOnChangeFilter([{
794
+ id: "email",
795
+ value: v,
796
+ filter: "email: \"".concat(v, "\"")
797
+ }]);
798
+ }
799
+ }))
800
+ }), /*#__PURE__*/React.createElement(ControlledField, {
801
+ module: "admin",
802
+ id: "userFilter.Phone",
803
+ field: /*#__PURE__*/React.createElement(Grid, {
804
+ item: true,
805
+ xs: 3,
806
+ className: classes.item
807
+ }, /*#__PURE__*/React.createElement(TextInput, {
808
+ module: "user",
809
+ label: "admin.user.phone",
810
+ name: "phone",
811
+ value: this.filterTextFieldValue("phone"),
812
+ onChange: function onChange(v) {
813
+ return _this2.debouncedOnChangeFilter([{
814
+ id: "phone",
815
+ value: v,
816
+ filter: "phone: \"".concat(v, "\"")
817
+ }]);
818
+ }
819
+ }))
820
+ }), /*#__PURE__*/React.createElement(ControlledField, {
821
+ module: "admin",
822
+ id: "UserFilter.dob",
823
+ field: /*#__PURE__*/React.createElement(Grid, {
824
+ item: true,
825
+ xs: 6
826
+ }, /*#__PURE__*/React.createElement(Grid, {
827
+ container: true
828
+ }, /*#__PURE__*/React.createElement(Grid, {
829
+ item: true,
830
+ xs: 6,
831
+ className: classes.item
832
+ }, /*#__PURE__*/React.createElement(PublishedComponent, {
833
+ pubRef: "core.DatePicker",
834
+ value: this.filterValue("dobFrom"),
835
+ module: "user",
836
+ label: "admin.user.dobFrom",
837
+ onChange: function onChange(d) {
838
+ return onChangeFilters([{
839
+ id: "dobFrom",
840
+ value: d,
841
+ filter: "birthDateFrom: \"".concat(d, "\"")
842
+ }]);
843
+ }
844
+ })), /*#__PURE__*/React.createElement(Grid, {
845
+ item: true,
846
+ xs: 6,
847
+ className: classes.item
848
+ }, /*#__PURE__*/React.createElement(PublishedComponent, {
849
+ pubRef: "core.DatePicker",
850
+ value: this.filterValue("dobTo"),
851
+ module: "user",
852
+ label: "admin.user.dobTo",
853
+ onChange: function onChange(d) {
854
+ return onChangeFilters([{
855
+ id: "dobTo",
856
+ value: d,
857
+ filter: "birthDateTo: \"".concat(d, "\"")
858
+ }]);
859
+ }
860
+ }))))
861
+ }), /*#__PURE__*/React.createElement(ControlledField, {
862
+ module: "policy",
863
+ id: "PolicyFilter.showDeleted",
864
+ field: /*#__PURE__*/React.createElement(Grid, {
865
+ item: true,
866
+ xs: 2,
867
+ className: classes.item
868
+ }, /*#__PURE__*/React.createElement(FormControlLabel, {
869
+ control: /*#__PURE__*/React.createElement(Checkbox, {
870
+ color: "primary",
871
+ checked: !!this.filterValue("showDeleted"),
872
+ onChange: function onChange(event) {
873
+ return _this2.onChangeCheckbox("showDeleted", event.target.checked);
874
+ }
875
+ }),
876
+ label: formatMessage(intl, "admin", "UserFilter.showDeleted")
877
+ }))
878
+ })));
879
+ }
880
+ }]);
881
+ }(Component);
882
+ var mapStateToProps$4 = function mapStateToProps(state) {
883
+ var _state$core$user$i_us, _state$core, _state$core2;
884
+ return {
885
+ rights: (_state$core$user$i_us = (_state$core = state.core) === null || _state$core === void 0 || (_state$core = _state$core.user) === null || _state$core === void 0 || (_state$core = _state$core.i_user) === null || _state$core === void 0 ? void 0 : _state$core.rights) !== null && _state$core$user$i_us !== void 0 ? _state$core$user$i_us : [],
886
+ module: (_state$core2 = state.core) === null || _state$core2 === void 0 || (_state$core2 = _state$core2.savedPagination) === null || _state$core2 === void 0 ? void 0 : _state$core2.module
887
+ };
888
+ };
889
+ var UserFilter$1 = withModulesManager(connect(mapStateToProps$4)(injectIntl(withTheme(withStyles(styles$9)(UserFilter)))));
890
+
891
+ function _callSuper$2(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$2() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
892
+ function _isNativeReflectConstruct$2() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$2 = function _isNativeReflectConstruct() { return !!t; })(); }
893
+ var USER_SEARCHER_CONTRIBUTION_KEY = "user.UserSearcher";
894
+ var styles$8 = function styles(theme) {
895
+ return {
896
+ horizontalButtonContainer: theme.buttonContainer.horizontal
897
+ };
898
+ };
899
+ var UserSearcher = /*#__PURE__*/function (_Component) {
900
+ function UserSearcher(props) {
901
+ var _this;
902
+ _classCallCheck(this, UserSearcher);
903
+ _this = _callSuper$2(this, UserSearcher, [props]);
904
+ _defineProperty(_this, "state", {
905
+ deleteUser: null,
906
+ params: {},
907
+ defaultParams: {}
908
+ });
909
+ _defineProperty(_this, "getHeaders", function () {
910
+ return ["admin.user.username", _this.renderLastNameFirst ? "admin.user.lastName" : "admin.user.otherNames", !_this.renderLastNameFirst ? "admin.user.lastName" : "admin.user.otherNames", "admin.user.email", "admin.user.phone", "admin.user.dob", ""];
911
+ });
912
+ _defineProperty(_this, "getSorts", function () {
913
+ return [["username", true], _this.renderLastNameFirst ? ["iUser_LastName", true] : ["iUser_OtherNames", true], !_this.renderLastNameFirst ? ["iUser_LastName", true] : ["iUser_OtherNames", true], ["iUser_Email", true], ["iUser_Phone", true], ["officer__dob", false]];
914
+ });
915
+ _defineProperty(_this, "getAligns", function () {
916
+ var aligns = _this.getHeaders().map(function () {
917
+ return null;
918
+ });
919
+ aligns.splice(-1, 1, "right");
920
+ return aligns;
921
+ });
922
+ _defineProperty(_this, "fetch", function (params) {
923
+ _this.setState({
924
+ params: params
925
+ });
926
+ if (_this.props.fetchedUserLocation) {
927
+ _this.props.fetchUsersSummaries(_this.props.modulesManager, params);
928
+ }
929
+ });
930
+ _defineProperty(_this, "setRegionIds", function (paramsArray) {
931
+ var _this$props$userL0s;
932
+ var regionIds = (_this$props$userL0s = _this.props.userL0s) === null || _this$props$userL0s === void 0 ? void 0 : _this$props$userL0s.map(function (region) {
933
+ return decodeId(region.id);
934
+ });
935
+ paramsArray.push("regionIds: [".concat(regionIds, "]"));
936
+ });
937
+ _defineProperty(_this, "componentDidUpdate", function (prevState) {
938
+ if (prevState.userL0s !== _this.props.userL0s) {
939
+ if (_this.props.userL0s && _this.props.fetchedUserLocation) {
940
+ var prms = _toConsumableArray(_this.state.params);
941
+ _this.setRegionIds(prms);
942
+ _this.props.fetchUsersSummaries(_this.props.modulesManager, prms);
943
+ }
944
+ }
945
+ });
946
+ _defineProperty(_this, "filtersToQueryParams", function (state) {
947
+ var prms = Object.keys(state.filters).filter(function (contrib) {
948
+ return !!state.filters[contrib].filter;
949
+ }).map(function (contrib) {
950
+ return state.filters[contrib].filter;
951
+ });
952
+ if (!state.beforeCursor && !state.afterCursor) {
953
+ prms.push("first: ".concat(state.pageSize));
954
+ }
955
+ if (state.afterCursor) {
956
+ prms.push("after: \"".concat(state.afterCursor, "\""));
957
+ prms.push("first: ".concat(state.pageSize));
958
+ }
959
+ if (state.beforeCursor) {
960
+ prms.push("before: \"".concat(state.beforeCursor, "\""));
961
+ prms.push("last: ".concat(state.pageSize));
962
+ }
963
+ if (state.orderBy) {
964
+ prms.push("orderBy: [\"".concat(state.orderBy, "\"]"));
965
+ }
966
+ if (_this.props.fetchedUserLocation) {
967
+ _this.setRegionIds(prms);
968
+ }
969
+ return prms;
970
+ });
971
+ _defineProperty(_this, "deleteUser", function (isConfirmed) {
972
+ if (!isConfirmed) {
973
+ _this.setState({
974
+ deleteUser: null
975
+ });
976
+ } else {
977
+ var user = _this.state.deleteUser;
978
+ _this.setState({
979
+ deleteUser: null
980
+ }, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
981
+ return _regeneratorRuntime.wrap(function (_context) {
982
+ while (1) switch (_context.prev = _context.next) {
983
+ case 0:
984
+ _context.next = 1;
985
+ return _this.props.deleteUser(_this.props.modulesManager, user, formatMessage(_this.props.intl, "admin.user", "deleteDialog.title"));
986
+ case 1:
987
+ _this.fetch(_this.state.params);
988
+ case 2:
989
+ case "end":
990
+ return _context.stop();
991
+ }
992
+ }, _callee);
993
+ })));
994
+ }
995
+ });
996
+ _defineProperty(_this, "getUserItem", function (user, item) {
997
+ return user.iUser && user.iUser[item] || user.officer && user.officer[item] || user.claimAdmin && user.claimAdmin[item];
998
+ });
999
+ _defineProperty(_this, "itemFormatters", function () {
1000
+ var formatters = [function (u) {
1001
+ return u.username;
1002
+ }, function (u) {
1003
+ return _this.renderLastNameFirst ? _this.getUserItem(u, "lastName") : _this.getUserItem(u, "otherNames");
1004
+ }, function (u) {
1005
+ return !_this.renderLastNameFirst ? _this.getUserItem(u, "lastName") : _this.getUserItem(u, "otherNames");
1006
+ }, function (u) {
1007
+ return _this.getUserItem(u, "email") || _this.getUserItem(u, "emailId");
1008
+ }, function (u) {
1009
+ return _this.getUserItem(u, "phone");
1010
+ }, function (u) {
1011
+ return (u.claimAdmin || u.officer) && formatDateFromISO(_this.props.modulesManager, _this.props.intl, _this.getUserItem(u, "dob"));
1012
+ }, function (u) {
1013
+ return /*#__PURE__*/React.createElement("div", {
1014
+ className: _this.props.classes.horizontalButtonContainer
1015
+ }, /*#__PURE__*/React.createElement(Tooltip, {
1016
+ title: formatMessage(_this.props.intl, "admin.user", "openNewTab")
1017
+ }, /*#__PURE__*/React.createElement(IconButton, {
1018
+ onClick: function onClick() {
1019
+ return _this.props.onDoubleClick(u, true);
1020
+ }
1021
+ }, /*#__PURE__*/React.createElement(Tab, null))), _this.props.rights.includes(RIGHT_USER_DELETE) && u.validityTo ? null : /*#__PURE__*/React.createElement(Tooltip, {
1022
+ title: formatMessage(_this.props.intl, "admin.user", "deleteUser.tooltip")
1023
+ }, /*#__PURE__*/React.createElement(IconButton, {
1024
+ onClick: function onClick() {
1025
+ return _this.setState({
1026
+ deleteUser: u
1027
+ });
1028
+ },
1029
+ disabled: u.validityTo
1030
+ }, /*#__PURE__*/React.createElement(Delete, null))));
1031
+ }];
1032
+ return formatters;
1033
+ });
1034
+ _this.renderLastNameFirst = props.modulesManager.getConf("fe-insuree", "renderLastNameFirst", DEFAULT.RENDER_LAST_NAME_FIRST);
1035
+ return _this;
1036
+ }
1037
+ _inherits(UserSearcher, _Component);
1038
+ return _createClass(UserSearcher, [{
1039
+ key: "render",
1040
+ value: function render() {
1041
+ var _usersPageInfo$totalC;
1042
+ var _this$props = this.props,
1043
+ intl = _this$props.intl,
1044
+ users = _this$props.users,
1045
+ usersPageInfo = _this$props.usersPageInfo,
1046
+ fetchingUsers = _this$props.fetchingUsers,
1047
+ fetchedUsers = _this$props.fetchedUsers,
1048
+ errorUsers = _this$props.errorUsers,
1049
+ cacheFiltersKey = _this$props.cacheFiltersKey,
1050
+ onDoubleClick = _this$props.onDoubleClick;
1051
+ return /*#__PURE__*/React.createElement(React.Fragment, null, this.state.deleteUser && /*#__PURE__*/React.createElement(ConfirmDialog, {
1052
+ confirm: {
1053
+ title: formatMessage(intl, "admin.user", "deleteDialog.title"),
1054
+ message: formatMessage(intl, "admin.user", "deleteDialog.message")
1055
+ },
1056
+ onConfirm: this.deleteUser
1057
+ }), /*#__PURE__*/React.createElement(Searcher, {
1058
+ module: "user",
1059
+ cacheFiltersKey: cacheFiltersKey,
1060
+ FilterPane: UserFilter$1,
1061
+ items: users,
1062
+ itemsPageInfo: usersPageInfo,
1063
+ fetchingItems: fetchingUsers,
1064
+ fetchedItems: fetchedUsers,
1065
+ errorItems: errorUsers,
1066
+ contributionKey: USER_SEARCHER_CONTRIBUTION_KEY,
1067
+ tableTitle: formatMessageWithValues(intl, "admin.user", "userSummaries", {
1068
+ count: (_usersPageInfo$totalC = usersPageInfo.totalCount) === null || _usersPageInfo$totalC === void 0 ? void 0 : _usersPageInfo$totalC.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")
1069
+ }),
1070
+ fetch: this.fetch,
1071
+ rowIdentifier: function rowIdentifier(r) {
1072
+ return r.uuid;
1073
+ },
1074
+ filtersToQueryParams: this.filtersToQueryParams,
1075
+ defaultOrderBy: "-username",
1076
+ headers: this.getHeaders,
1077
+ aligns: this.getAligns,
1078
+ itemFormatters: this.itemFormatters,
1079
+ sorts: this.getSorts,
1080
+ rowDisabled: function rowDisabled(_, i) {
1081
+ return i.validityTo || i.clientMutationId;
1082
+ },
1083
+ rowLocked: function rowLocked(_, i) {
1084
+ return i.clientMutationId;
1085
+ },
1086
+ onDoubleClick: onDoubleClick
1087
+ }));
1088
+ }
1089
+ }]);
1090
+ }(Component);
1091
+ var mapStateToProps$3 = function mapStateToProps(state) {
1092
+ var _state$core$i_user$ri, _state$core, _state$loc$userL0s;
1093
+ return {
1094
+ rights: (_state$core$i_user$ri = (_state$core = state.core) === null || _state$core === void 0 || (_state$core = _state$core.i_user) === null || _state$core === void 0 ? void 0 : _state$core.rights) !== null && _state$core$i_user$ri !== void 0 ? _state$core$i_user$ri : [],
1095
+ users: state.admin.usersSummaries.items,
1096
+ usersPageInfo: state.admin.usersSummaries.pageInfo,
1097
+ fetchingUsers: state.admin.usersSummaries.isFetching,
1098
+ fetchedUsers: state.admin.usersSummaries.fetched,
1099
+ errorUsers: state.admin.usersSummaries.error,
1100
+ userL0s: (_state$loc$userL0s = state.loc.userL0s) !== null && _state$loc$userL0s !== void 0 ? _state$loc$userL0s : [],
1101
+ fetchedUserLocation: state.loc.fetchedUserLocation
1102
+ };
1103
+ };
1104
+ var mapDispatchToProps$2 = function mapDispatchToProps(dispatch) {
1105
+ return bindActionCreators({
1106
+ fetchUsersSummaries: fetchUsersSummaries,
1107
+ deleteUser: deleteUser
1108
+ }, dispatch);
1109
+ };
1110
+ var UserSearcher$1 = withModulesManager(connect(mapStateToProps$3, mapDispatchToProps$2)(injectIntl(withTheme(withStyles(styles$8)(UserSearcher)))));
1111
+
1112
+ function _callSuper$1(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$1() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
1113
+ function _isNativeReflectConstruct$1() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$1 = function _isNativeReflectConstruct() { return !!t; })(); }
1114
+ var styles$7 = function styles(theme) {
1115
+ return {
1116
+ page: theme.page,
1117
+ fab: theme.fab
1118
+ };
1119
+ };
1120
+ var UsersPage = /*#__PURE__*/function (_Component) {
1121
+ function UsersPage() {
1122
+ var _this;
1123
+ _classCallCheck(this, UsersPage);
1124
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1125
+ args[_key] = arguments[_key];
1126
+ }
1127
+ _this = _callSuper$1(this, UsersPage, [].concat(args));
1128
+ _defineProperty(_this, "onDoubleClick", function (u) {
1129
+ var newTab = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1130
+ historyPush(_this.props.modulesManager, _this.props.history, "admin.userOverview", [u.id], newTab);
1131
+ });
1132
+ _defineProperty(_this, "onAdd", function () {
1133
+ historyPush(_this.props.modulesManager, _this.props.history, "admin.userNew");
1134
+ });
1135
+ _defineProperty(_this, "componentDidMount", function () {
1136
+ var module = _this.props.module;
1137
+ if (module !== MODULE_NAME) _this.props.clearCurrentPaginationPage();
1138
+ });
1139
+ return _this;
1140
+ }
1141
+ _inherits(UsersPage, _Component);
1142
+ return _createClass(UsersPage, [{
1143
+ key: "render",
1144
+ value: function render() {
1145
+ var _this$props = this.props,
1146
+ classes = _this$props.classes,
1147
+ rights = _this$props.rights,
1148
+ intl = _this$props.intl;
1149
+ return /*#__PURE__*/React.createElement("div", {
1150
+ className: classes.page
1151
+ }, /*#__PURE__*/React.createElement(UserSearcher$1, {
1152
+ cacheFiltersKey: "usersPageFiltersCache",
1153
+ onDoubleClick: this.onDoubleClick
1154
+ }), rights.includes(RIGHT_USER_ADD) && withTooltip(/*#__PURE__*/React.createElement("div", {
1155
+ className: classes.fab
1156
+ }, /*#__PURE__*/React.createElement(Fab, {
1157
+ color: "primary",
1158
+ onClick: this.onAdd
1159
+ }, /*#__PURE__*/React.createElement(AddIcon, null))), formatMessage(intl, "admin.user", "addNewUser.tooltip")));
1160
+ }
1161
+ }]);
1162
+ }(Component);
1163
+ var mapStateToProps$2 = function mapStateToProps(state) {
1164
+ var _state$core$user$i_us, _state$core, _state$core2;
1165
+ return {
1166
+ rights: (_state$core$user$i_us = (_state$core = state.core) === null || _state$core === void 0 || (_state$core = _state$core.user) === null || _state$core === void 0 || (_state$core = _state$core.i_user) === null || _state$core === void 0 ? void 0 : _state$core.rights) !== null && _state$core$user$i_us !== void 0 ? _state$core$user$i_us : [],
1167
+ module: (_state$core2 = state.core) === null || _state$core2 === void 0 || (_state$core2 = _state$core2.savedPagination) === null || _state$core2 === void 0 ? void 0 : _state$core2.module
1168
+ };
1169
+ };
1170
+ var mapDispatchToProps$1 = function mapDispatchToProps(dispatch) {
1171
+ return bindActionCreators({
1172
+ clearCurrentPaginationPage: clearCurrentPaginationPage
1173
+ }, dispatch);
1174
+ };
1175
+ var UsersPage$1 = injectIntl(withModulesManager(withHistory(connect(mapStateToProps$2, mapDispatchToProps$1)(withTheme(withStyles(styles$7)(UsersPage))))));
1176
+
1177
+ var styles$6 = function styles(theme) {
1178
+ return {
1179
+ footer: {
1180
+ marginInline: 16,
1181
+ marginBlock: 12
1182
+ },
1183
+ headerTitle: theme.table.title,
1184
+ actionCell: {
1185
+ width: 60
1186
+ },
1187
+ header: theme.table.header
1188
+ };
1189
+ };
1190
+ var groupVillagesByMunicipality = function groupVillagesByMunicipality(villages) {
1191
+ var result = [];
1192
+ villages === null || villages === void 0 || villages.forEach(function (village) {
1193
+ if (!result.find(function (x) {
1194
+ var _x$parent, _village$parent;
1195
+ return ((_x$parent = x.parent) === null || _x$parent === void 0 ? void 0 : _x$parent.id) === ((_village$parent = village.parent) === null || _village$parent === void 0 ? void 0 : _village$parent.id);
1196
+ })) {
1197
+ result.push({
1198
+ parent: village.parent,
1199
+ entities: []
1200
+ });
1201
+ }
1202
+ result.find(function (x) {
1203
+ var _x$parent2, _village$parent2;
1204
+ return ((_x$parent2 = x.parent) === null || _x$parent2 === void 0 ? void 0 : _x$parent2.id) === ((_village$parent2 = village.parent) === null || _village$parent2 === void 0 ? void 0 : _village$parent2.id);
1205
+ }).entities.push(village);
1206
+ });
1207
+ result.sort(function (a, b) {
1208
+ var _a$parent, _b$parent;
1209
+ return a.parent ? ((_a$parent = a.parent) === null || _a$parent === void 0 ? void 0 : _a$parent.id) > ((_b$parent = b.parent) === null || _b$parent === void 0 ? void 0 : _b$parent.id) : -1;
1210
+ });
1211
+ return result;
1212
+ };
1213
+ var EnrolmentVillagesPicker = function EnrolmentVillagesPicker(props) {
1214
+ var modulesManager = props.modulesManager,
1215
+ readOnly = props.readOnly,
1216
+ villages = props.villages,
1217
+ onChange = props.onChange,
1218
+ classes = props.classes,
1219
+ districts = props.districts,
1220
+ isOfficerPanelEnabled = props.isOfficerPanelEnabled;
1221
+ var dispatch = useDispatch();
1222
+ var _useState = useState([]),
1223
+ _useState2 = _slicedToArray(_useState, 2),
1224
+ items = _useState2[0],
1225
+ setItems = _useState2[1];
1226
+ var _useTranslations = useTranslations("admin.EnrolmentZonesPicker", modulesManager),
1227
+ formatMessage = _useTranslations.formatMessage;
1228
+ var pickedDistrictsUuids = districts && districts.map(function (district) {
1229
+ return district.uuid;
1230
+ });
1231
+ var savedEOVillages = useSelector(function (store) {
1232
+ var _store$admin$user;
1233
+ return (_store$admin$user = store.admin.user) === null || _store$admin$user === void 0 ? void 0 : _store$admin$user.officerVillages;
1234
+ });
1235
+ var isUserEdited = useSelector(function (store) {
1236
+ var _store$admin$user2;
1237
+ return (_store$admin$user2 = store.admin.user) === null || _store$admin$user2 === void 0 ? void 0 : _store$admin$user2.id;
1238
+ });
1239
+ var _useState3 = useState(false),
1240
+ _useState4 = _slicedToArray(_useState3, 2),
1241
+ wasEmpty = _useState4[0],
1242
+ setWasEmpty = _useState4[1];
1243
+ var _useSelector = useSelector(function (store) {
1244
+ return store.admin;
1245
+ }),
1246
+ districtMunAndVil = _useSelector.districtMunAndVil,
1247
+ fetchedDistrictMunAndVil = _useSelector.fetchedDistrictMunAndVil,
1248
+ fetchingDistrictMunAndVil = _useSelector.fetchingDistrictMunAndVil,
1249
+ errorDistrictMunAndVil = _useSelector.errorDistrictMunAndVil;
1250
+ var handleChange = function handleChange(newItems) {
1251
+ var villageIds = newItems.reduce(function (acc, item) {
1252
+ return item.entities ? acc.concat(item.entities) : acc;
1253
+ }, []);
1254
+ onChange(villageIds);
1255
+ };
1256
+ var onRemoveRow = function onRemoveRow(row) {
1257
+ handleChange(items.filter(function (i) {
1258
+ var _i$parent, _row$parent;
1259
+ return ((_i$parent = i.parent) === null || _i$parent === void 0 ? void 0 : _i$parent.id) !== ((_row$parent = row.parent) === null || _row$parent === void 0 ? void 0 : _row$parent.id);
1260
+ }));
1261
+ };
1262
+ useEffect(function () {
1263
+ setItems(groupVillagesByMunicipality(villages));
1264
+ }, [villages]);
1265
+ var onInsertRow = function onInsertRow() {
1266
+ setItems([].concat(_toConsumableArray(items), [{}]));
1267
+ };
1268
+ var onSelectParent = function onSelectParent(item, parent) {
1269
+ var rowItem = item;
1270
+ rowItem.parent = parent;
1271
+ setItems(_toConsumableArray(items));
1272
+ };
1273
+ var onVillagesChange = function onVillagesChange(item, entities) {
1274
+ var rowItem = item;
1275
+ rowItem.entities = entities;
1276
+ handleChange(items);
1277
+ };
1278
+ var createRow = function createRow(parent) {
1279
+ var _edges$map;
1280
+ var edges = parent.children.edges;
1281
+ var entities = (_edges$map = edges === null || edges === void 0 ? void 0 : edges.map(function (edge) {
1282
+ return edge.node;
1283
+ })) !== null && _edges$map !== void 0 ? _edges$map : [];
1284
+ var savedEntities = entities.filter(function (entity) {
1285
+ return savedEOVillages === null || savedEOVillages === void 0 ? void 0 : savedEOVillages.some(function (village) {
1286
+ return entity.uuid === (village === null || village === void 0 ? void 0 : village.uuid);
1287
+ });
1288
+ });
1289
+ var createdRow = {};
1290
+ createdRow.parent = parent;
1291
+ if (!isUserEdited) {
1292
+ createdRow.entities = entities;
1293
+ return createdRow;
1294
+ }
1295
+ if (isUserEdited && savedEntities && wasEmpty) {
1296
+ createdRow.entities = entities;
1297
+ return createdRow;
1298
+ }
1299
+ if (entities.find(function (entity) {
1300
+ return savedEntities.some(function (savedEntity) {
1301
+ return savedEntity.uuid !== entity.uuid;
1302
+ });
1303
+ })) {
1304
+ createdRow.entities = savedEntities;
1305
+ } else {
1306
+ createdRow.entities = entities;
1307
+ }
1308
+ return createdRow;
1309
+ };
1310
+ var rescheduleItems = function rescheduleItems(rows) {
1311
+ setItems([].concat(_toConsumableArray(items), _toConsumableArray(rows)));
1312
+ handleChange([].concat(_toConsumableArray(items), _toConsumableArray(rows)));
1313
+ };
1314
+ var clearItems = function clearItems() {
1315
+ setItems([]);
1316
+ handleChange([]);
1317
+ dispatch(clearDistrictData());
1318
+ };
1319
+ var executeNewRows = function executeNewRows(newRows, uniqueRows) {
1320
+ if (!items.length) {
1321
+ rescheduleItems(newRows);
1322
+ } else {
1323
+ rescheduleItems(uniqueRows);
1324
+ }
1325
+ };
1326
+ var filterParents = function filterParents(options) {
1327
+ return options.filter(function (p) {
1328
+ return !items.some(function (i) {
1329
+ var _i$parent2;
1330
+ return ((_i$parent2 = i.parent) === null || _i$parent2 === void 0 ? void 0 : _i$parent2.id) === p.id;
1331
+ });
1332
+ });
1333
+ };
1334
+ var filterVillages = function filterVillages(options) {
1335
+ return options.filter(function (option) {
1336
+ return !(villages !== null && villages !== void 0 && villages.some(function (village) {
1337
+ return (village === null || village === void 0 ? void 0 : village.id) === option.id;
1338
+ }));
1339
+ });
1340
+ };
1341
+ useEffect(function () {
1342
+ if (districts !== null && districts !== void 0 && districts.length) {
1343
+ dispatch(fetchDataFromDistrict(pickedDistrictsUuids));
1344
+ } else setWasEmpty(true);
1345
+ return clearItems();
1346
+ }, [districts]);
1347
+ useEffect(function () {
1348
+ if (fetchedDistrictMunAndVil) {
1349
+ var createdRows = districtMunAndVil.map(function (mun) {
1350
+ return createRow(mun);
1351
+ });
1352
+ var uniqueRows = createdRows.filter(function (row) {
1353
+ return !items.some(function (i) {
1354
+ return i.parent.uuid === row.parent.uuid;
1355
+ });
1356
+ });
1357
+ executeNewRows(createdRows, uniqueRows);
1358
+ }
1359
+ }, [districtMunAndVil]);
1360
+ useEffect(function () {
1361
+ if (isOfficerPanelEnabled) {
1362
+ clearItems();
1363
+ }
1364
+ }, [isOfficerPanelEnabled]);
1365
+ return /*#__PURE__*/React.createElement(TableContainer, {
1366
+ component: Paper
1367
+ }, /*#__PURE__*/React.createElement(Table, {
1368
+ size: "small"
1369
+ }, /*#__PURE__*/React.createElement(TableHead, {
1370
+ className: classes.header
1371
+ }, /*#__PURE__*/React.createElement(TableRow, {
1372
+ className: classes.headerTitle
1373
+ }, /*#__PURE__*/React.createElement(TableCell, null, formatMessage("table.municipality")), /*#__PURE__*/React.createElement(TableCell, null, formatMessage("table.villages")), /*#__PURE__*/React.createElement(TableCell, null))), /*#__PURE__*/React.createElement(TableBody, null, /*#__PURE__*/React.createElement(ProgressOrError, {
1374
+ progress: fetchingDistrictMunAndVil,
1375
+ error: errorDistrictMunAndVil
1376
+ }), items.map(function (item) {
1377
+ var _item$parent, _item$parent2;
1378
+ return /*#__PURE__*/React.createElement(TableRow, {
1379
+ key: (_item$parent = item.parent) === null || _item$parent === void 0 ? void 0 : _item$parent.id
1380
+ }, /*#__PURE__*/React.createElement(TableCell, null, item.parent ? "".concat(item.parent.code, " ").concat(item.parent.name) : /*#__PURE__*/React.createElement(PublishedComponent, {
1381
+ pubRef: "location.LocationPicker",
1382
+ parentLocations: pickedDistrictsUuids,
1383
+ onChange: function onChange(parent) {
1384
+ return onSelectParent(item, parent);
1385
+ },
1386
+ required: true,
1387
+ filterOptions: filterParents,
1388
+ value: item.parent,
1389
+ locationLevel: 2
1390
+ })), /*#__PURE__*/React.createElement(TableCell, null, /*#__PURE__*/React.createElement(PublishedComponent, {
1391
+ fullWidth: true,
1392
+ pubRef: "location.LocationPicker",
1393
+ parentLocation: item.parent,
1394
+ parentLocations: [(_item$parent2 = item.parent) === null || _item$parent2 === void 0 ? void 0 : _item$parent2.uuid],
1395
+ readOnly: readOnly,
1396
+ required: true,
1397
+ multiple: true,
1398
+ value: item.entities,
1399
+ onChange: function onChange(value) {
1400
+ return onVillagesChange(item, value);
1401
+ },
1402
+ filterOptions: filterVillages,
1403
+ locationLevel: 3
1404
+ })), /*#__PURE__*/React.createElement(TableCell, {
1405
+ className: classes.actionCell
1406
+ }, /*#__PURE__*/React.createElement(IconButton, {
1407
+ disabled: readOnly,
1408
+ onClick: function onClick() {
1409
+ return onRemoveRow(item);
1410
+ }
1411
+ }, /*#__PURE__*/React.createElement(DeleteIcon, null))));
1412
+ })), /*#__PURE__*/React.createElement(TableFooter, null, /*#__PURE__*/React.createElement(Button, {
1413
+ disabled: readOnly,
1414
+ variant: "contained",
1415
+ onClick: onInsertRow,
1416
+ startIcon: /*#__PURE__*/React.createElement(AddIcon, null),
1417
+ className: classes.footer
1418
+ }, formatMessage("table.newRow")))));
1419
+ };
1420
+ var enhance$3 = combine(withModulesManager, withTheme, withStyles(styles$6));
1421
+ var EnrolmentVillagesPicker$1 = enhance$3(EnrolmentVillagesPicker);
1422
+
1423
+ function ownKeys$5(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1424
+ function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$5(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$5(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1425
+ var styles$5 = function styles(theme) {
1426
+ return {
1427
+ item: theme.paper.item,
1428
+ paper: theme.paper.paper,
1429
+ title: theme.paper.title
1430
+ };
1431
+ };
1432
+ var EnrolmentOfficerFormPanel = function EnrolmentOfficerFormPanel(props) {
1433
+ var _edited$userTypes, _edited$worksTo, _edited$address;
1434
+ var edited = props.edited,
1435
+ classes = props.classes,
1436
+ modulesManager = props.modulesManager,
1437
+ onEditedChanged = props.onEditedChanged,
1438
+ readOnly = props.readOnly;
1439
+ var _useTranslations = useTranslations("admin.EnrolmentOfficerFormPanel", modulesManager),
1440
+ formatMessage = _useTranslations.formatMessage;
1441
+ var _useState = useState(false),
1442
+ _useState2 = _slicedToArray(_useState, 2),
1443
+ isEnabled = _useState2[0],
1444
+ setIsEnabled = _useState2[1];
1445
+ var hasOfficerUserType = (_edited$userTypes = edited.userTypes) === null || _edited$userTypes === void 0 ? void 0 : _edited$userTypes.includes(ENROLMENT_OFFICER_USER_TYPE);
1446
+ var hasOfficerRole = edited.roles ? edited.roles.filter(function (x) {
1447
+ return x.isSystem === OFFICER_ROLE_IS_SYSTEM;
1448
+ }).length !== 0 : false;
1449
+ var _useGraphqlQuery = useGraphqlQuery("\n query UserRolesPicker ($system_id: Int) {\n role(systemRoleId: $system_id) {\n edges {\n node {\n id name isSystem\n }\n }\n }\n }\n ", {
1450
+ system_id: OFFICER_ROLE_IS_SYSTEM
1451
+ }),
1452
+ isLoading = _useGraphqlQuery.isLoading,
1453
+ data = _useGraphqlQuery.data;
1454
+ _useGraphqlQuery.error;
1455
+ var isValid = !isLoading;
1456
+ useEffect(function () {
1457
+ toggleUserRoles(edited, data, isValid, isEnabled, hasOfficerRole, onEditedChanged, OFFICER_ROLE_IS_SYSTEM);
1458
+ }, [isEnabled]);
1459
+ useEffect(function () {
1460
+ toggleSwitchButton(edited, hasOfficerRole, hasOfficerUserType, setIsEnabled, onEditedChanged, ENROLMENT_OFFICER_USER_TYPE);
1461
+ }, [hasOfficerRole]);
1462
+ return /*#__PURE__*/React.createElement(Paper, {
1463
+ className: classes.paper
1464
+ }, /*#__PURE__*/React.createElement(Grid, {
1465
+ item: true,
1466
+ xs: 12,
1467
+ className: classes.title
1468
+ }, /*#__PURE__*/React.createElement(Grid, {
1469
+ container: true,
1470
+ justifyContent: "space-between",
1471
+ alignItems: "center"
1472
+ }, /*#__PURE__*/React.createElement(Typography, {
1473
+ variant: "h6"
1474
+ }, formatMessage("title")), (edited || !isEnabled) && /*#__PURE__*/React.createElement(Switch, {
1475
+ color: "secondary",
1476
+ disabled: readOnly,
1477
+ checked: isEnabled,
1478
+ onChange: function onChange() {
1479
+ return setIsEnabled(function () {
1480
+ return !isEnabled;
1481
+ });
1482
+ }
1483
+ }))), isEnabled && /*#__PURE__*/React.createElement(Grid, {
1484
+ item: true,
1485
+ xs: 12
1486
+ }, /*#__PURE__*/React.createElement(Grid, {
1487
+ container: true
1488
+ }, /*#__PURE__*/React.createElement(Grid, {
1489
+ item: true,
1490
+ xs: 4,
1491
+ className: classes.item
1492
+ }, /*#__PURE__*/React.createElement(PublishedComponent, {
1493
+ pubRef: "core.DatePicker",
1494
+ value: edited === null || edited === void 0 ? void 0 : edited.birthDate,
1495
+ module: "admin",
1496
+ label: "user.dob",
1497
+ readOnly: readOnly,
1498
+ maxDate: new Date(),
1499
+ onChange: function onChange(birthDate) {
1500
+ return onEditedChanged(_objectSpread$5(_objectSpread$5({}, edited), {}, {
1501
+ birthDate: birthDate
1502
+ }));
1503
+ }
1504
+ })), /*#__PURE__*/React.createElement(Grid, {
1505
+ item: true,
1506
+ xs: 4,
1507
+ className: classes.item
1508
+ }, /*#__PURE__*/React.createElement(PublishedComponent, {
1509
+ pubRef: "admin.SubstitutionEnrolmentOfficerPicker",
1510
+ module: "admin",
1511
+ readOnly: readOnly,
1512
+ withLabel: true,
1513
+ withPlaceholder: true,
1514
+ value: edited.substitutionOfficer,
1515
+ villages: edited.officerVillages,
1516
+ onChange: function onChange(substitutionOfficer) {
1517
+ return onEditedChanged(_objectSpread$5(_objectSpread$5({}, edited), {}, {
1518
+ substitutionOfficer: substitutionOfficer
1519
+ }));
1520
+ }
1521
+ })), /*#__PURE__*/React.createElement(Grid, {
1522
+ item: true,
1523
+ xs: 4,
1524
+ className: classes.item
1525
+ }, /*#__PURE__*/React.createElement(PublishedComponent, {
1526
+ pubRef: "core.DatePicker",
1527
+ value: (_edited$worksTo = edited === null || edited === void 0 ? void 0 : edited.worksTo) !== null && _edited$worksTo !== void 0 ? _edited$worksTo : "",
1528
+ module: "admin",
1529
+ label: "user.worksTo",
1530
+ readOnly: readOnly,
1531
+ onChange: function onChange(worksTo) {
1532
+ return onEditedChanged(_objectSpread$5(_objectSpread$5({}, edited), {}, {
1533
+ worksTo: worksTo
1534
+ }));
1535
+ }
1536
+ })), /*#__PURE__*/React.createElement(Grid, {
1537
+ item: true,
1538
+ xs: 12,
1539
+ className: classes.item
1540
+ }, /*#__PURE__*/React.createElement(TextInput, {
1541
+ module: "admin",
1542
+ label: "user.address",
1543
+ multiline: true,
1544
+ rows: 2,
1545
+ variant: "outlined",
1546
+ readOnly: readOnly,
1547
+ value: (_edited$address = edited === null || edited === void 0 ? void 0 : edited.address) !== null && _edited$address !== void 0 ? _edited$address : "",
1548
+ onChange: function onChange(address) {
1549
+ return onEditedChanged(_objectSpread$5(_objectSpread$5({}, edited), {}, {
1550
+ address: address
1551
+ }));
1552
+ }
1553
+ })), /*#__PURE__*/React.createElement(Grid, {
1554
+ item: true,
1555
+ xs: 12,
1556
+ className: classes.item
1557
+ }, /*#__PURE__*/React.createElement(EnrolmentVillagesPicker$1, {
1558
+ isOfficerPanelEnabled: isEnabled,
1559
+ readOnly: readOnly,
1560
+ districts: edited.districts,
1561
+ villages: edited.officerVillages,
1562
+ onChange: function onChange(officerVillages) {
1563
+ return onEditedChanged(_objectSpread$5(_objectSpread$5({}, edited), {}, {
1564
+ officerVillages: officerVillages
1565
+ }));
1566
+ }
1567
+ })))));
1568
+ };
1569
+ var enhance$2 = combine(withModulesManager, withTheme, withStyles(styles$5));
1570
+ var EnrolmentOfficerFormPanel$1 = enhance$2(EnrolmentOfficerFormPanel);
1571
+
1572
+ function ownKeys$4(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1573
+ function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1574
+ var styles$4 = function styles(theme) {
1575
+ return {
1576
+ item: theme.paper.item,
1577
+ paper: theme.paper.paper,
1578
+ title: theme.paper.title
1579
+ };
1580
+ };
1581
+ var ClaimAdministratorFormPanel = function ClaimAdministratorFormPanel(props) {
1582
+ var _edited$userTypes;
1583
+ var edited = props.edited,
1584
+ classes = props.classes,
1585
+ modulesManager = props.modulesManager,
1586
+ onEditedChanged = props.onEditedChanged,
1587
+ readOnly = props.readOnly;
1588
+ var _useTranslations = useTranslations("admin.ClaimAdministratorFormPanel", modulesManager),
1589
+ formatMessage = _useTranslations.formatMessage;
1590
+ var hasClaimUserType = (_edited$userTypes = edited.userTypes) === null || _edited$userTypes === void 0 ? void 0 : _edited$userTypes.includes(CLAIM_ADMIN_USER_TYPE);
1591
+ var hasClaimRole = edited.roles ? edited.roles.filter(function (x) {
1592
+ return x.isSystem === CLAIM_ADMIN_IS_SYSTEM;
1593
+ }).length !== 0 : false;
1594
+ var _useState = useState(false),
1595
+ _useState2 = _slicedToArray(_useState, 2),
1596
+ isEnabled = _useState2[0],
1597
+ setIsEnabled = _useState2[1];
1598
+ var _useGraphqlQuery = useGraphqlQuery("\n query UserRolesPicker ($system_id: Int) {\n role(systemRoleId: $system_id) {\n edges {\n node {\n id name isSystem\n }\n }\n }\n }\n ", {
1599
+ system_id: CLAIM_ADMIN_IS_SYSTEM
1600
+ }),
1601
+ isLoading = _useGraphqlQuery.isLoading,
1602
+ data = _useGraphqlQuery.data;
1603
+ _useGraphqlQuery.error;
1604
+ var isValid = !isLoading;
1605
+ useEffect(function () {
1606
+ toggleUserRoles(edited, data, isValid, isEnabled, hasClaimRole, onEditedChanged, CLAIM_ADMIN_IS_SYSTEM);
1607
+ }, [isEnabled]);
1608
+ useEffect(function () {
1609
+ toggleSwitchButton(edited, hasClaimRole, hasClaimUserType, setIsEnabled, onEditedChanged, CLAIM_ADMIN_USER_TYPE);
1610
+ }, [hasClaimRole]);
1611
+ return /*#__PURE__*/React.createElement(Paper, {
1612
+ className: classes.paper
1613
+ }, /*#__PURE__*/React.createElement(Grid, {
1614
+ item: true,
1615
+ xs: 12,
1616
+ className: classes.title
1617
+ }, /*#__PURE__*/React.createElement(Grid, {
1618
+ container: true,
1619
+ justifyContent: "space-between",
1620
+ alignItems: "center"
1621
+ }, /*#__PURE__*/React.createElement(Typography, {
1622
+ variant: "h6"
1623
+ }, formatMessage("title")), (edited || !isEnabled) && /*#__PURE__*/React.createElement(Switch, {
1624
+ color: "secondary",
1625
+ disabled: readOnly,
1626
+ checked: isEnabled,
1627
+ onChange: function onChange() {
1628
+ return setIsEnabled(function () {
1629
+ return !isEnabled;
1630
+ });
1631
+ }
1632
+ }))), isEnabled && /*#__PURE__*/React.createElement(Grid, {
1633
+ item: true,
1634
+ xs: 12
1635
+ }, /*#__PURE__*/React.createElement(Grid, {
1636
+ container: true
1637
+ }, /*#__PURE__*/React.createElement(Grid, {
1638
+ item: true,
1639
+ xs: 4,
1640
+ className: classes.item
1641
+ }, /*#__PURE__*/React.createElement(PublishedComponent, {
1642
+ pubRef: "core.DatePicker",
1643
+ value: edited === null || edited === void 0 ? void 0 : edited.birthDate,
1644
+ module: "admin",
1645
+ label: "user.dob",
1646
+ readOnly: readOnly,
1647
+ maxDate: new Date(),
1648
+ onChange: function onChange(birthDate) {
1649
+ return onEditedChanged(_objectSpread$4(_objectSpread$4({}, edited), {}, {
1650
+ birthDate: birthDate
1651
+ }));
1652
+ }
1653
+ })), /*#__PURE__*/React.createElement(Grid, {
1654
+ item: true,
1655
+ xs: 4,
1656
+ className: classes.item
1657
+ }, /*#__PURE__*/React.createElement(PublishedComponent, {
1658
+ pubRef: "location.HealthFacilityPicker",
1659
+ value: edited === null || edited === void 0 ? void 0 : edited.healthFacility,
1660
+ district: edited === null || edited === void 0 ? void 0 : edited.districts,
1661
+ required: true,
1662
+ module: "admin",
1663
+ readOnly: readOnly,
1664
+ onChange: function onChange(healthFacility) {
1665
+ return onEditedChanged(_objectSpread$4(_objectSpread$4({}, edited), {}, {
1666
+ healthFacility: healthFacility
1667
+ }));
1668
+ }
1669
+ })))));
1670
+ };
1671
+ var enhance$1 = combine(withModulesManager, withTheme, withStyles(styles$4));
1672
+ var ClaimAdministratorFormPanel$1 = enhance$1(ClaimAdministratorFormPanel);
1673
+
1674
+ function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1675
+ function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1676
+ var styles$3 = function styles(theme) {
1677
+ return {
1678
+ tableTitle: theme.table.title,
1679
+ item: theme.paper.item,
1680
+ fullHeight: {
1681
+ height: "100%"
1682
+ },
1683
+ sectionHeader: _objectSpread$3(_objectSpread$3({}, theme.paper.item), {}, {
1684
+ paddingBottom: 0
1685
+ }),
1686
+ sectionTitle: theme.typography.title
1687
+ };
1688
+ };
1689
+ var UserMasterPanel = function UserMasterPanel(props) {
1690
+ var _edited$username, _edited$userTypes, _edited$email, _edited$userTypes2, _edited$userTypes3, _edited$phoneNumber, _edited$roles, _edited$districts, _edited$language;
1691
+ var classes = props.classes,
1692
+ edited = props.edited,
1693
+ readOnly = props.readOnly,
1694
+ onEditedChanged = props.onEditedChanged,
1695
+ modulesManager = props.modulesManager,
1696
+ obligatoryUserFields = props.obligatoryUserFields,
1697
+ obligatoryEOFields = props.obligatoryEOFields,
1698
+ isUsernameValid = props.isUsernameValid,
1699
+ isUsernameValidating = props.isUsernameValidating,
1700
+ usernameValidationError = props.usernameValidationError,
1701
+ isUserEmailValid = props.isUserEmailValid,
1702
+ isUserEmailValidating = props.isUserEmailValidating,
1703
+ isUserEmailFormatInvalid = props.isUserEmailFormatInvalid,
1704
+ emailValidationError = props.emailValidationError,
1705
+ savedUsername = props.savedUsername,
1706
+ savedUserEmail = props.savedUserEmail,
1707
+ usernameLength = props.usernameLength,
1708
+ passwordPolicy = props.passwordPolicy,
1709
+ rights = props.rights;
1710
+ var _useTranslations = useTranslations("admin", modulesManager),
1711
+ formatMessage = _useTranslations.formatMessage,
1712
+ formatMessageWithValues = _useTranslations.formatMessageWithValues;
1713
+ var dispatch = useDispatch();
1714
+ useEffect(function () {
1715
+ dispatch(fetchPasswordPolicy());
1716
+ }, [dispatch]);
1717
+ var renderLastNameFirst = modulesManager.getConf("fe-insuree", "renderLastNameFirst", DEFAULT.RENDER_LAST_NAME_FIRST);
1718
+ var shouldValidateUsername = function shouldValidateUsername(inputValue) {
1719
+ var shouldBeValidated = inputValue !== savedUsername;
1720
+ return shouldBeValidated;
1721
+ };
1722
+ var shouldValidateEmail = function shouldValidateEmail(inputValue) {
1723
+ var shouldBeValidated = inputValue !== savedUserEmail;
1724
+ return shouldBeValidated;
1725
+ };
1726
+ var checkEmailFormatValidity = function checkEmailFormatValidity(emailInput) {
1727
+ if (!emailInput) return false;
1728
+ var isEmailInvalid = !EMAIL_REGEX_PATTERN.test(emailInput);
1729
+ return isEmailInvalid;
1730
+ };
1731
+ var handleEmailChange = function handleEmailChange(email) {
1732
+ var isFormatValid = checkEmailFormatValidity(email);
1733
+ dispatch(saveEmailFormatValidity(isFormatValid));
1734
+ onEditedChanged(_objectSpread$3(_objectSpread$3({}, edited), {}, {
1735
+ email: email
1736
+ }));
1737
+ };
1738
+ useEffect(function () {
1739
+ handleEmailChange(edited === null || edited === void 0 ? void 0 : edited.email);
1740
+ }, []);
1741
+ var _useState = useState(""),
1742
+ _useState2 = _slicedToArray(_useState, 2),
1743
+ passwordFeedback = _useState2[0],
1744
+ setPasswordFeedback = _useState2[1];
1745
+ var _useState3 = useState(0),
1746
+ _useState4 = _slicedToArray(_useState3, 2),
1747
+ passwordScore = _useState4[0],
1748
+ setPasswordScore = _useState4[1];
1749
+ var _useState5 = useState(false),
1750
+ _useState6 = _slicedToArray(_useState5, 2),
1751
+ showPassword = _useState6[0],
1752
+ setShowPassword = _useState6[1];
1753
+ var REQUIRED_SECURITY_LEVEL = 2;
1754
+ var IS_PASSWORD_SECURED = passwordScore >= REQUIRED_SECURITY_LEVEL;
1755
+ var handleClickShowPassword = function handleClickShowPassword() {
1756
+ return setShowPassword(function (show) {
1757
+ return !show;
1758
+ });
1759
+ };
1760
+ var handleMouseDownPassword = function handleMouseDownPassword(event) {
1761
+ event.preventDefault();
1762
+ };
1763
+ var handlePasswordChange = function handlePasswordChange(password) {
1764
+ var _validatePassword = validatePassword(password, passwordPolicy, formatMessage, formatMessageWithValues),
1765
+ feedback = _validatePassword.feedback,
1766
+ score = _validatePassword.score;
1767
+ setPasswordFeedback(feedback);
1768
+ setPasswordScore(score);
1769
+ IS_PASSWORD_SECURED = score >= REQUIRED_SECURITY_LEVEL;
1770
+ onEditedChanged(_objectSpread$3(_objectSpread$3({}, edited), {}, {
1771
+ password: password,
1772
+ isPasswordValid: IS_PASSWORD_SECURED
1773
+ }));
1774
+ };
1775
+ var generatePassword = function generatePassword() {
1776
+ var passwordGeneratorOptions = modulesManager.getConf("fe-admin", "passwordGeneratorOptions", {
1777
+ length: 12,
1778
+ isNumberRequired: true,
1779
+ isLowerCaseRequired: true,
1780
+ isUpperCaseRequired: true,
1781
+ isSpecialSymbolRequired: true
1782
+ });
1783
+ var generatedPassword = passwordGenerator(passwordGeneratorOptions);
1784
+ IS_PASSWORD_SECURED = true;
1785
+ onEditedChanged(_objectSpread$3(_objectSpread$3({}, edited), {}, {
1786
+ password: generatedPassword,
1787
+ confirmPassword: generatedPassword,
1788
+ isPasswordValid: IS_PASSWORD_SECURED
1789
+ }));
1790
+ };
1791
+ var renderLastNameField = function renderLastNameField(edited, classes, readOnly) {
1792
+ var _edited$lastName;
1793
+ return /*#__PURE__*/React.createElement(Grid, {
1794
+ item: true,
1795
+ xs: 4,
1796
+ className: classes.item
1797
+ }, /*#__PURE__*/React.createElement(TextInput, {
1798
+ module: "admin",
1799
+ label: "user.lastName",
1800
+ required: true,
1801
+ readOnly: readOnly,
1802
+ value: (_edited$lastName = edited === null || edited === void 0 ? void 0 : edited.lastName) !== null && _edited$lastName !== void 0 ? _edited$lastName : "",
1803
+ onChange: function onChange(lastName) {
1804
+ return onEditedChanged(_objectSpread$3(_objectSpread$3({}, edited), {}, {
1805
+ lastName: lastName
1806
+ }));
1807
+ }
1808
+ }));
1809
+ };
1810
+ var renderGivenNameField = function renderGivenNameField(edited, classes, readOnly) {
1811
+ var _edited$otherNames;
1812
+ return /*#__PURE__*/React.createElement(Grid, {
1813
+ item: true,
1814
+ xs: 4,
1815
+ className: classes.item
1816
+ }, /*#__PURE__*/React.createElement(TextInput, {
1817
+ module: "admin",
1818
+ label: "user.givenNames",
1819
+ required: true,
1820
+ readOnly: readOnly,
1821
+ value: (_edited$otherNames = edited === null || edited === void 0 ? void 0 : edited.otherNames) !== null && _edited$otherNames !== void 0 ? _edited$otherNames : "",
1822
+ onChange: function onChange(otherNames) {
1823
+ return onEditedChanged(_objectSpread$3(_objectSpread$3({}, edited), {}, {
1824
+ otherNames: otherNames
1825
+ }));
1826
+ }
1827
+ }));
1828
+ };
1829
+ return /*#__PURE__*/React.createElement(Grid, {
1830
+ container: true,
1831
+ direction: "row"
1832
+ }, /*#__PURE__*/React.createElement(Grid, {
1833
+ item: true,
1834
+ xs: 4,
1835
+ className: classes.item
1836
+ }, /*#__PURE__*/React.createElement(ValidatedTextInput, {
1837
+ itemQueryIdentifier: "username",
1838
+ shouldValidate: shouldValidateUsername,
1839
+ isValid: isUsernameValid,
1840
+ isValidating: isUsernameValidating,
1841
+ validationError: usernameValidationError,
1842
+ action: usernameValidationCheck,
1843
+ clearAction: usernameValidationClear,
1844
+ setValidAction: setUsernameValid,
1845
+ module: "admin",
1846
+ label: "user.username",
1847
+ codeTakenLabel: "user.usernameAlreadyTaken",
1848
+ required: true,
1849
+ value: (_edited$username = edited === null || edited === void 0 ? void 0 : edited.username) !== null && _edited$username !== void 0 ? _edited$username : "",
1850
+ readOnly: readOnly,
1851
+ onChange: function onChange(username) {
1852
+ return onEditedChanged(_objectSpread$3(_objectSpread$3({}, edited), {}, {
1853
+ username: username
1854
+ }));
1855
+ },
1856
+ inputProps: {
1857
+ "maxLength": usernameLength
1858
+ }
1859
+ })), renderLastNameFirst ? /*#__PURE__*/React.createElement(React.Fragment, null, renderLastNameField(edited, classes, readOnly), renderGivenNameField(edited, classes, readOnly)) : /*#__PURE__*/React.createElement(React.Fragment, null, renderGivenNameField(edited, classes, readOnly), renderLastNameField(edited, classes, readOnly)), !((obligatoryUserFields === null || obligatoryUserFields === void 0 ? void 0 : obligatoryUserFields.email) == "H" || (_edited$userTypes = edited.userTypes) !== null && _edited$userTypes !== void 0 && _edited$userTypes.includes(ENROLMENT_OFFICER_USER_TYPE) && (obligatoryEOFields === null || obligatoryEOFields === void 0 ? void 0 : obligatoryEOFields.email) == "H") && /*#__PURE__*/React.createElement(Grid, {
1860
+ item: true,
1861
+ xs: 4,
1862
+ className: classes.item
1863
+ }, /*#__PURE__*/React.createElement(ValidatedTextInput, {
1864
+ itemQueryIdentifier: "userEmail",
1865
+ shouldValidate: shouldValidateEmail,
1866
+ isValid: isUserEmailValid,
1867
+ isValidating: isUserEmailValidating,
1868
+ validationError: emailValidationError,
1869
+ invalidValueFormat: isUserEmailFormatInvalid,
1870
+ action: userEmailValidationCheck,
1871
+ clearAction: userEmailValidationClear,
1872
+ setValidAction: setUserEmailValid,
1873
+ readOnly: readOnly,
1874
+ module: "admin",
1875
+ label: "user.email",
1876
+ type: "email",
1877
+ codeTakenLabel: "user.emailAlreadyTaken",
1878
+ required: true,
1879
+ value: (_edited$email = edited === null || edited === void 0 ? void 0 : edited.email) !== null && _edited$email !== void 0 ? _edited$email : "",
1880
+ onChange: function onChange(email) {
1881
+ return handleEmailChange(email);
1882
+ }
1883
+ })), !((obligatoryUserFields === null || obligatoryUserFields === void 0 ? void 0 : obligatoryUserFields.phone) == "H" || (_edited$userTypes2 = edited.userTypes) !== null && _edited$userTypes2 !== void 0 && _edited$userTypes2.includes(ENROLMENT_OFFICER_USER_TYPE) && (obligatoryEOFields === null || obligatoryEOFields === void 0 ? void 0 : obligatoryEOFields.phone) == "H") && /*#__PURE__*/React.createElement(Grid, {
1884
+ item: true,
1885
+ xs: 4,
1886
+ className: classes.item
1887
+ }, /*#__PURE__*/React.createElement(TextInput, {
1888
+ module: "admin",
1889
+ type: "phone",
1890
+ label: "user.phone",
1891
+ required: (obligatoryUserFields === null || obligatoryUserFields === void 0 ? void 0 : obligatoryUserFields.phone) == "M" || ((_edited$userTypes3 = edited.userTypes) === null || _edited$userTypes3 === void 0 ? void 0 : _edited$userTypes3.includes(ENROLMENT_OFFICER_USER_TYPE)) && (obligatoryEOFields === null || obligatoryEOFields === void 0 ? void 0 : obligatoryEOFields.phone) == "M",
1892
+ readOnly: readOnly,
1893
+ value: (_edited$phoneNumber = edited === null || edited === void 0 ? void 0 : edited.phoneNumber) !== null && _edited$phoneNumber !== void 0 ? _edited$phoneNumber : "",
1894
+ onChange: function onChange(phoneNumber) {
1895
+ return onEditedChanged(_objectSpread$3(_objectSpread$3({}, edited), {}, {
1896
+ phoneNumber: phoneNumber
1897
+ }));
1898
+ }
1899
+ })), rights.includes(RIGHT_HEALTHFACILITIES) && /*#__PURE__*/React.createElement(Grid, {
1900
+ item: true,
1901
+ xs: 4,
1902
+ className: classes.item
1903
+ }, /*#__PURE__*/React.createElement(PublishedComponent, {
1904
+ pubRef: "location.HealthFacilityPicker",
1905
+ value: edited === null || edited === void 0 ? void 0 : edited.healthFacility,
1906
+ district: edited.districts,
1907
+ module: "admin",
1908
+ readOnly: readOnly,
1909
+ required: edited.userTypes.includes(CLAIM_ADMIN_USER_TYPE),
1910
+ onChange: function onChange(healthFacility) {
1911
+ return onEditedChanged(_objectSpread$3(_objectSpread$3({}, edited), {}, {
1912
+ healthFacility: healthFacility
1913
+ }));
1914
+ }
1915
+ })), /*#__PURE__*/React.createElement(Grid, {
1916
+ item: true,
1917
+ xs: 6,
1918
+ className: classes.item
1919
+ }, /*#__PURE__*/React.createElement(PublishedComponent, {
1920
+ pubRef: "admin.UserRolesPicker",
1921
+ required: true,
1922
+ value: (_edited$roles = edited === null || edited === void 0 ? void 0 : edited.roles) !== null && _edited$roles !== void 0 ? _edited$roles : [],
1923
+ module: "admin",
1924
+ readOnly: readOnly,
1925
+ onChange: function onChange(roles) {
1926
+ return onEditedChanged(_objectSpread$3(_objectSpread$3({}, edited), {}, {
1927
+ roles: roles
1928
+ }));
1929
+ }
1930
+ })), /*#__PURE__*/React.createElement(Grid, {
1931
+ item: true,
1932
+ xs: 2,
1933
+ className: classes.item
1934
+ }, /*#__PURE__*/React.createElement(PublishedComponent, {
1935
+ pubRef: "location.LocationPicker",
1936
+ locationLevel: 0,
1937
+ value: edited.region,
1938
+ onChange: function onChange(region) {
1939
+ return onEditedChanged(_objectSpread$3(_objectSpread$3({}, edited), {}, {
1940
+ region: region
1941
+ }));
1942
+ },
1943
+ readOnly: readOnly,
1944
+ multiple: true,
1945
+ withLabel: true,
1946
+ label: formatMessage("user.regions"),
1947
+ restrictedOptions: true
1948
+ })), /*#__PURE__*/React.createElement(Grid, {
1949
+ item: true,
1950
+ xs: 4,
1951
+ className: classes.item
1952
+ }, /*#__PURE__*/React.createElement(PublishedComponent, {
1953
+ pubRef: "location.LocationPicker",
1954
+ locationLevel: 1,
1955
+ value: (_edited$districts = edited === null || edited === void 0 ? void 0 : edited.districts) !== null && _edited$districts !== void 0 ? _edited$districts : [],
1956
+ onChange: function onChange(districts) {
1957
+ return onEditedChanged(_objectSpread$3(_objectSpread$3({}, edited), {}, {
1958
+ districts: districts
1959
+ }));
1960
+ },
1961
+ readOnly: readOnly,
1962
+ required: true,
1963
+ multiple: true,
1964
+ withLabel: true,
1965
+ label: formatMessage("user.districts"),
1966
+ restrictedOptions: true
1967
+ })), /*#__PURE__*/React.createElement(Grid, {
1968
+ item: true,
1969
+ xs: 12,
1970
+ className: classes.sectionHeader
1971
+ }, /*#__PURE__*/React.createElement(Typography, {
1972
+ className: classes.sectionTitle
1973
+ }, formatMessage("UserMasterPanel.loginDetailsTitle")), /*#__PURE__*/React.createElement(Divider, {
1974
+ variant: "fullWidth"
1975
+ })), /*#__PURE__*/React.createElement(Grid, {
1976
+ item: true,
1977
+ xs: 4,
1978
+ className: classes.item
1979
+ }, /*#__PURE__*/React.createElement(PublishedComponent, {
1980
+ pubRef: "core.LanguagePicker",
1981
+ module: "admin",
1982
+ label: "user.language",
1983
+ readOnly: readOnly,
1984
+ required: true,
1985
+ withNull: false,
1986
+ nullLabel: formatMessage("UserMasterPanel.language.null"),
1987
+ value: (_edited$language = edited.language) !== null && _edited$language !== void 0 ? _edited$language : "",
1988
+ onChange: function onChange(language) {
1989
+ return onEditedChanged(_objectSpread$3(_objectSpread$3({}, edited), {}, {
1990
+ language: language
1991
+ }));
1992
+ }
1993
+ })), /*#__PURE__*/React.createElement(Grid, {
1994
+ item: true,
1995
+ xs: 4,
1996
+ className: classes.item
1997
+ }, /*#__PURE__*/React.createElement(TextInput, {
1998
+ module: "admin",
1999
+ type: showPassword ? "text" : "password",
2000
+ label: "user.newPassword",
2001
+ readOnly: readOnly,
2002
+ value: edited.password,
2003
+ onChange: function onChange(password) {
2004
+ handlePasswordChange(password);
2005
+ },
2006
+ endAdornment: /*#__PURE__*/React.createElement(InputAdornment, {
2007
+ position: "end"
2008
+ }, /*#__PURE__*/React.createElement(IconButton, {
2009
+ "aria-label": "toggle password visibility",
2010
+ onClick: handleClickShowPassword,
2011
+ onMouseDown: handleMouseDownPassword,
2012
+ edge: "end"
2013
+ }, showPassword ? /*#__PURE__*/React.createElement(VisibilityOffIcon, null) : /*#__PURE__*/React.createElement(VisibilityIcon, null)))
2014
+ }), /*#__PURE__*/React.createElement(Typography, {
2015
+ color: IS_PASSWORD_SECURED ? "primary" : "error",
2016
+ className: classes.passwordFeedback
2017
+ }, passwordFeedback)), /*#__PURE__*/React.createElement(Grid, {
2018
+ item: true,
2019
+ xs: 4,
2020
+ className: classes.item
2021
+ }, /*#__PURE__*/React.createElement(TextInput, {
2022
+ module: "admin",
2023
+ type: showPassword ? "text" : "password",
2024
+ label: "user.confirmNewPassword",
2025
+ required: edited.password,
2026
+ readOnly: readOnly,
2027
+ value: edited.confirmPassword,
2028
+ onChange: function onChange(confirmPassword) {
2029
+ return onEditedChanged(_objectSpread$3(_objectSpread$3({}, edited), {}, {
2030
+ confirmPassword: confirmPassword
2031
+ }));
2032
+ },
2033
+ error: (edited === null || edited === void 0 ? void 0 : edited.password) !== (edited === null || edited === void 0 ? void 0 : edited.confirmPassword),
2034
+ endAdornment: /*#__PURE__*/React.createElement(InputAdornment, {
2035
+ position: "end"
2036
+ }, /*#__PURE__*/React.createElement(IconButton, {
2037
+ "aria-label": "toggle password visibility",
2038
+ onClick: handleClickShowPassword,
2039
+ onMouseDown: handleMouseDownPassword,
2040
+ edge: "end"
2041
+ }, showPassword ? /*#__PURE__*/React.createElement(VisibilityOffIcon, null) : /*#__PURE__*/React.createElement(VisibilityIcon, null)))
2042
+ })), /*#__PURE__*/React.createElement(Grid, {
2043
+ item: true,
2044
+ xs: 4,
2045
+ className: classes.item
2046
+ }, /*#__PURE__*/React.createElement(Button, {
2047
+ disabled: readOnly,
2048
+ variant: "contained",
2049
+ onClick: generatePassword
2050
+ }, formatMessage("user.generatePassword"))));
2051
+ };
2052
+ var mapStateToProps$1 = function mapStateToProps(state) {
2053
+ var _state$core$user$i_us, _state$core, _state$admin$validati, _state$admin$validati2, _state$admin$validati3, _state$admin, _state$admin$validati4, _state$admin$validati5, _state$admin$validati6, _state$admin2, _state$admin$validati7;
2054
+ return {
2055
+ rights: (_state$core$user$i_us = (_state$core = state.core) === null || _state$core === void 0 || (_state$core = _state$core.user) === null || _state$core === void 0 || (_state$core = _state$core.i_user) === null || _state$core === void 0 ? void 0 : _state$core.rights) !== null && _state$core$user$i_us !== void 0 ? _state$core$user$i_us : [],
2056
+ isUsernameValid: (_state$admin$validati = state.admin.validationFields) === null || _state$admin$validati === void 0 || (_state$admin$validati = _state$admin$validati.username) === null || _state$admin$validati === void 0 ? void 0 : _state$admin$validati.isValid,
2057
+ isUsernameValidating: (_state$admin$validati2 = state.admin.validationFields) === null || _state$admin$validati2 === void 0 || (_state$admin$validati2 = _state$admin$validati2.username) === null || _state$admin$validati2 === void 0 ? void 0 : _state$admin$validati2.isValidating,
2058
+ usernameValidationError: (_state$admin$validati3 = state.admin.validationFields) === null || _state$admin$validati3 === void 0 || (_state$admin$validati3 = _state$admin$validati3.username) === null || _state$admin$validati3 === void 0 ? void 0 : _state$admin$validati3.validationError,
2059
+ savedUsername: (_state$admin = state.admin) === null || _state$admin === void 0 || (_state$admin = _state$admin.user) === null || _state$admin === void 0 ? void 0 : _state$admin.username,
2060
+ isUserEmailValid: (_state$admin$validati4 = state.admin.validationFields) === null || _state$admin$validati4 === void 0 || (_state$admin$validati4 = _state$admin$validati4.userEmail) === null || _state$admin$validati4 === void 0 ? void 0 : _state$admin$validati4.isValid,
2061
+ isUserEmailValidating: (_state$admin$validati5 = state.admin.validationFields) === null || _state$admin$validati5 === void 0 || (_state$admin$validati5 = _state$admin$validati5.userEmail) === null || _state$admin$validati5 === void 0 ? void 0 : _state$admin$validati5.isValidating,
2062
+ emailValidationError: (_state$admin$validati6 = state.admin.validationFields) === null || _state$admin$validati6 === void 0 || (_state$admin$validati6 = _state$admin$validati6.userEmail) === null || _state$admin$validati6 === void 0 ? void 0 : _state$admin$validati6.validationError,
2063
+ savedUserEmail: (_state$admin2 = state.admin) === null || _state$admin2 === void 0 || (_state$admin2 = _state$admin2.user) === null || _state$admin2 === void 0 ? void 0 : _state$admin2.email,
2064
+ isUserEmailFormatInvalid: (_state$admin$validati7 = state.admin.validationFields) === null || _state$admin$validati7 === void 0 || (_state$admin$validati7 = _state$admin$validati7.userEmailFormat) === null || _state$admin$validati7 === void 0 ? void 0 : _state$admin$validati7.isInvalid
2065
+ };
2066
+ };
2067
+ var UserMasterPanel$1 = withModulesManager(connect(mapStateToProps$1)(withTheme(withStyles(styles$3)(UserMasterPanel))));
2068
+
2069
+ function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2070
+ function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2071
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
2072
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
2073
+ var styles$2 = function styles(theme) {
2074
+ return {
2075
+ lockedPage: theme.page.locked
2076
+ };
2077
+ };
2078
+ var USER_OVERVIEW_MUTATIONS_KEY = "user.UserOverview.mutations";
2079
+ var setupState = function setupState(props) {
2080
+ return {
2081
+ isLocked: false,
2082
+ user: !(props !== null && props !== void 0 && props.userId) ? {
2083
+ userTypes: [INTERACTIVE_USER_TYPE]
2084
+ } : props.user,
2085
+ isSaved: false,
2086
+ reset: 0
2087
+ };
2088
+ };
2089
+ var UserForm = /*#__PURE__*/function (_Component) {
2090
+ function UserForm(props) {
2091
+ var _this;
2092
+ _classCallCheck(this, UserForm);
2093
+ _this = _callSuper(this, UserForm, [props]);
2094
+ _defineProperty(_this, "reload", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
2095
+ var isSaved, _this$props, modulesManager, history, mutation, fetchUserMutation, userId, fetchUser, clientMutationId, response, createdUserId, _t, _t2;
2096
+ return _regeneratorRuntime.wrap(function (_context) {
2097
+ while (1) switch (_context.prev = _context.next) {
2098
+ case 0:
2099
+ isSaved = _this.state.isSaved; // eslint-disable-next-line no-shadow
2100
+ _this$props = _this.props, modulesManager = _this$props.modulesManager, history = _this$props.history, mutation = _this$props.mutation, fetchUserMutation = _this$props.fetchUserMutation, userId = _this$props.userId, fetchUser = _this$props.fetchUser;
2101
+ if (!userId) {
2102
+ _context.next = 5;
2103
+ break;
2104
+ }
2105
+ _context.prev = 1;
2106
+ _context.next = 2;
2107
+ return fetchUser(modulesManager, userId);
2108
+ case 2:
2109
+ _context.next = 4;
2110
+ break;
2111
+ case 3:
2112
+ _context.prev = 3;
2113
+ _t = _context["catch"](1);
2114
+ // eslint-disable-next-line no-console
2115
+ console.error("[RELOAD_USER]: Fetching user details failed. ".concat(_t));
2116
+ case 4:
2117
+ _this.setState(function (state) {
2118
+ return _objectSpread$2(_objectSpread$2({}, state), {}, {
2119
+ reset: state.reset + 1
2120
+ });
2121
+ });
2122
+ return _context.abrupt("return");
2123
+ case 5:
2124
+ if (!isSaved) {
2125
+ _context.next = 11;
2126
+ break;
2127
+ }
2128
+ _context.prev = 6;
2129
+ clientMutationId = mutation.clientMutationId;
2130
+ _context.next = 7;
2131
+ return fetchUserMutation(modulesManager, clientMutationId);
2132
+ case 7:
2133
+ response = _context.sent;
2134
+ createdUserId = parseData(response.payload.data.mutationLogs)[0].users[0].coreUser.id;
2135
+ _context.next = 8;
2136
+ return fetchUser(modulesManager, createdUserId);
2137
+ case 8:
2138
+ historyPush(modulesManager, history, "admin.userOverview", [createdUserId]);
2139
+ _context.next = 10;
2140
+ break;
2141
+ case 9:
2142
+ _context.prev = 9;
2143
+ _t2 = _context["catch"](6);
2144
+ // eslint-disable-next-line no-console
2145
+ console.error("[RELOAD_USER]: Fetching user details failed. ".concat(_t2));
2146
+ case 10:
2147
+ _this.setState(function (state) {
2148
+ return _objectSpread$2(_objectSpread$2({}, state), {}, {
2149
+ reset: state.reset + 1
2150
+ });
2151
+ });
2152
+ return _context.abrupt("return");
2153
+ case 11:
2154
+ _this.setState(setupState(_this.props));
2155
+ case 12:
2156
+ case "end":
2157
+ return _context.stop();
2158
+ }
2159
+ }, _callee, null, [[1, 3], [6, 9]]);
2160
+ })));
2161
+ _defineProperty(_this, "canSave", function () {
2162
+ var _user$roles, _user$districts, _user$userTypes, _user$userTypes2, _this$props$obligator, _user$userTypes3, _this$props$obligator2;
2163
+ var user = _this.state.user;
2164
+ if (!user) return false;
2165
+ if (!(user.lastName && user.otherNames && user.username && user.email && _this.props.isUserNameValid === true && _this.props.isUserEmailValid === true && !_this.props.isUserEmailFormatInvalid && (_user$roles = user.roles) !== null && _user$roles !== void 0 && _user$roles.length && ((_user$districts = user.districts) === null || _user$districts === void 0 ? void 0 : _user$districts.length) > 0 && user.language)) return false;
2166
+ if (!user.id && !user.password) return false;
2167
+ if (user.password && user.password !== user.confirmPassword) return false;
2168
+ if (user.password && !user.isPasswordValid) return false;
2169
+ if ((_user$userTypes = user.userTypes) !== null && _user$userTypes !== void 0 && _user$userTypes.includes(CLAIM_ADMIN_USER_TYPE) && !user.healthFacility) return false;
2170
+ if ((_user$userTypes2 = user.userTypes) !== null && _user$userTypes2 !== void 0 && _user$userTypes2.includes(ENROLMENT_OFFICER_USER_TYPE) && !user.officerVillages) return false;
2171
+ if ((((_this$props$obligator = _this.props.obligatory_user_fields) === null || _this$props$obligator === void 0 ? void 0 : _this$props$obligator.phone) === "M" || (_user$userTypes3 = user.userTypes) !== null && _user$userTypes3 !== void 0 && _user$userTypes3.includes(ENROLMENT_OFFICER_USER_TYPE) && ((_this$props$obligator2 = _this.props.obligatory_eo_fields) === null || _this$props$obligator2 === void 0 ? void 0 : _this$props$obligator2.phone) === "M") && !user.phoneNumber) return false;
2172
+ return true;
2173
+ });
2174
+ _defineProperty(_this, "save", function (user) {
2175
+ _this.setState({
2176
+ isLocked: !(user !== null && user !== void 0 && user.id),
2177
+ isSaved: true
2178
+ }, _this.props.save(user));
2179
+ });
2180
+ _defineProperty(_this, "onEditedChanged", function (user) {
2181
+ if (user.region) {
2182
+ user.region.forEach(function (region) {
2183
+ _this.props.fetchRegionDistricts(region);
2184
+ });
2185
+ }
2186
+ _this.setState({
2187
+ user: user
2188
+ });
2189
+ });
2190
+ _defineProperty(_this, "onActionToConfirm", function (title, message, confirmedAction) {
2191
+ _this.setState({
2192
+ confirmedAction: confirmedAction
2193
+ }, _this.props.coreConfirm(title, message));
2194
+ });
2195
+ _this.state = setupState(props);
2196
+ return _this;
2197
+ }
2198
+ _inherits(UserForm, _Component);
2199
+ return _createClass(UserForm, [{
2200
+ key: "componentDidMount",
2201
+ value: function componentDidMount() {
2202
+ if (this.props.userId) {
2203
+ this.props.fetchUser(this.props.modulesManager, this.props.userId);
2204
+ }
2205
+ if (!this.state.obligatory_user_fields) {
2206
+ this.props.fetchObligatoryUserFields();
2207
+ }
2208
+ if (!this.state.obligatory_eo_fields) {
2209
+ this.props.fetchObligatoryEnrolmentOfficerFields();
2210
+ }
2211
+ if (!this.state.usernameLength) {
2212
+ this.props.fetchUsernameLength();
2213
+ }
2214
+ if (!this.state.passwordPolicy) {
2215
+ this.props.fetchPasswordPolicy();
2216
+ }
2217
+ }
2218
+ }, {
2219
+ key: "componentWillUnmount",
2220
+ value: function componentWillUnmount() {
2221
+ this.props.clearUser();
2222
+ }
2223
+ }, {
2224
+ key: "componentDidUpdate",
2225
+ value: function componentDidUpdate(prevProps) {
2226
+ if (prevProps.region_districts !== this.props.region_districts) {
2227
+ if (this.props.region_districts) {
2228
+ var combined = [].concat(_toConsumableArray(this.state.user.districts ? this.state.user.districts : []), _toConsumableArray(this.props.region_districts));
2229
+ var noDuplicates = _toConsumableArray(new Map(combined.map(function (x) {
2230
+ return [x.uuid, x];
2231
+ })).values());
2232
+ this.setState(function (prevState) {
2233
+ return {
2234
+ user: _objectSpread$2(_objectSpread$2({}, prevState.user), {}, {
2235
+ districts: noDuplicates,
2236
+ region: []
2237
+ })
2238
+ };
2239
+ });
2240
+ }
2241
+ }
2242
+ if (!prevProps.fetchedUser && this.props.fetchedUser) {
2243
+ this.setState(setupState(this.props));
2244
+ } else if (prevProps.userId && !this.props.userId) {
2245
+ this.setState(setupState(this.props));
2246
+ } else if (prevProps.submittingMutation && !this.props.submittingMutation) {
2247
+ this.props.journalize(this.props.mutation);
2248
+ this.setState(function (state, props) {
2249
+ return {
2250
+ user: _objectSpread$2(_objectSpread$2({}, state.user), {}, {
2251
+ clientMutationId: props.mutation.clientMutationId
2252
+ })
2253
+ };
2254
+ });
2255
+ } else if (prevProps.confirmed !== this.props.confirmed && !!this.props.confirmed && !!this.state.confirmedAction) {
2256
+ this.state.confirmedAction();
2257
+ }
2258
+ }
2259
+ }, {
2260
+ key: "render",
2261
+ value: function render() {
2262
+ var _this$props2 = this.props,
2263
+ modulesManager = _this$props2.modulesManager,
2264
+ classes = _this$props2.classes,
2265
+ state = _this$props2.state,
2266
+ rights = _this$props2.rights,
2267
+ userId = _this$props2.userId,
2268
+ fetchingUser = _this$props2.fetchingUser,
2269
+ errorUser = _this$props2.errorUser,
2270
+ _this$props2$readOnly = _this$props2.readOnly,
2271
+ readOnly = _this$props2$readOnly === void 0 ? false : _this$props2$readOnly,
2272
+ add = _this$props2.add,
2273
+ save = _this$props2.save,
2274
+ back = _this$props2.back,
2275
+ obligatoryUserFields = _this$props2.obligatoryUserFields,
2276
+ obligatoryEoFields = _this$props2.obligatoryEoFields,
2277
+ usernameLength = _this$props2.usernameLength,
2278
+ passwordPolicy = _this$props2.passwordPolicy;
2279
+ var _this$state = this.state,
2280
+ user = _this$state.user,
2281
+ isSaved = _this$state.isSaved,
2282
+ reset = _this$state.reset;
2283
+ if (!rights.includes(RIGHT_USERS)) return null;
2284
+ var isInMutation = (user === null || user === void 0 ? void 0 : user.clientMutationId) || modulesManager.getContribs(USER_OVERVIEW_MUTATIONS_KEY).some(function (mutation) {
2285
+ return mutation(state);
2286
+ });
2287
+ var actions = [{
2288
+ doIt: this.reload,
2289
+ icon: /*#__PURE__*/React.createElement(ReplayIcon, null),
2290
+ onlyIfDirty: !readOnly && !isInMutation && !isSaved
2291
+ }];
2292
+ return /*#__PURE__*/React.createElement("div", {
2293
+ className: isInMutation || !!(user !== null && user !== void 0 && user.validityTo) ? classes.lockedPage : null
2294
+ }, /*#__PURE__*/React.createElement(Helmet, {
2295
+ title: formatMessageWithValues(this.props.intl, "admin.user", "UserOverview.title", {
2296
+ label: ""
2297
+ })
2298
+ }), /*#__PURE__*/React.createElement(ProgressOrError, {
2299
+ progress: fetchingUser,
2300
+ error: errorUser
2301
+ }), (!userId || (user === null || user === void 0 ? void 0 : user.id) === userId) && /*#__PURE__*/React.createElement(Form, {
2302
+ module: "user",
2303
+ title: userId ? "admin.user.UserOverview.title" : "admin.user.UserOverview.newTitle",
2304
+ edited_id: userId,
2305
+ edited: user,
2306
+ reset: reset,
2307
+ back: back,
2308
+ add: add,
2309
+ openDirty: save,
2310
+ readOnly: readOnly || isInMutation || (user === null || user === void 0 ? void 0 : user.validityTo),
2311
+ actions: actions,
2312
+ HeadPanel: UserMasterPanel$1,
2313
+ Panels: [].concat(_toConsumableArray(rights.includes(RIGHT_ENROLMENTOFFICER) ? [EnrolmentOfficerFormPanel$1] : []), _toConsumableArray(rights.includes(RIGHT_CLAIMADMINISTRATOR) ? [ClaimAdministratorFormPanel$1] : [])),
2314
+ user: user,
2315
+ onEditedChanged: this.onEditedChanged,
2316
+ canSave: !user.validityTo && this.canSave,
2317
+ save: save && !user.validityTo ? this.save : null,
2318
+ onActionToConfirm: this.onActionToConfirm,
2319
+ obligatory_user_fields: obligatoryUserFields,
2320
+ obligatory_eo_fields: obligatoryEoFields,
2321
+ usernameLength: usernameLength,
2322
+ passwordPolicy: passwordPolicy
2323
+ }));
2324
+ }
2325
+ }]);
2326
+ }(Component);
2327
+ var mapStateToProps = function mapStateToProps(state) {
2328
+ var _state$core$user$i_us, _state$core, _state$admin$validati, _state$admin$validati2, _state$admin, _state$admin2, _state$admin$validati3;
2329
+ return {
2330
+ rights: (_state$core$user$i_us = (_state$core = state.core) === null || _state$core === void 0 || (_state$core = _state$core.user) === null || _state$core === void 0 || (_state$core = _state$core.i_user) === null || _state$core === void 0 ? void 0 : _state$core.rights) !== null && _state$core$user$i_us !== void 0 ? _state$core$user$i_us : [],
2331
+ fetchingUser: state.admin.fetchingUser,
2332
+ errorUser: state.admin.errorUser,
2333
+ fetchedUser: state.admin.fetchedUser,
2334
+ submittingMutation: state.admin.submittingMutation,
2335
+ mutation: state.admin.mutation,
2336
+ user: state.admin.user,
2337
+ region_districts: state.admin.reg_dst,
2338
+ confirmed: state.core.confirmed,
2339
+ obligatoryUserFields: state.admin.obligatory_user_fields,
2340
+ obligatoryEoFields: state.admin.obligatory_eo_fields,
2341
+ isUserNameValid: (_state$admin$validati = state.admin.validationFields) === null || _state$admin$validati === void 0 || (_state$admin$validati = _state$admin$validati.username) === null || _state$admin$validati === void 0 ? void 0 : _state$admin$validati.isValid,
2342
+ isUserEmailValid: (_state$admin$validati2 = state.admin.validationFields) === null || _state$admin$validati2 === void 0 || (_state$admin$validati2 = _state$admin$validati2.userEmail) === null || _state$admin$validati2 === void 0 ? void 0 : _state$admin$validati2.isValid,
2343
+ usernameLength: (_state$admin = state.admin) === null || _state$admin === void 0 ? void 0 : _state$admin.usernameLength,
2344
+ passwordPolicy: (_state$admin2 = state.admin) === null || _state$admin2 === void 0 ? void 0 : _state$admin2.passwordPolicy,
2345
+ isUserEmailFormatInvalid: (_state$admin$validati3 = state.admin.validationFields) === null || _state$admin$validati3 === void 0 || (_state$admin$validati3 = _state$admin$validati3.userEmailFormat) === null || _state$admin$validati3 === void 0 ? void 0 : _state$admin$validati3.isInvalid
2346
+ };
2347
+ };
2348
+ var mapDispatchToProps = function mapDispatchToProps(dispatch) {
2349
+ return bindActionCreators({
2350
+ fetchUser: fetchUser,
2351
+ createUser: createUser,
2352
+ clearUser: clearUser,
2353
+ fetchUserMutation: fetchUserMutation,
2354
+ fetchRegionDistricts: fetchRegionDistricts,
2355
+ fetchObligatoryUserFields: fetchObligatoryUserFields,
2356
+ fetchObligatoryEnrolmentOfficerFields: fetchObligatoryEnrolmentOfficerFields,
2357
+ fetchUsernameLength: fetchUsernameLength,
2358
+ fetchPasswordPolicy: fetchPasswordPolicy,
2359
+ journalize: journalize,
2360
+ coreConfirm: coreConfirm
2361
+ }, dispatch);
2362
+ };
2363
+ var UserForm$1 = withHistory(withModulesManager(connect(mapStateToProps, mapDispatchToProps)(injectIntl(withTheme(withStyles(styles$2)(UserForm))))));
2364
+
2365
+ var styles$1 = function styles(theme) {
2366
+ return {
2367
+ page: theme.page
2368
+ };
2369
+ };
2370
+ var UserPage = function UserPage(props) {
2371
+ var modulesManager = props.modulesManager,
2372
+ history = props.history,
2373
+ match = props.match,
2374
+ classes = props.classes;
2375
+ var rights = useSelector(function (state) {
2376
+ var _state$core$user$i_us, _state$core;
2377
+ return (_state$core$user$i_us = (_state$core = state.core) === null || _state$core === void 0 || (_state$core = _state$core.user) === null || _state$core === void 0 || (_state$core = _state$core.i_user) === null || _state$core === void 0 ? void 0 : _state$core.rights) !== null && _state$core$user$i_us !== void 0 ? _state$core$user$i_us : [];
2378
+ });
2379
+ var _useState = useState(Date.now()),
2380
+ _useState2 = _slicedToArray(_useState, 2),
2381
+ resetKey = _useState2[0],
2382
+ setResetKey = _useState2[1];
2383
+ var _useTranslations = useTranslations("admin", modulesManager),
2384
+ formatMessageWithValues = _useTranslations.formatMessageWithValues;
2385
+ var dispatch = useDispatch();
2386
+ var add = function add() {
2387
+ setResetKey(Date.now());
2388
+ historyPush(modulesManager, history, "admin.userNew");
2389
+ };
2390
+ var save = function save(user) {
2391
+ if (!user.id) {
2392
+ dispatch(createUser(modulesManager, user, formatMessageWithValues("user.createUser.mutationLabel")));
2393
+ } else {
2394
+ dispatch(updateUser(modulesManager, user, formatMessageWithValues("user.updateUser.mutationLabel")));
2395
+ }
2396
+ };
2397
+ return /*#__PURE__*/React.createElement("div", {
2398
+ className: classes.page
2399
+ }, /*#__PURE__*/React.createElement(UserForm$1, {
2400
+ key: resetKey,
2401
+ readOnly: match.params.user_id ? !rights.includes(RIGHT_USER_EDIT) : !rights.includes(RIGHT_USER_ADD),
2402
+ userId: match.params.user_id,
2403
+ back: function back() {
2404
+ return historyPush(modulesManager, history, "admin.users");
2405
+ },
2406
+ add: rights.includes(RIGHT_USER_ADD) ? add : null,
2407
+ save: rights.includes(RIGHT_USER_EDIT) ? save : null
2408
+ }));
2409
+ };
2410
+ var enhance = combine(withHistory, withModulesManager, withTheme, withStyles(styles$1));
2411
+ var UserPage$1 = enhance(UserPage);
2412
+
2413
+ var messagesEn = {
2414
+ "admin.UserPicker.label": "User",
2415
+ "admin.UserPicker.null": "Any",
2416
+ "admin.mainMenu": "Administration",
2417
+ "admin.menu.claimAdministrators": "Claim Administrators",
2418
+ "admin.menu.enrollmentOfficers": "Enrollment Officers",
2419
+ "admin.menu.healthFacilities": "Health Facilities",
2420
+ "admin.menu.locations": "Locations",
2421
+ "admin.menu.medicalItems": "Medical Items",
2422
+ "admin.menu.medicalItemsPrices": "Medical Items Price Lists",
2423
+ "admin.menu.medicalServices": "Medical Services",
2424
+ "admin.menu.medicalServicesPrices": "Medical Services Price Lists",
2425
+ "admin.menu.payers": "Payers",
2426
+ "admin.menu.products": "Products",
2427
+ "admin.menu.users": "Users",
2428
+ "admin.menu.usersProfiles": "Users Profiles",
2429
+ "admin.showHistory": "Show historical values",
2430
+ "admin.user.CreateUser.mutationLabel": "Create user",
2431
+ "admin.user.UserOverview.newTitle": "New User",
2432
+ "admin.user.UserOverview.title": "User Details",
2433
+ "admin.user.address": "Address",
2434
+ "admin.user.addNewUser.tooltip": "Add new user",
2435
+ "admin.user.addNewUserTooltip": "Add new user",
2436
+ "admin.user.usernameAlreadyTaken": "Username already in use",
2437
+ "admin.user.emailAlreadyTaken": "User email already in use",
2438
+ "admin.user.emailFormatInvalid": "Invalid email format",
2439
+ "admin.user.createUser.mutationLabel": "Create user",
2440
+ "admin.user.deleteDialog.message": "Are you sure you want to delete this user?",
2441
+ "admin.user.deleteDialog.title": "Delete user",
2442
+ "admin.user.deleteDialog.yes.button": "Yes",
2443
+ "admin.user.deleteUser.tooltip": "Delete user",
2444
+ "admin.user.deleteUserDialog.message": "Are you sure you want to delete this user?",
2445
+ "admin.user.dob": "Birth date",
2446
+ "admin.user.dobFrom": "Birth date from",
2447
+ "admin.user.dobTo": "Birth date to",
2448
+ "admin.user.email": "Email",
2449
+ "admin.user.districts": "Districts",
2450
+ "admin.user.regions": "Regions",
2451
+ "admin.user.lastName": "Last name",
2452
+ "admin.user.language": "Interface Language",
2453
+ "admin.user.openNewTab": "Open in new tab",
2454
+ "admin.user.otherNames": "Other names",
2455
+ "admin.user.givenNames": "Given names",
2456
+ "admin.user.password": "Password",
2457
+ "admin.user.newPassword": "New Password",
2458
+ "admin.user.confirmNewPassword": "Confirm Password",
2459
+ "admin.user.generatePassword": "Generate Password",
2460
+ "admin.user.phone": "Phone",
2461
+ "admin.user.updateUser.mutationLabel": "Update user",
2462
+ "admin.user.userRoles.placeholder": "Select User Role(s)",
2463
+ "admin.user.userRoles": "User role(s)",
2464
+ "admin.user.userSummaries": "{count} user(s) found",
2465
+ "admin.user.userTypes": "User type(s)",
2466
+ "admin.user.userTypes.CLAIM_ADMIN": "Claim admin",
2467
+ "admin.user.userTypes.INTERACTIVE": "Interactive",
2468
+ "admin.user.userTypes.OFFICER": "Enrolment Officer",
2469
+ "admin.user.userTypes.noOptions": "No user type found",
2470
+ "admin.user.userTypes.none": " ",
2471
+ "admin.user.userTypes.null": "Any",
2472
+ "admin.user.username": "User name",
2473
+ "admin.PaymentPointManagerPicker.placeholder": "Search for an PPM...",
2474
+ "admin.PaymentPointManagerPicker.label": "Payment Point Manager",
2475
+ "admin.user.worksTo": "Works to",
2476
+ "admin.EnrolmentOfficerFormPanel.title": "Enrolment Officer",
2477
+ "admin.ClaimAdministratorFormPanel.title": "Claim Administrator",
2478
+ "admin.InteractiveUserFormPanel.title": "Interactive User",
2479
+ "admin.EnrolmentZonesPicker.table.municipality": "Municipality",
2480
+ "admin.EnrolmentZonesPicker.table.newRow": "Add a municipality",
2481
+ "admin.EnrolmentZonesPicker.table.villages": "Villages",
2482
+ "admin.EnrolmentZonesPicker.table.addButton": "Add a municipality",
2483
+ "admin.EnrolmentOfficerFormPanel.substitutionOfficer": "Substitution Officer",
2484
+ "admin.EnrolmentOfficerFormPanel.substitutionOfficer.placeholder": "Search for an Officer...",
2485
+ "admin.UserPicker.loadingText": "Loading...",
2486
+ "admin.UserPicker.clearText": "Clear",
2487
+ "admin.UserPicker.openText": "Open",
2488
+ "admin.UserPicker.closeText": "Close",
2489
+ "admin.UserMasterPanel.loginDetailsTitle": "Login Details",
2490
+ "admin.UserMasterPanel.language.null": "Select a language",
2491
+ "admin.EnrolmentOfficerPicker.label": "Select an Officer",
2492
+ "admin.EnrolmentOfficerPicker.loadingText": "Loading...",
2493
+ "admin.EnrolmentOfficerPicker.clearText": "Clear",
2494
+ "admin.EnrolmentOfficerPicker.openText": "Open",
2495
+ "admin.EnrolmentOfficerPicker.closeText": "Close",
2496
+ "admin.UserFilter.showHistory": "Show History",
2497
+ "admin.UserFilter.showDeleted": "Show Deleted",
2498
+ "admin.password.minLength": "at least {count} characters",
2499
+ "admin.password.lowerCase": "{count, plural, one {# lowercase letter} other {# lowercase letters}}",
2500
+ "admin.password.upperCase": "{count, plural, one {# uppercase letter} other {# uppercase letters}}",
2501
+ "admin.password.numbers": "{count, plural, one {# number} other {# numbers}}",
2502
+ "admin.password.specialCharacters": "{count, plural, one {# special character} other {# special characters}}",
2503
+ "admin.password.requirements": "Password must include: {requirements}.",
2504
+ "admin.password.weak": "Weak",
2505
+ "admin.password.medium": "Medium",
2506
+ "admin.password.strong": "Password is strong.",
2507
+ "admin.password.veryStrong": "Password is very strong.",
2508
+ "admin.password.unknownScore": "Unknown score."
2509
+ };
2510
+
2511
+ var styles = function styles(theme) {
2512
+ return {
2513
+ label: {
2514
+ color: theme.palette.primary.main
2515
+ }
2516
+ };
2517
+ };
2518
+ var UserPicker = function UserPicker(props) {
2519
+ var onChange = props.onChange,
2520
+ modulesManager = props.modulesManager,
2521
+ _props$readOnly = props.readOnly,
2522
+ readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
2523
+ _props$required = props.required,
2524
+ required = _props$required === void 0 ? false : _props$required,
2525
+ _props$withLabel = props.withLabel,
2526
+ withLabel = _props$withLabel === void 0 ? true : _props$withLabel,
2527
+ healthFacility = props.healthFacility,
2528
+ _props$filters = props.filters,
2529
+ filters = _props$filters === void 0 ? [] : _props$filters,
2530
+ value = props.value,
2531
+ label = props.label,
2532
+ filterOptions = props.filterOptions,
2533
+ filterSelectedOptions = props.filterSelectedOptions,
2534
+ placeholder = props.placeholder,
2535
+ _props$multiple = props.multiple,
2536
+ multiple = _props$multiple === void 0 ? false : _props$multiple;
2537
+ var minCharLookup = modulesManager.getConf("fe-admin", "usersMinCharLookup", 2);
2538
+ var dispatch = useDispatch();
2539
+ var _useState = useState(null),
2540
+ _useState2 = _slicedToArray(_useState, 2),
2541
+ searchString = _useState2[0],
2542
+ setSearchString = _useState2[1];
2543
+ var _useTranslations = useTranslations("admin.UserPicker", modulesManager),
2544
+ formatMessage = _useTranslations.formatMessage;
2545
+ var _useState3 = useState(false),
2546
+ _useState4 = _slicedToArray(_useState3, 2),
2547
+ open = _useState4[0],
2548
+ setOpen = _useState4[1];
2549
+ var users = useSelector(function (state) {
2550
+ return state.admin.users.items;
2551
+ });
2552
+ var isLoading = useSelector(function (state) {
2553
+ return state.admin.users.isLoading;
2554
+ });
2555
+ var _onInputChange = useDebounceCb(setSearchString, modulesManager.getConf("fe-admin", "debounceTime", 400));
2556
+ // eslint-disable-next-line no-shadow
2557
+ var handleChange = function handleChange(__, value) {
2558
+ onChange(value);
2559
+ if (!multiple) setOpen(false);
2560
+ };
2561
+ var formatSuggestion = function formatSuggestion(p) {
2562
+ var _p$iUser, _p$iUser2, _p$iUser3, _p$iUser4;
2563
+ var renderLastNameFirst = modulesManager.getConf("fe-insuree", "renderLastNameFirst", DEFAULT.RENDER_LAST_NAME_FIRST);
2564
+ if (!p) return "?";
2565
+ return [p.username, renderLastNameFirst ? (_p$iUser = p.iUser) === null || _p$iUser === void 0 ? void 0 : _p$iUser.lastName : (_p$iUser2 = p.iUser) === null || _p$iUser2 === void 0 ? void 0 : _p$iUser2.otherNames, !renderLastNameFirst ? (_p$iUser3 = p.iUser) === null || _p$iUser3 === void 0 ? void 0 : _p$iUser3.lastName : (_p$iUser4 = p.iUser) === null || _p$iUser4 === void 0 ? void 0 : _p$iUser4.otherNames].filter(Boolean).join(" ");
2566
+ };
2567
+ useEffect(function () {
2568
+ if ((searchString === null || searchString === void 0 ? void 0 : searchString.length) > minCharLookup) {
2569
+ dispatch(fetchUsers(modulesManager, [searchString && "str: \"".concat(searchString, "\"")].concat(_toConsumableArray(filters !== null && filters !== void 0 ? filters : [])).filter(Boolean), !healthFacility));
2570
+ }
2571
+ }, [searchString]);
2572
+ useEffect(function () {
2573
+ if (open) {
2574
+ dispatch(fetchUsers(modulesManager, ["first: 10"].concat(_toConsumableArray(filters !== null && filters !== void 0 ? filters : [])), !healthFacility));
2575
+ }
2576
+ }, [open]);
2577
+ return /*#__PURE__*/React.createElement(Autocomplete, {
2578
+ loadingText: formatMessage("loadingText"),
2579
+ openText: formatMessage("openText"),
2580
+ closeText: formatMessage("closeText"),
2581
+ clearText: formatMessage("clearText"),
2582
+ openOnFocus: true,
2583
+ multiple: multiple,
2584
+ disabled: readOnly,
2585
+ options: users,
2586
+ loading: isLoading,
2587
+ open: open,
2588
+ onOpen: function onOpen() {
2589
+ return setOpen(true);
2590
+ },
2591
+ onClose: function onClose() {
2592
+ return setOpen(false);
2593
+ },
2594
+ autoComplete: true,
2595
+ value: value,
2596
+ getOptionLabel: function getOptionLabel(option) {
2597
+ return formatSuggestion(option);
2598
+ },
2599
+ getOptionSelected: function getOptionSelected(option, v) {
2600
+ return option.id === v.id;
2601
+ },
2602
+ onChange: handleChange,
2603
+ filterOptions: filterOptions,
2604
+ filterSelectedOptions: filterSelectedOptions,
2605
+ onInputChange: function onInputChange(__, query) {
2606
+ return _onInputChange(query);
2607
+ },
2608
+ renderInput: function renderInput(inputProps) {
2609
+ return /*#__PURE__*/React.createElement(TextField, _extends({}, inputProps, {
2610
+ variant: "standard",
2611
+ required: required,
2612
+ label: withLabel && (label || formatMessage("label")),
2613
+ placeholder: placeholder
2614
+ }));
2615
+ }
2616
+ });
2617
+ };
2618
+ var UserPicker$1 = withModulesManager(withTheme(withStyles(styles)(UserPicker)));
2619
+
2620
+ var EnrolmentOfficerPicker = function EnrolmentOfficerPicker(props) {
2621
+ var onChange = props.onChange,
2622
+ modulesManager = props.modulesManager,
2623
+ _props$readOnly = props.readOnly,
2624
+ readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
2625
+ _props$required = props.required,
2626
+ required = _props$required === void 0 ? false : _props$required,
2627
+ _props$withLabel = props.withLabel,
2628
+ withLabel = _props$withLabel === void 0 ? true : _props$withLabel,
2629
+ value = props.value,
2630
+ label = props.label,
2631
+ filterOptions = props.filterOptions,
2632
+ filterSelectedOptions = props.filterSelectedOptions,
2633
+ placeholder = props.placeholder,
2634
+ _props$multiple = props.multiple,
2635
+ multiple = _props$multiple === void 0 ? false : _props$multiple;
2636
+ var dispatch = useDispatch();
2637
+ var _useState = useState(null),
2638
+ _useState2 = _slicedToArray(_useState, 2),
2639
+ searchString = _useState2[0],
2640
+ setSearchString = _useState2[1];
2641
+ var isLoading = useSelector(function (state) {
2642
+ return state.admin.enrolmentOfficers.isFetching;
2643
+ });
2644
+ var options = useSelector(function (state) {
2645
+ return state.admin.enrolmentOfficers.items;
2646
+ });
2647
+ useEffect(function () {
2648
+ dispatch(fetchEnrolmentOfficers(modulesManager, {
2649
+ first: searchString ? undefined : 10,
2650
+ searchString: searchString
2651
+ }));
2652
+ }, [searchString]);
2653
+ var formatSuggestion = function formatSuggestion(p) {
2654
+ var renderLastNameFirst = modulesManager.getConf("fe-insuree", "renderLastNameFirst", DEFAULT.RENDER_LAST_NAME_FIRST);
2655
+ if (!p) return "?";
2656
+ return [p.username, renderLastNameFirst ? p.lastName : p.otherNames, !renderLastNameFirst ? p.lastName : p.otherNames].filter(Boolean).join(" ");
2657
+ };
2658
+ return /*#__PURE__*/React.createElement(Autocomplete$1, {
2659
+ multiple: multiple,
2660
+ required: required,
2661
+ placeholder: placeholder,
2662
+ label: label,
2663
+ withLabel: withLabel,
2664
+ readOnly: readOnly,
2665
+ options: options,
2666
+ isLoading: isLoading,
2667
+ value: value,
2668
+ getOptionLabel: formatSuggestion,
2669
+ onChange: onChange,
2670
+ filterOptions: filterOptions,
2671
+ filterSelectedOptions: filterSelectedOptions,
2672
+ onInputChange: setSearchString
2673
+ });
2674
+ };
2675
+ var EnrolmentOfficerPicker$1 = withModulesManager(EnrolmentOfficerPicker);
2676
+
2677
+ var SubstitutionEnrolmentOfficerPicker = function SubstitutionEnrolmentOfficerPicker(props) {
2678
+ var _useSelector2;
2679
+ var onChange = props.onChange,
2680
+ modulesManager = props.modulesManager,
2681
+ _props$readOnly = props.readOnly,
2682
+ readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
2683
+ _props$required = props.required,
2684
+ required = _props$required === void 0 ? false : _props$required,
2685
+ value = props.value,
2686
+ villages = props.villages,
2687
+ filterOptions = props.filterOptions,
2688
+ filterSelectedOptions = props.filterSelectedOptions,
2689
+ _props$multiple = props.multiple,
2690
+ multiple = _props$multiple === void 0 ? false : _props$multiple,
2691
+ _props$withLabel = props.withLabel,
2692
+ withLabel = _props$withLabel === void 0 ? true : _props$withLabel,
2693
+ label = props.label,
2694
+ _props$withPlaceholde = props.withPlaceholder,
2695
+ withPlaceholder = _props$withPlaceholde === void 0 ? false : _props$withPlaceholde,
2696
+ placeholder = props.placeholder;
2697
+ var dispatch = useDispatch();
2698
+ var _useTranslations = useTranslations("admin", modulesManager),
2699
+ formatMessage = _useTranslations.formatMessage;
2700
+ var _useState = useState(""),
2701
+ _useState2 = _slicedToArray(_useState, 2),
2702
+ searchString = _useState2[0],
2703
+ setSearchString = _useState2[1];
2704
+ var _useSelector = useSelector(function (state) {
2705
+ return state.admin.substitutionEnrolmentOfficers;
2706
+ }),
2707
+ isFetching = _useSelector.isFetching,
2708
+ items = _useSelector.items;
2709
+ var officerUuid = (_useSelector2 = useSelector(function (state) {
2710
+ var _state$admin;
2711
+ return (_state$admin = state.admin) === null || _state$admin === void 0 || (_state$admin = _state$admin.user) === null || _state$admin === void 0 || (_state$admin = _state$admin.officer) === null || _state$admin === void 0 ? void 0 : _state$admin.uuid;
2712
+ })) !== null && _useSelector2 !== void 0 ? _useSelector2 : null;
2713
+ var handleInputChange = function handleInputChange(str) {
2714
+ setSearchString(str);
2715
+ fetchSubstitutionEOs(dispatch, modulesManager, officerUuid, searchString, villages);
2716
+ };
2717
+ var formatSuggestion = function formatSuggestion(p) {
2718
+ var renderLastNameFirst = modulesManager.getConf("fe-insuree", "renderLastNameFirst", DEFAULT.RENDER_LAST_NAME_FIRST);
2719
+ if (!p) return "?";
2720
+ return [p.username, renderLastNameFirst ? p.lastName : p.otherNames, !renderLastNameFirst ? p.lastName : p.otherNames].filter(Boolean).join(" ");
2721
+ };
2722
+ return /*#__PURE__*/React.createElement(Autocomplete$1, {
2723
+ multiple: multiple,
2724
+ required: required,
2725
+ placeholder: placeholder,
2726
+ label: label,
2727
+ withLabel: withLabel,
2728
+ readOnly: readOnly,
2729
+ options: items,
2730
+ isLoading: isFetching,
2731
+ value: value,
2732
+ getOptionLabel: formatSuggestion,
2733
+ onChange: onChange,
2734
+ filterOptions: filterOptions,
2735
+ filterSelectedOptions: filterSelectedOptions,
2736
+ onInputChange: handleInputChange,
2737
+ renderInput: function renderInput(inputProps) {
2738
+ return /*#__PURE__*/React.createElement(TextField, _extends({}, inputProps, {
2739
+ label: withLabel && (label || formatMessage("EnrolmentOfficerFormPanel.substitutionOfficer")),
2740
+ placeholder: withPlaceholder && (placeholder || formatMessage("EnrolmentOfficerFormPanel.substitutionOfficer.placeholder"))
2741
+ }));
2742
+ }
2743
+ });
2744
+ };
2745
+ var SubstitutionEnrolmentOfficerPicker$1 = withModulesManager(SubstitutionEnrolmentOfficerPicker);
2746
+
2747
+ var UserRolesPicker = function UserRolesPicker(_ref) {
2748
+ var _data$role$edges$map, _data$role;
2749
+ var readOnly = _ref.readOnly,
2750
+ value = _ref.value,
2751
+ _onChange = _ref.onChange,
2752
+ required = _ref.required,
2753
+ _ref$multiple = _ref.multiple,
2754
+ multiple = _ref$multiple === void 0 ? true : _ref$multiple,
2755
+ placeholder = _ref.placeholder,
2756
+ withLabel = _ref.withLabel,
2757
+ withPlaceholder = _ref.withPlaceholder,
2758
+ label = _ref.label,
2759
+ filterOptions = _ref.filterOptions,
2760
+ filterSelectedOptions = _ref.filterSelectedOptions;
2761
+ var _useState = useState(),
2762
+ _useState2 = _slicedToArray(_useState, 2),
2763
+ searchString = _useState2[0],
2764
+ setSearchString = _useState2[1];
2765
+ var _useTranslations = useTranslations("admin"),
2766
+ formatMessage = _useTranslations.formatMessage;
2767
+ var _useGraphqlQuery = useGraphqlQuery("\n query UserRolesPicker ($str: String) {\n role(str: $str) {\n edges {\n node {\n id name isSystem\n }\n }\n }\n }\n ", {
2768
+ str: searchString
2769
+ }),
2770
+ isLoading = _useGraphqlQuery.isLoading,
2771
+ data = _useGraphqlQuery.data,
2772
+ error = _useGraphqlQuery.error;
2773
+ var roles = (_data$role$edges$map = data === null || data === void 0 || (_data$role = data.role) === null || _data$role === void 0 ? void 0 : _data$role.edges.map(function (edge) {
2774
+ return edge.node;
2775
+ })) !== null && _data$role$edges$map !== void 0 ? _data$role$edges$map : [];
2776
+ var uniqueValues = _toConsumableArray(new Map(value === null || value === void 0 ? void 0 : value.map(function (role) {
2777
+ return [role.id, role];
2778
+ })).values());
2779
+ return /*#__PURE__*/React.createElement(Autocomplete$1, {
2780
+ multiple: multiple,
2781
+ required: required,
2782
+ placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : formatMessage("user.userRoles.placeholder"),
2783
+ label: label !== null && label !== void 0 ? label : formatMessage("user.userRoles"),
2784
+ error: error,
2785
+ withLabel: withLabel,
2786
+ withPlaceholder: withPlaceholder,
2787
+ readOnly: readOnly,
2788
+ options: roles,
2789
+ isLoading: isLoading,
2790
+ value: uniqueValues,
2791
+ getOptionLabel: function getOptionLabel(o) {
2792
+ return o === null || o === void 0 ? void 0 : o.name;
2793
+ },
2794
+ onChange: function onChange(option) {
2795
+ return _onChange(option, option === null || option === void 0 ? void 0 : option.name);
2796
+ },
2797
+ filterOptions: filterOptions,
2798
+ filterSelectedOptions: filterSelectedOptions,
2799
+ onInputChange: function onInputChange() {
2800
+ return setSearchString(searchString);
2801
+ }
2802
+ });
2803
+ };
2804
+
2805
+ var UserTypesPicker = function UserTypesPicker(props) {
2806
+ var intl = useIntl();
2807
+ var rights = useSelector(function (state) {
2808
+ return !!state.core && !!state.core.user && !!state.core.user.i_user ? state.core.user.i_user.rights : [];
2809
+ });
2810
+ var options = USER_TYPES(rights).map(function (ut) {
2811
+ return {
2812
+ id: ut,
2813
+ label: formatMessage(intl, "admin.user", "userTypes.".concat(ut))
2814
+ };
2815
+ });
2816
+ var value = [];
2817
+ if (props.value) {
2818
+ props.value.forEach(function (v) {
2819
+ var fullValue = options.find(function (o) {
2820
+ return o.id === v;
2821
+ });
2822
+ if (fullValue) {
2823
+ value.push(fullValue);
2824
+ }
2825
+ });
2826
+ }
2827
+ return /*#__PURE__*/React.createElement(Autocomplete$2, {
2828
+ multiple: true,
2829
+ noOptionsText: formatMessage(intl, "admin.user", "userTypes.noOptions"),
2830
+ disabled: props.readOnly,
2831
+ id: "user-types-select",
2832
+ options: options,
2833
+ getOptionLabel: function getOptionLabel(option) {
2834
+ return option.label;
2835
+ },
2836
+ onChange: function onChange(e, userTypes) {
2837
+ return props.onChange(userTypes.map(function (ut) {
2838
+ return ut.id;
2839
+ }));
2840
+ },
2841
+ renderInput: function renderInput(params) {
2842
+ return /*#__PURE__*/React.createElement(TextField$1, _extends({}, params, {
2843
+ variant: "standard",
2844
+ label: "".concat(formatMessage(intl, "admin.user", "userTypes")).concat(props.required ? "*" : ""),
2845
+ placeholder: ""
2846
+ }));
2847
+ },
2848
+ value: value
2849
+ });
2850
+ };
2851
+
2852
+ function PaymentPointManagerPicker(_ref) {
2853
+ var _data$users$edges$map, _data$users;
2854
+ var readOnly = _ref.readOnly,
2855
+ value = _ref.value,
2856
+ _onChange = _ref.onChange,
2857
+ required = _ref.required,
2858
+ withLabel = _ref.withLabel,
2859
+ withPlaceholder = _ref.withPlaceholder,
2860
+ filterOptions = _ref.filterOptions,
2861
+ filterSelectedOptions = _ref.filterSelectedOptions;
2862
+ var _useState = useState(),
2863
+ _useState2 = _slicedToArray(_useState, 2),
2864
+ searchString = _useState2[0],
2865
+ setSearchString = _useState2[1];
2866
+ var _useTranslations = useTranslations("admin"),
2867
+ formatMessage = _useTranslations.formatMessage;
2868
+
2869
+ // Note: IMIS Administrator covers all Payment Point Manager permissions
2870
+ var paymentPointManagerRoleId = 7;
2871
+ var formatSuggestion = function formatSuggestion(ppm) {
2872
+ var _ppm$iUser, _ppm$iUser2;
2873
+ return [ppm === null || ppm === void 0 ? void 0 : ppm.username, ppm === null || ppm === void 0 || (_ppm$iUser = ppm.iUser) === null || _ppm$iUser === void 0 ? void 0 : _ppm$iUser.lastName, ppm === null || ppm === void 0 || (_ppm$iUser2 = ppm.iUser) === null || _ppm$iUser2 === void 0 ? void 0 : _ppm$iUser2.otherNames].filter(Boolean).join(" ");
2874
+ };
2875
+ var _useGraphqlQuery = useGraphqlQuery("\n query paymentPointManager($searchString: String, $roleId: Int) {\n users(str: $searchString, roleId: $roleId) {\n edges {\n node {\n ".concat(USER_PICKER_PROJECTION.join(" "), "\n }\n }\n }\n }\n "), {
2876
+ str: searchString,
2877
+ roleId: paymentPointManagerRoleId
2878
+ }),
2879
+ isLoading = _useGraphqlQuery.isLoading,
2880
+ data = _useGraphqlQuery.data,
2881
+ error = _useGraphqlQuery.error;
2882
+ var paymentPointManagers = (_data$users$edges$map = data === null || data === void 0 || (_data$users = data.users) === null || _data$users === void 0 ? void 0 : _data$users.edges.map(function (edge) {
2883
+ return edge.node;
2884
+ })) !== null && _data$users$edges$map !== void 0 ? _data$users$edges$map : [];
2885
+ return /*#__PURE__*/React.createElement(Autocomplete$1, {
2886
+ withLabel: withLabel,
2887
+ withPlaceholder: withPlaceholder,
2888
+ readOnly: readOnly,
2889
+ value: value,
2890
+ placeholder: formatMessage("PaymentPointManagerPicker.placeholder"),
2891
+ label: formatMessage("PaymentPointManagerPicker.label"),
2892
+ isLoading: isLoading,
2893
+ options: paymentPointManagers,
2894
+ error: error,
2895
+ getOptionLabel: function getOptionLabel(option) {
2896
+ return formatSuggestion(option);
2897
+ },
2898
+ onChange: function onChange(user) {
2899
+ return _onChange(user);
2900
+ },
2901
+ filterOptions: filterOptions,
2902
+ filterSelectedOptions: filterSelectedOptions,
2903
+ onInputChange: function onInputChange() {
2904
+ return setSearchString(searchString);
2905
+ },
2906
+ renderInput: function renderInput(inputProps) {
2907
+ return /*#__PURE__*/React.createElement(TextField, _extends({}, inputProps, {
2908
+ variant: "standard",
2909
+ required: required,
2910
+ label: withLabel && formatMessage("PaymentPointManagerPicker.label"),
2911
+ placeholder: withPlaceholder && formatMessage("PaymentPointManagerPicker.placeholder")
2912
+ }));
2913
+ }
2914
+ });
2915
+ }
2916
+
2917
+ function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2918
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2919
+ function reducer() {
2920
+ var _action$payload, _action$payload2, _action$payload3;
2921
+ var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
2922
+ enrolmentOfficers: {
2923
+ items: [],
2924
+ isFetching: false,
2925
+ pageInfo: {
2926
+ totalCount: 0
2927
+ },
2928
+ error: null
2929
+ },
2930
+ substitutionEnrolmentOfficers: {
2931
+ items: [],
2932
+ isFetching: false,
2933
+ pageInfo: {
2934
+ totalCount: 0
2935
+ },
2936
+ error: null
2937
+ },
2938
+ usersSummaries: {
2939
+ items: [],
2940
+ isFetching: false,
2941
+ isFetched: false,
2942
+ fetched: null,
2943
+ pageInfo: {
2944
+ totalCount: 0
2945
+ },
2946
+ error: null
2947
+ },
2948
+ users: {
2949
+ items: [],
2950
+ isFetching: false,
2951
+ isFetched: false,
2952
+ error: null
2953
+ },
2954
+ fetchingUser: false,
2955
+ fetchedUser: false,
2956
+ errorUser: null,
2957
+ user: null,
2958
+ submittingMutation: false,
2959
+ mutation: {},
2960
+ reg_dst: [],
2961
+ dst_mun_vil: [],
2962
+ obligatory_user_fields: {},
2963
+ obligatory_eo_fields: {}
2964
+ };
2965
+ var action = arguments.length > 1 ? arguments[1] : undefined;
2966
+ switch (action.type) {
2967
+ case "ADMIN_ENROLMENT_OFFICERS_REQ":
2968
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
2969
+ enrolmentOfficers: _objectSpread$1(_objectSpread$1({}, state.enrolmentOfficers), {}, {
2970
+ isFetching: true
2971
+ })
2972
+ });
2973
+ case "ADMIN_ENROLMENT_OFFICERS_RESP":
2974
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
2975
+ enrolmentOfficers: _objectSpread$1(_objectSpread$1({}, state.enrolmentOfficers), {}, {
2976
+ isFetching: false,
2977
+ pageInfo: pageInfo(action.payload.data.enrolmentOfficers),
2978
+ items: parseData(action.payload.data.enrolmentOfficers)
2979
+ })
2980
+ });
2981
+ case "ADMIN_ENROLMENT_OFFICERS_ERR":
2982
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
2983
+ enrolmentOfficers: _objectSpread$1(_objectSpread$1({}, state.enrolmentOfficers), {}, {
2984
+ isFetching: false,
2985
+ error: formatGraphQLError(action.payload)
2986
+ })
2987
+ });
2988
+ case "ADMIN_SUBSTITUTION_ENROLMENT_OFFICERS_REQ":
2989
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
2990
+ substitutionEnrolmentOfficers: _objectSpread$1(_objectSpread$1({}, state.substitutionEnrolmentOfficers), {}, {
2991
+ isFetching: true
2992
+ })
2993
+ });
2994
+ case "ADMIN_SUBSTITUTION_ENROLMENT_OFFICERS_RESP":
2995
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
2996
+ substitutionEnrolmentOfficers: _objectSpread$1(_objectSpread$1({}, state.substitutionEnrolmentOfficers), {}, {
2997
+ isFetching: false,
2998
+ pageInfo: pageInfo(action.payload.data.substitutionEnrolmentOfficers),
2999
+ items: parseData(action.payload.data.substitutionEnrolmentOfficers)
3000
+ })
3001
+ });
3002
+ case "ADMIN_SUBSTITUTION_ENROLMENT_OFFICERS_ERR":
3003
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3004
+ substitutionEnrolmentOfficers: _objectSpread$1(_objectSpread$1({}, state.substitutionEnrolmentOfficers), {}, {
3005
+ isFetching: false,
3006
+ error: formatGraphQLError(action.payload)
3007
+ })
3008
+ });
3009
+ case "ADMIN_USERS_REQ":
3010
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3011
+ users: _objectSpread$1(_objectSpread$1({}, state.users), {}, {
3012
+ isFetching: true,
3013
+ fetched: null,
3014
+ error: null
3015
+ })
3016
+ });
3017
+ case "ADMIN_USERS_RESP":
3018
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3019
+ users: _objectSpread$1(_objectSpread$1({}, state.users), {}, {
3020
+ isFetching: false,
3021
+ fetched: action.meta,
3022
+ items: parseData(action.payload.data.users).map(function (user) {
3023
+ return _objectSpread$1(_objectSpread$1({}, user), {}, {
3024
+ userTypes: checkRolesAndGetUserTypes(user)
3025
+ });
3026
+ }),
3027
+ error: formatGraphQLError(action.payload)
3028
+ })
3029
+ });
3030
+ case "ADMIN_USERS_ERR":
3031
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3032
+ users: _objectSpread$1(_objectSpread$1({}, state.users), {}, {
3033
+ error: formatServerError(action.payload),
3034
+ isFetching: false,
3035
+ items: []
3036
+ })
3037
+ });
3038
+ case "ADMIN_USERS_SUMMARIES_REQ":
3039
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3040
+ usersSummaries: _objectSpread$1(_objectSpread$1({}, state.usersSummaries), {}, {
3041
+ isFetching: true,
3042
+ isFetched: false,
3043
+ error: null
3044
+ })
3045
+ });
3046
+ case "ADMIN_USERS_SUMMARIES_RESP":
3047
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3048
+ usersSummaries: _objectSpread$1(_objectSpread$1({}, state.usersSummaries), {}, {
3049
+ isFetching: false,
3050
+ isFetched: true,
3051
+ fetched: action.meta,
3052
+ pageInfo: pageInfo(action.payload.data.users),
3053
+ items: parseData(action.payload.data.users),
3054
+ error: formatGraphQLError(action.payload)
3055
+ })
3056
+ });
3057
+ case "ADMIN_USERS_SUMMARIES_ERR":
3058
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3059
+ usersSummaries: _objectSpread$1(_objectSpread$1({}, state.usersSummaries), {}, {
3060
+ isFetching: false,
3061
+ isFetched: true,
3062
+ fetched: null,
3063
+ items: [],
3064
+ error: formatGraphQLError(action.payload)
3065
+ })
3066
+ });
3067
+ case "ADMIN_USER_OVERVIEW_REQ":
3068
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3069
+ fetchingUser: true,
3070
+ fetchedUser: false,
3071
+ errorUser: null
3072
+ });
3073
+ case "ADMIN_USER_OVERVIEW_RESP":
3074
+ var users = parseData(action.payload.data.users);
3075
+ var user = null;
3076
+ if ((users === null || users === void 0 ? void 0 : users.length) > 0) {
3077
+ var _users = _slicedToArray(users, 1);
3078
+ user = _users[0];
3079
+ user = mapQueriesUserToStore(user);
3080
+ }
3081
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3082
+ fetchingUser: false,
3083
+ fetchedUser: true,
3084
+ user: user,
3085
+ errorUser: formatGraphQLError(action.payload)
3086
+ });
3087
+ case "ADMIN_USER_OVERVIEW_ERR":
3088
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3089
+ fetchedUser: false,
3090
+ errorUser: formatServerError(action.payload)
3091
+ });
3092
+ case "ADMIN_USER_OVERVIEW_CLEAR":
3093
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3094
+ isValidating: false,
3095
+ isValid: false,
3096
+ user: null,
3097
+ validationError: null
3098
+ });
3099
+ case "ADMIN_USER_NEW":
3100
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3101
+ usersPageInfo: {
3102
+ totalCount: 0
3103
+ },
3104
+ user: null
3105
+ });
3106
+ case "LOCATION_REGION_DISTRICTS_REQ":
3107
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3108
+ fetching_reg_dst: true,
3109
+ fetched_reg_dst: false,
3110
+ reg_dst: [],
3111
+ errorL1s: null
3112
+ });
3113
+ case "LOCATION_REGION_DISTRICTS_RESP":
3114
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3115
+ fetching_reg_dst: false,
3116
+ fetfetched_reg_dstchedL1s: true,
3117
+ reg_dst: parseData(action.payload.data.locations || action.payload.data.locationsStr),
3118
+ errorL1s: formatGraphQLError(action.payload)
3119
+ });
3120
+ case "LOCATION_REGION_DISTRICTS_ERR":
3121
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3122
+ fetching_reg_dst: false,
3123
+ errorL1s: formatServerError(action.payload)
3124
+ });
3125
+ case "LOCATION_REGION_DISTRICTS_CLEAR":
3126
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3127
+ reg_dst: []
3128
+ });
3129
+ case "LOCATION_DISTRICT_DATA_REQ":
3130
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3131
+ fetchingDistrictMunAndVil: true,
3132
+ fetchedDistrictMunAndVil: false,
3133
+ errorDistrictMunAndVil: null
3134
+ });
3135
+ case "LOCATION_DISTRICT_DATA_RESP":
3136
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3137
+ fetchingDistrictMunAndVil: false,
3138
+ fetchedDistrictMunAndVil: true,
3139
+ districtMunAndVil: parseData(action.payload.data.locations || action.payload.data.locationsStr),
3140
+ errorDistrictMunAndVil: formatGraphQLError(action.payload)
3141
+ });
3142
+ case "LOCATION_DISTRICT_DATA_ERR":
3143
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3144
+ fetchingDistrictMunAndVil: false,
3145
+ errorDistrictMunAndVil: formatServerError(action.payload)
3146
+ });
3147
+ case "LOCATION_DISTRICT_DATA_CLEAR":
3148
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3149
+ districtMunAndVil: []
3150
+ });
3151
+ case "OBLIGTORY_USER_FIELDS_REQ":
3152
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3153
+ fetching_obligatory_user_fields: true,
3154
+ fetched_obligatory_user_fields: false,
3155
+ obligatory_user_fields: null,
3156
+ errorL1s: null
3157
+ });
3158
+ case "OBLIGTORY_USER_FIELDS_RESP":
3159
+ console.log("USER FILED RESPONSE ", action.payload.data.userObligatoryFields);
3160
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3161
+ fetching_obligatory_user_fields: false,
3162
+ fetched_obligatory_user_fields: true,
3163
+ obligatory_user_fields: action.payload.data.userObligatoryFields,
3164
+ errorL1s: formatGraphQLError(action.payload)
3165
+ });
3166
+ case "OBLIGTORY_USER_FIELDS_ERR":
3167
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3168
+ fetching_obligatory_user_fields: false,
3169
+ errorL1s: formatServerError(action.payload)
3170
+ });
3171
+ case "OBLIGTORY_EO_FIELDS_REQ":
3172
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3173
+ fetching_obligatory_eo_fields: true,
3174
+ fetched_obligatory_eo_fields: false,
3175
+ obligatory_eo_fields: null,
3176
+ errorL1s: null
3177
+ });
3178
+ case "OBLIGTORY_EO_FIELDS_RESP":
3179
+ console.log("EO FILED RESPONSE ", action.payload.data.eoObligatoryFields);
3180
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3181
+ fetching_obligatory_eo_fields: false,
3182
+ fetched_obligatory_eo_fields: true,
3183
+ obligatory_eo_fields: action.payload.data.eoObligatoryFields,
3184
+ errorL1s: formatGraphQLError(action.payload)
3185
+ });
3186
+ case "OBLIGTORY_EO_FIELDS_ERR":
3187
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3188
+ fetching_obligatory_eo_fields: false,
3189
+ errorL1s: formatServerError(action.payload)
3190
+ });
3191
+ case "USERNAME_FIELDS_VALIDATION_REQ":
3192
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3193
+ validationFields: _objectSpread$1(_objectSpread$1({}, state.validationFields), {}, {
3194
+ username: {
3195
+ isValidating: true,
3196
+ isValid: false,
3197
+ validationError: null
3198
+ }
3199
+ })
3200
+ });
3201
+ case "USERNAME_FIELDS_VALIDATION_RESP":
3202
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3203
+ validationFields: _objectSpread$1(_objectSpread$1({}, state.validationFields), {}, {
3204
+ username: {
3205
+ isValidating: false,
3206
+ isValid: (_action$payload = action.payload) === null || _action$payload === void 0 ? void 0 : _action$payload.data.isValid,
3207
+ validationError: formatGraphQLError(action.payload)
3208
+ }
3209
+ })
3210
+ });
3211
+ case "USERNAME_FIELDS_VALIDATION_ERR":
3212
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3213
+ validationFields: _objectSpread$1(_objectSpread$1({}, state.validationFields), {}, {
3214
+ username: {
3215
+ isValidating: false,
3216
+ isValid: false,
3217
+ validationError: formatServerError(action.payload)
3218
+ }
3219
+ })
3220
+ });
3221
+ case "USERNAME_FIELDS_VALIDATION_CLEAR":
3222
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3223
+ validationFields: _objectSpread$1(_objectSpread$1({}, state.validationFields), {}, {
3224
+ username: {
3225
+ isValidating: true,
3226
+ isValid: false,
3227
+ validationError: null
3228
+ }
3229
+ })
3230
+ });
3231
+ case "USERNAME_FIELDS_VALIDATION_SET_VALID":
3232
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3233
+ validationFields: _objectSpread$1(_objectSpread$1({}, state.validationFields), {}, {
3234
+ username: {
3235
+ isValidating: false,
3236
+ isValid: true,
3237
+ validationError: null
3238
+ }
3239
+ })
3240
+ });
3241
+ case "USER_EMAIL_FIELDS_VALIDATION_REQ":
3242
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3243
+ validationFields: _objectSpread$1(_objectSpread$1({}, state.validationFields), {}, {
3244
+ userEmail: {
3245
+ isValidating: true,
3246
+ isValid: false,
3247
+ validationError: null
3248
+ }
3249
+ })
3250
+ });
3251
+ case "USER_EMAIL_FIELDS_VALIDATION_RESP":
3252
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3253
+ validationFields: _objectSpread$1(_objectSpread$1({}, state.validationFields), {}, {
3254
+ userEmail: {
3255
+ isValidating: false,
3256
+ isValid: (_action$payload2 = action.payload) === null || _action$payload2 === void 0 ? void 0 : _action$payload2.data.isValid,
3257
+ validationError: formatGraphQLError(action.payload)
3258
+ }
3259
+ })
3260
+ });
3261
+ case "USER_EMAIL_FIELDS_VALIDATION_ERR":
3262
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3263
+ validationFields: _objectSpread$1(_objectSpread$1({}, state.validationFields), {}, {
3264
+ userEmail: {
3265
+ isValidating: false,
3266
+ isValid: false,
3267
+ validationError: formatServerError(action.payload)
3268
+ }
3269
+ })
3270
+ });
3271
+ case "USER_EMAIL_FIELDS_VALIDATION_CLEAR":
3272
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3273
+ validationFields: _objectSpread$1(_objectSpread$1({}, state.validationFields), {}, {
3274
+ userEmail: {
3275
+ isValidating: true,
3276
+ isValid: false,
3277
+ validationError: null
3278
+ }
3279
+ })
3280
+ });
3281
+ case "USER_EMAIL_FIELDS_VALIDATION_SET_VALID":
3282
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3283
+ validationFields: _objectSpread$1(_objectSpread$1({}, state.validationFields), {}, {
3284
+ userEmail: {
3285
+ isValidating: false,
3286
+ isValid: true,
3287
+ validationError: null
3288
+ }
3289
+ })
3290
+ });
3291
+ case "USER_EMAIL_FORMAT_VALIDATION_CHECK":
3292
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3293
+ validationFields: _objectSpread$1(_objectSpread$1({}, state.validationFields), {}, {
3294
+ userEmailFormat: {
3295
+ isInvalid: (_action$payload3 = action.payload) === null || _action$payload3 === void 0 || (_action$payload3 = _action$payload3.data) === null || _action$payload3 === void 0 ? void 0 : _action$payload3.isFormatInvalid
3296
+ }
3297
+ })
3298
+ });
3299
+ case "USERNAME_LENGTH_FIELDS_REQ":
3300
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3301
+ fetchingUsernameLength: true,
3302
+ fetchedUsernameLength: false,
3303
+ usernameLength: null,
3304
+ errorUsernameLength: null
3305
+ });
3306
+ case "USERNAME_LENGTH_FIELDS_RESP":
3307
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3308
+ fetchingUsernameLength: false,
3309
+ fetchedUsernameLength: true,
3310
+ usernameLength: action.payload.data.usernameLength,
3311
+ errorUsernameLength: formatGraphQLError(action.payload)
3312
+ });
3313
+ case "USERNAME_LENGTH_FIELDS_ERR":
3314
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3315
+ fetchingUsernameLength: false,
3316
+ errorUsernameLength: formatServerError(action.payload)
3317
+ });
3318
+ case "PASSWORD_POLICY_FIELDS_REQ":
3319
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3320
+ fetchingPasswordPolicy: true,
3321
+ fetchedPasswordPolicy: false,
3322
+ passwordPolicy: null,
3323
+ errorPasswordPolicy: null
3324
+ });
3325
+ case "PASSWORD_POLICY_FIELDS_RESP":
3326
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3327
+ fetchingPasswordPolicy: false,
3328
+ fetchedPasswordPolicy: true,
3329
+ passwordPolicy: action.payload.data.passwordPolicy,
3330
+ errorPasswordPolicy: formatGraphQLError(action.payload)
3331
+ });
3332
+ case "PASSWORD_POLICY_FIELDS_ERR":
3333
+ return _objectSpread$1(_objectSpread$1({}, state), {}, {
3334
+ fetchingPasswordPolicy: false,
3335
+ errorPasswordPolicy: formatServerError(action.payload)
3336
+ });
3337
+ case "ADMIN_USER_MUTATION_REQ":
3338
+ return dispatchMutationReq(state, action);
3339
+ case "ADMIN_USER_MUTATION_ERR":
3340
+ return dispatchMutationErr(state, action);
3341
+ case "ADMIN_USER_UPDATE_RESP":
3342
+ return dispatchMutationResp(state, "updateUser", action);
3343
+ case "ADMIN_USER_DELETE_RESP":
3344
+ return dispatchMutationResp(state, "deleteUser", action);
3345
+ case "ADMIN_USER_CREATE_RESP":
3346
+ return dispatchMutationResp(state, "createUser", action);
3347
+ default:
3348
+ return state;
3349
+ }
3350
+ }
3351
+
3352
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3353
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3354
+ var ROUTE_ADMIN_USERS = "admin/users";
3355
+ var ROUTE_ADMIN_USER_OVERVIEW = "admin/users/overview";
3356
+ var ROUTE_ADMIN_USER_NEW = "admin/users/new";
3357
+ var DEFAULT_CONFIG = {
3358
+ translations: [{
3359
+ key: "en",
3360
+ messages: messagesEn
3361
+ }],
3362
+ reducers: [{
3363
+ key: "admin",
3364
+ reducer: reducer
3365
+ }],
3366
+ "core.Router": [{
3367
+ path: ROUTE_ADMIN_USERS,
3368
+ component: UsersPage$1
3369
+ }, {
3370
+ path: ROUTE_ADMIN_USER_NEW,
3371
+ component: UserPage$1
3372
+ }, {
3373
+ path: "".concat(ROUTE_ADMIN_USER_OVERVIEW, "/:user_id"),
3374
+ component: UserPage$1
3375
+ }],
3376
+ "core.MainMenu": [{
3377
+ name: "AdminMainMenu",
3378
+ component: AdminMainMenu$1
3379
+ }],
3380
+ refs: [{
3381
+ key: "admin.UserPicker",
3382
+ ref: UserPicker$1
3383
+ }, {
3384
+ key: "admin.EnrolmentOfficerPicker",
3385
+ ref: EnrolmentOfficerPicker$1
3386
+ }, {
3387
+ key: "admin.SubstitutionEnrolmentOfficerPicker",
3388
+ ref: SubstitutionEnrolmentOfficerPicker$1
3389
+ }, {
3390
+ key: "admin.UserRolesPicker",
3391
+ ref: UserRolesPicker
3392
+ }, {
3393
+ key: "admin.UserTypesPicker",
3394
+ ref: UserTypesPicker
3395
+ }, {
3396
+ key: "admin.UserPicker.projection",
3397
+ ref: USER_PICKER_PROJECTION
3398
+ }, {
3399
+ key: "admin.users",
3400
+ ref: ROUTE_ADMIN_USERS
3401
+ }, {
3402
+ key: "admin.userOverview",
3403
+ ref: ROUTE_ADMIN_USER_OVERVIEW
3404
+ }, {
3405
+ key: "admin.userNew",
3406
+ ref: ROUTE_ADMIN_USER_NEW
3407
+ }, {
3408
+ key: "admin.PaymentPointManagerPicker",
3409
+ ref: PaymentPointManagerPicker
3410
+ }],
3411
+ "invoice.SubjectAndThirdpartyPicker": [{
3412
+ type: "user",
3413
+ picker: UserPicker$1,
3414
+ pickerProjection: USER_PICKER_PROJECTION
3415
+ }],
3416
+ "admin.MainMenu": [{
3417
+ text: /*#__PURE__*/React.createElement(FormattedMessage, {
3418
+ module: "admin",
3419
+ id: "menu.products"
3420
+ }),
3421
+ icon: /*#__PURE__*/React.createElement(Tune, null),
3422
+ route: "/admin/products",
3423
+ id: "admin.products",
3424
+ filter: function filter(rights) {
3425
+ return rights.includes(RIGHT_PRODUCTS);
3426
+ }
3427
+ }, {
3428
+ text: /*#__PURE__*/React.createElement(FormattedMessage, {
3429
+ module: "admin",
3430
+ id: "menu.healthFacilities"
3431
+ }),
3432
+ icon: /*#__PURE__*/React.createElement(LocalHospital, null),
3433
+ route: "/location/healthFacilities",
3434
+ withDivider: true,
3435
+ id: "admin.healthFacilities",
3436
+ filter: function filter(rights) {
3437
+ return rights.includes(RIGHT_HEALTHFACILITIES);
3438
+ }
3439
+ }, {
3440
+ text: /*#__PURE__*/React.createElement(FormattedMessage, {
3441
+ module: "admin",
3442
+ id: "menu.medicalServicesPrices"
3443
+ }),
3444
+ icon: /*#__PURE__*/React.createElement(HealingOutlined, null),
3445
+ route: "/medical/pricelists/services",
3446
+ id: "admin.services",
3447
+ filter: function filter(rights) {
3448
+ return rights.includes(RIGHT_PRICELISTMS);
3449
+ }
3450
+ }, {
3451
+ text: /*#__PURE__*/React.createElement(FormattedMessage, {
3452
+ module: "admin",
3453
+ id: "menu.medicalItemsPrices"
3454
+ }),
3455
+ icon: /*#__PURE__*/React.createElement(LocalPharmacyOutlined, null),
3456
+ route: "/medical/pricelists/items",
3457
+ withDivider: true,
3458
+ id: "admin.items",
3459
+ filter: function filter(rights) {
3460
+ return rights.includes(RIGHT_PRICELISTMI);
3461
+ }
3462
+ }, {
3463
+ text: /*#__PURE__*/React.createElement(FormattedMessage, {
3464
+ module: "admin",
3465
+ id: "menu.medicalServices"
3466
+ }),
3467
+ icon: /*#__PURE__*/React.createElement(Healing, null),
3468
+ route: "/medical/medicalServices",
3469
+ id: "admin.medicalServices",
3470
+ filter: function filter(rights) {
3471
+ return rights.includes(RIGHT_MEDICALSERVICES);
3472
+ }
3473
+ }, {
3474
+ text: /*#__PURE__*/React.createElement(FormattedMessage, {
3475
+ module: "admin",
3476
+ id: "menu.medicalItems"
3477
+ }),
3478
+ icon: /*#__PURE__*/React.createElement(LocalPharmacy, null),
3479
+ route: "/medical/medicalItems",
3480
+ withDivider: true,
3481
+ id: "admin.medicalItems",
3482
+ filter: function filter(rights) {
3483
+ return rights.includes(RIGHT_MEDICALITEMS);
3484
+ }
3485
+ }, {
3486
+ text: /*#__PURE__*/React.createElement(FormattedMessage, {
3487
+ module: "admin",
3488
+ id: "menu.users"
3489
+ }),
3490
+ icon: /*#__PURE__*/React.createElement(Person, null),
3491
+ route: "/admin/users",
3492
+ id: "admin.users",
3493
+ filter: function filter(rights) {
3494
+ return rights.includes(RIGHT_USERS);
3495
+ }
3496
+ }, {
3497
+ text: /*#__PURE__*/React.createElement(FormattedMessage, {
3498
+ module: "admin",
3499
+ id: "menu.locations"
3500
+ }),
3501
+ icon: /*#__PURE__*/React.createElement(PinDrop, null),
3502
+ route: "/location/locations",
3503
+ id: "admin.locations",
3504
+ filter: function filter(rights) {
3505
+ return rights.includes(RIGHT_LOCATIONS);
3506
+ }
3507
+ }]
3508
+ };
3509
+ var AdminModule = function AdminModule(cfg) {
3510
+ return _objectSpread(_objectSpread({}, DEFAULT_CONFIG), cfg);
3511
+ };
3512
+
3513
+ export { AdminModule };
3514
+ //# sourceMappingURL=index.es.js.map