@sprucelabs/spruce-organization-utils 0.8.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/README.md +4 -0
- package/build/esm/index-module.d.ts +1 -0
- package/build/esm/index-module.js +1 -0
- package/build/esm/viewControllers/OrgListCard.vc.d.ts +28 -0
- package/build/esm/viewControllers/OrgListCard.vc.js +114 -0
- package/build/index-module.d.ts +1 -0
- package/build/index-module.js +8 -0
- package/build/viewControllers/OrgListCard.vc.d.ts +28 -0
- package/build/viewControllers/OrgListCard.vc.js +102 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as OrgListCardViewController } from './viewControllers/OrgListCard.vc';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as OrgListCardViewController } from './viewControllers/OrgListCard.vc.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AbstractViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
3
|
+
declare type Organization = SpruceSchemas.Spruce.v2020_07_22.Organization;
|
|
4
|
+
declare type Button = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Button;
|
|
5
|
+
declare type Row = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.ListRow;
|
|
6
|
+
declare type OnDeleteHandler = (organization: Organization) => void | Promise<void>;
|
|
7
|
+
declare type OnEditHandler = (organization: Organization) => void | Promise<void>;
|
|
8
|
+
export default class OrgListCardViewController extends AbstractViewController<Card> {
|
|
9
|
+
static id: string;
|
|
10
|
+
private activeRecordCardVc;
|
|
11
|
+
private onDelete;
|
|
12
|
+
private onEdit?;
|
|
13
|
+
private selectedOrgId?;
|
|
14
|
+
constructor(options: {
|
|
15
|
+
onDelete?: OnDeleteHandler;
|
|
16
|
+
onEdit?: OnEditHandler;
|
|
17
|
+
footerButtons?: Button[];
|
|
18
|
+
selectedOrgId?: string;
|
|
19
|
+
} & ViewControllerOptions);
|
|
20
|
+
private handleClickDeleteOrg;
|
|
21
|
+
buildRow(org: Organization): Row;
|
|
22
|
+
handleDeletOrg(org: SpruceSchemas.Spruce.v2020_07_22.Organization): Promise<void>;
|
|
23
|
+
load(): Promise<void>;
|
|
24
|
+
getListVc(): import("@sprucelabs/heartwood-view-controllers").ListViewController;
|
|
25
|
+
getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
|
|
26
|
+
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
export default class OrgListCardViewController extends AbstractViewController {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options);
|
|
14
|
+
this.onDelete = options.onDelete;
|
|
15
|
+
this.selectedOrgId = options.selectedOrgId;
|
|
16
|
+
this.onEdit = options.onEdit;
|
|
17
|
+
this.activeRecordCardVc = this.Controller('activeRecordCard', buildActiveRecordCard({
|
|
18
|
+
eventName: 'list-organizations::v2020_12_25',
|
|
19
|
+
responseKey: 'organizations',
|
|
20
|
+
columnWidths: ['fill'],
|
|
21
|
+
shouldRenderRowDividers: true,
|
|
22
|
+
rowTransformer: this.buildRow.bind(this),
|
|
23
|
+
payload: {
|
|
24
|
+
shouldOnlyShowMine: true,
|
|
25
|
+
},
|
|
26
|
+
header: {
|
|
27
|
+
title: 'Your organizations',
|
|
28
|
+
subtitle: 'Each of your brands, companies, or teams are here! 👇',
|
|
29
|
+
},
|
|
30
|
+
footer: {
|
|
31
|
+
buttons: options.footerButtons,
|
|
32
|
+
},
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
handleClickDeleteOrg(org) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const shouldDelete = yield this.confirm({
|
|
38
|
+
title: `Delete ${org.name}`,
|
|
39
|
+
isDestructive: true,
|
|
40
|
+
});
|
|
41
|
+
if (!shouldDelete) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
yield this.handleDeletOrg(org);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
buildRow(org) {
|
|
48
|
+
return {
|
|
49
|
+
id: org.id,
|
|
50
|
+
//@ts-ignore
|
|
51
|
+
cells: [
|
|
52
|
+
{
|
|
53
|
+
text: {
|
|
54
|
+
content: org.name,
|
|
55
|
+
},
|
|
56
|
+
subText: {
|
|
57
|
+
content: `${org.address
|
|
58
|
+
? `${org.address.street1}${org.address.street2 ? ` ${org.address.street2}` : ``} ${org.address.city} ${org.address.zip}`
|
|
59
|
+
: ``}`,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
this.selectedOrgId !== org.id && {
|
|
63
|
+
button: {
|
|
64
|
+
lineIcon: 'edit-box',
|
|
65
|
+
id: 'edit',
|
|
66
|
+
onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
var _a;
|
|
68
|
+
yield ((_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this, org));
|
|
69
|
+
}),
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
button: {
|
|
74
|
+
type: 'destructive',
|
|
75
|
+
lineIcon: 'delete',
|
|
76
|
+
onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
yield this.handleClickDeleteOrg(org);
|
|
78
|
+
}),
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
].filter((b) => !!b),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
handleDeletOrg(org) {
|
|
85
|
+
var _a;
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
yield ((_a = this.onDelete) === null || _a === void 0 ? void 0 : _a.call(this, org));
|
|
88
|
+
this.activeRecordCardVc.deleteRow(org.id);
|
|
89
|
+
this.activeRecordCardVc.setIsBusy(true);
|
|
90
|
+
const client = yield this.connectToApi();
|
|
91
|
+
yield client.emit('delete-organization::v2020_12_25', {
|
|
92
|
+
target: {
|
|
93
|
+
organizationId: org.id,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
this.activeRecordCardVc.setIsBusy(false);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
load() {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
yield this.activeRecordCardVc.load();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
getListVc() {
|
|
105
|
+
return this.activeRecordCardVc.getListVc();
|
|
106
|
+
}
|
|
107
|
+
getCardVc() {
|
|
108
|
+
return this.activeRecordCardVc.getCardVc();
|
|
109
|
+
}
|
|
110
|
+
render() {
|
|
111
|
+
return this.activeRecordCardVc.render();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
OrgListCardViewController.id = 'org-list-card';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as OrgListCardViewController } from './viewControllers/OrgListCard.vc';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OrgListCardViewController = void 0;
|
|
7
|
+
var OrgListCard_vc_1 = require("./viewControllers/OrgListCard.vc");
|
|
8
|
+
Object.defineProperty(exports, "OrgListCardViewController", { enumerable: true, get: function () { return __importDefault(OrgListCard_vc_1).default; } });
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AbstractViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
3
|
+
declare type Organization = SpruceSchemas.Spruce.v2020_07_22.Organization;
|
|
4
|
+
declare type Button = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Button;
|
|
5
|
+
declare type Row = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.ListRow;
|
|
6
|
+
declare type OnDeleteHandler = (organization: Organization) => void | Promise<void>;
|
|
7
|
+
declare type OnEditHandler = (organization: Organization) => void | Promise<void>;
|
|
8
|
+
export default class OrgListCardViewController extends AbstractViewController<Card> {
|
|
9
|
+
static id: string;
|
|
10
|
+
private activeRecordCardVc;
|
|
11
|
+
private onDelete;
|
|
12
|
+
private onEdit?;
|
|
13
|
+
private selectedOrgId?;
|
|
14
|
+
constructor(options: {
|
|
15
|
+
onDelete?: OnDeleteHandler;
|
|
16
|
+
onEdit?: OnEditHandler;
|
|
17
|
+
footerButtons?: Button[];
|
|
18
|
+
selectedOrgId?: string;
|
|
19
|
+
} & ViewControllerOptions);
|
|
20
|
+
private handleClickDeleteOrg;
|
|
21
|
+
buildRow(org: Organization): Row;
|
|
22
|
+
handleDeletOrg(org: SpruceSchemas.Spruce.v2020_07_22.Organization): Promise<void>;
|
|
23
|
+
load(): Promise<void>;
|
|
24
|
+
getListVc(): import("@sprucelabs/heartwood-view-controllers").ListViewController;
|
|
25
|
+
getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
|
|
26
|
+
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
|
|
4
|
+
class OrgListCardViewController extends heartwood_view_controllers_1.AbstractViewController {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
super(options);
|
|
7
|
+
this.onDelete = options.onDelete;
|
|
8
|
+
this.selectedOrgId = options.selectedOrgId;
|
|
9
|
+
this.onEdit = options.onEdit;
|
|
10
|
+
this.activeRecordCardVc = this.Controller('activeRecordCard', (0, heartwood_view_controllers_1.buildActiveRecordCard)({
|
|
11
|
+
eventName: 'list-organizations::v2020_12_25',
|
|
12
|
+
responseKey: 'organizations',
|
|
13
|
+
columnWidths: ['fill'],
|
|
14
|
+
shouldRenderRowDividers: true,
|
|
15
|
+
rowTransformer: this.buildRow.bind(this),
|
|
16
|
+
payload: {
|
|
17
|
+
shouldOnlyShowMine: true,
|
|
18
|
+
},
|
|
19
|
+
header: {
|
|
20
|
+
title: 'Your organizations',
|
|
21
|
+
subtitle: 'Each of your brands, companies, or teams are here! 👇',
|
|
22
|
+
},
|
|
23
|
+
footer: {
|
|
24
|
+
buttons: options.footerButtons,
|
|
25
|
+
},
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
async handleClickDeleteOrg(org) {
|
|
29
|
+
const shouldDelete = await this.confirm({
|
|
30
|
+
title: `Delete ${org.name}`,
|
|
31
|
+
isDestructive: true,
|
|
32
|
+
});
|
|
33
|
+
if (!shouldDelete) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
await this.handleDeletOrg(org);
|
|
37
|
+
}
|
|
38
|
+
buildRow(org) {
|
|
39
|
+
return {
|
|
40
|
+
id: org.id,
|
|
41
|
+
//@ts-ignore
|
|
42
|
+
cells: [
|
|
43
|
+
{
|
|
44
|
+
text: {
|
|
45
|
+
content: org.name,
|
|
46
|
+
},
|
|
47
|
+
subText: {
|
|
48
|
+
content: `${org.address
|
|
49
|
+
? `${org.address.street1}${org.address.street2 ? ` ${org.address.street2}` : ``} ${org.address.city} ${org.address.zip}`
|
|
50
|
+
: ``}`,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
this.selectedOrgId !== org.id && {
|
|
54
|
+
button: {
|
|
55
|
+
lineIcon: 'edit-box',
|
|
56
|
+
id: 'edit',
|
|
57
|
+
onClick: async () => {
|
|
58
|
+
var _a;
|
|
59
|
+
await ((_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this, org));
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
button: {
|
|
65
|
+
type: 'destructive',
|
|
66
|
+
lineIcon: 'delete',
|
|
67
|
+
onClick: async () => {
|
|
68
|
+
await this.handleClickDeleteOrg(org);
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
].filter((b) => !!b),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
async handleDeletOrg(org) {
|
|
76
|
+
var _a;
|
|
77
|
+
await ((_a = this.onDelete) === null || _a === void 0 ? void 0 : _a.call(this, org));
|
|
78
|
+
this.activeRecordCardVc.deleteRow(org.id);
|
|
79
|
+
this.activeRecordCardVc.setIsBusy(true);
|
|
80
|
+
const client = await this.connectToApi();
|
|
81
|
+
await client.emit('delete-organization::v2020_12_25', {
|
|
82
|
+
target: {
|
|
83
|
+
organizationId: org.id,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
this.activeRecordCardVc.setIsBusy(false);
|
|
87
|
+
}
|
|
88
|
+
async load() {
|
|
89
|
+
await this.activeRecordCardVc.load();
|
|
90
|
+
}
|
|
91
|
+
getListVc() {
|
|
92
|
+
return this.activeRecordCardVc.getListVc();
|
|
93
|
+
}
|
|
94
|
+
getCardVc() {
|
|
95
|
+
return this.activeRecordCardVc.getCardVc();
|
|
96
|
+
}
|
|
97
|
+
render() {
|
|
98
|
+
return this.activeRecordCardVc.render();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.default = OrgListCardViewController;
|
|
102
|
+
OrgListCardViewController.id = 'org-list-card';
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sprucelabs/spruce-organization-utils",
|
|
3
|
+
"description": "Support for working with organizations and Sprucebot. 📈",
|
|
4
|
+
"version": "0.8.0",
|
|
5
|
+
"skill": {
|
|
6
|
+
"namespace": "organization"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://github.com/sprucelabsai/spruce-organization-skill",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/sprucelabsai/spruce-organization-skill/issues"
|
|
11
|
+
},
|
|
12
|
+
"main": "./build/index-module.js",
|
|
13
|
+
"types": "./build/index-module.d.ts",
|
|
14
|
+
"module": "./build/esm/index-module.js",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"files": [
|
|
17
|
+
"build/index-module.js",
|
|
18
|
+
"build/index-module.d.ts",
|
|
19
|
+
"build/viewControllers/OrgListCard.vc.js",
|
|
20
|
+
"build/viewControllers/OrgListCard.vc.d.ts",
|
|
21
|
+
"build/esm/index-module.js",
|
|
22
|
+
"build/esm/index-module.d.ts",
|
|
23
|
+
"build/esm/viewControllers/OrgListCard.vc.js",
|
|
24
|
+
"build/esm/viewControllers/OrgListCard.vc.d.ts"
|
|
25
|
+
],
|
|
26
|
+
"keywords": [],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"release": "npm publish"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@sprucelabs/test": "latest"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": "16.x",
|
|
35
|
+
"yarn": "1.x"
|
|
36
|
+
}
|
|
37
|
+
}
|