@sprucelabs/spruce-location-utils 2.0.13 → 2.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/index-module.d.ts +1 -0
- package/build/esm/index-module.js +1 -0
- package/build/esm/viewControllers/LocationListCard.vc.d.ts +27 -0
- package/build/esm/viewControllers/LocationListCard.vc.js +128 -0
- package/build/index-module.d.ts +1 -0
- package/build/index-module.js +3 -1
- package/build/viewControllers/LocationListCard.vc.d.ts +27 -0
- package/build/viewControllers/LocationListCard.vc.js +118 -0
- package/package.json +7 -2
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AbstractViewController, SpruceSchemas, ViewControllerOptions, ActiveRecordCardViewController } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
3
|
+
declare type Location = SpruceSchemas.Spruce.v2020_07_22.Location;
|
|
4
|
+
declare type Button = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Button;
|
|
5
|
+
export default class LocationListCardViewController extends AbstractViewController<Card> {
|
|
6
|
+
static id: string;
|
|
7
|
+
private onDeleteHandler?;
|
|
8
|
+
private selectedLocationId?;
|
|
9
|
+
private onEdit?;
|
|
10
|
+
private activeRecordCardVc;
|
|
11
|
+
constructor(options: ViewControllerOptions & {
|
|
12
|
+
onDelete?: (location: Location) => void;
|
|
13
|
+
onEdit?: (location: Location) => void;
|
|
14
|
+
currentOrganizationId: string;
|
|
15
|
+
selectedLocationId?: string;
|
|
16
|
+
footerButtons?: Button[];
|
|
17
|
+
});
|
|
18
|
+
private buildRow;
|
|
19
|
+
private handleDeleteLocation;
|
|
20
|
+
getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
|
|
21
|
+
getActiveRecordVc(): ActiveRecordCardViewController;
|
|
22
|
+
getSelectedLocationId(): string | undefined;
|
|
23
|
+
getListVc(): import("@sprucelabs/heartwood-view-controllers").ListViewController;
|
|
24
|
+
load(): Promise<void>;
|
|
25
|
+
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
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, buildActiveRecordCard, } from '@sprucelabs/heartwood-view-controllers';
|
|
11
|
+
import { eventResponseUtil } from '@sprucelabs/spruce-event-utils';
|
|
12
|
+
export default class LocationListCardViewController extends AbstractViewController {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
super(options);
|
|
15
|
+
const { onDelete, selectedLocationId, footerButtons, currentOrganizationId, onEdit, } = options;
|
|
16
|
+
this.onDeleteHandler = onDelete;
|
|
17
|
+
this.selectedLocationId = selectedLocationId;
|
|
18
|
+
this.onEdit = onEdit;
|
|
19
|
+
this.activeRecordCardVc = this.Controller('activeRecordCard', buildActiveRecordCard({
|
|
20
|
+
header: {
|
|
21
|
+
title: 'Your locations',
|
|
22
|
+
},
|
|
23
|
+
eventName: 'list-locations::v2020_12_25',
|
|
24
|
+
target: {
|
|
25
|
+
organizationId: currentOrganizationId,
|
|
26
|
+
},
|
|
27
|
+
payload: {
|
|
28
|
+
includePrivateLocations: true,
|
|
29
|
+
},
|
|
30
|
+
responseKey: 'locations',
|
|
31
|
+
rowTransformer: this.buildRow.bind(this),
|
|
32
|
+
footer: footerButtons && {
|
|
33
|
+
buttons: footerButtons,
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
buildRow(location) {
|
|
38
|
+
return {
|
|
39
|
+
id: location.id,
|
|
40
|
+
cells: [
|
|
41
|
+
{
|
|
42
|
+
text: {
|
|
43
|
+
content: location.name,
|
|
44
|
+
},
|
|
45
|
+
subText: {
|
|
46
|
+
content: `${location.address
|
|
47
|
+
? `${location.address.street1}${location.address.street2
|
|
48
|
+
? ` ${location.address.street2}`
|
|
49
|
+
: ``} ${location.address.city} ${location.address.zip}`
|
|
50
|
+
: ``}`,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
this.selectedLocationId !== location.id && {
|
|
54
|
+
button: {
|
|
55
|
+
id: 'edit',
|
|
56
|
+
lineIcon: 'edit-box',
|
|
57
|
+
onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
var _a;
|
|
59
|
+
return (_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this, location);
|
|
60
|
+
}),
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
button: {
|
|
65
|
+
id: 'delete',
|
|
66
|
+
lineIcon: 'delete',
|
|
67
|
+
type: 'destructive',
|
|
68
|
+
onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
return this.handleDeleteLocation(location);
|
|
70
|
+
}),
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
].filter((c) => !!c),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
handleDeleteLocation(location) {
|
|
77
|
+
var _a;
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const shouldDelete = yield this.confirm({
|
|
80
|
+
title: `Delete ${location.name}`,
|
|
81
|
+
isDestructive: true,
|
|
82
|
+
});
|
|
83
|
+
if (!shouldDelete) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.activeRecordCardVc.setIsBusy(true);
|
|
87
|
+
try {
|
|
88
|
+
const client = yield this.connectToApi();
|
|
89
|
+
const results = yield client.emit('delete-location::v2020_12_25', {
|
|
90
|
+
target: {
|
|
91
|
+
locationId: location.id,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
eventResponseUtil.getFirstResponseOrThrow(results);
|
|
95
|
+
(_a = this.onDeleteHandler) === null || _a === void 0 ? void 0 : _a.call(this, location);
|
|
96
|
+
this.activeRecordCardVc.deleteRow(location.id);
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
yield this.alert({
|
|
100
|
+
message: err.message,
|
|
101
|
+
style: 'error',
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
this.activeRecordCardVc.setIsBusy(false);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
getCardVc() {
|
|
108
|
+
return this.activeRecordCardVc.getCardVc();
|
|
109
|
+
}
|
|
110
|
+
getActiveRecordVc() {
|
|
111
|
+
return this.activeRecordCardVc;
|
|
112
|
+
}
|
|
113
|
+
getSelectedLocationId() {
|
|
114
|
+
return this.selectedLocationId;
|
|
115
|
+
}
|
|
116
|
+
getListVc() {
|
|
117
|
+
return this.activeRecordCardVc.getListVc();
|
|
118
|
+
}
|
|
119
|
+
load() {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
yield this.activeRecordCardVc.load();
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
render() {
|
|
125
|
+
return this.activeRecordCardVc.render();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
LocationListCardViewController.id = 'location-list-card';
|
package/build/index-module.d.ts
CHANGED
package/build/index-module.js
CHANGED
|
@@ -3,6 +3,8 @@ 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
|
-
exports.organizationAssert = void 0;
|
|
6
|
+
exports.LocationListViewController = exports.organizationAssert = void 0;
|
|
7
7
|
var organizationAssert_1 = require("./tests/utilities/organizationAssert");
|
|
8
8
|
Object.defineProperty(exports, "organizationAssert", { enumerable: true, get: function () { return __importDefault(organizationAssert_1).default; } });
|
|
9
|
+
var LocationListCard_vc_1 = require("./viewControllers/LocationListCard.vc");
|
|
10
|
+
Object.defineProperty(exports, "LocationListViewController", { enumerable: true, get: function () { return __importDefault(LocationListCard_vc_1).default; } });
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AbstractViewController, SpruceSchemas, ViewControllerOptions, ActiveRecordCardViewController } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
3
|
+
declare type Location = SpruceSchemas.Spruce.v2020_07_22.Location;
|
|
4
|
+
declare type Button = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Button;
|
|
5
|
+
export default class LocationListCardViewController extends AbstractViewController<Card> {
|
|
6
|
+
static id: string;
|
|
7
|
+
private onDeleteHandler?;
|
|
8
|
+
private selectedLocationId?;
|
|
9
|
+
private onEdit?;
|
|
10
|
+
private activeRecordCardVc;
|
|
11
|
+
constructor(options: ViewControllerOptions & {
|
|
12
|
+
onDelete?: (location: Location) => void;
|
|
13
|
+
onEdit?: (location: Location) => void;
|
|
14
|
+
currentOrganizationId: string;
|
|
15
|
+
selectedLocationId?: string;
|
|
16
|
+
footerButtons?: Button[];
|
|
17
|
+
});
|
|
18
|
+
private buildRow;
|
|
19
|
+
private handleDeleteLocation;
|
|
20
|
+
getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
|
|
21
|
+
getActiveRecordVc(): ActiveRecordCardViewController;
|
|
22
|
+
getSelectedLocationId(): string | undefined;
|
|
23
|
+
getListVc(): import("@sprucelabs/heartwood-view-controllers").ListViewController;
|
|
24
|
+
load(): Promise<void>;
|
|
25
|
+
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
|
|
4
|
+
const spruce_event_utils_1 = require("@sprucelabs/spruce-event-utils");
|
|
5
|
+
class LocationListCardViewController extends heartwood_view_controllers_1.AbstractViewController {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super(options);
|
|
8
|
+
const { onDelete, selectedLocationId, footerButtons, currentOrganizationId, onEdit, } = options;
|
|
9
|
+
this.onDeleteHandler = onDelete;
|
|
10
|
+
this.selectedLocationId = selectedLocationId;
|
|
11
|
+
this.onEdit = onEdit;
|
|
12
|
+
this.activeRecordCardVc = this.Controller('activeRecordCard', (0, heartwood_view_controllers_1.buildActiveRecordCard)({
|
|
13
|
+
header: {
|
|
14
|
+
title: 'Your locations',
|
|
15
|
+
},
|
|
16
|
+
eventName: 'list-locations::v2020_12_25',
|
|
17
|
+
target: {
|
|
18
|
+
organizationId: currentOrganizationId,
|
|
19
|
+
},
|
|
20
|
+
payload: {
|
|
21
|
+
includePrivateLocations: true,
|
|
22
|
+
},
|
|
23
|
+
responseKey: 'locations',
|
|
24
|
+
rowTransformer: this.buildRow.bind(this),
|
|
25
|
+
footer: footerButtons && {
|
|
26
|
+
buttons: footerButtons,
|
|
27
|
+
},
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
buildRow(location) {
|
|
31
|
+
return {
|
|
32
|
+
id: location.id,
|
|
33
|
+
cells: [
|
|
34
|
+
{
|
|
35
|
+
text: {
|
|
36
|
+
content: location.name,
|
|
37
|
+
},
|
|
38
|
+
subText: {
|
|
39
|
+
content: `${location.address
|
|
40
|
+
? `${location.address.street1}${location.address.street2
|
|
41
|
+
? ` ${location.address.street2}`
|
|
42
|
+
: ``} ${location.address.city} ${location.address.zip}`
|
|
43
|
+
: ``}`,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
this.selectedLocationId !== location.id && {
|
|
47
|
+
button: {
|
|
48
|
+
id: 'edit',
|
|
49
|
+
lineIcon: 'edit-box',
|
|
50
|
+
onClick: async () => {
|
|
51
|
+
var _a;
|
|
52
|
+
return (_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this, location);
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
button: {
|
|
58
|
+
id: 'delete',
|
|
59
|
+
lineIcon: 'delete',
|
|
60
|
+
type: 'destructive',
|
|
61
|
+
onClick: async () => {
|
|
62
|
+
return this.handleDeleteLocation(location);
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
].filter((c) => !!c),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
async handleDeleteLocation(location) {
|
|
70
|
+
var _a;
|
|
71
|
+
const shouldDelete = await this.confirm({
|
|
72
|
+
title: `Delete ${location.name}`,
|
|
73
|
+
isDestructive: true,
|
|
74
|
+
});
|
|
75
|
+
if (!shouldDelete) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this.activeRecordCardVc.setIsBusy(true);
|
|
79
|
+
try {
|
|
80
|
+
const client = await this.connectToApi();
|
|
81
|
+
const results = await client.emit('delete-location::v2020_12_25', {
|
|
82
|
+
target: {
|
|
83
|
+
locationId: location.id,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
spruce_event_utils_1.eventResponseUtil.getFirstResponseOrThrow(results);
|
|
87
|
+
(_a = this.onDeleteHandler) === null || _a === void 0 ? void 0 : _a.call(this, location);
|
|
88
|
+
this.activeRecordCardVc.deleteRow(location.id);
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
await this.alert({
|
|
92
|
+
message: err.message,
|
|
93
|
+
style: 'error',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
this.activeRecordCardVc.setIsBusy(false);
|
|
97
|
+
}
|
|
98
|
+
getCardVc() {
|
|
99
|
+
return this.activeRecordCardVc.getCardVc();
|
|
100
|
+
}
|
|
101
|
+
getActiveRecordVc() {
|
|
102
|
+
return this.activeRecordCardVc;
|
|
103
|
+
}
|
|
104
|
+
getSelectedLocationId() {
|
|
105
|
+
return this.selectedLocationId;
|
|
106
|
+
}
|
|
107
|
+
getListVc() {
|
|
108
|
+
return this.activeRecordCardVc.getListVc();
|
|
109
|
+
}
|
|
110
|
+
async load() {
|
|
111
|
+
await this.activeRecordCardVc.load();
|
|
112
|
+
}
|
|
113
|
+
render() {
|
|
114
|
+
return this.activeRecordCardVc.render();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.default = LocationListCardViewController;
|
|
118
|
+
LocationListCardViewController.id = 'location-list-card';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sprucelabs/spruce-location-utils",
|
|
3
3
|
"description": "Location Utilities",
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"skill": {
|
|
6
6
|
"namespace": "locations"
|
|
7
7
|
},
|
|
@@ -18,10 +18,14 @@
|
|
|
18
18
|
"build/index-module.d.ts",
|
|
19
19
|
"build/tests/utilities/organizationAssert.js",
|
|
20
20
|
"build/tests/utilities/organizationAssert.d.ts",
|
|
21
|
+
"build/viewControllers/LocationListCard.vc.js",
|
|
22
|
+
"build/viewControllers/LocationListCard.vc.d.ts",
|
|
21
23
|
"build/esm/index-module.js",
|
|
22
24
|
"build/esm/index-module.d.ts",
|
|
23
25
|
"build/esm/tests/utilities/organizationAssert.js",
|
|
24
|
-
"build/esm/tests/utilities/organizationAssert.d.ts"
|
|
26
|
+
"build/esm/tests/utilities/organizationAssert.d.ts",
|
|
27
|
+
"build/esm/viewControllers/LocationListCard.vc.js",
|
|
28
|
+
"build/esm/viewControllers/LocationListCard.vc.d.ts"
|
|
25
29
|
],
|
|
26
30
|
"keywords": [],
|
|
27
31
|
"scripts": {
|
|
@@ -29,6 +33,7 @@
|
|
|
29
33
|
},
|
|
30
34
|
"dependencies": {
|
|
31
35
|
"@sprucelabs/heartwood-view-controllers": "latest",
|
|
36
|
+
"@sprucelabs/spruce-event-utils": "latest",
|
|
32
37
|
"@sprucelabs/spruce-test-fixtures": "latest",
|
|
33
38
|
"@sprucelabs/test": "latest"
|
|
34
39
|
},
|