@sprucelabs/spruce-appointment-utils 7.7.16 → 7.7.19
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/stores/RemoteRoleCapabilityStore.js +0 -3
- package/build/esm/viewControllers/AbstractCapabilityCardViewController.d.ts +12 -8
- package/build/esm/viewControllers/AbstractCapabilityCardViewController.js +46 -32
- package/build/esm/viewControllers/DurationList.vc.js +1 -0
- package/build/esm/viewControllers/EditOverrideDetailsCard.vc.d.ts +5 -8
- package/build/esm/viewControllers/EditOverrideDetailsCard.vc.js +4 -5
- package/build/esm/viewControllers/EditTimeBlockTitleCard.vc.js +9 -1
- package/build/esm/viewControllers/RolesCard.vc.d.ts +1 -1
- package/build/esm/viewControllers/RolesCard.vc.js +1 -1
- package/build/stores/RemoteRoleCapabilityStore.js +0 -3
- package/build/viewControllers/AbstractCapabilityCardViewController.d.ts +12 -8
- package/build/viewControllers/AbstractCapabilityCardViewController.js +42 -32
- package/build/viewControllers/DurationList.vc.js +1 -0
- package/build/viewControllers/EditOverrideDetailsCard.vc.d.ts +5 -8
- package/build/viewControllers/EditOverrideDetailsCard.vc.js +4 -5
- package/build/viewControllers/EditTimeBlockTitleCard.vc.js +9 -1
- package/build/viewControllers/RolesCard.vc.d.ts +1 -1
- package/build/viewControllers/RolesCard.vc.js +1 -1
- package/package.json +1 -1
|
@@ -31,9 +31,6 @@ export default class RemoteRoleCapabilityStore {
|
|
|
31
31
|
assertOptions(value, ['serviceId', 'roleId']);
|
|
32
32
|
const id = `${this.organizationId}-${value.serviceId}-${value.roleId}`;
|
|
33
33
|
this.queuedCapabilities[id] = Object.assign(Object.assign({}, this.queuedCapabilities[id]), value);
|
|
34
|
-
if (!value.id) {
|
|
35
|
-
return Object.assign(Object.assign({}, value), { id });
|
|
36
|
-
}
|
|
37
34
|
return value;
|
|
38
35
|
});
|
|
39
36
|
}
|
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import { AbstractViewController, ActiveRecordCardViewController, SpruceSchemas } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import EditOverrideDetailsCardViewController from './EditOverrideDetailsCard.vc';
|
|
3
3
|
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
4
|
-
declare type
|
|
4
|
+
declare type ToggleDoesOfferHandler = (serviceId: string, isSelected: boolean) => void;
|
|
5
5
|
declare type Service = SpruceSchemas.Appointments.v2021_06_23.ListService;
|
|
6
|
+
declare type Capability = SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability;
|
|
6
7
|
export default abstract class AbstractCapabilityCardViewController extends AbstractViewController<Card> {
|
|
7
8
|
protected activeRecordCardVc: ActiveRecordCardViewController;
|
|
8
|
-
protected
|
|
9
|
+
protected toggleDoesOfferHandler?: ToggleDoesOfferHandler;
|
|
9
10
|
protected onEdit?: (row: any) => void;
|
|
10
|
-
protected capabilities:
|
|
11
|
+
protected capabilities: Capability[];
|
|
11
12
|
protected locationId?: string;
|
|
12
13
|
protected organizationId?: string;
|
|
13
14
|
protected editVc?: EditOverrideDetailsCardViewController;
|
|
14
15
|
protected abstract insertOrUpdateCapability(serviceId: string, values: any, capability: SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability | undefined): Promise<SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability | undefined>;
|
|
15
16
|
protected abstract loadCapabilities(): Promise<any>;
|
|
16
17
|
ActiveRecordCard(row: any): ActiveRecordCardViewController;
|
|
17
|
-
protected
|
|
18
|
-
private
|
|
18
|
+
protected renderRow(service: Service): any;
|
|
19
|
+
private getCapabilityForService;
|
|
20
|
+
private handleClickCheckbox;
|
|
21
|
+
private handleClickRow;
|
|
19
22
|
private upsertCapabilities;
|
|
20
|
-
private
|
|
21
|
-
private
|
|
23
|
+
private handleToggleDoesOffer;
|
|
24
|
+
private updateCapabilityForService;
|
|
25
|
+
private handleToggleEnableCapability;
|
|
22
26
|
protected loadVc(organizationId: string): Promise<void>;
|
|
23
27
|
private calculateDuration;
|
|
24
28
|
getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
|
|
@@ -26,7 +30,7 @@ export default abstract class AbstractCapabilityCardViewController extends Abstr
|
|
|
26
30
|
getListVc(): import("@sprucelabs/heartwood-view-controllers").ListViewController;
|
|
27
31
|
getEditVc(): EditOverrideDetailsCardViewController | undefined;
|
|
28
32
|
getOrganizationId(): string | undefined;
|
|
29
|
-
getCapabilities():
|
|
33
|
+
getCapabilities(): SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability[];
|
|
30
34
|
getLocationId(): string;
|
|
31
35
|
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
32
36
|
}
|
|
@@ -24,27 +24,27 @@ export default class AbstractCapabilityCardViewController extends AbstractViewCo
|
|
|
24
24
|
},
|
|
25
25
|
eventName: 'appointments.list-services::v2021_06_23',
|
|
26
26
|
responseKey: 'services',
|
|
27
|
-
rowTransformer: this.
|
|
27
|
+
rowTransformer: this.renderRow.bind(this),
|
|
28
28
|
}));
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
var _a, _b, _c, _d, _e
|
|
32
|
-
const serviceCapability =
|
|
30
|
+
renderRow(service) {
|
|
31
|
+
var _a, _b, _c, _d, _e;
|
|
32
|
+
const serviceCapability = this.getCapabilityForService(service.id);
|
|
33
33
|
const rowId = service.id;
|
|
34
34
|
return {
|
|
35
35
|
id: rowId,
|
|
36
36
|
onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
yield this.
|
|
37
|
+
yield this.handleClickRow(service);
|
|
38
38
|
}),
|
|
39
|
-
isEnabled: (
|
|
39
|
+
isEnabled: (_a = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.isEnabled) !== null && _a !== void 0 ? _a : false,
|
|
40
40
|
cells: [
|
|
41
41
|
{
|
|
42
42
|
checkboxInput: {
|
|
43
43
|
name: 'isEnabled',
|
|
44
|
-
value: (
|
|
44
|
+
value: (_b = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.isEnabled) !== null && _b !== void 0 ? _b : false,
|
|
45
45
|
onChange: (value) => __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
|
|
47
|
-
yield this.
|
|
46
|
+
console.log('toggling is enabled');
|
|
47
|
+
yield this.handleClickCheckbox(service, value);
|
|
48
48
|
}),
|
|
49
49
|
},
|
|
50
50
|
},
|
|
@@ -53,76 +53,90 @@ export default class AbstractCapabilityCardViewController extends AbstractViewCo
|
|
|
53
53
|
content: service.name,
|
|
54
54
|
},
|
|
55
55
|
subText: {
|
|
56
|
-
content: `$${(
|
|
56
|
+
content: `$${(_c = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.price) !== null && _c !== void 0 ? _c : service.price} - ${this.calculateDuration((_d = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.timeBlocks) !== null && _d !== void 0 ? _d : service.timeBlocks)}`,
|
|
57
57
|
},
|
|
58
58
|
},
|
|
59
59
|
{
|
|
60
60
|
toggleInput: {
|
|
61
61
|
name: 'doesOffer',
|
|
62
|
-
value: (
|
|
62
|
+
value: (_e = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.doesOffer) !== null && _e !== void 0 ? _e : false,
|
|
63
63
|
onChange: (value) => __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
|
|
64
|
+
console.log('toggling does offer');
|
|
65
|
+
yield this.handleToggleDoesOffer(service, value);
|
|
65
66
|
}),
|
|
66
67
|
},
|
|
67
68
|
},
|
|
68
69
|
].filter((c) => !!c),
|
|
69
70
|
};
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
+
getCapabilityForService(id) {
|
|
73
|
+
var _a;
|
|
74
|
+
return (_a = this.capabilities) === null || _a === void 0 ? void 0 : _a.find((r) => r.serviceId === id);
|
|
75
|
+
}
|
|
76
|
+
handleClickCheckbox(service, value) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
this.getListVc().getRowVc(service.id).setIsEnabled(value);
|
|
79
|
+
yield this.handleToggleEnableCapability(service, value !== null && value !== void 0 ? value : false);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
handleClickRow(service) {
|
|
72
83
|
var _a;
|
|
73
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const serviceRoleCapability = this.getCapabilityForService(service.id);
|
|
74
86
|
this.editVc = this.Controller('appointments.edit-override-details-card', {
|
|
75
87
|
onCancel: () => { },
|
|
76
|
-
onSubmit: (price, timeBlocks
|
|
88
|
+
onSubmit: (price, timeBlocks) => __awaiter(this, void 0, void 0, function* () {
|
|
77
89
|
yield dlgVc.hide();
|
|
78
|
-
|
|
79
|
-
if (newServiceCapability) {
|
|
80
|
-
this.upsertCapabilities(newServiceCapability, serviceRow);
|
|
81
|
-
}
|
|
90
|
+
yield this.updateCapabilityForService(service, { price, timeBlocks });
|
|
82
91
|
}),
|
|
83
|
-
service
|
|
92
|
+
service,
|
|
84
93
|
serviceRoleCapability,
|
|
85
94
|
});
|
|
86
95
|
const dlgVc = this.renderInDialog(Object.assign({}, this.editVc.render()));
|
|
87
|
-
return (_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this,
|
|
96
|
+
return (_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this, service);
|
|
88
97
|
});
|
|
89
98
|
}
|
|
90
99
|
upsertCapabilities(newServiceCapability, service) {
|
|
91
100
|
var _a, _b;
|
|
92
|
-
const listVc = this.
|
|
101
|
+
const listVc = this.activeRecordCardVc;
|
|
93
102
|
if (newServiceCapability) {
|
|
94
103
|
const oldCapability = (_a = this.capabilities) === null || _a === void 0 ? void 0 : _a.find((r) => r.id === newServiceCapability.id);
|
|
95
104
|
this.capabilities = (_b = this.capabilities) === null || _b === void 0 ? void 0 : _b.filter((r) => r.id !== newServiceCapability.id);
|
|
96
105
|
const rowId = service.id;
|
|
97
106
|
this.capabilities.push(Object.assign(Object.assign({}, oldCapability), newServiceCapability));
|
|
98
|
-
listVc.upsertRow(rowId, Object.assign({}, this.
|
|
99
|
-
listVc.triggerRender();
|
|
100
|
-
this.getActiveRecordVc().triggerRender();
|
|
107
|
+
listVc.upsertRow(rowId, Object.assign({}, this.renderRow(service)));
|
|
101
108
|
}
|
|
102
109
|
}
|
|
103
|
-
|
|
110
|
+
handleToggleDoesOffer(service, doesOffer) {
|
|
104
111
|
var _a;
|
|
105
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
(_a = this.
|
|
107
|
-
|
|
113
|
+
(_a = this.toggleDoesOfferHandler) === null || _a === void 0 ? void 0 : _a.call(this, service.id, doesOffer);
|
|
114
|
+
yield this.updateCapabilityForService(service, { doesOffer });
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
updateCapabilityForService(service, changes) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
const capability = this.getCapabilityForService(service.id);
|
|
120
|
+
const newCapability = yield this.insertOrUpdateCapability(service.id, changes, capability);
|
|
108
121
|
if (newCapability) {
|
|
109
122
|
this.upsertCapabilities(newCapability, service);
|
|
110
123
|
}
|
|
111
124
|
});
|
|
112
125
|
}
|
|
113
|
-
|
|
126
|
+
handleToggleEnableCapability(service, isEnabled) {
|
|
114
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
const
|
|
116
|
-
if (
|
|
117
|
-
|
|
128
|
+
const changes = { isEnabled };
|
|
129
|
+
if (isEnabled) {
|
|
130
|
+
changes.doesOffer = true;
|
|
118
131
|
}
|
|
132
|
+
yield this.updateCapabilityForService(service, changes);
|
|
119
133
|
});
|
|
120
134
|
}
|
|
121
135
|
loadVc(organizationId) {
|
|
122
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
123
137
|
this.organizationId = organizationId;
|
|
124
138
|
this.activeRecordCardVc.setTarget({ organizationId });
|
|
125
|
-
this.activeRecordCardVc.
|
|
139
|
+
this.activeRecordCardVc.setIsBusy(false);
|
|
126
140
|
yield this.loadCapabilities();
|
|
127
141
|
yield this.activeRecordCardVc.load();
|
|
128
142
|
});
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { SpruceSchemas as SpruceSchemasCalendarUtils } from '@sprucelabs/calendar-utils';
|
|
2
1
|
import { AbstractViewController, FormViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
3
2
|
import DurationCardViewController from './DurationCard.vc';
|
|
4
3
|
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
5
|
-
declare type EventTimeBlock = Omit<SpruceSchemasCalendarUtils.CalendarUtils.v2021_05_19.EventTimeBlock, 'durationMinutes'> & {
|
|
6
|
-
durationMinutes?: number;
|
|
7
|
-
};
|
|
8
4
|
declare const schema: {
|
|
9
5
|
id: string;
|
|
10
6
|
fields: {
|
|
@@ -16,11 +12,12 @@ declare const schema: {
|
|
|
16
12
|
};
|
|
17
13
|
declare type Schema = typeof schema;
|
|
18
14
|
export declare type FormVc = FormViewController<Schema>;
|
|
15
|
+
declare type SubmitHandler = (price: number | undefined, timeBlocks: SpruceSchemas.Appointments.v2021_06_23.CapabilityTimeBlock[] | undefined) => void;
|
|
19
16
|
interface EditOverrideDetailsOptions {
|
|
20
17
|
service?: any;
|
|
21
18
|
serviceRoleCapability?: any;
|
|
22
19
|
onCancel: () => void;
|
|
23
|
-
onSubmit:
|
|
20
|
+
onSubmit: SubmitHandler;
|
|
24
21
|
}
|
|
25
22
|
export declare type EditOverrideDetailsCardViewControllerOptions = ViewControllerOptions & EditOverrideDetailsOptions;
|
|
26
23
|
export default class EditOverrideDetailsCardViewController extends AbstractViewController<Card> {
|
|
@@ -29,8 +26,8 @@ export default class EditOverrideDetailsCardViewController extends AbstractViewC
|
|
|
29
26
|
private formVc;
|
|
30
27
|
private durationVc;
|
|
31
28
|
private durationListVc;
|
|
32
|
-
private
|
|
33
|
-
private
|
|
29
|
+
private submitHandler;
|
|
30
|
+
private cancelHandler;
|
|
34
31
|
private service;
|
|
35
32
|
private serviceRoleCapability;
|
|
36
33
|
constructor(options: EditOverrideDetailsCardViewControllerOptions);
|
|
@@ -39,6 +36,6 @@ export default class EditOverrideDetailsCardViewController extends AbstractViewC
|
|
|
39
36
|
private CardVc;
|
|
40
37
|
getFormVc(): FormVc;
|
|
41
38
|
getDurationVc(): DurationCardViewController;
|
|
42
|
-
render():
|
|
39
|
+
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
43
40
|
}
|
|
44
41
|
export {};
|
|
@@ -25,8 +25,8 @@ export default class EditOverrideDetailsCardViewController extends AbstractViewC
|
|
|
25
25
|
assertOptions(options, ['onCancel', 'onSubmit']);
|
|
26
26
|
this.service = options === null || options === void 0 ? void 0 : options.service;
|
|
27
27
|
this.serviceRoleCapability = options === null || options === void 0 ? void 0 : options.serviceRoleCapability;
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
28
|
+
this.submitHandler = options.onSubmit;
|
|
29
|
+
this.cancelHandler = options.onCancel;
|
|
30
30
|
this.durationVc = this.Controller('appointments.duration-card', {});
|
|
31
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
32
|
this.durationListVc = this.durationVc.getDurationListVc();
|
|
@@ -40,11 +40,10 @@ export default class EditOverrideDetailsCardViewController extends AbstractViewC
|
|
|
40
40
|
schema,
|
|
41
41
|
shouldShowCancelButton: false,
|
|
42
42
|
onSubmit: ({ values }) => {
|
|
43
|
-
|
|
44
|
-
this.onSubmitHandler((_a = values.price) !== null && _a !== void 0 ? _a : undefined, this.getDurationVc().getTimeBlocks(), this.service, this.serviceRoleCapability);
|
|
43
|
+
this.submitHandler(values.price ? parseInt(values.price, 10) : undefined, this.getDurationVc().getTimeBlocks());
|
|
45
44
|
},
|
|
46
45
|
onCancel: () => {
|
|
47
|
-
this.
|
|
46
|
+
this.cancelHandler();
|
|
48
47
|
},
|
|
49
48
|
sections: [
|
|
50
49
|
{
|
|
@@ -51,7 +51,15 @@ export default class EditTimeBlockTitleCardViewController extends AbstractViewCo
|
|
|
51
51
|
sections: [
|
|
52
52
|
{
|
|
53
53
|
text: {
|
|
54
|
-
|
|
54
|
+
html: `<p>Example: Let's say you are adding a hair color service and what to break it up into 3 blocks of time:</p>
|
|
55
|
+
|
|
56
|
+
<ol>
|
|
57
|
+
<li>Primary</li>
|
|
58
|
+
<li>Processing</li>
|
|
59
|
+
<li>Finishing</li>
|
|
60
|
+
</ol>
|
|
61
|
+
|
|
62
|
+
`,
|
|
55
63
|
},
|
|
56
64
|
},
|
|
57
65
|
{
|
|
@@ -19,6 +19,6 @@ export default class RolesCardViewController extends AbstractCapabilityCardViewC
|
|
|
19
19
|
}): Promise<void>;
|
|
20
20
|
protected loadCapabilities(): Promise<void>;
|
|
21
21
|
protected insertOrUpdateCapability(serviceId: string, values: any, serviceCapability: SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability | undefined): Promise<SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability | undefined>;
|
|
22
|
-
getCapabilities():
|
|
22
|
+
getCapabilities(): SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability[];
|
|
23
23
|
}
|
|
24
24
|
export {};
|
|
@@ -15,7 +15,7 @@ export default class RolesCardViewController extends AbstractCapabilityCardViewC
|
|
|
15
15
|
super(options);
|
|
16
16
|
assertOptions(options, ['role', 'onInsertOrUpdateCapability']);
|
|
17
17
|
this.role = options.role;
|
|
18
|
-
this.
|
|
18
|
+
this.toggleDoesOfferHandler = options.onUpdateHasCapability;
|
|
19
19
|
this.onInsertOrUpdateCapability = options.onInsertOrUpdateCapability;
|
|
20
20
|
this.onEdit = options === null || options === void 0 ? void 0 : options.onEdit;
|
|
21
21
|
this.activeRecordCardVc = this.ActiveRecordCard(options.role);
|
|
@@ -23,9 +23,6 @@ class RemoteRoleCapabilityStore {
|
|
|
23
23
|
(0, schema_1.assertOptions)(value, ['serviceId', 'roleId']);
|
|
24
24
|
const id = `${this.organizationId}-${value.serviceId}-${value.roleId}`;
|
|
25
25
|
this.queuedCapabilities[id] = Object.assign(Object.assign({}, this.queuedCapabilities[id]), value);
|
|
26
|
-
if (!value.id) {
|
|
27
|
-
return Object.assign(Object.assign({}, value), { id });
|
|
28
|
-
}
|
|
29
26
|
return value;
|
|
30
27
|
}
|
|
31
28
|
async persist() {
|
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import { AbstractViewController, ActiveRecordCardViewController, SpruceSchemas } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import EditOverrideDetailsCardViewController from './EditOverrideDetailsCard.vc';
|
|
3
3
|
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
4
|
-
declare type
|
|
4
|
+
declare type ToggleDoesOfferHandler = (serviceId: string, isSelected: boolean) => void;
|
|
5
5
|
declare type Service = SpruceSchemas.Appointments.v2021_06_23.ListService;
|
|
6
|
+
declare type Capability = SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability;
|
|
6
7
|
export default abstract class AbstractCapabilityCardViewController extends AbstractViewController<Card> {
|
|
7
8
|
protected activeRecordCardVc: ActiveRecordCardViewController;
|
|
8
|
-
protected
|
|
9
|
+
protected toggleDoesOfferHandler?: ToggleDoesOfferHandler;
|
|
9
10
|
protected onEdit?: (row: any) => void;
|
|
10
|
-
protected capabilities:
|
|
11
|
+
protected capabilities: Capability[];
|
|
11
12
|
protected locationId?: string;
|
|
12
13
|
protected organizationId?: string;
|
|
13
14
|
protected editVc?: EditOverrideDetailsCardViewController;
|
|
14
15
|
protected abstract insertOrUpdateCapability(serviceId: string, values: any, capability: SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability | undefined): Promise<SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability | undefined>;
|
|
15
16
|
protected abstract loadCapabilities(): Promise<any>;
|
|
16
17
|
ActiveRecordCard(row: any): ActiveRecordCardViewController;
|
|
17
|
-
protected
|
|
18
|
-
private
|
|
18
|
+
protected renderRow(service: Service): any;
|
|
19
|
+
private getCapabilityForService;
|
|
20
|
+
private handleClickCheckbox;
|
|
21
|
+
private handleClickRow;
|
|
19
22
|
private upsertCapabilities;
|
|
20
|
-
private
|
|
21
|
-
private
|
|
23
|
+
private handleToggleDoesOffer;
|
|
24
|
+
private updateCapabilityForService;
|
|
25
|
+
private handleToggleEnableCapability;
|
|
22
26
|
protected loadVc(organizationId: string): Promise<void>;
|
|
23
27
|
private calculateDuration;
|
|
24
28
|
getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
|
|
@@ -26,7 +30,7 @@ export default abstract class AbstractCapabilityCardViewController extends Abstr
|
|
|
26
30
|
getListVc(): import("@sprucelabs/heartwood-view-controllers").ListViewController;
|
|
27
31
|
getEditVc(): EditOverrideDetailsCardViewController | undefined;
|
|
28
32
|
getOrganizationId(): string | undefined;
|
|
29
|
-
getCapabilities():
|
|
33
|
+
getCapabilities(): SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability[];
|
|
30
34
|
getLocationId(): string;
|
|
31
35
|
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
32
36
|
}
|
|
@@ -17,27 +17,27 @@ class AbstractCapabilityCardViewController extends heartwood_view_controllers_1.
|
|
|
17
17
|
},
|
|
18
18
|
eventName: 'appointments.list-services::v2021_06_23',
|
|
19
19
|
responseKey: 'services',
|
|
20
|
-
rowTransformer: this.
|
|
20
|
+
rowTransformer: this.renderRow.bind(this),
|
|
21
21
|
}));
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
var _a, _b, _c, _d, _e
|
|
25
|
-
const serviceCapability =
|
|
23
|
+
renderRow(service) {
|
|
24
|
+
var _a, _b, _c, _d, _e;
|
|
25
|
+
const serviceCapability = this.getCapabilityForService(service.id);
|
|
26
26
|
const rowId = service.id;
|
|
27
27
|
return {
|
|
28
28
|
id: rowId,
|
|
29
29
|
onClick: async () => {
|
|
30
|
-
await this.
|
|
30
|
+
await this.handleClickRow(service);
|
|
31
31
|
},
|
|
32
|
-
isEnabled: (
|
|
32
|
+
isEnabled: (_a = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.isEnabled) !== null && _a !== void 0 ? _a : false,
|
|
33
33
|
cells: [
|
|
34
34
|
{
|
|
35
35
|
checkboxInput: {
|
|
36
36
|
name: 'isEnabled',
|
|
37
|
-
value: (
|
|
37
|
+
value: (_b = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.isEnabled) !== null && _b !== void 0 ? _b : false,
|
|
38
38
|
onChange: async (value) => {
|
|
39
|
-
|
|
40
|
-
await this.
|
|
39
|
+
console.log('toggling is enabled');
|
|
40
|
+
await this.handleClickCheckbox(service, value);
|
|
41
41
|
},
|
|
42
42
|
},
|
|
43
43
|
},
|
|
@@ -46,69 +46,79 @@ class AbstractCapabilityCardViewController extends heartwood_view_controllers_1.
|
|
|
46
46
|
content: service.name,
|
|
47
47
|
},
|
|
48
48
|
subText: {
|
|
49
|
-
content: `$${(
|
|
49
|
+
content: `$${(_c = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.price) !== null && _c !== void 0 ? _c : service.price} - ${this.calculateDuration((_d = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.timeBlocks) !== null && _d !== void 0 ? _d : service.timeBlocks)}`,
|
|
50
50
|
},
|
|
51
51
|
},
|
|
52
52
|
{
|
|
53
53
|
toggleInput: {
|
|
54
54
|
name: 'doesOffer',
|
|
55
|
-
value: (
|
|
55
|
+
value: (_e = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.doesOffer) !== null && _e !== void 0 ? _e : false,
|
|
56
56
|
onChange: async (value) => {
|
|
57
|
-
|
|
57
|
+
console.log('toggling does offer');
|
|
58
|
+
await this.handleToggleDoesOffer(service, value);
|
|
58
59
|
},
|
|
59
60
|
},
|
|
60
61
|
},
|
|
61
62
|
].filter((c) => !!c),
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
+
getCapabilityForService(id) {
|
|
65
66
|
var _a;
|
|
67
|
+
return (_a = this.capabilities) === null || _a === void 0 ? void 0 : _a.find((r) => r.serviceId === id);
|
|
68
|
+
}
|
|
69
|
+
async handleClickCheckbox(service, value) {
|
|
70
|
+
this.getListVc().getRowVc(service.id).setIsEnabled(value);
|
|
71
|
+
await this.handleToggleEnableCapability(service, value !== null && value !== void 0 ? value : false);
|
|
72
|
+
}
|
|
73
|
+
async handleClickRow(service) {
|
|
74
|
+
var _a;
|
|
75
|
+
const serviceRoleCapability = this.getCapabilityForService(service.id);
|
|
66
76
|
this.editVc = this.Controller('appointments.edit-override-details-card', {
|
|
67
77
|
onCancel: () => { },
|
|
68
|
-
onSubmit: async (price, timeBlocks
|
|
78
|
+
onSubmit: async (price, timeBlocks) => {
|
|
69
79
|
await dlgVc.hide();
|
|
70
|
-
|
|
71
|
-
if (newServiceCapability) {
|
|
72
|
-
this.upsertCapabilities(newServiceCapability, serviceRow);
|
|
73
|
-
}
|
|
80
|
+
await this.updateCapabilityForService(service, { price, timeBlocks });
|
|
74
81
|
},
|
|
75
|
-
service
|
|
82
|
+
service,
|
|
76
83
|
serviceRoleCapability,
|
|
77
84
|
});
|
|
78
85
|
const dlgVc = this.renderInDialog(Object.assign({}, this.editVc.render()));
|
|
79
|
-
return (_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this,
|
|
86
|
+
return (_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this, service);
|
|
80
87
|
}
|
|
81
88
|
upsertCapabilities(newServiceCapability, service) {
|
|
82
89
|
var _a, _b;
|
|
83
|
-
const listVc = this.
|
|
90
|
+
const listVc = this.activeRecordCardVc;
|
|
84
91
|
if (newServiceCapability) {
|
|
85
92
|
const oldCapability = (_a = this.capabilities) === null || _a === void 0 ? void 0 : _a.find((r) => r.id === newServiceCapability.id);
|
|
86
93
|
this.capabilities = (_b = this.capabilities) === null || _b === void 0 ? void 0 : _b.filter((r) => r.id !== newServiceCapability.id);
|
|
87
94
|
const rowId = service.id;
|
|
88
95
|
this.capabilities.push(Object.assign(Object.assign({}, oldCapability), newServiceCapability));
|
|
89
|
-
listVc.upsertRow(rowId, Object.assign({}, this.
|
|
90
|
-
listVc.triggerRender();
|
|
91
|
-
this.getActiveRecordVc().triggerRender();
|
|
96
|
+
listVc.upsertRow(rowId, Object.assign({}, this.renderRow(service)));
|
|
92
97
|
}
|
|
93
98
|
}
|
|
94
|
-
async
|
|
99
|
+
async handleToggleDoesOffer(service, doesOffer) {
|
|
95
100
|
var _a;
|
|
96
|
-
(_a = this.
|
|
97
|
-
|
|
101
|
+
(_a = this.toggleDoesOfferHandler) === null || _a === void 0 ? void 0 : _a.call(this, service.id, doesOffer);
|
|
102
|
+
await this.updateCapabilityForService(service, { doesOffer });
|
|
103
|
+
}
|
|
104
|
+
async updateCapabilityForService(service, changes) {
|
|
105
|
+
const capability = this.getCapabilityForService(service.id);
|
|
106
|
+
const newCapability = await this.insertOrUpdateCapability(service.id, changes, capability);
|
|
98
107
|
if (newCapability) {
|
|
99
108
|
this.upsertCapabilities(newCapability, service);
|
|
100
109
|
}
|
|
101
110
|
}
|
|
102
|
-
async
|
|
103
|
-
const
|
|
104
|
-
if (
|
|
105
|
-
|
|
111
|
+
async handleToggleEnableCapability(service, isEnabled) {
|
|
112
|
+
const changes = { isEnabled };
|
|
113
|
+
if (isEnabled) {
|
|
114
|
+
changes.doesOffer = true;
|
|
106
115
|
}
|
|
116
|
+
await this.updateCapabilityForService(service, changes);
|
|
107
117
|
}
|
|
108
118
|
async loadVc(organizationId) {
|
|
109
119
|
this.organizationId = organizationId;
|
|
110
120
|
this.activeRecordCardVc.setTarget({ organizationId });
|
|
111
|
-
this.activeRecordCardVc.
|
|
121
|
+
this.activeRecordCardVc.setIsBusy(false);
|
|
112
122
|
await this.loadCapabilities();
|
|
113
123
|
await this.activeRecordCardVc.load();
|
|
114
124
|
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { SpruceSchemas as SpruceSchemasCalendarUtils } from '@sprucelabs/calendar-utils';
|
|
2
1
|
import { AbstractViewController, FormViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
3
2
|
import DurationCardViewController from './DurationCard.vc';
|
|
4
3
|
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
5
|
-
declare type EventTimeBlock = Omit<SpruceSchemasCalendarUtils.CalendarUtils.v2021_05_19.EventTimeBlock, 'durationMinutes'> & {
|
|
6
|
-
durationMinutes?: number;
|
|
7
|
-
};
|
|
8
4
|
declare const schema: {
|
|
9
5
|
id: string;
|
|
10
6
|
fields: {
|
|
@@ -16,11 +12,12 @@ declare const schema: {
|
|
|
16
12
|
};
|
|
17
13
|
declare type Schema = typeof schema;
|
|
18
14
|
export declare type FormVc = FormViewController<Schema>;
|
|
15
|
+
declare type SubmitHandler = (price: number | undefined, timeBlocks: SpruceSchemas.Appointments.v2021_06_23.CapabilityTimeBlock[] | undefined) => void;
|
|
19
16
|
interface EditOverrideDetailsOptions {
|
|
20
17
|
service?: any;
|
|
21
18
|
serviceRoleCapability?: any;
|
|
22
19
|
onCancel: () => void;
|
|
23
|
-
onSubmit:
|
|
20
|
+
onSubmit: SubmitHandler;
|
|
24
21
|
}
|
|
25
22
|
export declare type EditOverrideDetailsCardViewControllerOptions = ViewControllerOptions & EditOverrideDetailsOptions;
|
|
26
23
|
export default class EditOverrideDetailsCardViewController extends AbstractViewController<Card> {
|
|
@@ -29,8 +26,8 @@ export default class EditOverrideDetailsCardViewController extends AbstractViewC
|
|
|
29
26
|
private formVc;
|
|
30
27
|
private durationVc;
|
|
31
28
|
private durationListVc;
|
|
32
|
-
private
|
|
33
|
-
private
|
|
29
|
+
private submitHandler;
|
|
30
|
+
private cancelHandler;
|
|
34
31
|
private service;
|
|
35
32
|
private serviceRoleCapability;
|
|
36
33
|
constructor(options: EditOverrideDetailsCardViewControllerOptions);
|
|
@@ -39,6 +36,6 @@ export default class EditOverrideDetailsCardViewController extends AbstractViewC
|
|
|
39
36
|
private CardVc;
|
|
40
37
|
getFormVc(): FormVc;
|
|
41
38
|
getDurationVc(): DurationCardViewController;
|
|
42
|
-
render():
|
|
39
|
+
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
43
40
|
}
|
|
44
41
|
export {};
|
|
@@ -18,8 +18,8 @@ class EditOverrideDetailsCardViewController extends heartwood_view_controllers_1
|
|
|
18
18
|
(0, schema_1.assertOptions)(options, ['onCancel', 'onSubmit']);
|
|
19
19
|
this.service = options === null || options === void 0 ? void 0 : options.service;
|
|
20
20
|
this.serviceRoleCapability = options === null || options === void 0 ? void 0 : options.serviceRoleCapability;
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
21
|
+
this.submitHandler = options.onSubmit;
|
|
22
|
+
this.cancelHandler = options.onCancel;
|
|
23
23
|
this.durationVc = this.Controller('appointments.duration-card', {});
|
|
24
24
|
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);
|
|
25
25
|
this.durationListVc = this.durationVc.getDurationListVc();
|
|
@@ -33,11 +33,10 @@ class EditOverrideDetailsCardViewController extends heartwood_view_controllers_1
|
|
|
33
33
|
schema,
|
|
34
34
|
shouldShowCancelButton: false,
|
|
35
35
|
onSubmit: ({ values }) => {
|
|
36
|
-
|
|
37
|
-
this.onSubmitHandler((_a = values.price) !== null && _a !== void 0 ? _a : undefined, this.getDurationVc().getTimeBlocks(), this.service, this.serviceRoleCapability);
|
|
36
|
+
this.submitHandler(values.price ? parseInt(values.price, 10) : undefined, this.getDurationVc().getTimeBlocks());
|
|
38
37
|
},
|
|
39
38
|
onCancel: () => {
|
|
40
|
-
this.
|
|
39
|
+
this.cancelHandler();
|
|
41
40
|
},
|
|
42
41
|
sections: [
|
|
43
42
|
{
|
|
@@ -53,7 +53,15 @@ class EditTimeBlockTitleCardViewController extends heartwood_view_controllers_1.
|
|
|
53
53
|
sections: [
|
|
54
54
|
{
|
|
55
55
|
text: {
|
|
56
|
-
|
|
56
|
+
html: `<p>Example: Let's say you are adding a hair color service and what to break it up into 3 blocks of time:</p>
|
|
57
|
+
|
|
58
|
+
<ol>
|
|
59
|
+
<li>Primary</li>
|
|
60
|
+
<li>Processing</li>
|
|
61
|
+
<li>Finishing</li>
|
|
62
|
+
</ol>
|
|
63
|
+
|
|
64
|
+
`,
|
|
57
65
|
},
|
|
58
66
|
},
|
|
59
67
|
{
|
|
@@ -19,6 +19,6 @@ export default class RolesCardViewController extends AbstractCapabilityCardViewC
|
|
|
19
19
|
}): Promise<void>;
|
|
20
20
|
protected loadCapabilities(): Promise<void>;
|
|
21
21
|
protected insertOrUpdateCapability(serviceId: string, values: any, serviceCapability: SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability | undefined): Promise<SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability | undefined>;
|
|
22
|
-
getCapabilities():
|
|
22
|
+
getCapabilities(): SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability[];
|
|
23
23
|
}
|
|
24
24
|
export {};
|
|
@@ -11,7 +11,7 @@ class RolesCardViewController extends AbstractCapabilityCardViewController_1.def
|
|
|
11
11
|
super(options);
|
|
12
12
|
(0, schema_1.assertOptions)(options, ['role', 'onInsertOrUpdateCapability']);
|
|
13
13
|
this.role = options.role;
|
|
14
|
-
this.
|
|
14
|
+
this.toggleDoesOfferHandler = options.onUpdateHasCapability;
|
|
15
15
|
this.onInsertOrUpdateCapability = options.onInsertOrUpdateCapability;
|
|
16
16
|
this.onEdit = options === null || options === void 0 ? void 0 : options.onEdit;
|
|
17
17
|
this.activeRecordCardVc = this.ActiveRecordCard(options.role);
|