257718e9d6
* fix(ssl): Ensure edit form saves notification_id and template_id in DB. - The SSL edit form was not saving the `notification_id` and `template_id` fields to the PB database when re-assigning the Notification Channel and Alert Template. * chore(partners): add Cloudflare to Ecosystem & Community Partner section - Cloudflare has been added to the Ecosystem & Community Partner list to acknowledge their support and contribution. * ⏳ chore(project): update development status and progress - fix(ssl): ensure edit form saves notification_id and template_id in DB - feat(notifications): add Notifiarr notification channel (planned) * feat: Add Notifiarr to notification channels (UI) - Add Notifiarr as a new channel type in the notification settings. The Notifiarr channel will use the `api_token` field for API key storage in PB. * feat: Add channel_id field for Notifiarr - Add channel_id field for Notifiarr to store record of the discord channel_id into the PB. * feat: Implement Notifiarr notification service - The Notifiarr notification functionality has been implemented. The alert configuration channel will now use the `api_token` and `channel_id` field for send to the Notifiarr API endpoint. * ⏳ chore(project): update development status and progress - feat: Add channel_id field for Notifiarr - feat: Implement Notifiarr notification service Closes: #133 * feat: add SSL history and Notifiarr notification channel schema * Fix: Remove duplicate close button - Removed the duplicate close button from the test email dialog. * feat: Add Gotify to notification channels - Add Gotify as a new channel type in the notification settings. The Gotify channel will use the `api_token` and `server_url` field for API key storage in PB. * feat: Implement Gotify notification service - The Gotify notification functionality has been implemented. The alert configuration channel will now use the `api_token` and `server_url` field for send to the Gotify API endpoint. * ⏳ chore(project): update development status and progress - feat: Add server_url field for Gotify - feat: Implement Gotify notification service * refactory(i18n): Improve internationalization configuration and add new translations - Added multiple new translation items - Updated the two language files: en and zhcn - Added type definitions for new translation items in types/services.ts - Modified some components to use the new translation items * refactory(i18n): Added architecture import function translation for the "About" page - Added translation items related to schema import in English, Chinese, and type definition files - Replaced hard-coded text with new translation items in the AboutSystem component * refactory(i18n): Added architecture import function translation for the "About" page - Added translation items related to schema import in English, Chinese, and type definition files - Replaced hard-coded text with new translation items in the AboutSystem component * refactory(i18n): Add internationalization support for the service statistics card * feat: Add NTFY API token field for Token-based authentication to ntfy server - Add the api_token field for NTFY notifications in both the dialog and service to save it to PB. NTFY schema to include api_token field. * feat(auth): add token support for ntfy - Updated the NTFY service to support API token authentication by adding Authorization Bearer header when api_token is provided. Closes: #89 * refactor(i18n): Added Chinese translations for Create Event and Maintenance - Supplemented missing Chinese translations - Added translation entries related to Create Event and Maintenance in both English and Chinese translation files * chore: deactivate GitHub donation * refactor(i18n): Optimize internationalization configuration and add new translation items - Add internationalization support to the LoadingState component - Implement internationalization translations in the Profile page - Use internationalized text in the TestEmailDialog component - Update English and Chinese translation files by adding new translation entries * docs(readme): deactivate donations, accept only infra support (cloud, domain, hosting) * feat(i18n): Enhanced internationalization support with variable interpolation - Refactored the `t` function in LanguageContext to support multiple parameter combinations - Added variable interpolation feature, allowing variables in translated texts - Optimized translation logic to improve accuracy and performance - Enhanced type safety by using TypeScript generics to ensure correct typing * refactor(i18n): Optimize service pagination internationalization copy - Added service pagination related copy in English and Chinese translation files - Updated type definitions to include new translation fields - Modified the ServicesPagination component to use the newly added translation fields * docs(README_zhcn): Update documentation content and sponsorship policy - Update image links in the documentation - Revise the sponsorship policy to no longer accept individual sponsorships, only enterprise-level collaborations - Update the display method for supporters and partners - Add Cloudflare and DigitalOcean as new partners * feat: Integrate data retention service - Implemented the data retention service in Go (service-operation) that manages cleanup of old records based on configured retention periods. The service runs once per day to ensure outdated data is removed automatically. * refactor: Remove manual cleanup buttons from Data Retention Settings - The three manual cleanup buttons have been removed from the dashboard. - The data retention service now automatically runs once per day, cleaning up older data based on the configured retention settings. --------- Co-authored-by: YiZixuan <sqkkyzx@qq.com> Co-authored-by: YiZixuan <sqkkyzx@outlook.com>
175 lines
5.6 KiB
TypeScript
175 lines
5.6 KiB
TypeScript
|
|
import { AlertConfiguration } from "@/services/alertConfigService";
|
|
import { Bell, Edit, Trash2 } from "lucide-react";
|
|
import {
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableHead,
|
|
TableHeader,
|
|
TableRow
|
|
} from "@/components/ui/table";
|
|
import { Switch } from "@/components/ui/switch";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { alertConfigService } from "@/services/alertConfigService";
|
|
import { pb } from "@/lib/pocketbase";
|
|
|
|
interface CombinedChannel extends Partial<AlertConfiguration> {
|
|
isWebhook?: boolean;
|
|
url?: string;
|
|
method?: string;
|
|
description?: string;
|
|
}
|
|
|
|
interface NotificationChannelListProps {
|
|
channels: CombinedChannel[];
|
|
onEdit: (config: AlertConfiguration) => void;
|
|
onDelete: (id: string) => void;
|
|
}
|
|
|
|
export const NotificationChannelList = ({
|
|
channels,
|
|
onEdit,
|
|
onDelete
|
|
}: NotificationChannelListProps) => {
|
|
const toggleEnabled = async (config: CombinedChannel) => {
|
|
if (!config.id) return;
|
|
|
|
if (config.isWebhook) {
|
|
// Handle webhook toggle
|
|
try {
|
|
const newEnabled = config.enabled ? "off" : "on";
|
|
await pb.collection('webhook').update(config.id, {
|
|
enabled: newEnabled
|
|
});
|
|
// Trigger refresh by calling onEdit with empty config
|
|
onEdit({} as AlertConfiguration);
|
|
} catch (error) {
|
|
console.error("Error updating webhook:", error);
|
|
}
|
|
} else {
|
|
// Handle alert config toggle
|
|
await alertConfigService.updateAlertConfiguration(config.id, {
|
|
enabled: !config.enabled
|
|
});
|
|
|
|
// The parent component will refresh the list
|
|
onEdit(config as AlertConfiguration);
|
|
}
|
|
};
|
|
|
|
const getChannelTypeLabel = (type: string | undefined) => {
|
|
switch(type) {
|
|
case "telegram": return "Telegram";
|
|
case "discord": return "Discord";
|
|
case "slack": return "Slack";
|
|
case "signal": return "Signal";
|
|
case "google_chat": return "Google Chat";
|
|
case "email": return "Email";
|
|
case "pushover": return "Pushover";
|
|
case "notifiarr": return "Notifiarr";
|
|
case "webhook": return "Webhook";
|
|
default: return type || "Unknown";
|
|
}
|
|
};
|
|
|
|
const getChannelDetails = (config: CombinedChannel) => {
|
|
if (config.isWebhook) {
|
|
return `${config.method || 'POST'} ${config.url || ''}`;
|
|
}
|
|
|
|
switch(config.notification_type) {
|
|
case "telegram":
|
|
return config.telegram_chat_id || '';
|
|
case "discord":
|
|
case "slack":
|
|
case "google_chat":
|
|
return config.discord_webhook_url || config.slack_webhook_url || config.google_chat_webhook_url || '';
|
|
case "signal":
|
|
return config.signal_number || '';
|
|
case "email":
|
|
return config.email_address || '';
|
|
default:
|
|
return '';
|
|
}
|
|
};
|
|
|
|
if (channels.length === 0) {
|
|
return (
|
|
<div className="flex flex-col items-center justify-center py-10 text-center">
|
|
<Bell className="h-12 w-12 text-muted-foreground mb-4" />
|
|
<h3 className="text-lg font-medium">No notification channels configured</h3>
|
|
<p className="text-muted-foreground mt-2">
|
|
Add a notification channel to get alerts when your services go down.
|
|
</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="rounded-md border">
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow>
|
|
<TableHead>Name</TableHead>
|
|
<TableHead>Type</TableHead>
|
|
<TableHead>Details</TableHead>
|
|
<TableHead>Status</TableHead>
|
|
<TableHead>Created</TableHead>
|
|
<TableHead className="text-right">Actions</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{channels.map((channel) => (
|
|
<TableRow key={channel.id}>
|
|
<TableCell className="font-medium">{channel.notify_name}</TableCell>
|
|
<TableCell>
|
|
<Badge variant="outline">{getChannelTypeLabel(channel.notification_type)}</Badge>
|
|
</TableCell>
|
|
<TableCell className="max-w-xs truncate text-sm text-muted-foreground">
|
|
{getChannelDetails(channel)}
|
|
</TableCell>
|
|
<TableCell>
|
|
<Switch
|
|
checked={
|
|
typeof channel.enabled === 'string'
|
|
? channel.enabled === "true" || channel.enabled === "on"
|
|
: !!channel.enabled
|
|
}
|
|
onCheckedChange={() => toggleEnabled(channel)}
|
|
/>
|
|
</TableCell>
|
|
<TableCell>
|
|
{channel.created ? new Date(channel.created).toLocaleDateString() : "-"}
|
|
</TableCell>
|
|
<TableCell className="text-right">
|
|
<div className="flex justify-end gap-2">
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={() => onEdit(channel as AlertConfiguration)}
|
|
disabled={channel.isWebhook} // Disable edit for webhooks for now
|
|
>
|
|
<Edit className="h-4 w-4" />
|
|
</Button>
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={() => {
|
|
if (channel.id && confirm("Are you sure you want to delete this notification channel?")) {
|
|
onDelete(channel.id)
|
|
}
|
|
}}
|
|
>
|
|
<Trash2 className="h-4 w-4 text-destructive" />
|
|
</Button>
|
|
</div>
|
|
</TableCell>
|
|
</TableRow>
|
|
))}
|
|
</TableBody>
|
|
</Table>
|
|
</div>
|
|
);
|
|
}; |