@sprucelabs/spruce-organization-utils 1.0.0 → 2.0.3

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