@sprucelabs/spruce-appointment-utils 5.1.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.
Files changed (34) hide show
  1. package/README.md +5 -0
  2. package/build/esm/index-module.d.ts +7 -0
  3. package/build/esm/index-module.js +7 -0
  4. package/build/esm/types-module.d.ts +21 -0
  5. package/build/esm/types-module.js +1 -0
  6. package/build/esm/viewControllers/AbstractCapabilityCardViewController.d.ts +32 -0
  7. package/build/esm/viewControllers/AbstractCapabilityCardViewController.js +143 -0
  8. package/build/esm/viewControllers/DurationCard.vc.d.ts +33 -0
  9. package/build/esm/viewControllers/DurationCard.vc.js +75 -0
  10. package/build/esm/viewControllers/DurationList.vc.d.ts +37 -0
  11. package/build/esm/viewControllers/DurationList.vc.js +188 -0
  12. package/build/esm/viewControllers/EditOverrideDetailsCard.vc.d.ts +44 -0
  13. package/build/esm/viewControllers/EditOverrideDetailsCard.vc.js +98 -0
  14. package/build/esm/viewControllers/EditTimeBlockTitleCard.vc.d.ts +33 -0
  15. package/build/esm/viewControllers/EditTimeBlockTitleCard.vc.js +69 -0
  16. package/build/esm/viewControllers/RolesCard.vc.d.ts +22 -0
  17. package/build/esm/viewControllers/RolesCard.vc.js +75 -0
  18. package/build/index-module.d.ts +7 -0
  19. package/build/index-module.js +29 -0
  20. package/build/types-module.d.ts +21 -0
  21. package/build/types-module.js +2 -0
  22. package/build/viewControllers/AbstractCapabilityCardViewController.d.ts +32 -0
  23. package/build/viewControllers/AbstractCapabilityCardViewController.js +131 -0
  24. package/build/viewControllers/DurationCard.vc.d.ts +33 -0
  25. package/build/viewControllers/DurationCard.vc.js +69 -0
  26. package/build/viewControllers/DurationList.vc.d.ts +37 -0
  27. package/build/viewControllers/DurationList.vc.js +178 -0
  28. package/build/viewControllers/EditOverrideDetailsCard.vc.d.ts +44 -0
  29. package/build/viewControllers/EditOverrideDetailsCard.vc.js +92 -0
  30. package/build/viewControllers/EditTimeBlockTitleCard.vc.d.ts +33 -0
  31. package/build/viewControllers/EditTimeBlockTitleCard.vc.js +72 -0
  32. package/build/viewControllers/RolesCard.vc.d.ts +22 -0
  33. package/build/viewControllers/RolesCard.vc.js +66 -0
  34. package/package.json +64 -0
