From c19a29f32644f04097d5f1d562e4bebe1ac12baa Mon Sep 17 00:00:00 2001 From: shamsmosowi Date: Wed, 20 Apr 2022 12:46:39 +0100 Subject: [PATCH] webform --- .../TableHeader/Extensions/index.tsx | 3 - .../TableHeader/Webhooks/Schemas/index.ts | 3 +- .../TableHeader/Webhooks/Schemas/webform.tsx | 93 +++++++++++++++++++ src/components/TableHeader/Webhooks/utils.tsx | 5 +- src/hooks/useTable/useTableConfig.ts | 3 +- 5 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 src/components/TableHeader/Webhooks/Schemas/webform.tsx diff --git a/src/components/TableHeader/Extensions/index.tsx b/src/components/TableHeader/Extensions/index.tsx index d6891824..894a4fe6 100644 --- a/src/components/TableHeader/Extensions/index.tsx +++ b/src/components/TableHeader/Extensions/index.tsx @@ -207,7 +207,6 @@ export default function Extensions() { onClick={handleOpen} icon={} /> - {open && !!tableState && ( )} - {extensionModal && ( setExtensionModal(null)} @@ -262,7 +260,6 @@ export default function Extensions() { extensionObject={extensionModal.extensionObject} /> )} - {openMigrationGuide && ( setOpenMigrationGuide(false)} diff --git a/src/components/TableHeader/Webhooks/Schemas/index.ts b/src/components/TableHeader/Webhooks/Schemas/index.ts index 85b55ae2..15ea2a1a 100644 --- a/src/components/TableHeader/Webhooks/Schemas/index.ts +++ b/src/components/TableHeader/Webhooks/Schemas/index.ts @@ -1,5 +1,6 @@ import basic from "./basic"; import typeform from "./typeform"; import sendgrid from "./sendgrid"; +import webform from "./webform"; -export { basic, typeform, sendgrid }; +export { basic, typeform, sendgrid, webform }; diff --git a/src/components/TableHeader/Webhooks/Schemas/webform.tsx b/src/components/TableHeader/Webhooks/Schemas/webform.tsx new file mode 100644 index 00000000..df3bdffa --- /dev/null +++ b/src/components/TableHeader/Webhooks/Schemas/webform.tsx @@ -0,0 +1,93 @@ +import { Typography, Link, TextField } from "@mui/material"; +import InlineOpenInNewIcon from "@src/components/InlineOpenInNewIcon"; + +export const webhook = { + name: "Web Form", + type: "webform", + parser: { + additionalVariables: null, + extraLibs: null, + template: (table) => `const formParser: Parser = async({req, db,ref}) => { + // request is the request object from the webhook + // db is the database object + // ref is the reference to collection of the table + // the returned object will be added as a new row to the table + // eg: adding the webhook body as row + const {body} = req; + ${ + table.audit !== false + ? ` + // auditField + const ${ + table.auditFieldCreatedBy ?? "_createdBy" + } = await rowy.metadata.serviceAccountUser() + return { + ...body, + ${table.auditFieldCreatedBy ?? "_createdBy"} + } + ` + : ` + return body; + ` + } + + }`, + }, + condition: { + additionalVariables: null, + extraLibs: null, + template: (table) => `const condition: Condition = async({ref,req,db}) => { + // feel free to add your own code logic here + return true; + }`, + }, + auth: (webhookObject, setWebhookObject) => { + return ( + <> + + Add your capture key + + these instructions + + +
+ Then add the secret below. +
+ + { + setWebhookObject({ + ...webhookObject, + auth: { ...webhookObject.auth, secret: e.target.value }, + }); + }} + /> + + { + setWebhookObject({ + ...webhookObject, + auth: { ...webhookObject.auth, minimumScore: e.target.value }, + }); + }} + /> + + ); + }, +}; + +export default webhook; diff --git a/src/components/TableHeader/Webhooks/utils.tsx b/src/components/TableHeader/Webhooks/utils.tsx index b5f95510..83014721 100644 --- a/src/components/TableHeader/Webhooks/utils.tsx +++ b/src/components/TableHeader/Webhooks/utils.tsx @@ -1,9 +1,10 @@ import { generateRandomId } from "@src/utils/fns"; -import { typeform, basic, sendgrid } from "./Schemas"; +import { typeform, basic, sendgrid, webform } from "./Schemas"; export const webhookTypes = [ "basic", "typeform", "sendgrid", + "webform", //"shopify", //"twitter", //"stripe", @@ -53,6 +54,7 @@ export const webhookNames: Record = { // twitter: "Twitter", // stripe: "Stripe", basic: "Basic", + webform: "Web form", }; export interface IWebhookEditor { @@ -78,6 +80,7 @@ export const webhookSchemas = { basic, typeform, sendgrid, + webform, }; export function emptyWebhookObject( diff --git a/src/hooks/useTable/useTableConfig.ts b/src/hooks/useTable/useTableConfig.ts index 76e40cdc..bf6ad3c2 100644 --- a/src/hooks/useTable/useTableConfig.ts +++ b/src/hooks/useTable/useTableConfig.ts @@ -210,13 +210,12 @@ const useTableConfig = (tableId?: string) => { * @param key name of parameter eg. rowHeight * @param value new value eg. 65 */ - const updateConfig = (key: string, value: any, callback?: Function) => { + const updateConfig = (key: string, value: any, callback?: Function) => documentDispatch({ action: DocActions.update, data: { [key]: value }, callback, }); - }; const actions = { insert, updateColumn,