This commit is contained in:
shamsmosowi
2022-04-20 12:46:39 +01:00
parent d54e8c5eeb
commit c19a29f326
5 changed files with 100 additions and 7 deletions

View File

@@ -207,7 +207,6 @@ export default function Extensions() {
onClick={handleOpen}
icon={<ExtensionIcon />}
/>
{open && !!tableState && (
<Modal
onClose={handleClose}
@@ -252,7 +251,6 @@ export default function Extensions() {
}}
/>
)}
{extensionModal && (
<ExtensionModal
handleClose={() => setExtensionModal(null)}
@@ -262,7 +260,6 @@ export default function Extensions() {
extensionObject={extensionModal.extensionObject}
/>
)}
{openMigrationGuide && (
<ExtensionMigration
handleClose={() => setOpenMigrationGuide(false)}

View File

@@ -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 };

View File

@@ -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 (
<>
<Typography gutterBottom>
Add your capture key
<Link
href=""
target="_blank"
rel="noopener noreferrer"
variant="inherit"
>
these instructions
<InlineOpenInNewIcon />
</Link>
<br />
Then add the secret below.
</Typography>
<TextField
id="api-key"
label="API Key"
fullWidth
value={webhookObject.auth.secret}
onChange={(e) => {
setWebhookObject({
...webhookObject,
auth: { ...webhookObject.auth, secret: e.target.value },
});
}}
/>
<TextField
id="minimum-score"
label="Minimum score"
fullWidth
type="number"
value={webhookObject.auth.minimumScore}
onChange={(e) => {
setWebhookObject({
...webhookObject,
auth: { ...webhookObject.auth, minimumScore: e.target.value },
});
}}
/>
</>
);
},
};
export default webhook;

View File

@@ -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<WebhookType, string> = {
// 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(

View File

@@ -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,