@sprucelabs/spruce-profile-utils 6.0.179 → 6.0.181
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.
|
@@ -38,8 +38,7 @@ class RoleSelectCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
38
38
|
return this.activeRecordCardVc.getListVc();
|
|
39
39
|
}
|
|
40
40
|
getRoles() {
|
|
41
|
-
|
|
42
|
-
return (_a = this.roles) !== null && _a !== void 0 ? _a : [];
|
|
41
|
+
return this.roles ?? [];
|
|
43
42
|
}
|
|
44
43
|
async setRoles(roles) {
|
|
45
44
|
this.roles = roles;
|
|
@@ -75,8 +74,7 @@ class RoleSelectCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
75
74
|
isRequired: true,
|
|
76
75
|
value: this.getRequirementsForRole(role.id),
|
|
77
76
|
onChange: async (value) => {
|
|
78
|
-
|
|
79
|
-
await ((_a = this.onChangeHandler) === null || _a === void 0 ? void 0 : _a.call(this, role.id, value !== null && value !== void 0 ? value : 'skip'));
|
|
77
|
+
await this.onChangeHandler?.(role.id, value ?? 'skip');
|
|
80
78
|
this.roles = this.roles.filter((r) => r.roleId !== role.id);
|
|
81
79
|
if (value !== 'skip') {
|
|
82
80
|
this.roles.push({
|
|
@@ -105,8 +103,7 @@ class RoleSelectCardViewController extends heartwood_view_controllers_1.Abstract
|
|
|
105
103
|
};
|
|
106
104
|
}
|
|
107
105
|
getRequirementsForRole(roleId) {
|
|
108
|
-
|
|
109
|
-
return (_a = this.roles.find((r) => r.roleId === roleId)) === null || _a === void 0 ? void 0 : _a.requirements;
|
|
106
|
+
return this.roles.find((r) => r.roleId === roleId)?.requirements;
|
|
110
107
|
}
|
|
111
108
|
async load(options) {
|
|
112
109
|
this.activeRecordCardVc.setTarget(options);
|
|
@@ -26,7 +26,6 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
|
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
FormVc() {
|
|
29
|
-
var _a, _b;
|
|
30
29
|
return this.Controller('form', (0, heartwood_view_controllers_1.buildForm)({
|
|
31
30
|
id: 'profile',
|
|
32
31
|
schema: spruce_core_schemas_1.personSchema,
|
|
@@ -37,8 +36,8 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
|
|
|
37
36
|
onSubmit: this.handleSubmit.bind(this),
|
|
38
37
|
isEnabled: false,
|
|
39
38
|
values: {
|
|
40
|
-
firstName:
|
|
41
|
-
lastName:
|
|
39
|
+
firstName: this.person?.firstName,
|
|
40
|
+
lastName: this.person?.lastName,
|
|
42
41
|
timezone: 'America/Boise',
|
|
43
42
|
},
|
|
44
43
|
submitButtonLabel: 'Save',
|
|
@@ -56,13 +55,12 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
|
|
|
56
55
|
}));
|
|
57
56
|
}
|
|
58
57
|
async handleSubmit() {
|
|
59
|
-
var _a, _b, _c, _d;
|
|
60
58
|
try {
|
|
61
59
|
const client = await this.connectToApi();
|
|
62
60
|
const values = this.formVc.getValues();
|
|
63
61
|
const [{ person: updatedPerson }] = await client.emitAndFlattenResponses('update-person::v2020_12_25', {
|
|
64
62
|
target: {
|
|
65
|
-
personId:
|
|
63
|
+
personId: this.person?.id,
|
|
66
64
|
organizationId: this.organizationId,
|
|
67
65
|
locationId: this.locationId,
|
|
68
66
|
},
|
|
@@ -71,10 +69,10 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
|
|
|
71
69
|
},
|
|
72
70
|
});
|
|
73
71
|
const loggedInPerson = this.authenticator.getPerson();
|
|
74
|
-
const isMe = loggedInPerson.id ===
|
|
72
|
+
const isMe = loggedInPerson.id === this.person?.id;
|
|
75
73
|
if (isMe) {
|
|
76
74
|
const token = this.authenticator.getSessionToken();
|
|
77
|
-
|
|
75
|
+
this.authenticator?.setSessionToken(token, updatedPerson);
|
|
78
76
|
}
|
|
79
77
|
await this.alert({
|
|
80
78
|
title: 'Changes saved!',
|
|
@@ -83,7 +81,7 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
|
|
|
83
81
|
: `Profile saved!`,
|
|
84
82
|
style: 'success',
|
|
85
83
|
});
|
|
86
|
-
await
|
|
84
|
+
await this.onSubmitHandler?.(updatedPerson);
|
|
87
85
|
}
|
|
88
86
|
catch (err) {
|
|
89
87
|
await this.alert({ message: err.message, style: 'error' });
|
|
@@ -91,8 +89,7 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
|
|
|
91
89
|
this.formVc.disable();
|
|
92
90
|
}
|
|
93
91
|
async load(options) {
|
|
94
|
-
|
|
95
|
-
const { person, authenticator, locale, locationId, organizationId } = (0, schema_1.assertOptions)(options !== null && options !== void 0 ? options : {}, ['person', 'authenticator']);
|
|
92
|
+
const { person, authenticator, locale, locationId, organizationId } = (0, schema_1.assertOptions)(options ?? {}, ['person', 'authenticator']);
|
|
96
93
|
this.person = person;
|
|
97
94
|
this.authenticator = authenticator;
|
|
98
95
|
this.locationId = locationId;
|
|
@@ -110,7 +107,7 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
|
|
|
110
107
|
}
|
|
111
108
|
await this.formVc.setValues({
|
|
112
109
|
...options.person,
|
|
113
|
-
timezone:
|
|
110
|
+
timezone: person.timezone ?? locale?.getZoneName(),
|
|
114
111
|
});
|
|
115
112
|
this.formVc.disable();
|
|
116
113
|
this.cardVc.setIsBusy(false);
|