@sprucelabs/spruce-profile-utils 3.0.2 → 3.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.
@@ -8,6 +8,8 @@ export default class ProfileCardViewController extends AbstractViewController<Ca
8
8
  protected person?: Person;
9
9
  protected authenticator: Authenticator;
10
10
  protected onSubmitHandler?: OnSubmitHandler;
11
+ protected locationId?: string;
12
+ protected organizationId?: string;
11
13
  constructor(options: ViewControllerOptions & ProfileCardViewControllerOptions);
12
14
  private CardVc;
13
15
  private FormVc;
@@ -19,6 +21,8 @@ export interface ProfileCardLoadOptions {
19
21
  person: Person;
20
22
  authenticator: Authenticator;
21
23
  locale: Locale;
24
+ locationId?: string;
25
+ organizationId?: string;
22
26
  }
23
27
  export type OnSubmitHandler = (person: Person) => Promise<void>;
24
28
  export interface ProfileCardViewControllerOptions {
@@ -61,26 +61,31 @@ class ProfileCardViewController extends AbstractViewController {
61
61
  }));
62
62
  }
63
63
  handleSubmit() {
64
- var _a, _b, _c;
64
+ var _a, _b, _c, _d;
65
65
  return __awaiter(this, void 0, void 0, function* () {
66
66
  try {
67
67
  const client = yield this.connectToApi();
68
68
  const values = this.formVc.getValues();
69
69
  yield client.emitAndFlattenResponses('update-person::v2020_12_25', {
70
+ target: {
71
+ personId: (_a = this.person) === null || _a === void 0 ? void 0 : _a.id,
72
+ organizationId: this.organizationId,
73
+ locationId: this.locationId,
74
+ },
70
75
  payload: Object.assign({}, values),
71
76
  });
72
- const token = this.authenticator.getSessionToken();
73
- const current = this.authenticator.getPerson();
74
- const updatedPerson = Object.assign(Object.assign({}, current), values);
75
- if (current.id === ((_a = this.person) === null || _a === void 0 ? void 0 : _a.id)) {
76
- (_b = this.authenticator) === null || _b === void 0 ? void 0 : _b.setSessionToken(token, updatedPerson);
77
+ const loggedInPerson = this.authenticator.getPerson();
78
+ const updatedPerson = Object.assign(Object.assign({}, this.person), values);
79
+ if (loggedInPerson.id === ((_b = this.person) === null || _b === void 0 ? void 0 : _b.id)) {
80
+ const token = this.authenticator.getSessionToken();
81
+ (_c = this.authenticator) === null || _c === void 0 ? void 0 : _c.setSessionToken(token, updatedPerson);
77
82
  }
78
83
  yield this.alert({
79
84
  title: 'Changes saved!',
80
85
  message: 'Your profile has been updated. This is so much fun!',
81
86
  style: 'success',
82
87
  });
83
- yield ((_c = this.onSubmitHandler) === null || _c === void 0 ? void 0 : _c.call(this, updatedPerson));
88
+ yield ((_d = this.onSubmitHandler) === null || _d === void 0 ? void 0 : _d.call(this, updatedPerson));
84
89
  }
85
90
  catch (err) {
86
91
  yield this.alert({ message: err.message, style: 'error' });
@@ -91,14 +96,12 @@ class ProfileCardViewController extends AbstractViewController {
91
96
  load(options) {
92
97
  var _a;
93
98
  return __awaiter(this, void 0, void 0, function* () {
94
- const { person, authenticator, locale } = assertOptions(options !== null && options !== void 0 ? options : {}, [
95
- 'person',
96
- 'authenticator',
97
- 'locale',
98
- ]);
99
+ const { person, authenticator, locale, locationId, organizationId } = assertOptions(options !== null && options !== void 0 ? options : {}, ['person', 'authenticator', 'locale']);
99
100
  const sortedSchema = sortTimezoneChoices(locale, personSchema, 'timezone');
100
101
  this.person = person;
101
102
  this.authenticator = authenticator;
103
+ this.locationId = locationId;
104
+ this.organizationId = organizationId;
102
105
  this.formVc.updateField('timezone', {
103
106
  fieldDefinition: Object.assign({}, sortedSchema.fields.timezone),
104
107
  });
@@ -8,6 +8,8 @@ export default class ProfileCardViewController extends AbstractViewController<Ca
8
8
  protected person?: Person;
9
9
  protected authenticator: Authenticator;
10
10
  protected onSubmitHandler?: OnSubmitHandler;
11
+ protected locationId?: string;
12
+ protected organizationId?: string;
11
13
  constructor(options: ViewControllerOptions & ProfileCardViewControllerOptions);
12
14
  private CardVc;
13
15
  private FormVc;
@@ -19,6 +21,8 @@ export interface ProfileCardLoadOptions {
19
21
  person: Person;
20
22
  authenticator: Authenticator;
21
23
  locale: Locale;
24
+ locationId?: string;
25
+ organizationId?: string;
22
26
  }
23
27
  export type OnSubmitHandler = (person: Person) => Promise<void>;
24
28
  export interface ProfileCardViewControllerOptions {
@@ -54,25 +54,30 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
54
54
  }));
55
55
  }
56
56
  async handleSubmit() {
57
- var _a, _b, _c;
57
+ var _a, _b, _c, _d;
58
58
  try {
59
59
  const client = await this.connectToApi();
60
60
  const values = this.formVc.getValues();
61
61
  await client.emitAndFlattenResponses('update-person::v2020_12_25', {
62
+ target: {
63
+ personId: (_a = this.person) === null || _a === void 0 ? void 0 : _a.id,
64
+ organizationId: this.organizationId,
65
+ locationId: this.locationId,
66
+ },
62
67
  payload: Object.assign({}, values),
63
68
  });
64
- const token = this.authenticator.getSessionToken();
65
- const current = this.authenticator.getPerson();
66
- const updatedPerson = Object.assign(Object.assign({}, current), values);
67
- if (current.id === ((_a = this.person) === null || _a === void 0 ? void 0 : _a.id)) {
68
- (_b = this.authenticator) === null || _b === void 0 ? void 0 : _b.setSessionToken(token, updatedPerson);
69
+ const loggedInPerson = this.authenticator.getPerson();
70
+ const updatedPerson = Object.assign(Object.assign({}, this.person), values);
71
+ if (loggedInPerson.id === ((_b = this.person) === null || _b === void 0 ? void 0 : _b.id)) {
72
+ const token = this.authenticator.getSessionToken();
73
+ (_c = this.authenticator) === null || _c === void 0 ? void 0 : _c.setSessionToken(token, updatedPerson);
69
74
  }
70
75
  await this.alert({
71
76
  title: 'Changes saved!',
72
77
  message: 'Your profile has been updated. This is so much fun!',
73
78
  style: 'success',
74
79
  });
75
- await ((_c = this.onSubmitHandler) === null || _c === void 0 ? void 0 : _c.call(this, updatedPerson));
80
+ await ((_d = this.onSubmitHandler) === null || _d === void 0 ? void 0 : _d.call(this, updatedPerson));
76
81
  }
77
82
  catch (err) {
78
83
  await this.alert({ message: err.message, style: 'error' });
@@ -81,14 +86,12 @@ class ProfileCardViewController extends heartwood_view_controllers_1.AbstractVie
81
86
  }
82
87
  async load(options) {
83
88
  var _a;
84
- const { person, authenticator, locale } = (0, schema_1.assertOptions)(options !== null && options !== void 0 ? options : {}, [
85
- 'person',
86
- 'authenticator',
87
- 'locale',
88
- ]);
89
+ const { person, authenticator, locale, locationId, organizationId } = (0, schema_1.assertOptions)(options !== null && options !== void 0 ? options : {}, ['person', 'authenticator', 'locale']);
89
90
  const sortedSchema = (0, calendar_utils_1.sortTimezoneChoices)(locale, spruce_core_schemas_1.personSchema, 'timezone');
90
91
  this.person = person;
91
92
  this.authenticator = authenticator;
93
+ this.locationId = locationId;
94
+ this.organizationId = organizationId;
92
95
  this.formVc.updateField('timezone', {
93
96
  fieldDefinition: Object.assign({}, sortedSchema.fields.timezone),
94
97
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-profile-utils",
3
3
  "description": "Useeful utilities",
4
- "version": "3.0.2",
4
+ "version": "3.0.4",
5
5
  "skill": {
6
6
  "namespace": "profile"
7
7
  },