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