Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion web/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,15 @@
"notificationHours": "Notification Hours",
"notificationHoursHint": "Notifications are sent at most once per hour. Leave empty to allow every hour.",
"notificationHoursClear": "Clear",
"notificationHoursNoLimit": "No restriction"
"notificationHoursNoLimit": "No restriction",
"fromName": "From Name (optional)",
"smtpHost": "SMTP Host",
"smtpPort": "SMTP Port",
"smtpUsername": "SMTP Username",
"smtpPassword": "SMTP Password",
"smtpFrom": "From Address",
"smtpPasswordHint": "Leave empty or keep the placeholder to retain the saved password.",
"emailSmtpHint": "Notification emails are sent through your own SMTP server, independently of the system email settings under Settings → Email Service. Port 465 uses SSL, other ports use STARTTLS."
},
"setup": {
"title": "Setup",
Expand Down
10 changes: 9 additions & 1 deletion web/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,15 @@
"notificationHours": "通知时段",
"notificationHoursHint": "每小时仅发送一次通知。不选则每小时都会发送通知。",
"notificationHoursClear": "清空",
"notificationHoursNoLimit": "不限制"
"notificationHoursNoLimit": "不限制",
"fromName": "发件人显示名(可选)",
"smtpHost": "SMTP 主机",
"smtpPort": "SMTP 端口",
"smtpUsername": "SMTP 用户名",
"smtpPassword": "SMTP 密码",
"smtpFrom": "发件地址",
"smtpPasswordHint": "留空或保留占位符即保持已保存的密码不变。",
"emailSmtpHint": "通知邮件通过你自己的 SMTP 服务器发送,与设置页「邮件服务」的系统邮件配置互不影响。端口 465 使用 SSL 加密,其他端口使用 STARTTLS。"
},
"setup": {
"title": "初始化",
Expand Down
86 changes: 83 additions & 3 deletions web/src/pages/channels/ChannelPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@ import type { NotificationConfig } from "@/types";

interface ChannelFieldDef {
key: string;
/** Fallback label, used when no i18n key is given. */
label: string;
/** i18n key for the label (e.g. "channels.smtpHost"). */
labelKey?: string;
/** i18n key for a helper line rendered under the input. */
hintKey?: string;
type: "text" | "password" | "textarea" | "select";
options?: string[];
placeholder?: string;
inputMode?: "text" | "numeric";
/** Trim surrounding whitespace before submitting (values stay strings). */
trim?: boolean;
}

interface ChannelDef {
id: string;
label: string;
/** i18n key for a helper line rendered above the fields. */
hintKey?: string;
fields: ChannelFieldDef[];
}

Expand Down Expand Up @@ -84,12 +94,64 @@ const CHANNELS: ChannelDef[] = [
{
id: "email",
label: "Email",
hintKey: "channels.emailSmtpHint",
fields: [
{
key: "to",
label: "To Address",
labelKey: "channels.toAddress",
type: "text",
placeholder: "<EMAIL_ADDRESS>",
trim: true,
},
{
key: "from_name",
label: "From Name (optional)",
labelKey: "channels.fromName",
type: "text",
trim: true,
},
{
key: "smtp_host",
label: "SMTP Host",
labelKey: "channels.smtpHost",
type: "text",
placeholder: "smtp.example.com",
trim: true,
},
{
// Kept as a string end to end: the API contract takes smtp_port as a
// string and converts it to a number when sending.
key: "smtp_port",
label: "SMTP Port",
labelKey: "channels.smtpPort",
type: "text",
placeholder: "465",
inputMode: "numeric",
trim: true,
},
{
key: "smtp_username",
label: "SMTP Username",
labelKey: "channels.smtpUsername",
type: "text",
placeholder: "user@example.com",
trim: true,
},
{
key: "smtp_password",
label: "SMTP Password",
labelKey: "channels.smtpPassword",
type: "password",
hintKey: "channels.smtpPasswordHint",
},
{
key: "smtp_from",
label: "From Address",
labelKey: "channels.smtpFrom",
type: "text",
placeholder: "sender@example.com",
trim: true,
},
],
},
Expand Down Expand Up @@ -194,6 +256,7 @@ function FormField({
return (
<input
type={def.type === "password" ? "password" : "text"}
inputMode={def.inputMode}
value={value}
onChange={(e) => onChange(e.target.value)}
className={base}
Expand Down Expand Up @@ -260,9 +323,16 @@ function ChannelCard({
e.preventDefault();
setSaving(true);
setFeedback(null);
const payload: Record<string, string> = { ...localFields };
for (const field of channel.fields) {
if (field.trim && typeof payload[field.key] === "string") {
payload[field.key] = payload[field.key].trim();
}
}
try {
await api.put("/me/notifications", { [configKey]: localFields });
const next: NotificationConfig = { ...config, [configKey]: localFields };
await api.put("/me/notifications", { [configKey]: payload });
setLocalFields(payload);
const next: NotificationConfig = { ...config, [configKey]: payload };
onConfigChange(next);
setFeedback({ ok: true, msg: t("common.success") });
} catch (err: any) {
Expand Down Expand Up @@ -326,11 +396,16 @@ function ChannelCard({

{expanded && (
<div className="border-t px-4 py-4 space-y-3">
{channel.hintKey && (
<p className="text-xs text-muted-foreground">
{t(channel.hintKey)}
</p>
)}
<form onSubmit={handleSave} className="space-y-3">
{channel.fields.map((field) => (
<div key={field.key}>
<label className="block text-xs font-medium text-foreground mb-1">
{field.label}
{field.labelKey ? t(field.labelKey) : field.label}
</label>
<FormField
def={field}
Expand All @@ -339,6 +414,11 @@ function ChannelCard({
setLocalFields((p) => ({ ...p, [field.key]: v }))
}
/>
{field.hintKey && (
<p className="text-xs text-muted-foreground mt-1">
{t(field.hintKey)}
</p>
)}
</div>
))}

Expand Down
Loading