diff --git a/ui/src/components/access/AccessFormWebhookConfig.tsx b/ui/src/components/access/AccessFormWebhookConfig.tsx index f05d3097..e393b058 100644 --- a/ui/src/components/access/AccessFormWebhookConfig.tsx +++ b/ui/src/components/access/AccessFormWebhookConfig.tsx @@ -1,5 +1,6 @@ import { useTranslation } from "react-i18next"; -import { Alert, Button, Form, type FormInstance, Input, Select, Switch } from "antd"; +import { DownOutlined as DownOutlinedIcon } from "@ant-design/icons"; +import { Alert, Button, Dropdown, Form, type FormInstance, Input, Select, Switch } from "antd"; import { createSchemaFieldRule } from "antd-zod"; import { z } from "zod"; @@ -128,8 +129,124 @@ const AccessFormWebhookConfig = ({ form: formInst, formName, disabled, initialVa formInst.setFieldValue("defaultDataForDeployment", initFormModel().defaultDataForDeployment); }; - const handlePresetDataForNotificationClick = () => { - formInst.setFieldValue("defaultDataForNotification", initFormModel().defaultDataForNotification); + const handlePresetDataForNotificationClick = (key: string) => { + switch (key) { + case "bark": + formInst.setFieldValue("url", "https://api.day.app/push"); + formInst.setFieldValue("method", "POST"); + formInst.setFieldValue("headers", "Content-Type: application/json\r\nAuthorization: Bearer "); + formInst.setFieldValue( + "defaultDataForNotification", + JSON.stringify( + { + title: "${SUBJECT}", + body: "${MESSAGE}", + group: "", + device_keys: "", + }, + null, + 2 + ) + ); + break; + + case "gotify": + formInst.setFieldValue("url", "https:///"); + formInst.setFieldValue("method", "POST"); + formInst.setFieldValue("headers", "Content-Type: application/json\r\nAuthorization: Bearer "); + formInst.setFieldValue( + "defaultDataForNotification", + JSON.stringify( + { + title: "${SUBJECT}", + message: "${MESSAGE}", + priority: 1, + }, + null, + 2 + ) + ); + break; + + case "ntfy": + formInst.setFieldValue("url", "https:///"); + formInst.setFieldValue("method", "POST"); + formInst.setFieldValue("headers", "Content-Type: application/json"); + formInst.setFieldValue( + "defaultDataForNotification", + JSON.stringify( + { + topic: "", + title: "${SUBJECT}", + message: "${MESSAGE}", + priority: 1, + }, + null, + 2 + ) + ); + break; + + case "pushover": + formInst.setFieldValue("url", "https://api.pushover.net/1/messages.json"); + formInst.setFieldValue("method", "POST"); + formInst.setFieldValue("headers", "Content-Type: application/json"); + formInst.setFieldValue( + "defaultDataForNotification", + JSON.stringify( + { + token: "", + user: "", + title: "${SUBJECT}", + message: "${MESSAGE}", + }, + null, + 2 + ) + ); + break; + + case "pushplus": + formInst.setFieldValue("url", "https://www.pushplus.plus/send"); + formInst.setFieldValue("method", "POST"); + formInst.setFieldValue("headers", "Content-Type: application/json"); + formInst.setFieldValue( + "defaultDataForNotification", + JSON.stringify( + { + token: "", + title: "${SUBJECT}", + content: "${MESSAGE}", + }, + null, + 2 + ) + ); + break; + + case "serverchan": + formInst.setFieldValue("url", "https://sctapi.ftqq.com/.send"); + formInst.setFieldValue("method", "POST"); + formInst.setFieldValue("headers", "Content-Type: application/json"); + formInst.setFieldValue( + "defaultDataForNotification", + JSON.stringify( + { + text: "${SUBJECT}", + desp: "${MESSAGE}", + }, + null, + 2 + ) + ); + break; + + default: + formInst.setFieldValue("method", "POST"); + formInst.setFieldValue("headers", "Content-Type: application/json"); + formInst.setFieldValue("defaultDataForNotification", initFormModel().defaultDataForNotification); + break; + } }; const handleFormChange = (_: unknown, values: z.infer) => { @@ -169,10 +286,12 @@ const AccessFormWebhookConfig = ({ form: formInst, formName, disabled, initialVa