@@ -0,0 +1,98 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { AbstractViewController, buildForm, } from '@sprucelabs/heartwood-view-controllers';
11
+ import { assertOptions, buildSchema } from '@sprucelabs/schema';
12
+ const schema = buildSchema({
13
+ id: 'priceSchema',
14
+ fields: {
15
+ price: {
16
+ type: 'text',
17
+ label: 'Price',
18
+ },
19
+ },
20
+ });
21
+ export default class EditOverrideDetailsCardViewController extends AbstractViewController {
22
+ constructor(options) {
23
+ var _a, _b, _c;
24
+ super(options);
25
+ assertOptions(options, ['onCancel', 'onSubmit']);
26
+ this.service = options === null || options === void 0 ? void 0 : options.service;
27
+ this.serviceRoleCapability = options === null || options === void 0 ? void 0 : options.serviceRoleCapability;
28
+ this.onSubmitHandler = options.onSubmit;
29
+ this.onCancelHandler = options.onCancel;
30
+ this.durationVc = this.Controller('appointments.duration-card', {});
31
+ void this.durationVc.load((_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);
32
+ this.durationListVc = this.durationVc.getDurationListVc();
33
+ this.formVc = this.FormVc();
34
+ this.cardVc = this.CardVc();
35
+ }
36
+ FormVc() {
37
+ var _a, _b, _c;
38
+ return this.Controller('form', buildForm({
39
+ id: 'editOverrideForm',
40
+ schema,
41
+ shouldShowCancelButton: false,
42
+ onSubmit: ({ values }) => {
43
+ var _a;
44
+ this.onSubmitHandler((_a = values.price) !== null && _a !== void 0 ? _a : undefined, this.getDurationVc().getTimeBlocks(), this.service, this.serviceRoleCapability);
45
+ },
46
+ onCancel: () => {
47
+ this.onCancelHandler();
48
+ },
49
+ sections: [
50
+ {
51
+ fields: ['price'],
52
+ },
53
+ {
54
+ title: 'Duration',
55
+ list: this.durationVc.getDurationListVc().render(),
56
+ },
57
+ ],
58
+ footer: {
59
+ buttons: [
60
+ {
61
+ id: 'addDuration',
62
+ label: 'Add block of time',
63
+ onClick: () => __awaiter(this, void 0, void 0, function* () {
64
+ this.handleClickAddTimeBlock();
65
+ }),
66
+ },
67
+ ],
68
+ },
69
+ values: {
70
+ price: (_b = (_a = this.serviceRoleCapability) === null || _a === void 0 ? void 0 : _a.price) !== null && _b !== void 0 ? _b : (_c = this.service) === null || _c === void 0 ? void 0 : _c.price,
71
+ },
72
+ }));
73
+ }
74
+ handleClickAddTimeBlock() {
75
+ this.durationListVc.addNewTimeBlock();
76
+ }
77
+ CardVc() {
78
+ return this.Controller('card', {
79
+ header: {
80
+ title: 'Overrides',
81
+ subtitle: `You can set a custom price and duration for this service!`,
82
+ },
83
+ body: {
84
+ sections: [{ form: this.formVc.render() }],
85
+ },
86
+ });
87
+ }
88
+ getFormVc() {
89
+ return this.formVc;
90
+ }
91
+ getDurationVc() {
92
+ return this.durationVc;
93
+ }
94
+ render() {
95
+ return this.cardVc.render();
96
+ }
97
+ }
98
+ EditOverrideDetailsCardViewController.id = 'edit-override-details-card';
@@ -0,0 +1,33 @@
1
+ import { AbstractViewController, FormViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
2
+ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
3
+ declare const schema: {
4
+ id: string;
5
+ fields: {
6
+ title: {
7
+ type: "text";
8
+ label: string;
9
+ };
10
+ };
11
+ };
12
+ declare type Schema = typeof schema;
13
+ export declare type FormVc = FormViewController<Schema>;
14
+ interface EditTimeBlockOptions {
15
+ title?: string;
16
+ onCancel: () => void;
17
+ onSubmit: (title: string | undefined) => void;
18
+ }
19
+ export declare type EditTimeBlockTitleCardViewControllerOptions = ViewControllerOptions & EditTimeBlockOptions;
20
+ export default class EditTimeBlockTitleCardViewController extends AbstractViewController<Card> {
21
+ static id: string;
22
+ private cardVc;
23
+ private formVc;
24
+ private onSubmitHandler;
25
+ private onCancelHandler;
26
+ private title?;
27
+ constructor(options: EditTimeBlockTitleCardViewControllerOptions);
28
+ private FormVc;
29
+ private CardVc;
30
+ getFormVc(): FormVc;
31
+ render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
32
+ }
33
+ export {};
@@ -0,0 +1,69 @@
1
+ import { AbstractViewController, buildForm, } from '@sprucelabs/heartwood-view-controllers';
2
+ import { assertOptions, buildSchema } from '@sprucelabs/schema';
3
+ const schema = buildSchema({
4
+ id: 'titleSchema',
5
+ fields: {
6
+ title: {
7
+ type: 'text',
8
+ label: 'Name of timeblock',
9
+ },
10
+ },
11
+ });
12
+ export default class EditTimeBlockTitleCardViewController extends AbstractViewController {
13
+ constructor(options) {
14
+ super(options);
15
+ assertOptions(options, ['onCancel', 'onSubmit']);
16
+ this.title = options === null || options === void 0 ? void 0 : options.title;
17
+ this.onSubmitHandler = options.onSubmit;
18
+ this.onCancelHandler = options.onCancel;
19
+ this.formVc = this.FormVc();
20
+ this.cardVc = this.CardVc();
21
+ }
22
+ FormVc() {
23
+ return this.Controller('form', buildForm({
24
+ id: 'titleForm',
25
+ schema,
26
+ shouldShowCancelButton: false,
27
+ onSubmit: ({ values }) => {
28
+ var _a;
29
+ this.onSubmitHandler((_a = values.title) !== null && _a !== void 0 ? _a : undefined);
30
+ },
31
+ onCancel: () => {
32
+ this.onCancelHandler();
33
+ },
34
+ sections: [
35
+ {
36
+ fields: ['title'],
37
+ },
38
+ ],
39
+ values: { title: this.title },
40
+ }));
41
+ }
42
+ CardVc() {
43
+ return this.Controller('card', {
44
+ header: {
45
+ title: 'Name this block of time!',
46
+ subtitle: `You only need to think about this if a service takes more than one discrete chunk of time.`,
47
+ },
48
+ body: {
49
+ sections: [
50
+ {
51
+ text: {
52
+ content: 'Here we go!',
53
+ },
54
+ },
55
+ {
56
+ form: this.formVc.render(),
57
+ },
58
+ ],
59
+ },
60
+ });
61
+ }
62
+ getFormVc() {
63
+ return this.formVc;
64
+ }
65
+ render() {
66
+ return this.cardVc.render();
67
+ }
68
+ }
69
+ EditTimeBlockTitleCardViewController.id = 'edit-time-block-title-card';
@@ -0,0 +1,22 @@
1
+ import { SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
2
+ import AbstractCapabilityCardViewController from './AbstractCapabilityCardViewController';
3
+ declare type Role = SpruceSchemas.Spruce.v2020_07_22.Role;
4
+ declare type ToggleHandler = (serviceId: string, isSelected: boolean) => void;
5
+ export declare type RolesCardViewControllerOptions = ViewControllerOptions & {
6
+ role: Role;
7
+ onUpdateHasCapability?: ToggleHandler;
8
+ onEdit?: (row: any) => void;
9
+ };
10
+ export default class RolesCardViewController extends AbstractCapabilityCardViewController {
11
+ static id: string;
12
+ private role;
13
+ constructor(options: RolesCardViewControllerOptions);
14
+ load(options: {
15
+ organizationId?: string;
16
+ shouldIncludePrivateFields?: boolean;
17
+ }): Promise<void>;
18
+ protected loadCapabilities(): Promise<void>;
19
+ protected insertOrUpdateCapability(serviceId: string, values: any, serviceCapability: SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability | undefined): Promise<SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability | undefined>;
20
+ getCapabilities(): any[];
21
+ }
22
+ export {};
@@ -0,0 +1,75 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { eventResponseUtil } from '@sprucelabs/spruce-event-utils';
11
+ import AbstractCapabilityCardViewController from './AbstractCapabilityCardViewController.js';
12
+ export default class RolesCardViewController extends AbstractCapabilityCardViewController {
13
+ constructor(options) {
14
+ super(options);
15
+ this.role = options.role;
16
+ this.onUpdateHasCapability = options.onUpdateHasCapability;
17
+ this.onEdit = options.onEdit;
18
+ this.activeRecordCardVc = this.ActiveRecordCard(options.role);
19
+ }
20
+ load(options) {
21
+ var _a;
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ yield this.loadVc((_a = options.organizationId) !== null && _a !== void 0 ? _a : 'missing-org');
24
+ });
25
+ }
26
+ loadCapabilities() {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const client = yield this.connectToApi();
29
+ const results = yield client.emit('appointments.list-role-capabilities::v2021_06_23', {
30
+ target: {
31
+ organizationId: this.organizationId,
32
+ roleId: this.role.id,
33
+ },
34
+ });
35
+ const { capabilities } = eventResponseUtil.getFirstResponseOrThrow(results);
36
+ this.capabilities = capabilities;
37
+ });
38
+ }
39
+ insertOrUpdateCapability(serviceId, values, serviceCapability) {
40
+ var _a, _b;
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const client = yield this.connectToApi();
43
+ try {
44
+ if (serviceCapability) {
45
+ const [{ capability }] = yield client.emitAndFlattenResponses('appointments.update-role-capability::v2021_06_23', {
46
+ target: {
47
+ organizationId: (_a = this.organizationId) !== null && _a !== void 0 ? _a : 'org id',
48
+ capabilityId: serviceCapability.id,
49
+ },
50
+ payload: Object.assign({}, values),
51
+ });
52
+ return capability;
53
+ }
54
+ else {
55
+ const [{ capability }] = yield client.emitAndFlattenResponses('appointments.create-role-capability::v2021_06_23', {
56
+ target: {
57
+ organizationId: (_b = this.organizationId) !== null && _b !== void 0 ? _b : 'org id',
58
+ roleId: this.role.id,
59
+ },
60
+ payload: Object.assign({ serviceId, isEnabled: true }, values),
61
+ });
62
+ return capability;
63
+ }
64
+ }
65
+ catch (err) {
66
+ yield this.alert({ message: err.message });
67
+ }
68
+ return;
69
+ });
70
+ }
71
+ getCapabilities() {
72
+ return this.capabilities;
73
+ }
74
+ }
75
+ RolesCardViewController.id = 'roles-card';
@@ -0,0 +1,7 @@
1
+ export { default as AbstractCapabilityCardViewController } from './viewControllers/AbstractCapabilityCardViewController';
2
+ export { default as DurationCardViewController } from './viewControllers/DurationCard.vc';
3
+ export { default as DurationListViewController } from './viewControllers/DurationList.vc';
4
+ export { default as EditOverrideDetailsCardViewController } from './viewControllers/EditOverrideDetailsCard.vc';
5
+ export { default as EditTimeBlockTitleCardViewController } from './viewControllers/EditTimeBlockTitleCard.vc';
6
+ export { default as RolesCardViewController } from './viewControllers/RolesCard.vc';
7
+ export * from './types-module';
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.RolesCardViewController = exports.EditTimeBlockTitleCardViewController = exports.EditOverrideDetailsCardViewController = exports.DurationListViewController = exports.DurationCardViewController = exports.AbstractCapabilityCardViewController = void 0;
17
+ var AbstractCapabilityCardViewController_1 = require("./viewControllers/AbstractCapabilityCardViewController");
18
+ Object.defineProperty(exports, "AbstractCapabilityCardViewController", { enumerable: true, get: function () { return __importDefault(AbstractCapabilityCardViewController_1).default; } });
19
+ var DurationCard_vc_1 = require("./viewControllers/DurationCard.vc");
20
+ Object.defineProperty(exports, "DurationCardViewController", { enumerable: true, get: function () { return __importDefault(DurationCard_vc_1).default; } });
21
+ var DurationList_vc_1 = require("./viewControllers/DurationList.vc");
22
+ Object.defineProperty(exports, "DurationListViewController", { enumerable: true, get: function () { return __importDefault(DurationList_vc_1).default; } });
23
+ var EditOverrideDetailsCard_vc_1 = require("./viewControllers/EditOverrideDetailsCard.vc");
24
+ Object.defineProperty(exports, "EditOverrideDetailsCardViewController", { enumerable: true, get: function () { return __importDefault(EditOverrideDetailsCard_vc_1).default; } });
25
+ var EditTimeBlockTitleCard_vc_1 = require("./viewControllers/EditTimeBlockTitleCard.vc");
26
+ Object.defineProperty(exports, "EditTimeBlockTitleCardViewController", { enumerable: true, get: function () { return __importDefault(EditTimeBlockTitleCard_vc_1).default; } });
27
+ var RolesCard_vc_1 = require("./viewControllers/RolesCard.vc");
28
+ Object.defineProperty(exports, "RolesCardViewController", { enumerable: true, get: function () { return __importDefault(RolesCard_vc_1).default; } });
29
+ __exportStar(require("./types-module"), exports);
@@ -0,0 +1,21 @@
1
+ import DurationCardViewController, { DurationCardViewControllerOptions } from './viewControllers/DurationCard.vc';
2
+ import DurationListViewController, { DurationListViewControllerOptions } from './viewControllers/DurationList.vc';
3
+ import EditOverrideDetailsCardViewController, { EditOverrideDetailsCardViewControllerOptions } from './viewControllers/EditOverrideDetailsCard.vc';
4
+ import EditTimeBlockTitleCardViewController, { EditTimeBlockTitleCardViewControllerOptions } from './viewControllers/EditTimeBlockTitleCard.vc';
5
+ import RolesCardViewController, { RolesCardViewControllerOptions } from './viewControllers/RolesCard.vc';
6
+ declare module '@sprucelabs/heartwood-view-controllers/build/types/heartwood.types' {
7
+ interface ViewControllerMap {
8
+ durationCard: DurationCardViewController;
9
+ durationList: DurationListViewController;
10
+ editOverrideDetailsCard: EditOverrideDetailsCardViewController;
11
+ editTimeBlockTitleCard: EditTimeBlockTitleCardViewController;
12
+ rolesCard: RolesCardViewController;
13
+ }
14
+ interface ViewControllerOptionsMap {
15
+ durationCard: DurationCardViewControllerOptions;
16
+ durationList: DurationListViewControllerOptions;
17
+ editOverrideDetailsCard: EditOverrideDetailsCardViewControllerOptions;
18
+ editTimeBlockTitleCard: EditTimeBlockTitleCardViewControllerOptions;
19
+ rolesCard: RolesCardViewControllerOptions;
20
+ }
21
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,32 @@
1
+ import { AbstractViewController, ActiveRecordCardViewController, SpruceSchemas } from '@sprucelabs/heartwood-view-controllers';
2
+ import EditOverrideDetailsCardViewController from './EditOverrideDetailsCard.vc';
3
+ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
4
+ declare type ToggleHandler = (serviceId: string, isSelected: boolean) => void;
5
+ declare type Service = SpruceSchemas.Appointments.v2021_06_23.ListService;
6
+ export default abstract class AbstractCapabilityCardViewController extends AbstractViewController<Card> {
7
+ protected activeRecordCardVc: ActiveRecordCardViewController;
8
+ protected onUpdateHasCapability?: ToggleHandler;
9
+ protected onEdit?: (row: any) => void;
10
+ protected capabilities: any[];
11
+ protected locationId?: string;
12
+ protected organizationId?: string;
13
+ protected editVc?: EditOverrideDetailsCardViewController;
14
+ protected abstract insertOrUpdateCapability(serviceId: string, values: any, capability: SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability | undefined): Promise<SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability | undefined>;
15
+ protected abstract loadCapabilities(): Promise<any>;
16
+ ActiveRecordCard(row: any): ActiveRecordCardViewController;
17
+ protected buildRow(service: Service): any;
18
+ private handleEdit;
19
+ private upsertCapabilities;
20
+ private handleToggleChange;
21
+ protected loadVc(organizationId: string): Promise<void>;
22
+ private calculateDuration;
23
+ getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
24
+ getActiveRecordVc(): ActiveRecordCardViewController;
25
+ getListVc(): import("@sprucelabs/heartwood-view-controllers").ListViewController;
26
+ getEditVc(): EditOverrideDetailsCardViewController | undefined;
27
+ getOrganizationId(): string | undefined;
28
+ getCapabilities(): any[];
29
+ getLocationId(): string;
30
+ render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
31
+ }
32
+ export {};
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const calendar_utils_1 = require("@sprucelabs/calendar-utils");
4
+ const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
5
+ class AbstractCapabilityCardViewController extends heartwood_view_controllers_1.AbstractViewController {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.capabilities = [];
9
+ }
10
+ ActiveRecordCard(row) {
11
+ return this.Controller('activeRecordCard', (0, heartwood_view_controllers_1.buildActiveRecordCard)({
12
+ id: row.id,
13
+ columnWidths: ['fill'],
14
+ shouldRenderRowDividers: true,
15
+ header: {
16
+ title: row.name,
17
+ },
18
+ eventName: 'appointments.list-services::v2021_06_23',
19
+ responseKey: 'services',
20
+ footer: {},
21
+ rowTransformer: this.buildRow.bind(this),
22
+ }));
23
+ }
24
+ buildRow(service) {
25
+ var _a, _b, _c, _d;
26
+ const serviceCapability = (_a = this.capabilities) === null || _a === void 0 ? void 0 : _a.find((r) => r.serviceId === service.id);
27
+ return {
28
+ id: service.id,
29
+ onClick: async () => {
30
+ await this.handleEdit(service, serviceCapability);
31
+ },
32
+ cells: [
33
+ {
34
+ text: {
35
+ content: service.name,
36
+ },
37
+ subText: {
38
+ content: `$${(_b = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.price) !== null && _b !== void 0 ? _b : service.price} - ${this.calculateDuration((_c = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.timeBlocks) !== null && _c !== void 0 ? _c : service.timeBlocks)}`,
39
+ },
40
+ },
41
+ {
42
+ toggleInput: {
43
+ name: 'isEnabled',
44
+ value: (_d = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.isEnabled) !== null && _d !== void 0 ? _d : false,
45
+ onChange: async (value) => {
46
+ await this.handleToggleChange(service, value !== null && value !== void 0 ? value : false, serviceCapability);
47
+ },
48
+ },
49
+ },
50
+ ].filter((c) => !!c),
51
+ };
52
+ }
53
+ async handleEdit(serviceRow, serviceRoleCapability) {
54
+ var _a;
55
+ this.editVc = this.Controller('appointments.edit-override-details-card', {
56
+ onCancel: () => { },
57
+ onSubmit: async (price, timeBlocks, serviceRow, serviceRoleCapability) => {
58
+ await dlgVc.hide();
59
+ const newServiceCapability = await this.insertOrUpdateCapability(serviceRow.id, { price, timeBlocks, isEnabled: true }, serviceRoleCapability);
60
+ if (newServiceCapability) {
61
+ this.upsertCapabilities(newServiceCapability, serviceRow);
62
+ }
63
+ },
64
+ service: serviceRow,
65
+ serviceRoleCapability,
66
+ });
67
+ const dlgVc = this.renderInDialog(Object.assign({}, this.editVc.render()));
68
+ return (_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this, serviceRow);
69
+ }
70
+ upsertCapabilities(newServiceCapability, service) {
71
+ var _a;
72
+ const listVc = this.getListVc();
73
+ if (newServiceCapability) {
74
+ this.capabilities = (_a = this.capabilities) === null || _a === void 0 ? void 0 : _a.filter((r) => r.id !== newServiceCapability.id);
75
+ this.capabilities.push(newServiceCapability);
76
+ listVc.upsertRow(service.id, Object.assign({}, this.buildRow(service)));
77
+ listVc.triggerRender();
78
+ this.getActiveRecordVc().triggerRender();
79
+ }
80
+ }
81
+ async handleToggleChange(service, value, capability) {
82
+ var _a;
83
+ (_a = this.onUpdateHasCapability) === null || _a === void 0 ? void 0 : _a.call(this, service, value);
84
+ const newCapability = await this.insertOrUpdateCapability(service.id, { isEnabled: value }, capability);
85
+ if (newCapability) {
86
+ this.upsertCapabilities(newCapability, service);
87
+ }
88
+ }
89
+ async loadVc(organizationId) {
90
+ this.organizationId = organizationId;
91
+ this.activeRecordCardVc.setTarget({ organizationId });
92
+ this.activeRecordCardVc.getCardVc().setIsBusy(false);
93
+ await this.loadCapabilities();
94
+ await this.activeRecordCardVc.load();
95
+ }
96
+ calculateDuration(timeblocks) {
97
+ const duration = timeblocks
98
+ .map((a) => a.durationMinutes)
99
+ .reduce(function (a, b) {
100
+ return a + b;
101
+ });
102
+ const r = calendar_utils_1.durationUtil.msToFriendly(duration * 60000);
103
+ return r;
104
+ }
105
+ getCardVc() {
106
+ return this.activeRecordCardVc.getCardVc();
107
+ }
108
+ getActiveRecordVc() {
109
+ return this.activeRecordCardVc;
110
+ }
111
+ getListVc() {
112
+ return this.activeRecordCardVc.getListVc();
113
+ }
114
+ getEditVc() {
115
+ return this.editVc;
116
+ }
117
+ getOrganizationId() {
118
+ return this.organizationId;
119
+ }
120
+ getCapabilities() {
121
+ return this.capabilities;
122
+ }
123
+ getLocationId() {
124
+ var _a;
125
+ return (_a = this.locationId) !== null && _a !== void 0 ? _a : 'no location id';
126
+ }
127
+ render() {
128
+ return this.activeRecordCardVc.render();
129
+ }
130
+ }
131
+ exports.default = AbstractCapabilityCardViewController;
@@ -0,0 +1,33 @@
1
+ import { SpruceSchemas as SpruceSchemasCalendarUtils } from '@sprucelabs/calendar-utils';
2
+ import { AbstractViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
3
+ import DurationListViewController from './DurationList.vc';
4
+ export declare type EventTimeBlock = Omit<SpruceSchemasCalendarUtils.CalendarUtils.v2021_05_19.EventTimeBlock, 'durationMinutes'> & {
5
+ durationMinutes?: number;
6
+ };
7
+ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
8
+ export declare type DurationCardViewControllerOptions = ViewControllerOptions;
9
+ export default class DurationCardViewController extends AbstractViewController<Card> {
10
+ static id: string;
11
+ private listVc;
12
+ private cardVc;
13
+ constructor(options: DurationCardViewControllerOptions);
14
+ private CardVc;
15
+ load(timeBlocks?: EventTimeBlock[]): void;
16
+ setValues(timeBlocks?: EventTimeBlock[]): void;
17
+ private handleClickAddTimeBlock;
18
+ private ListVc;
19
+ getEditTitleFormVc(): import("./EditTimeBlockTitleCard.vc").FormVc | undefined;
20
+ payAttentionToMe(): void;
21
+ getDurationListVc(): DurationListViewController;
22
+ getTimeBlocks(): {
23
+ title?: string | null | undefined;
24
+ subtitle?: string | null | undefined;
25
+ isBusy: boolean;
26
+ rightIcons?: SpruceSchemasCalendarUtils.CalendarUtils.v2021_05_19.CalendarEventLineIcon[] | null | undefined;
27
+ leftIcons?: SpruceSchemasCalendarUtils.CalendarUtils.v2021_05_19.CalendarEventLineIcon[] | null | undefined;
28
+ durationMinutes?: number | undefined;
29
+ id: string;
30
+ }[];
31
+ render(): SpruceSchemasCalendarUtils.HeartwoodViewControllers.v2021_02_11.Card;
32
+ }
33
+ export {};
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
4
+ class DurationCardViewController extends heartwood_view_controllers_1.AbstractViewController {
5
+ constructor(options) {
6
+ super(options);
7
+ this.listVc = this.ListVc();
8
+ this.cardVc = this.CardVc();
9
+ }
10
+ CardVc() {
11
+ return this.Controller('card', {
12
+ id: 'durations',
13
+ header: {
14
+ title: 'Durations',
15
+ subtitle: 'You can set how long a services going to take. You can even break a service up into distinct blocks of time to handle things like setup, teardown, breaks, or whenever!',
16
+ },
17
+ body: {
18
+ isBusy: true,
19
+ sections: [
20
+ {
21
+ list: this.listVc.render(),
22
+ },
23
+ ],
24
+ },
25
+ footer: {
26
+ buttons: [
27
+ {
28
+ label: 'Add block of time',
29
+ id: 'addDuration',
30
+ type: 'primary',
31
+ onClick: async () => {
32
+ this.handleClickAddTimeBlock();
33
+ },
34
+ },
35
+ ],
36
+ },
37
+ });
38
+ }
39
+ load(timeBlocks) {
40
+ this.setValues(timeBlocks);
41
+ this.cardVc.setIsBusy(false);
42
+ }
43
+ setValues(timeBlocks) {
44
+ this.listVc.setValues(timeBlocks);
45
+ }
46
+ handleClickAddTimeBlock() {
47
+ this.listVc.addNewTimeBlock();
48
+ }
49
+ ListVc() {
50
+ return this.Controller('appointments.duration-list', {});
51
+ }
52
+ getEditTitleFormVc() {
53
+ return this.listVc.getEditTitleFormVc();
54
+ }
55
+ payAttentionToMe() {
56
+ this.cardVc.payAttentionToMe();
57
+ }
58
+ getDurationListVc() {
59
+ return this.listVc;
60
+ }
61
+ getTimeBlocks() {
62
+ return this.listVc.getTimeBlocks();
63
+ }
64
+ render() {
65
+ return this.cardVc.render();
66
+ }
67
+ }
68
+ exports.default = DurationCardViewController;
69
+ DurationCardViewController.id = 'duration-card';