mirror of
https://github.com/usual2970/certimate.git
synced 2025-08-30 13:11:45 +00:00
feat: support template variables in webhook deployment
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Form, Input } from "antd";
|
||||
import { Alert, Button, Form, Input } from "antd";
|
||||
import { createSchemaFieldRule } from "antd-zod";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -14,11 +14,23 @@ const DeployNodeFormWebhookFields = () => {
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}, t("workflow_node.deploy.form.webhook_data.placeholder")),
|
||||
}, t("workflow_node.deploy.form.webhook_data.errmsg.json_invalid")),
|
||||
});
|
||||
const formRule = createSchemaFieldRule(formSchema);
|
||||
const formInst = Form.useFormInstance();
|
||||
|
||||
const initialValues: Partial<z.infer<typeof formSchema>> = {
|
||||
webhookData: JSON.stringify(
|
||||
{
|
||||
name: "${DOMAINS}",
|
||||
cert: "${CERTIFICATE}",
|
||||
privkey: "${PRIVATE_KEY}",
|
||||
},
|
||||
null,
|
||||
2
|
||||
),
|
||||
};
|
||||
|
||||
const handleWebhookDataBlur = (e: React.FocusEvent<HTMLTextAreaElement>) => {
|
||||
const value = e.target.value;
|
||||
try {
|
||||
@@ -29,19 +41,34 @@ const DeployNodeFormWebhookFields = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handlePresetDataClick = () => {
|
||||
formInst.setFieldValue("webhookData", initialValues.webhookData);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Form.Item
|
||||
name="webhookData"
|
||||
label={t("workflow_node.deploy.form.webhook_data.label")}
|
||||
rules={[formRule]}
|
||||
tooltip={<span dangerouslySetInnerHTML={{ __html: t("workflow_node.deploy.form.webhook_data.tooltip") }}></span>}
|
||||
>
|
||||
<Input.TextArea
|
||||
autoSize={{ minRows: 3, maxRows: 10 }}
|
||||
placeholder={t("workflow_node.deploy.form.webhook_data.placeholder")}
|
||||
onBlur={handleWebhookDataBlur}
|
||||
/>
|
||||
<Form.Item className="mb-0">
|
||||
<label className="mb-1 block">
|
||||
<div className="flex w-full items-center justify-between gap-4">
|
||||
<div className="max-w-full grow truncate">{t("workflow_node.deploy.form.webhook_data.label")}</div>
|
||||
<div className="text-right">
|
||||
<Button size="small" type="link" onClick={handlePresetDataClick}>
|
||||
{t("workflow_node.deploy.form.webhook_data_preset.button")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
<Form.Item name="webhookData" rules={[formRule]} initialValue={initialValues.webhookData}>
|
||||
<Input.TextArea
|
||||
autoSize={{ minRows: 3, maxRows: 10 }}
|
||||
placeholder={t("workflow_node.deploy.form.webhook_data.placeholder")}
|
||||
onBlur={handleWebhookDataBlur}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item>
|
||||
<Alert type="info" message={<span dangerouslySetInnerHTML={{ __html: t("workflow_node.deploy.form.webhook_data.guide") }}></span>} />
|
||||
</Form.Item>
|
||||
</>
|
||||
);
|
||||
|
Reference in New Issue
Block a user