Skip to content

Commit de5775c

Browse files
authored
New Components - widgetform (#16558)
* new components * pnpm-lock.yaml
1 parent d9950a6 commit de5775c

File tree

5 files changed

+167
-8
lines changed

5 files changed

+167
-8
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import widgetform from "../../widgetform.app.mjs";
2+
3+
export default {
4+
key: "widgetform-get-recent-submissions",
5+
name: "Get Recent Submissions",
6+
description: "Retrieves the 10 most recent submissions. [See the documentation](https://usewidgetform.notion.site/Zapier-API-185312164ccf808eb902f411608aa35d)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
widgetform,
11+
form: {
12+
propDefinition: [
13+
widgetform,
14+
"form",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.widgetform.listResponses({
20+
$,
21+
});
22+
const submissions = this.form
23+
? response.filter(({ form_name }) => form_name === this.form)
24+
: response;
25+
$.export("$summary", `Successfully retrieved ${submissions.length} submission${submissions.length === 1
26+
? ""
27+
: "s"}`);
28+
return submissions;
29+
},
30+
};

components/widgetform/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/widgetform",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Widgetform Components",
55
"main": "widgetform.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import widgetform from "../../widgetform.app.mjs";
2+
3+
export default {
4+
key: "widgetform-new-submission-instant",
5+
name: "New Form Submission (Instant)",
6+
description: "Emit new event when a form submission is received. [See the documentation](https://usewidgetform.notion.site/Zapier-API-185312164ccf808eb902f411608aa35d)",
7+
version: "0.0.1",
8+
type: "source",
9+
props: {
10+
widgetform,
11+
db: "$.service.db",
12+
http: "$.interface.http",
13+
form: {
14+
propDefinition: [
15+
widgetform,
16+
"form",
17+
],
18+
},
19+
},
20+
hooks: {
21+
async activate() {
22+
const { id } = await this.widgetform.createSubscription({
23+
data: {
24+
hook_url: this.http.endpoint,
25+
},
26+
});
27+
if (!id) {
28+
throw new Error("Error creating subscription");
29+
}
30+
this._setSubscriptionId(id);
31+
},
32+
async deactivate() {
33+
const id = this._getSubscriptionId();
34+
if (!id) {
35+
return;
36+
}
37+
await this.widgetform.deleteSubscription({
38+
data: {
39+
subscription_id: id,
40+
},
41+
});
42+
},
43+
async deploy() {
44+
const response = await this.widgetform.listResponses();
45+
if (!response?.length) {
46+
return;
47+
}
48+
const submissions = this.form
49+
? response.filter(({ form_name }) => form_name === this.form)
50+
: response;
51+
submissions.reverse().forEach((submission) => {
52+
const meta = this.generateMeta(submission);
53+
this.$emit(submission, meta);
54+
});
55+
},
56+
},
57+
methods: {
58+
_getSubscriptionId() {
59+
return this.db.get("subscriptionId");
60+
},
61+
_setSubscriptionId(subscriptionId) {
62+
this.db.set("subscriptionId", subscriptionId);
63+
},
64+
generateMeta(submission) {
65+
const ts = Date.now();
66+
return {
67+
id: ts,
68+
summary: `New Submission for ${submission.form_name}`,
69+
ts,
70+
};
71+
},
72+
},
73+
async run(event) {
74+
const submission = event.body;
75+
if (!submission || (this.form && (submission.form_name !== this.form))) {
76+
return;
77+
}
78+
const meta = this.generateMeta(submission);
79+
this.$emit(submission, meta);
80+
},
81+
};
Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,52 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "widgetform",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
form: {
8+
type: "string",
9+
label: "Form",
10+
description: "Filter results by form name",
11+
optional: true,
12+
},
13+
},
514
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
15+
_baseUrl() {
16+
return "https://usewidgetform.com/api/v1";
17+
},
18+
_makeRequest({
19+
$ = this,
20+
path,
21+
...otherOpts
22+
}) {
23+
return axios($, {
24+
url: `${this._baseUrl()}${path}`,
25+
headers: {
26+
"x-api-key": this.$auth.api_key,
27+
},
28+
...otherOpts,
29+
});
30+
},
31+
listResponses(opts = {}) {
32+
return this._makeRequest({
33+
path: "/hooks/zapier/responses",
34+
...opts,
35+
});
36+
},
37+
createSubscription(opts = {}) {
38+
return this._makeRequest({
39+
method: "POST",
40+
path: "/hooks/zapier/subscription",
41+
...opts,
42+
});
43+
},
44+
deleteSubscription(opts = {}) {
45+
return this._makeRequest({
46+
method: "DELETE",
47+
path: "/hooks/zapier/subscription",
48+
...opts,
49+
});
950
},
1051
},
11-
};
52+
};

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)