@sprucelabs/spruce-profile-utils 6.0.2 → 6.0.4
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.
|
@@ -3,13 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
|
|
4
4
|
const schema_1 = require("@sprucelabs/schema");
|
|
5
5
|
class RoleSelectCardViewController extends heartwood_view_controllers_1.AbstractViewController {
|
|
6
|
-
static id = 'role-select-card';
|
|
7
|
-
activeRecordCardVc;
|
|
8
|
-
isLoaded = false;
|
|
9
|
-
onChangeHandler;
|
|
10
|
-
roles = [];
|
|
11
6
|
constructor(options) {
|
|
12
7
|
super(options);
|
|
8
|
+
this.isLoaded = false;
|
|
9
|
+
this.roles = [];
|
|
13
10
|
this.onChangeHandler = options.onChange;
|
|
14
11
|
this.activeRecordCardVc = this.ActiveRecordVc();
|
|
15
12
|
}
|
|
@@ -41,7 +38,8 @@ class RoleSelectCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
41
38
|
return this.activeRecordCardVc.getListVc();
|
|
42
39
|
}
|
|
43
40
|
getRoles() {
|
|
44
|
-
|
|
41
|
+
var _a;
|
|
42
|
+
return (_a = this.roles) !== null && _a !== void 0 ? _a : [];
|
|
45
43
|
}
|
|
46
44
|
async setRoles(roles) {
|
|
47
45
|
this.roles = roles;
|
|
@@ -77,7 +75,8 @@ class RoleSelectCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
77
75
|
isRequired: true,
|
|
78
76
|
value: this.getRequirementsForRole(role.id),
|
|
79
77
|
onChange: async (value) => {
|
|
80
|
-
|
|
78
|
+
var _a;
|
|
79
|
+
await ((_a = this.onChangeHandler) === null || _a === void 0 ? void 0 : _a.call(this, role.id, value !== null && value !== void 0 ? value : 'skip'));
|
|
81
80
|
this.roles = this.roles.filter((r) => r.roleId !== role.id);
|
|
82
81
|
if (value !== 'skip') {
|
|
83
82
|
this.roles.push({
|
|
@@ -106,7 +105,8 @@ class RoleSelectCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
106
105
|
};
|
|
107
106
|
}
|
|
108
107
|
getRequirementsForRole(roleId) {
|
|
109
|
-
|
|
108
|
+
var _a;
|
|
109
|
+
return (_a = this.roles.find((r) => r.roleId === roleId)) === null || _a === void 0 ? void 0 : _a.requirements;
|
|
110
110
|
}
|
|
111
111
|
async load(options) {
|
|
112
112
|
this.activeRecordCardVc.setTarget(options);
|
|
@@ -117,4 +117,5 @@ class RoleSelectCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
117
117
|
return this.activeRecordCardVc.render();
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
+
RoleSelectCardViewController.id = 'role-select-card';
|
|
120
121
|
exports.default = RoleSelectCardViewController;
|
|
@@ -5,14 +5,6 @@ const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-control
|
|
|
5
5
|
const schema_1 = require("@sprucelabs/schema");
|
|
6
6
|
const spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
|
|
7
7
|
class ProfileCardViewController extends heartwood_view_controllers_1.AbstractViewController {
|
|
8
|
-
static id = 'profile-card';
|
|
9
|
-
cardVc;
|
|
10
|
-
formVc;
|
|
11
|
-
person;
|
|
12
|
-
authenticator;
|
|
13
|
-
onSubmitHandler;
|
|
14
|
-
locationId;
|
|
15
|
-
organizationId;
|
|
16
8
|
constructor(options) {
|
|
17
9
|
super(options);
|
|
18
10
|
const { onSubmit, header } = options;
|
|
@@ -34,6 +26,7 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
|
|
|
34
26
|
});
|
|
35
27
|
}
|
|
36
28
|
FormVc() {
|
|
29
|
+
var _a, _b;
|
|
37
30
|
return this.Controller('form', (0, heartwood_view_controllers_1.buildForm)({
|
|
38
31
|
id: 'profile',
|
|
39
32
|
schema: spruce_core_schemas_1.personSchema,
|
|
@@ -44,8 +37,8 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
|
|
|
44
37
|
onSubmit: this.handleSubmit.bind(this),
|
|
45
38
|
isEnabled: false,
|
|
46
39
|
values: {
|
|
47
|
-
firstName: this.person
|
|
48
|
-
lastName: this.person
|
|
40
|
+
firstName: (_a = this.person) === null || _a === void 0 ? void 0 : _a.firstName,
|
|
41
|
+
lastName: (_b = this.person) === null || _b === void 0 ? void 0 : _b.lastName,
|
|
49
42
|
timezone: 'America/Boise',
|
|
50
43
|
},
|
|
51
44
|
submitButtonLabel: 'Save',
|
|
@@ -63,12 +56,13 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
|
|
|
63
56
|
}));
|
|
64
57
|
}
|
|
65
58
|
async handleSubmit() {
|
|
59
|
+
var _a, _b, _c, _d;
|
|
66
60
|
try {
|
|
67
61
|
const client = await this.connectToApi();
|
|
68
62
|
const values = this.formVc.getValues();
|
|
69
63
|
const [{ person: updatedPerson }] = await client.emitAndFlattenResponses('update-person::v2020_12_25', {
|
|
70
64
|
target: {
|
|
71
|
-
personId: this.person
|
|
65
|
+
personId: (_a = this.person) === null || _a === void 0 ? void 0 : _a.id,
|
|
72
66
|
organizationId: this.organizationId,
|
|
73
67
|
locationId: this.locationId,
|
|
74
68
|
},
|
|
@@ -77,10 +71,10 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
|
|
|
77
71
|
},
|
|
78
72
|
});
|
|
79
73
|
const loggedInPerson = this.authenticator.getPerson();
|
|
80
|
-
const isMe = loggedInPerson.id === this.person
|
|
74
|
+
const isMe = loggedInPerson.id === ((_b = this.person) === null || _b === void 0 ? void 0 : _b.id);
|
|
81
75
|
if (isMe) {
|
|
82
76
|
const token = this.authenticator.getSessionToken();
|
|
83
|
-
this.authenticator
|
|
77
|
+
(_c = this.authenticator) === null || _c === void 0 ? void 0 : _c.setSessionToken(token, updatedPerson);
|
|
84
78
|
}
|
|
85
79
|
await this.alert({
|
|
86
80
|
title: 'Changes saved!',
|
|
@@ -89,7 +83,7 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
|
|
|
89
83
|
: `Profile saved!`,
|
|
90
84
|
style: 'success',
|
|
91
85
|
});
|
|
92
|
-
await this.onSubmitHandler
|
|
86
|
+
await ((_d = this.onSubmitHandler) === null || _d === void 0 ? void 0 : _d.call(this, updatedPerson));
|
|
93
87
|
}
|
|
94
88
|
catch (err) {
|
|
95
89
|
await this.alert({ message: err.message, style: 'error' });
|
|
@@ -97,7 +91,8 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
|
|
|
97
91
|
this.formVc.disable();
|
|
98
92
|
}
|
|
99
93
|
async load(options) {
|
|
100
|
-
|
|
94
|
+
var _a;
|
|
95
|
+
const { person, authenticator, locale, locationId, organizationId } = (0, schema_1.assertOptions)(options !== null && options !== void 0 ? options : {}, ['person', 'authenticator']);
|
|
101
96
|
this.person = person;
|
|
102
97
|
this.authenticator = authenticator;
|
|
103
98
|
this.locationId = locationId;
|
|
@@ -115,7 +110,7 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
|
|
|
115
110
|
}
|
|
116
111
|
await this.formVc.setValues({
|
|
117
112
|
...options.person,
|
|
118
|
-
timezone: person.timezone
|
|
113
|
+
timezone: (_a = person.timezone) !== null && _a !== void 0 ? _a : locale === null || locale === void 0 ? void 0 : locale.getZoneName(),
|
|
119
114
|
});
|
|
120
115
|
this.formVc.disable();
|
|
121
116
|
this.cardVc.setIsBusy(false);
|
|
@@ -124,4 +119,5 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
|
|
|
124
119
|
return this.cardVc.render();
|
|
125
120
|
}
|
|
126
121
|
}
|
|
122
|
+
ProfileCardViewController.id = 'profile-card';
|
|
127
123
|
exports.default = ProfileCardViewController;
|