@sprucelabs/spruce-appointment-utils 14.0.147 → 14.0.149

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.
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  const schema_1 = require("@sprucelabs/schema");
15
4
  class RemoteRoleCapabilityStore {
@@ -23,13 +12,16 @@ class RemoteRoleCapabilityStore {
23
12
  (0, schema_1.assertOptions)(value, ['serviceId', 'roleId']);
24
13
  const id = `${this.organizationId}-${value.serviceId}-${value.roleId}`;
25
14
  const cleaned = this.clean(value);
26
- this.queuedCapabilities[id] = Object.assign(Object.assign({}, this.queuedCapabilities[id]), cleaned);
15
+ this.queuedCapabilities[id] = {
16
+ ...this.queuedCapabilities[id],
17
+ ...cleaned,
18
+ };
27
19
  return this.queuedCapabilities[id];
28
20
  }
29
21
  async persist() {
30
22
  let response = [];
31
23
  for (let key in this.queuedCapabilities) {
32
- const _a = this.queuedCapabilities[key], { id, roleId, serviceId } = _a, values = __rest(_a, ["id", "roleId", "serviceId"]);
24
+ const { id, roleId, serviceId, ...values } = this.queuedCapabilities[key];
33
25
  if (id) {
34
26
  const capability = await this.updateCapability(id, values);
35
27
  response.push(capability);
@@ -48,7 +40,12 @@ class RemoteRoleCapabilityStore {
48
40
  organizationId: this.organizationId,
49
41
  roleId,
50
42
  },
51
- payload: Object.assign({ serviceId, isEnabled: false, doesOffer: false }, values),
43
+ payload: {
44
+ serviceId,
45
+ isEnabled: false,
46
+ doesOffer: false,
47
+ ...values,
48
+ },
52
49
  });
53
50
  return capability;
54
51
  }
@@ -58,12 +55,14 @@ class RemoteRoleCapabilityStore {
58
55
  organizationId: this.organizationId,
59
56
  capabilityId: id,
60
57
  },
61
- payload: Object.assign({}, values),
58
+ payload: {
59
+ ...values,
60
+ },
62
61
  });
63
62
  return capability;
64
63
  }
65
64
  clean(value) {
66
- const cleaned = Object.assign({}, value);
65
+ const cleaned = { ...value };
67
66
  if (!cleaned.timeBlocks) {
68
67
  return cleaned;
69
68
  }
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
15
4
  class DurationListViewController extends heartwood_view_controllers_1.AbstractViewController {
@@ -33,7 +22,10 @@ class DurationListViewController extends heartwood_view_controllers_1.AbstractVi
33
22
  { title: 'Duration', isBusy: true, durationMinutes: undefined },
34
23
  ];
35
24
  }
36
- this.timeBlocksWithId = timeBlocks.map((tb) => (Object.assign({ id: this.generateBlockId() }, tb)));
25
+ this.timeBlocksWithId = timeBlocks.map((tb) => ({
26
+ id: this.generateBlockId(),
27
+ ...tb,
28
+ }));
37
29
  for (const timeBlock of this.timeBlocksWithId) {
38
30
  this.addRow(timeBlock);
39
31
  }
@@ -49,17 +41,14 @@ class DurationListViewController extends heartwood_view_controllers_1.AbstractVi
49
41
  }
50
42
  getTimeBlocks() {
51
43
  return this.timeBlocksWithId.map((tb) => {
52
- const values = __rest(tb
53
- //@ts-ignore
54
- , []);
44
+ const { ...values } = tb;
55
45
  //@ts-ignore
56
46
  delete values.id;
57
47
  return values;
58
48
  });
59
49
  }
