From 5cf9c4d0f8c9a690334e2f641068acaf44e32e15 Mon Sep 17 00:00:00 2001 From: Sidney Alcantara Date: Tue, 2 Nov 2021 16:56:51 +1100 Subject: [PATCH] remove old Table/Settings/Webhooks file --- src/components/Table/Settings/Webhooks.tsx | 186 --------------------- 1 file changed, 186 deletions(-) delete mode 100644 src/components/Table/Settings/Webhooks.tsx diff --git a/src/components/Table/Settings/Webhooks.tsx b/src/components/Table/Settings/Webhooks.tsx deleted file mode 100644 index 7bc09cb4..00000000 --- a/src/components/Table/Settings/Webhooks.tsx +++ /dev/null @@ -1,186 +0,0 @@ -import React, { useState, useEffect } from "react"; -import { makeStyles, createStyles } from "@mui/styles"; - -import Button from "@mui/material/Button"; -import Dialog, { DialogProps } from "@mui/material/Dialog"; -import DialogActions from "@mui/material/DialogActions"; -import DialogContent from "@mui/material/DialogContent"; - -import DialogTitle from "@mui/material/DialogTitle"; -import FormControl from "@mui/material/FormControl"; -import Typography from "@mui/material/Typography"; - -import FormControlLabel from "@mui/material/FormControlLabel"; -import InputLabel from "@mui/material/InputLabel"; -import MenuItem from "@mui/material/MenuItem"; -import Select from "@mui/material/Select"; -import Switch from "@mui/material/Switch"; -// import CodeEditor from "../editors/CodeEditor"; -import { useProjectContext } from "@src/contexts/ProjectContext"; -import { makeId } from "../../../utils/fns"; - -const useStyles = makeStyles((theme) => - createStyles({ - form: { - display: "flex", - flexDirection: "column", - margin: "auto", - width: "fit-content", - }, - formControl: { - marginTop: theme.spacing(2), - minWidth: 120, - }, - formControlLabel: { - marginTop: theme.spacing(1), - }, - }) -); - -enum WebhookTypes { - custom = "CUSTOM", - typeForm = "TYPE_FORM", -} -const EmptyState = { - enabled: false, - type: WebhookTypes.custom, - secret: "", - customParser: "", -}; -export default function WebhooksDialog({ open, handleClose }) { - const classes = useStyles(); - - const { tableState, tableActions } = useProjectContext(); - - const [state, setState] = useState<{ - enabled: boolean; - type: WebhookTypes; - secret: string; - customParser: string; - }>(EmptyState); - const tableFields = Object.keys(tableState?.columns as any); - const fullWidth = true; - const maxWidth: DialogProps["maxWidth"] = "xl"; - const handleChange = (key: string) => (value: any) => { - setState((s) => ({ ...s, [key]: value })); - }; - const initializeWebhooksConfig = () => { - const secret = makeId(32); - handleChange("secret")(secret); - setState({ ...EmptyState, secret }); - tableActions?.table.updateConfig("webhooks", { - enabled: false, - type: WebhookTypes.custom, - secret, - customParser: "", // TODO: add a boilerplate/example - }); - }; - useEffect(() => { - if ( - tableState && - !tableState.config.tableConfig.loading && - !tableState?.config.webhooks && - !state.secret - ) { - initializeWebhooksConfig(); - } else if (tableState?.config.webhooks) { - setState({ ...tableState?.config.webhooks }); - } - }, [tableState?.config]); - - const handleWebhookTypeChange = ( - event: React.ChangeEvent<{ value: unknown }> - ) => { - handleChange("type")(event.target.value as WebhookTypes); - }; - - const handleSave = async () => { - handleClose(); - await tableActions?.table.updateConfig("webhooks", { - ...state, - }); - }; - const handleCancel = () => { - handleClose(); - setState({ ...tableState?.config.webhooks }); - }; - return ( - - - Webhooks - - - } - label={"Enable webhooks for this table"} - labelPlacement="end" - checked={state.enabled} - onChange={() => { - handleChange("enabled")(!state.enabled); - }} - sx={{ - alignItems: "center", - "& .MuiFormControlLabel-label": { mt: 0 }, - }} - // classes={{ root: classes.formControlLabel, label: classes.label }} - /> - Webhook type - - - {/* {state.type === WebhookTypes.custom && ( - - )} */} -
- {state.type === WebhookTypes.typeForm && ( - <> - Web hook url: - - {/* {WEBHOOK_URL}?tablePath={tableState?.tablePath} - &type=TYPE_FORM&secret={state.secret} */} - - instructions: - - please set the question reference in typeform to the following - field keys :{" "} - {tableFields.map((key) => ( - <> - {" "} - {key}, - - ))} - - - )} -
- - - - -
-
- ); -}