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
15 changes: 11 additions & 4 deletions web/src/components/ChannelSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function ChannelSelector({
const { t } = useTranslation();
const [open, setOpen] = useState(false);
const [enabledChannels, setEnabledChannels] = useState<string[]>([]);
const [defaultChannel, setDefaultChannel] = useState("");
const [loading, setLoading] = useState(true);
const ref = useRef<HTMLDivElement>(null);

Expand All @@ -24,8 +25,10 @@ export function ChannelSelector({
try {
const config = await api.get<NotificationConfig>("/me/notifications");
setEnabledChannels(config.enabled_channels || []);
setDefaultChannel(config.default_channel || "");
} catch {
setEnabledChannels([]);
setDefaultChannel("");
} finally {
setLoading(false);
}
Expand All @@ -48,6 +51,12 @@ export function ChannelSelector({
const availableChannels = CHANNELS.filter((ch) =>
enabledChannels.includes(ch.id),
);
const defaultChannelLabel = CHANNELS.find(
(channel) => channel.id === defaultChannel,
)?.label;
const emptySelectionLabel = defaultChannelLabel
? t("channels.defaultChannelOption", { name: defaultChannelLabel })
: t("channels.noChannelsSelected");

const toggleChannel = (channelId: string) => {
const newSelected = selected.includes(channelId)
Expand Down Expand Up @@ -84,7 +93,7 @@ export function ChannelSelector({
>
<span className="text-foreground">
{selected.length === 0
? t("channels.allChannels")
? emptySelectionLabel
: t("channels.selectedChannels", { count: selected.length })}
</span>
<ChevronDown
Expand Down Expand Up @@ -147,9 +156,7 @@ export function ChannelSelector({
<div className="w-4 h-4 rounded-full border flex items-center justify-center">
{selected.length === 0 && <Radio className="w-3 h-3" />}
</div>
<span className="text-sm flex-1">
{t("channels.allChannels")}
</span>
<span className="text-sm flex-1">{emptySelectionLabel}</span>
{selected.length === 0 && (
<Check className="w-4 h-4 text-primary" />
)}
Expand Down
6 changes: 4 additions & 2 deletions web/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
},
"channels": {
"title": "Channel Management",
"description": "Configure notification channels. Notifications will be sent to all enabled channels by default. Each notification item can individually select which channels to use.",
"description": "Configure notification channels. Notifications without a channel selection are sent only to the default channel. Each item can individually select one or more channels.",
"telegram": "Telegram",
"webhook": "Webhook",
"wechatbot": "WeCom Bot",
Expand All @@ -383,7 +383,9 @@
"apiKey": "API Key",
"token": "Token",
"selectChannels": "Select Notification Channels",
"allChannels": "All enabled channels",
"defaultChannel": "Default channel",
"setAsDefault": "Set as default",
"defaultChannelOption": "Default channel ({{name}})",
"selectedChannels": "{{count}} channels selected",
"noChannelsSelected": "None selected (use default)",
"noChannelsEnabled": "No channels enabled, please configure in Channel Management first",
Expand Down
6 changes: 4 additions & 2 deletions web/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
},
"channels": {
"title": "通道管理",
"description": "配置通知通道,设置将发送到所有已启用的通道。每个通知项可以单独选择要使用的通道。",
"description": "配置通知渠道。未指定渠道的通知将只发送到默认渠道;每个事项可以单独多选要使用的渠道。",
"telegram": "Telegram",
"webhook": "Webhook",
"wechatbot": "企业微信机器人",
Expand All @@ -383,7 +383,9 @@
"apiKey": "API 密钥",
"token": "令牌",
"selectChannels": "选择通知渠道",
"allChannels": "所有已启用的渠道",
"defaultChannel": "默认渠道",
"setAsDefault": "设为默认",
"defaultChannelOption": "默认渠道({{name}})",
"selectedChannels": "已选择 {{count}} 个渠道",
"noChannelsSelected": "未选择(使用默认)",
"noChannelsEnabled": "未启用任何通道,请先到通道管理页面配置",
Expand Down
27 changes: 25 additions & 2 deletions web/src/pages/channels/ChannelPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,18 @@ function ChannelCard({
enabled_channels: next.enabled_channels,
});
onConfigChange(next);
} catch {
// no state change on error
} catch (err: any) {
setFeedback({ ok: false, msg: err.message || t("common.error") });
}
};

const handleSetDefault = async () => {
setFeedback(null);
try {
await api.put("/me/notifications", { default_channel: channel.id });
onConfigChange({ ...config, default_channel: channel.id });
} catch (err: any) {
setFeedback({ ok: false, msg: err.message || t("common.error") });
}
};

Expand Down Expand Up @@ -390,6 +400,19 @@ function ChannelCard({
>
{isEnabled ? t("common.enabled") : t("common.disabled")}
</span>
{config.default_channel === channel.id ? (
<span className="rounded-full px-2 py-0.5 text-caption font-medium bg-primary/10 text-primary">
{t("channels.defaultChannel")}
</span>
) : isEnabled ? (
<button
type="button"
onClick={handleSetDefault}
className="py-0.5 px-2 bg-secondary hover:bg-secondary/80 text-secondary-foreground text-xs font-medium rounded-md transition-colors"
>
{t("channels.setAsDefault")}
</button>
) : null}
</div>
<button
type="button"
Expand Down
1 change: 1 addition & 0 deletions web/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export interface DashboardStats {

export interface NotificationConfig {
enabled_channels: string[];
default_channel: string;
notification_hours: number[];
[key: string]: unknown;
}
Expand Down
Loading