-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - widgetform #16558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - widgetform #16558
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
components/widgetform/actions/get-recent-submissions/get-recent-submissions.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import widgetform from "../../widgetform.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "widgetform-get-recent-submissions", | ||
| name: "Get Recent Submissions", | ||
| description: "Retrieves the 10 most recent submissions. [See the documentation](https://usewidgetform.notion.site/Zapier-API-185312164ccf808eb902f411608aa35d)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| widgetform, | ||
| form: { | ||
| propDefinition: [ | ||
| widgetform, | ||
| "form", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.widgetform.listResponses({ | ||
| $, | ||
| }); | ||
| const submissions = this.form | ||
| ? response.filter(({ form_name }) => form_name === this.form) | ||
| : response; | ||
| $.export("$summary", `Successfully retrieved ${submissions.length} submission${submissions.length === 1 | ||
| ? "" | ||
| : "s"}`); | ||
| return submissions; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/widgetform", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Widgetform Components", | ||
| "main": "widgetform.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3" | ||
| } | ||
| } | ||
| } | ||
81 changes: 81 additions & 0 deletions
81
components/widgetform/sources/new-submission-instant/new-submission-instant.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import widgetform from "../../widgetform.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "widgetform-new-submission-instant", | ||
| name: "New Form Submission (Instant)", | ||
| description: "Emit new event when a form submission is received. [See the documentation](https://usewidgetform.notion.site/Zapier-API-185312164ccf808eb902f411608aa35d)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| props: { | ||
| widgetform, | ||
| db: "$.service.db", | ||
| http: "$.interface.http", | ||
| form: { | ||
| propDefinition: [ | ||
| widgetform, | ||
| "form", | ||
| ], | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async activate() { | ||
| const { id } = await this.widgetform.createSubscription({ | ||
| data: { | ||
| hook_url: this.http.endpoint, | ||
| }, | ||
| }); | ||
| if (!id) { | ||
| throw new Error("Error creating subscription"); | ||
| } | ||
| this._setSubscriptionId(id); | ||
| }, | ||
| async deactivate() { | ||
| const id = this._getSubscriptionId(); | ||
| if (!id) { | ||
| return; | ||
| } | ||
| await this.widgetform.deleteSubscription({ | ||
| data: { | ||
| subscription_id: id, | ||
| }, | ||
| }); | ||
| }, | ||
| async deploy() { | ||
| const response = await this.widgetform.listResponses(); | ||
| if (!response?.length) { | ||
| return; | ||
| } | ||
| const submissions = this.form | ||
| ? response.filter(({ form_name }) => form_name === this.form) | ||
| : response; | ||
| submissions.reverse().forEach((submission) => { | ||
| const meta = this.generateMeta(submission); | ||
| this.$emit(submission, meta); | ||
| }); | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getSubscriptionId() { | ||
| return this.db.get("subscriptionId"); | ||
| }, | ||
| _setSubscriptionId(subscriptionId) { | ||
| this.db.set("subscriptionId", subscriptionId); | ||
| }, | ||
| generateMeta(submission) { | ||
| const ts = Date.now(); | ||
| return { | ||
| id: ts, | ||
| summary: `New Submission for ${submission.form_name}`, | ||
| ts, | ||
| }; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| async run(event) { | ||
| const submission = event.body; | ||
| if (!submission || (this.form && (submission.form_name !== this.form))) { | ||
| return; | ||
| } | ||
| const meta = this.generateMeta(submission); | ||
| this.$emit(submission, meta); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,52 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "widgetform", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| form: { | ||
| type: "string", | ||
| label: "Form", | ||
| description: "Filter results by form name", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://usewidgetform.com/api/v1"; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, | ||
| path, | ||
| ...otherOpts | ||
| }) { | ||
| return axios($, { | ||
| url: `${this._baseUrl()}${path}`, | ||
| headers: { | ||
| "x-api-key": this.$auth.api_key, | ||
| }, | ||
| ...otherOpts, | ||
| }); | ||
| }, | ||
| listResponses(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/hooks/zapier/responses", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| createSubscription(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/hooks/zapier/subscription", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| deleteSubscription(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "DELETE", | ||
| path: "/hooks/zapier/subscription", | ||
| ...opts, | ||
| }); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }; | ||
| }; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.