60
50
  buildRow(timeBlockWithId) {
61
- var _a, _b;
62
- const { id: rowId } = timeBlockWithId, timeBlock = __rest(timeBlockWithId, ["id"]);
51
+ const { id: rowId, ...timeBlock } = timeBlockWithId;
63
52
  return {
64
53
  id: rowId,
65
54
  height: 'content',
@@ -68,7 +57,7 @@ class DurationListViewController extends heartwood_view_controllers_1.AbstractVi
68
57
  button: {
69
58
  id: 'edit-title',
70
59
  lineIcon: 'edit-line',
71
- label: (_a = timeBlock.title) !== null && _a !== void 0 ? _a : 'Duration',
60
+ label: timeBlock.title ?? 'Duration',
72
61
  onClick: async () => {
73
62
  await this.handleClickEditTitle(timeBlockWithId);
74
63
  },
@@ -78,8 +67,8 @@ class DurationListViewController extends heartwood_view_controllers_1.AbstractVi
78
67
  textInput: {
79
68
  name: 'durationMinutes',
80
69
  label: 'Minutes',
81
- value: (timeBlock === null || timeBlock === void 0 ? void 0 : timeBlock.durationMinutes)
82
- ? `${timeBlock === null || timeBlock === void 0 ? void 0 : timeBlock.durationMinutes}`
70
+ value: timeBlock?.durationMinutes
71
+ ? `${timeBlock?.durationMinutes}`
83
72
  : undefined,
84
73
  onChange: async (value) => {
85
74
  if (value) {
@@ -99,9 +88,9 @@ class DurationListViewController extends heartwood_view_controllers_1.AbstractVi
99
88
  {
100
89
  toggleInput: {
101
90
  name: 'isBusy',
102
- value: (_b = timeBlock === null || timeBlock === void 0 ? void 0 : timeBlock.isBusy) !== null && _b !== void 0 ? _b : true,
91
+ value: timeBlock?.isBusy ?? true,
103
92
  onChange: async (value) => {
104
- timeBlockWithId.isBusy = value !== null && value !== void 0 ? value : false;
93
+ timeBlockWithId.isBusy = value ?? false;
105
94
  await this.alertOnFirstBusyToggle();
106
95
  },
107
96
  },
@@ -138,19 +127,22 @@ class DurationListViewController extends heartwood_view_controllers_1.AbstractVi
138
127
  this.addRow(timeBlock);
139
128
  }
140
129
  async handleClickEditTitle(timeBlock) {
141
- var _a;
142
130
  const editVc = this.Controller('appointments.edit-time-block-title-card', {
143
131
  onCancel: () => { },
144
132
  onSubmit: async (title) => {
145
133
  timeBlock.title = title;
146
- this.listVc.upsertRow(timeBlock.id, Object.assign({}, this.buildRow(timeBlock)));
134
+ this.listVc.upsertRow(timeBlock.id, {
135
+ ...this.buildRow(timeBlock),
136
+ });
147
137
  this.listVc.triggerRender();
148
138
  await dlgVc.hide();
149
139
  },
150
- title: (_a = timeBlock === null || timeBlock === void 0 ? void 0 : timeBlock.title) !== null && _a !== void 0 ? _a : '',
140
+ title: timeBlock?.title ?? '',
151
141
  });
152
142
  this.editTitleFormVc = editVc.getFormVc();
153
- const dlgVc = this.renderInDialog(Object.assign({}, editVc.render()));
143
+ const dlgVc = this.renderInDialog({
144
+ ...editVc.render(),
145
+ });
154
146
  }
155
147
  async handleClickDelete(timeBlock) {
156
148
  const shouldDelete = await this.confirm({
@@ -4,20 +4,18 @@ const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-control
4
4
  const schema_1 = require("@sprucelabs/schema");
5
5
  class EditOverrideDetailsCardViewController extends heartwood_view_controllers_1.AbstractViewController {
6
6
  constructor(options) {
7
- var _a, _b, _c;
8
7
  super(options);
9
8
  (0, schema_1.assertOptions)(options, ['onCancel', 'onSubmit']);
10
- this.service = options === null || options === void 0 ? void 0 : options.service;
11
- this.serviceRoleCapability = options === null || options === void 0 ? void 0 : options.serviceRoleCapability;
9
+ this.service = options?.service;
10
+ this.serviceRoleCapability = options?.serviceRoleCapability;
12
11
  this.submitHandler = options.onSubmit;
13
12
  this.cancelHandler = options.onCancel;
14
13
  this.durationListVc = this.Controller('appointments.duration-list', {});
15
- this.durationListVc.setValues((_b = (_a = this.serviceRoleCapability) === null || _a === void 0 ? void 0 : _a.timeBlocks) !== null && _b !== void 0 ? _b : (_c = this.service) === null || _c === void 0 ? void 0 : _c.timeBlocks);
14
+ this.durationListVc.setValues(this.serviceRoleCapability?.timeBlocks ?? this.service?.timeBlocks);
16
15
  this.formVc = this.FormVc();
17
16
  this.cardVc = this.CardVc();
18
17
  }
19
18
  FormVc() {
20
- var _a, _b;
21
19
  return this.Controller('form', (0, heartwood_view_controllers_1.buildForm)({
22
20
  id: 'editOverrideForm',
23
21
  schema,
@@ -34,7 +32,7 @@ class EditOverrideDetailsCardViewController extends heartwood_view_controllers_1
34
32
  {
35
33
  name: 'price',
36
34
  label: 'Price',
37
- placeholder: (_a = this.service) === null || _a === void 0 ? void 0 : _a.price,
35
+ placeholder: this.service?.price,
38
36
  },
39
37
  ],
40
38
  },
@@ -55,7 +53,7 @@ class EditOverrideDetailsCardViewController extends heartwood_view_controllers_1
55
53
  ],
56
54
  },
57
55
  values: {
58
- price: (_b = this.serviceRoleCapability) === null || _b === void 0 ? void 0 : _b.price,
56
+ price: this.serviceRoleCapability?.price,
59
57
  },
60
58
  }));
61
59
  }
@@ -15,7 +15,7 @@ class EditTimeBlockTitleCardViewController extends heartwood_view_controllers_1.
15
15
  constructor(options) {
16
16
  super(options);
17
17
  (0, schema_1.assertOptions)(options, ['onCancel', 'onSubmit']);
18
- this.title = options === null || options === void 0 ? void 0 : options.title;
18
+ this.title = options?.title;
19
19
  this.onSubmitHandler = options.onSubmit;
20
20
  this.onCancelHandler = options.onCancel;
21
21
  this.formVc = this.FormVc();
@@ -27,8 +27,7 @@ class EditTimeBlockTitleCardViewController extends heartwood_view_controllers_1.
27
27
  schema,
28
28
  shouldShowCancelButton: false,
29
29
  onSubmit: ({ values }) => {
30
- var _a;
31
- this.onSubmitHandler((_a = values.title) !== null && _a !== void 0 ? _a : undefined);
30
+ this.onSubmitHandler(values.title ?? undefined);
32
31
  },
33
32
  onCancel: () => {
34
33
  this.onCancelHandler();
@@ -21,7 +21,6 @@ class AbstractCapabilityCardViewController extends heartwood_view_controllers_1.
21
21
  }));
22
22
  }
23
23
  renderRow(service) {
24
- var _a, _b, _c;
25
24
  const serviceCapability = this.getCapabilityForService(service.id);
26
25
  const rowId = service.id;
27
26
  return {
@@ -29,12 +28,12 @@ class AbstractCapabilityCardViewController extends heartwood_view_controllers_1.
29
28
  onClick: async () => {
30
29
  await this.handleClickRow(service);
31
30
  },
32
- isEnabled: (_a = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.isEnabled) !== null && _a !== void 0 ? _a : false,
31
+ isEnabled: serviceCapability?.isEnabled ?? false,
33
32
  cells: [
34
33
  {
35
34
  checkboxInput: {
36
35
  name: 'isEnabled',
37
- value: (_b = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.isEnabled) !== null && _b !== void 0 ? _b : false,
36
+ value: serviceCapability?.isEnabled ?? false,
38
37
  onChange: async (value) => {
39
38
  await this.handleClickCheckbox(service, value);
40
39
  },
@@ -51,7 +50,7 @@ class AbstractCapabilityCardViewController extends heartwood_view_controllers_1.
51
50
  {
52
51
  toggleInput: {
53
52
  name: 'doesOffer',
54
- value: (_c = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.doesOffer) !== null && _c !== void 0 ? _c : false,
53
+ value: serviceCapability?.doesOffer ?? false,
55
54
  onChange: async (value) => {
56
55
  await this.handleToggleDoesOffer(service, value);
57
56
  },
@@ -61,23 +60,20 @@ class AbstractCapabilityCardViewController extends heartwood_view_controllers_1.
61
60
  };
62
61
  }
63
62
  renderPrice(service, capability) {
64
- var _a, _b;
65
63
  let price = '';
66
- if (service.price || !(capability === null || capability === void 0 ? void 0 : capability.price)) {
67
- price = `$${(_a = capability === null || capability === void 0 ? void 0 : capability.price) !== null && _a !== void 0 ? _a : service.price} - `;
64
+ if (service.price || !capability?.price) {
65
+ price = `$${capability?.price ?? service.price} - `;
68
66
  }
69
- return `${price}${this.calculateDuration((_b = capability === null || capability === void 0 ? void 0 : capability.timeBlocks) !== null && _b !== void 0 ? _b : service.timeBlocks)}`;
67
+ return `${price}${this.calculateDuration(capability?.timeBlocks ?? service.timeBlocks)}`;
70
68
  }
71
69
  getCapabilityForService(id) {
72
- var _a;
73
- return (_a = this.capabilities) === null || _a === void 0 ? void 0 : _a.find((r) => r.serviceId === id);
70
+ return this.capabilities?.find((r) => r.serviceId === id);
74
71
  }
75
72
  async handleClickCheckbox(service, value) {
76
73
  this.getListVc().getRowVc(service.id).setIsEnabled(value);
77
- await this.handleToggleEnableCapability(service, value !== null && value !== void 0 ? value : false);
74
+ await this.handleToggleEnableCapability(service, value ?? false);
78
75
  }
79
76
  async handleClickRow(service) {
80
- var _a;
81
77
  const serviceRoleCapability = this.getCapabilityForService(service.id);
82
78
  this.editVc = this.Controller('appointments.edit-override-details-card', {
83
79
  onCancel: () => { },
@@ -91,23 +87,28 @@ class AbstractCapabilityCardViewController extends heartwood_view_controllers_1.
91
87
  service,
92
88
  serviceRoleCapability,
93
89
  });
94
- const dlgVc = this.renderInDialog(Object.assign({}, this.editVc.render()));
95
- return (_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this, service);
90
+ const dlgVc = this.renderInDialog({
91
+ ...this.editVc.render(),
92
+ });
93
+ return this.onEdit?.(service);
96
94
  }
97
95
  upsertCapabilities(newServiceCapability, service) {
98
- var _a, _b;
99
96
  const listVc = this.activeRecordCardVc;
100
97
  if (newServiceCapability) {
101
- const oldCapability = (_a = this.capabilities) === null || _a === void 0 ? void 0 : _a.find((r) => r.id === newServiceCapability.id);
102
- this.capabilities = (_b = this.capabilities) === null || _b === void 0 ? void 0 : _b.filter((r) => r.id !== newServiceCapability.id);
98
+ const oldCapability = this.capabilities?.find((r) => r.id === newServiceCapability.id);
99
+ this.capabilities = this.capabilities?.filter((r) => r.id !== newServiceCapability.id);
103
100
  const rowId = service.id;
104
- this.capabilities.push(Object.assign(Object.assign({}, oldCapability), newServiceCapability));
105
- listVc.upsertRow(rowId, Object.assign({}, this.renderRow(service)));
101
+ this.capabilities.push({
102
+ ...oldCapability,
103
+ ...newServiceCapability,
104
+ });
105
+ listVc.upsertRow(rowId, {
106
+ ...this.renderRow(service),
107
+ });
106
108
  }
107
109
  }
108
110
  async handleToggleDoesOffer(service, doesOffer) {
109
- var _a;
110
- (_a = this.toggleDoesOfferHandler) === null || _a === void 0 ? void 0 : _a.call(this, service.id, doesOffer);
111
+ this.toggleDoesOfferHandler?.(service.id, doesOffer);
111
112
  await this.updateCapabilityForService(service, { doesOffer });
112
113
  }
113
114
  async updateCapabilityForService(service, changes) {
@@ -159,8 +160,7 @@ class AbstractCapabilityCardViewController extends heartwood_view_controllers_1.
159
160
  return this.capabilities;
160
161
  }
161
162
  getLocationId() {
162
- var _a;
163
- return (_a = this.locationId) !== null && _a !== void 0 ? _a : 'no location id';
163
+ return this.locationId ?? 'no location id';
164
164
  }
165
165
  render() {
166
166
  return this.activeRecordCardVc.render();
@@ -17,15 +17,14 @@ class RolesCardViewController extends AbstractCapabilityCardViewController_1.def
17
17
  this.role = role;
18
18
  this.toggleDoesOfferHandler = options.onUpdateHasCapability;
19
19
  this.onInsertOrUpdateCapability = options.onInsertOrUpdateCapability;
20
- this.onEdit = options === null || options === void 0 ? void 0 : options.onEdit;
20
+ this.onEdit = options?.onEdit;
21
21
  this.activeRecordCardVc = this.ActiveRecordCard({
22
22
  id: (0, spruce_skill_utils_1.slug)(role.name),
23
23
  name: role.name,
24
24
  });
25
25
  }
26
26
  async load(options) {
27
- var _a;
28
- await this.loadVc((_a = options.organizationId) !== null && _a !== void 0 ? _a : 'missing-org');
27
+ await this.loadVc(options.organizationId ?? 'missing-org');
29
28
  }
30
29
  async loadCapabilities() {
31
30
  const client = await this.connectToApi();
@@ -39,7 +38,11 @@ class RolesCardViewController extends AbstractCapabilityCardViewController_1.def
39
38
  this.capabilities = capabilities;
40
39
  }
41
40
  async insertOrUpdateCapability(serviceId, values, serviceCapability) {
42
- return await this.onInsertOrUpdateCapability(Object.assign(Object.assign({}, values), { serviceId, id: serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.id }));
41
+ return await this.onInsertOrUpdateCapability({
42
+ ...values,
43
+ serviceId,
44
+ id: serviceCapability?.id,
45
+ });
43
46
  }
44
47
  getCapabilities() {
45
48
  return this.capabilities;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-appointment-utils",
3
3
  "description": "Utils for working with appointments and Sprucebot.",
4
- "version": "14.0.147",
4
+ "version": "14.0.149",
5
5
  "skill": {
6
6
  "namespace": "appointments"
7
7
  },