diff --git a/src/routes/settings/notifications/+page.svelte b/src/routes/settings/notifications/+page.svelte index caf081a..d757386 100644 --- a/src/routes/settings/notifications/+page.svelte +++ b/src/routes/settings/notifications/+page.svelte @@ -4,11 +4,23 @@ import { Plus, Trash2, Bell, BellOff, MessageSquare, Send, Loader2, Pencil } from 'lucide-svelte'; import Modal from '$ui/modal/Modal.svelte'; import NotificationHistory from './components/NotificationHistory.svelte'; + import Table from '$ui/table/Table.svelte'; + import Badge from '$ui/badge/Badge.svelte'; + import type { Column } from '$ui/table/types'; import { siDiscord } from 'simple-icons'; import type { PageData } from './$types'; export let data: PageData; + type Service = (typeof data.services)[0]; + + const columns: Column[] = [ + { key: 'name', header: 'Service', sortable: true }, + { key: 'service_type', header: 'Type', sortable: true }, + { key: 'enabled', header: 'Status', sortable: true }, + { key: 'stats', header: 'Stats' } + ]; + // Modal state let showDeleteModal = false; let selectedService: string | null = null; @@ -91,10 +103,10 @@
-
+
-

Notifications

-

+

Notifications

+

Manage notification services and delivery settings

@@ -102,7 +114,7 @@ Add Service @@ -110,252 +122,134 @@
- -
+ - -
-
- -

- Notification Services -

-
-
- - -
-
- - - - - - - - - - - - {#each data.services as service (service.id)} - - - - - - - - - - - - - - - - - - - + + {:else} - - - - {/each} - -
+ {#if column.key === 'name'} + {row.name} + {:else if column.key === 'service_type'} +
+ {#if row.service_type === 'discord'} + - Service -
- Type - - Status - - Enabled Types - - Statistics - - Actions -
- {service.name} - -
- {#if service.service_type === 'discord'} - - - - {:else} - - {/if} - {getServiceTypeName(service.service_type)} -
-
-
{ - return async ({ result, update }) => { - if (result.type === 'failure' && result.data) { - alertStore.add( - 'error', - (result.data as { error?: string }).error || 'Failed to update service' - ); - } else if (result.type === 'success') { - alertStore.add('success', 'Service updated successfully'); - } - await update(); - }; - }} - > - - - -
-
-
- {#each getEnabledTypes(service.enabled_types) as type} - - {formatNotificationType(type)} - - {:else} - None - {/each} -
-
- {#if service.successCount + service.failedCount > 0} -
- {service.successCount} sent - • - {service.failedCount} failed - • - {formatSuccessRate(service.successRate)} -
- {:else} - No notifications sent - {/if} -
-
- -
{ - testingServiceId = service.id; - return async ({ result, update }) => { - if (result.type === 'failure' && result.data) { - alertStore.add( - 'error', - (result.data as { error?: string }).error || - 'Failed to send test notification' - ); - } else if (result.type === 'success') { - alertStore.add('success', 'Test notification sent successfully'); - } - testingServiceId = null; - await update(); - }; - }} - > - - -
- - - - - - - -
{ - return async ({ result, update }) => { - if (result.type === 'failure' && result.data) { - alertStore.add( - 'error', - (result.data as { error?: string }).error || 'Failed to delete service' - ); - } else if (result.type === 'success') { - alertStore.add('success', 'Service deleted successfully'); - } - await update(); - }; - }} - > - - -
-
-
- No notification services configured. Click "Add Service" to get started. -
-
-
+ + {/if} + {getServiceTypeName(row.service_type)} +
+ {:else if column.key === 'enabled'} + + {row.enabled ? 'Enabled' : 'Disabled'} + + {:else if column.key === 'stats'} + {#if row.successCount + row.failedCount > 0} + + {row.successCount} + / + {row.failedCount} + + {:else} + - + {/if} + {/if} + + + +
+ +
{ + testingServiceId = row.id; + return async ({ result, update }) => { + if (result.type === 'failure' && result.data) { + alertStore.add( + 'error', + (result.data as { error?: string }).error || 'Failed to send test notification' + ); + } else if (result.type === 'success') { + alertStore.add('success', 'Test notification sent successfully'); + } + testingServiceId = null; + await update(); + }; + }} + > + + +
+ + +
+ + + + +
{ + return async ({ result, update }) => { + if (result.type === 'failure' && result.data) { + alertStore.add( + 'error', + (result.data as { error?: string }).error || 'Failed to delete service' + ); + } else if (result.type === 'success') { + alertStore.add('success', 'Service deleted successfully'); + } + await update(); + }; + }} + > + + +
+
+ +
diff --git a/src/routes/settings/notifications/components/NotificationHistory.svelte b/src/routes/settings/notifications/components/NotificationHistory.svelte index 9c9743b..007e5b3 100644 --- a/src/routes/settings/notifications/components/NotificationHistory.svelte +++ b/src/routes/settings/notifications/components/NotificationHistory.svelte @@ -1,23 +1,48 @@ -
- -
-
- -

- Recent Notifications -

-
+
+
+ +

+ Recent Notifications +

- -
- - - - - - - - - - - - {#each history as record (record.id)} - - - - - - - - - - - - - - - - - {:else} - - - - {/each} - -
- Time - - Service - - Type - - Title - - Status -
- {formatDateTime(record.sent_at)} - - {getServiceName(record.service_id)} - - - {formatNotificationType(record.notification_type)} - - - {record.title} - - {#if record.status === 'success'} - - Success - - {:else} - - Failed - - {/if} -
- No notification history available yet. -
-
+ + + {#if column.key === 'title'} + {row.title} + {:else if column.key === 'service_id'} + {getServiceName(row.service_id)} + {:else if column.key === 'notification_type'} + {formatNotificationType(row.notification_type)} + {:else if column.key === 'status'} + + {row.status === 'success' ? 'Success' : 'Failed'} + + {:else if column.key === 'sent_at'} + {getRelativeTime(row.sent_at)} + {/if} + +