@sprucelabs/spruce-appointment-utils 6.0.1 → 6.1.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.
- package/build/esm/viewControllers/AbstractCapabilityCardViewController.js +9 -6
- package/build/esm/viewControllers/EditOverrideDetailsCard.vc.js +9 -3
- package/build/esm/viewControllers/EditTimeBlockTitleCard.vc.js +3 -1
- package/build/esm/viewControllers/RolesCard.vc.d.ts +2 -0
- package/build/esm/viewControllers/RolesCard.vc.js +44 -29
- package/build/viewControllers/AbstractCapabilityCardViewController.js +9 -6
- package/build/viewControllers/EditOverrideDetailsCard.vc.js +9 -3
- package/build/viewControllers/EditTimeBlockTitleCard.vc.js +3 -1
- package/build/viewControllers/RolesCard.vc.d.ts +2 -0
- package/build/viewControllers/RolesCard.vc.js +44 -29
- package/package.json +1 -1
|
@@ -31,8 +31,9 @@ export default class AbstractCapabilityCardViewController extends AbstractViewCo
|
|
|
31
31
|
buildRow(service) {
|
|
32
32
|
var _a, _b, _c, _d, _e, _f;
|
|
33
33
|
const serviceCapability = (_a = this.capabilities) === null || _a === void 0 ? void 0 : _a.find((r) => r.serviceId === service.id);
|
|
34
|
+
const rowId = service.id;
|
|
34
35
|
return {
|
|
35
|
-
id:
|
|
36
|
+
id: rowId,
|
|
36
37
|
onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
37
38
|
yield this.handleEdit(service, serviceCapability);
|
|
38
39
|
}),
|
|
@@ -74,7 +75,7 @@ export default class AbstractCapabilityCardViewController extends AbstractViewCo
|
|
|
74
75
|
onCancel: () => { },
|
|
75
76
|
onSubmit: (price, timeBlocks, serviceRow, serviceRoleCapability) => __awaiter(this, void 0, void 0, function* () {
|
|
76
77
|
yield dlgVc.hide();
|
|
77
|
-
const newServiceCapability = yield this.insertOrUpdateCapability(serviceRow.id, { price, timeBlocks, isEnabled: true }, serviceRoleCapability);
|
|
78
|
+
const newServiceCapability = yield this.insertOrUpdateCapability(serviceRow.id, { price, timeBlocks, isEnabled: true, doesOffer: true }, serviceRoleCapability);
|
|
78
79
|
if (newServiceCapability) {
|
|
79
80
|
this.upsertCapabilities(newServiceCapability, serviceRow);
|
|
80
81
|
}
|
|
@@ -87,12 +88,14 @@ export default class AbstractCapabilityCardViewController extends AbstractViewCo
|
|
|
87
88
|
});
|
|
88
89
|
}
|
|
89
90
|
upsertCapabilities(newServiceCapability, service) {
|
|
90
|
-
var _a;
|
|
91
|
+
var _a, _b;
|
|
91
92
|
const listVc = this.getListVc();
|
|
92
93
|
if (newServiceCapability) {
|
|
93
|
-
|
|
94
|
-
this.capabilities.
|
|
95
|
-
|
|
94
|
+
const oldCapability = (_a = this.capabilities) === null || _a === void 0 ? void 0 : _a.find((r) => r.id === newServiceCapability.id);
|
|
95
|
+
this.capabilities = (_b = this.capabilities) === null || _b === void 0 ? void 0 : _b.filter((r) => r.id !== newServiceCapability.id);
|
|
96
|
+
const rowId = service.id;
|
|
97
|
+
this.capabilities.push(Object.assign(Object.assign({}, oldCapability), newServiceCapability));
|
|
98
|
+
listVc.upsertRow(rowId, Object.assign({}, this.buildRow(service)));
|
|
96
99
|
listVc.triggerRender();
|
|
97
100
|
this.getActiveRecordVc().triggerRender();
|
|
98
101
|
}
|
|
@@ -34,7 +34,7 @@ export default class EditOverrideDetailsCardViewController extends AbstractViewC
|
|
|
34
34
|
this.cardVc = this.CardVc();
|
|
35
35
|
}
|
|
36
36
|
FormVc() {
|
|
37
|
-
var _a, _b
|
|
37
|
+
var _a, _b;
|
|
38
38
|
return this.Controller('form', buildForm({
|
|
39
39
|
id: 'editOverrideForm',
|
|
40
40
|
schema,
|
|
@@ -48,7 +48,13 @@ export default class EditOverrideDetailsCardViewController extends AbstractViewC
|
|
|
48
48
|
},
|
|
49
49
|
sections: [
|
|
50
50
|
{
|
|
51
|
-
fields: [
|
|
51
|
+
fields: [
|
|
52
|
+
{
|
|
53
|
+
name: 'price',
|
|
54
|
+
label: 'Price',
|
|
55
|
+
placeholder: (_a = this.service) === null || _a === void 0 ? void 0 : _a.price,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
52
58
|
},
|
|
53
59
|
{
|
|
54
60
|
title: 'Duration',
|
|
@@ -67,7 +73,7 @@ export default class EditOverrideDetailsCardViewController extends AbstractViewC
|
|
|
67
73
|
],
|
|
68
74
|
},
|
|
69
75
|
values: {
|
|
70
|
-
price: (_b =
|
|
76
|
+
price: (_b = this.serviceRoleCapability) === null || _b === void 0 ? void 0 : _b.price,
|
|
71
77
|
},
|
|
72
78
|
}));
|
|
73
79
|
}
|
|
@@ -33,7 +33,9 @@ export default class EditTimeBlockTitleCardViewController extends AbstractViewCo
|
|
|
33
33
|
},
|
|
34
34
|
sections: [
|
|
35
35
|
{
|
|
36
|
-
fields: [
|
|
36
|
+
fields: [
|
|
37
|
+
{ name: 'title', label: 'Title', placeholder: 'Duration' },
|
|
38
|
+
],
|
|
37
39
|
},
|
|
38
40
|
],
|
|
39
41
|
values: { title: this.title },
|
|
@@ -4,12 +4,14 @@ declare type Role = SpruceSchemas.Spruce.v2020_07_22.Role;
|
|
|
4
4
|
declare type ToggleHandler = (serviceId: string, isSelected: boolean) => void;
|
|
5
5
|
export declare type RolesCardViewControllerOptions = ViewControllerOptions & {
|
|
6
6
|
role: Role;
|
|
7
|
+
onInsertOrUpdateCapability: (values: any) => void;
|
|
7
8
|
onUpdateHasCapability?: ToggleHandler;
|
|
8
9
|
onEdit?: (row: any) => void;
|
|
9
10
|
};
|
|
10
11
|
export default class RolesCardViewController extends AbstractCapabilityCardViewController {
|
|
11
12
|
static id: string;
|
|
12
13
|
protected role: Role;
|
|
14
|
+
protected onInsertOrUpdateCapability: any;
|
|
13
15
|
constructor(options: RolesCardViewControllerOptions);
|
|
14
16
|
load(options: {
|
|
15
17
|
organizationId?: string;
|
|
@@ -7,14 +7,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { assertOptions } from '@sprucelabs/schema';
|
|
10
11
|
import { eventResponseUtil } from '@sprucelabs/spruce-event-utils';
|
|
11
12
|
import AbstractCapabilityCardViewController from './AbstractCapabilityCardViewController.js';
|
|
12
13
|
export default class RolesCardViewController extends AbstractCapabilityCardViewController {
|
|
13
14
|
constructor(options) {
|
|
14
15
|
super(options);
|
|
16
|
+
assertOptions(options, ['role', 'onInsertOrUpdateCapability']);
|
|
15
17
|
this.role = options.role;
|
|
16
18
|
this.onUpdateHasCapability = options.onUpdateHasCapability;
|
|
17
|
-
this.
|
|
19
|
+
this.onInsertOrUpdateCapability = options.onInsertOrUpdateCapability;
|
|
20
|
+
this.onEdit = options === null || options === void 0 ? void 0 : options.onEdit;
|
|
18
21
|
this.activeRecordCardVc = this.ActiveRecordCard(options.role);
|
|
19
22
|
}
|
|
20
23
|
load(options) {
|
|
@@ -37,35 +40,47 @@ export default class RolesCardViewController extends AbstractCapabilityCardViewC
|
|
|
37
40
|
});
|
|
38
41
|
}
|
|
39
42
|
insertOrUpdateCapability(serviceId, values, serviceCapability) {
|
|
40
|
-
var _a, _b;
|
|
41
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
44
|
+
return yield this.onInsertOrUpdateCapability(Object.assign(Object.assign({}, values), { serviceId, id: serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.id }));
|
|
45
|
+
// else {
|
|
46
|
+
// try {
|
|
47
|
+
// if (serviceCapability) {
|
|
48
|
+
// const [{ capability }] = await client.emitAndFlattenResponses(
|
|
49
|
+
// 'appointments.update-role-capability::v2021_06_23',
|
|
50
|
+
// {
|
|
51
|
+
// target: {
|
|
52
|
+
// organizationId: this.organizationId ?? 'org id',
|
|
53
|
+
// capabilityId: serviceCapability.id,
|
|
54
|
+
// },
|
|
55
|
+
// payload: {
|
|
56
|
+
// ...values,
|
|
57
|
+
// },
|
|
58
|
+
// }
|
|
59
|
+
// )
|
|
60
|
+
// return capability
|
|
61
|
+
// } else {
|
|
62
|
+
// const [{ capability }] = await client.emitAndFlattenResponses(
|
|
63
|
+
// 'appointments.create-role-capability::v2021_06_23',
|
|
64
|
+
// {
|
|
65
|
+
// target: {
|
|
66
|
+
// organizationId: this.organizationId ?? 'org id',
|
|
67
|
+
// roleId: this.role.id,
|
|
68
|
+
// },
|
|
69
|
+
// payload: {
|
|
70
|
+
// serviceId,
|
|
71
|
+
// doesOffer: true,
|
|
72
|
+
// isEnabled: true,
|
|
73
|
+
// ...values,
|
|
74
|
+
// },
|
|
75
|
+
// }
|
|
76
|
+
// )
|
|
77
|
+
// return capability
|
|
78
|
+
// }
|
|
79
|
+
// } catch (err: any) {
|
|
80
|
+
// await this.alert({ message: err.message })
|
|
81
|
+
// }
|
|
82
|
+
// }
|
|
83
|
+
//return
|
|
69
84
|
});
|
|
70
85
|
}
|
|
71
86
|
getCapabilities() {
|
|
@@ -24,8 +24,9 @@ class AbstractCapabilityCardViewController extends heartwood_view_controllers_1.
|
|
|
24
24
|
buildRow(service) {
|
|
25
25
|
var _a, _b, _c, _d, _e, _f;
|
|
26
26
|
const serviceCapability = (_a = this.capabilities) === null || _a === void 0 ? void 0 : _a.find((r) => r.serviceId === service.id);
|
|
27
|
+
const rowId = service.id;
|
|
27
28
|
return {
|
|
28
|
-
id:
|
|
29
|
+
id: rowId,
|
|
29
30
|
onClick: async () => {
|
|
30
31
|
await this.handleEdit(service, serviceCapability);
|
|
31
32
|
},
|
|
@@ -66,7 +67,7 @@ class AbstractCapabilityCardViewController extends heartwood_view_controllers_1.
|
|
|
66
67
|
onCancel: () => { },
|
|
67
68
|
onSubmit: async (price, timeBlocks, serviceRow, serviceRoleCapability) => {
|
|
68
69
|
await dlgVc.hide();
|
|
69
|
-
const newServiceCapability = await this.insertOrUpdateCapability(serviceRow.id, { price, timeBlocks, isEnabled: true }, serviceRoleCapability);
|
|
70
|
+
const newServiceCapability = await this.insertOrUpdateCapability(serviceRow.id, { price, timeBlocks, isEnabled: true, doesOffer: true }, serviceRoleCapability);
|
|
70
71
|
if (newServiceCapability) {
|
|
71
72
|
this.upsertCapabilities(newServiceCapability, serviceRow);
|
|
72
73
|
}
|
|
@@ -78,12 +79,14 @@ class AbstractCapabilityCardViewController extends heartwood_view_controllers_1.
|
|
|
78
79
|
return (_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this, serviceRow);
|
|
79
80
|
}
|
|
80
81
|
upsertCapabilities(newServiceCapability, service) {
|
|
81
|
-
var _a;
|
|
82
|
+
var _a, _b;
|
|
82
83
|
const listVc = this.getListVc();
|
|
83
84
|
if (newServiceCapability) {
|
|
84
|
-
|
|
85
|
-
this.capabilities.
|
|
86
|
-
|
|
85
|
+
const oldCapability = (_a = this.capabilities) === null || _a === void 0 ? void 0 : _a.find((r) => r.id === newServiceCapability.id);
|
|
86
|
+
this.capabilities = (_b = this.capabilities) === null || _b === void 0 ? void 0 : _b.filter((r) => r.id !== newServiceCapability.id);
|
|
87
|
+
const rowId = service.id;
|
|
88
|
+
this.capabilities.push(Object.assign(Object.assign({}, oldCapability), newServiceCapability));
|
|
89
|
+
listVc.upsertRow(rowId, Object.assign({}, this.buildRow(service)));
|
|
87
90
|
listVc.triggerRender();
|
|
88
91
|
this.getActiveRecordVc().triggerRender();
|
|
89
92
|
}
|
|
@@ -27,7 +27,7 @@ class EditOverrideDetailsCardViewController extends heartwood_view_controllers_1
|
|
|
27
27
|
this.cardVc = this.CardVc();
|
|
28
28
|
}
|
|
29
29
|
FormVc() {
|
|
30
|
-
var _a, _b
|
|
30
|
+
var _a, _b;
|
|
31
31
|
return this.Controller('form', (0, heartwood_view_controllers_1.buildForm)({
|
|
32
32
|
id: 'editOverrideForm',
|
|
33
33
|
schema,
|
|
@@ -41,7 +41,13 @@ class EditOverrideDetailsCardViewController extends heartwood_view_controllers_1
|
|
|
41
41
|
},
|
|
42
42
|
sections: [
|
|
43
43
|
{
|
|
44
|
-
fields: [
|
|
44
|
+
fields: [
|
|
45
|
+
{
|
|
46
|
+
name: 'price',
|
|
47
|
+
label: 'Price',
|
|
48
|
+
placeholder: (_a = this.service) === null || _a === void 0 ? void 0 : _a.price,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
45
51
|
},
|
|
46
52
|
{
|
|
47
53
|
title: 'Duration',
|
|
@@ -60,7 +66,7 @@ class EditOverrideDetailsCardViewController extends heartwood_view_controllers_1
|
|
|
60
66
|
],
|
|
61
67
|
},
|
|
62
68
|
values: {
|
|
63
|
-
price: (_b =
|
|
69
|
+
price: (_b = this.serviceRoleCapability) === null || _b === void 0 ? void 0 : _b.price,
|
|
64
70
|
},
|
|
65
71
|
}));
|
|
66
72
|
}
|
|
@@ -35,7 +35,9 @@ class EditTimeBlockTitleCardViewController extends heartwood_view_controllers_1.
|
|
|
35
35
|
},
|
|
36
36
|
sections: [
|
|
37
37
|
{
|
|
38
|
-
fields: [
|
|
38
|
+
fields: [
|
|
39
|
+
{ name: 'title', label: 'Title', placeholder: 'Duration' },
|
|
40
|
+
],
|
|
39
41
|
},
|
|
40
42
|
],
|
|
41
43
|
values: { title: this.title },
|
|
@@ -4,12 +4,14 @@ declare type Role = SpruceSchemas.Spruce.v2020_07_22.Role;
|
|
|
4
4
|
declare type ToggleHandler = (serviceId: string, isSelected: boolean) => void;
|
|
5
5
|
export declare type RolesCardViewControllerOptions = ViewControllerOptions & {
|
|
6
6
|
role: Role;
|
|
7
|
+
onInsertOrUpdateCapability: (values: any) => void;
|
|
7
8
|
onUpdateHasCapability?: ToggleHandler;
|
|
8
9
|
onEdit?: (row: any) => void;
|
|
9
10
|
};
|
|
10
11
|
export default class RolesCardViewController extends AbstractCapabilityCardViewController {
|
|
11
12
|
static id: string;
|
|
12
13
|
protected role: Role;
|
|
14
|
+
protected onInsertOrUpdateCapability: any;
|
|
13
15
|
constructor(options: RolesCardViewControllerOptions);
|
|
14
16
|
load(options: {
|
|
15
17
|
organizationId?: string;
|
|
@@ -3,14 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const schema_1 = require("@sprucelabs/schema");
|
|
6
7
|
const spruce_event_utils_1 = require("@sprucelabs/spruce-event-utils");
|
|
7
8
|
const AbstractCapabilityCardViewController_1 = __importDefault(require("./AbstractCapabilityCardViewController"));
|
|
8
9
|
class RolesCardViewController extends AbstractCapabilityCardViewController_1.default {
|
|
9
10
|
constructor(options) {
|
|
10
11
|
super(options);
|
|
12
|
+
(0, schema_1.assertOptions)(options, ['role', 'onInsertOrUpdateCapability']);
|
|
11
13
|
this.role = options.role;
|
|
12
14
|
this.onUpdateHasCapability = options.onUpdateHasCapability;
|
|
13
|
-
this.
|
|
15
|
+
this.onInsertOrUpdateCapability = options.onInsertOrUpdateCapability;
|
|
16
|
+
this.onEdit = options === null || options === void 0 ? void 0 : options.onEdit;
|
|
14
17
|
this.activeRecordCardVc = this.ActiveRecordCard(options.role);
|
|
15
18
|
}
|
|
16
19
|
async load(options) {
|
|
@@ -29,34 +32,46 @@ class RolesCardViewController extends AbstractCapabilityCardViewController_1.def
|
|
|
29
32
|
this.capabilities = capabilities;
|
|
30
33
|
}
|
|
31
34
|
async insertOrUpdateCapability(serviceId, values, serviceCapability) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
35
|
+
return await this.onInsertOrUpdateCapability(Object.assign(Object.assign({}, values), { serviceId, id: serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.id }));
|
|
36
|
+
// else {
|
|
37
|
+
// try {
|
|
38
|
+
// if (serviceCapability) {
|
|
39
|
+
// const [{ capability }] = await client.emitAndFlattenResponses(
|
|
40
|
+
// 'appointments.update-role-capability::v2021_06_23',
|
|
41
|
+
// {
|
|
42
|
+
// target: {
|
|
43
|
+
// organizationId: this.organizationId ?? 'org id',
|
|
44
|
+
// capabilityId: serviceCapability.id,
|
|
45
|
+
// },
|
|
46
|
+
// payload: {
|
|
47
|
+
// ...values,
|
|
48
|
+
// },
|
|
49
|
+
// }
|
|
50
|
+
// )
|
|
51
|
+
// return capability
|
|
52
|
+
// } else {
|
|
53
|
+
// const [{ capability }] = await client.emitAndFlattenResponses(
|
|
54
|
+
// 'appointments.create-role-capability::v2021_06_23',
|
|
55
|
+
// {
|
|
56
|
+
// target: {
|
|
57
|
+
// organizationId: this.organizationId ?? 'org id',
|
|
58
|
+
// roleId: this.role.id,
|
|
59
|
+
// },
|
|
60
|
+
// payload: {
|
|
61
|
+
// serviceId,
|
|
62
|
+
// doesOffer: true,
|
|
63
|
+
// isEnabled: true,
|
|
64
|
+
// ...values,
|
|
65
|
+
// },
|
|
66
|
+
// }
|
|
67
|
+
// )
|
|
68
|
+
// return capability
|
|
69
|
+
// }
|
|
70
|
+
// } catch (err: any) {
|
|
71
|
+
// await this.alert({ message: err.message })
|
|
72
|
+
// }
|
|
73
|
+
// }
|
|
74
|
+
//return
|
|
60
75
|
}
|
|
61
76
|
getCapabilities() {
|
|
62
77
|
return this.capabilities;
|