/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Input, InputNumber, Select } from '@/components/ui';
/**
* 通用通知渠道表单(受控组件)。按后端 dto.UserSetting 的通知子集工作,
* 支持 email / webhook / bark / gotify 四渠道。企业「通知预警」等场景复用。
*
* props:
* value: {
* notify_type, notification_email,
* webhook_url, webhook_secret,
* bark_url,
* gotify_url, gotify_token, gotify_priority
* }
* onChange(nextValue): 整对象回传
* disabled?: boolean
* channels?: 可选渠道白名单(如 ['email','webhook']),默认全部四种。
* 成员个人预警场景仅开放邮箱/Webhook。
* emailPlaceholder?: 通知邮箱输入框占位文案。默认"留空则使用企业联系邮箱"
* 是企业级预警的兜底语义;成员场景没有该兜底,须传入"必填"提示。
*/
const ALL_CHANNELS = ['email', 'webhook', 'bark', 'gotify'];
const NotifyChannelForm = ({
value = {},
onChange,
disabled = false,
channels,
emailPlaceholder,
}) => {
const { t } = useTranslation();
const v = value || {};
const allowed = ALL_CHANNELS.filter(
(c) => !Array.isArray(channels) || channels.includes(c),
);
const type =
v.notify_type && allowed.includes(v.notify_type)
? v.notify_type
: allowed[0] || 'email';
const patch = (fields) => onChange?.({ ...v, ...fields });
const Label = ({ children }) => (
);
// 原型:渠道下拉(≤360px)+ 浅底详情框承载各渠道字段(竖排标签)
return (
{type === 'email' && (
patch({ notification_email: val })}
placeholder={emailPlaceholder || t('留空则使用企业联系邮箱')}
disabled={disabled}
/>
)}
{type === 'webhook' && (
<>
patch({ webhook_url: val })}
placeholder='https://example.com/webhook'
disabled={disabled}
/>
patch({ webhook_secret: val })}
placeholder={t('可选,将以 Bearer 方式加入请求头')}
disabled={disabled}
/>
>
)}
{type === 'bark' && (
patch({ bark_url: val })}
placeholder='https://api.day.app/xxx'
disabled={disabled}
/>
)}
{type === 'gotify' && (
<>
patch({ gotify_url: val })}
placeholder='https://gotify.example.com'
disabled={disabled}
/>
patch({ gotify_token: val })}
disabled={disabled}
/>