Skip to content

Commit 9b9f279

Browse files
committed
new components
1 parent 3e72137 commit 9b9f279

File tree

7 files changed

+181
-2
lines changed

7 files changed

+181
-2
lines changed

components/hubspot/actions/common/common-create-object.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@ export default {
3333
isDefaultProperty() {
3434
return false;
3535
},
36+
createObject(opts = {}) {
37+
return this.hubspot.createObject(opts);
38+
},
3639
},
3740
async run({ $ }) {
3841
const {
3942
hubspot,
4043
/* eslint-disable no-unused-vars */
4144
propertyGroups,
45+
customObjectType,
46+
contactId,
4247
$db,
4348
updateIfExists,
4449
...properties
@@ -54,7 +59,7 @@ export default {
5459
}
5560
});
5661
try {
57-
const response = await hubspot.createObject({
62+
const response = await this.createObject({
5863
$,
5964
objectType,
6065
data: {

components/hubspot/actions/common/common-update-object.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default {
3232
hubspot,
3333
/* eslint-disable no-unused-vars */
3434
propertyGroups,
35+
customObjectType,
3536
$db,
3637
objectId,
3738
...properties
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import hubspot from "../../hubspot.app.mjs";
2+
import common from "../common/common-create-object.mjs";
3+
4+
export default {
5+
...common,
6+
key: "hubspot-create-custom-object",
7+
name: "Create Custom Object",
8+
description: "Create a new custom object in Hubspot. [See the documentation](https://developers.hubspot.com/beta-docs/guides/api/crm/objects/custom-objects#create-a-custom-object)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
hubspot,
13+
customObjectType: {
14+
propDefinition: [
15+
hubspot,
16+
"customObjectType",
17+
],
18+
},
19+
...common.props,
20+
},
21+
methods: {
22+
...common.methods,
23+
getObjectType() {
24+
return this.customObjectType;
25+
},
26+
},
27+
};
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import {
2+
OBJECT_TYPE, ASSOCIATION_CATEGORY,
3+
} from "../../common/constants.mjs";
4+
import common from "../common/common-create-object.mjs";
5+
import hubspot from "../../hubspot.app.mjs";
6+
7+
export default {
8+
...common,
9+
key: "hubspot-create-lead",
10+
name: "Create Lead",
11+
description: "Create a lead in Hubspot. [See the documentation](https://developers.hubspot.com/beta-docs/guides/api/crm/objects/leads#create-leads)",
12+
version: "0.0.1",
13+
type: "action",
14+
props: {
15+
hubspot,
16+
contactId: {
17+
propDefinition: [
18+
hubspot,
19+
"objectId",
20+
() => ({
21+
objectType: "contact",
22+
}),
23+
],
24+
label: "Contact ID",
25+
description: "The contact to associate with the lead",
26+
},
27+
...common.props,
28+
},
29+
methods: {
30+
...common.methods,
31+
getObjectType() {
32+
return OBJECT_TYPE.LEAD;
33+
},
34+
createObject(opts) {
35+
return this.hubspot.createObject({
36+
...opts,
37+
data: {
38+
...opts?.data,
39+
associations: [
40+
{
41+
types: [
42+
{
43+
associationCategory: ASSOCIATION_CATEGORY.HUBSPOT_DEFINED,
44+
associationTypeId: 578, // ID for "Lead with Primary Contact"
45+
},
46+
],
47+
to: {
48+
id: this.contactId,
49+
},
50+
},
51+
],
52+
},
53+
});
54+
},
55+
},
56+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import common from "../common/common-update-object.mjs";
2+
import hubspot from "../../hubspot.app.mjs";
3+
4+
export default {
5+
...common,
6+
key: "hubspot-update-custom-object",
7+
name: "Update Custom Object",
8+
description: "Update a custom object in Hubspot. [See the documentation](https://developers.hubspot.com/beta-docs/guides/api/crm/objects/custom-objects#update-existing-custom-objects)",
9+
version: "0.0.1",
10+
type: "action",
11+
methods: {
12+
...common.methods,
13+
getObjectType() {
14+
return this.customObjectType;
15+
},
16+
},
17+
props: {
18+
hubspot,
19+
customObjectType: {
20+
propDefinition: [
21+
hubspot,
22+
"customObjectType",
23+
],
24+
},
25+
objectId: {
26+
propDefinition: [
27+
hubspot,
28+
"objectId",
29+
(c) => ({
30+
objectType: c.customObjectType,
31+
}),
32+
],
33+
description: "The ID of the custom object",
34+
},
35+
...common.props,
36+
},
37+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { OBJECT_TYPE } from "../../common/constants.mjs";
2+
import common from "../common/common-update-object.mjs";
3+
import hubspot from "../../hubspot.app.mjs";
4+
5+
export default {
6+
...common,
7+
key: "hubspot-update-lead",
8+
name: "Update Lead",
9+
description: "Update a lead in Hubspot. [See the documentation](https://developers.hubspot.com/beta-docs/guides/api/crm/objects/leads#update-leads)",
10+
version: "0.0.1",
11+
type: "action",
12+
methods: {
13+
...common.methods,
14+
getObjectType() {
15+
return OBJECT_TYPE.LEAD;
16+
},
17+
},
18+
props: {
19+
hubspot,
20+
objectId: {
21+
propDefinition: [
22+
hubspot,
23+
"leadId",
24+
],
25+
},
26+
...common.props,
27+
},
28+
};

components/hubspot/hubspot.app.mjs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export default {
124124
description: "Watch for new events concerning the objects selected.",
125125
async options({
126126
objectType, ...opts
127-
}) { console.log(opts);
127+
}) {
128128
return objectType
129129
? await this.createOptions(objectType, opts)
130130
: [];
@@ -412,6 +412,31 @@ export default {
412412
}));
413413
},
414414
},
415+
leadId: {
416+
type: "string",
417+
label: "Lead ID",
418+
description: "The identifier of the lead",
419+
async options() {
420+
const { results } = await this.listObjectsInPage("lead", undefined, {
421+
properties: "hs_lead_name",
422+
});
423+
return results?.map(({
424+
id: value, properties,
425+
}) => ({
426+
value,
427+
label: properties?.hs_lead_name || value,
428+
})) || [];
429+
},
430+
},
431+
customObjectType: {
432+
type: "string",
433+
label: "Custom Object Type",
434+
description: "Tye type of custom object to create",
435+
async options() {
436+
const { results } = await this.listSchemas();
437+
return results?.map(({ name }) => name ) || [];
438+
},
439+
},
415440
},
416441
methods: {
417442
_getHeaders() {

0 commit comments

Comments
 (0)