Skip to content
Open
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
12 changes: 4 additions & 8 deletions dashboard/app/admin-alerts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { useState } from "react";
import { AddChannelDialog } from "@/components/admin-alerts/add-channel-dialog";
import type { AdminChannel } from "@/lib/types";
import { CHANNEL_ICONS } from "@/components/admin-alerts/add-channel-dialog";
import { withBasePath } from "@/lib/utils";
const fetcher = (url: string) => fetch(withBasePath(url)).then((res) => res.json());
import { apiClient, adminChannelService } from "@/lib/api-client";
const fetcher = <T,>(url: string): Promise<T> => apiClient.get(url) as unknown as Promise<T>;

const ALERT_TYPE_LABELS: Record<string, string> = {
failed_notifications: "Failed Notifications",
Expand All @@ -43,11 +43,7 @@ export default function AdminAlertsPage() {

const handleToggle = async (id: string, enabled: boolean) => {
try {
await fetch(withBasePath(`/api/admin-channels/${id}`), {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ enabled }),
});
await adminChannelService.update(id, { enabled });
mutate();
} catch (error) {
console.error("Failed to toggle channel:", error);
Expand All @@ -56,7 +52,7 @@ export default function AdminAlertsPage() {

const handleDelete = async (id: string) => {
try {
await fetch(withBasePath(`/api/admin-channels/${id}`), { method: "DELETE" });
await adminChannelService.delete(id);
mutate();
} catch (error) {
console.error("Failed to delete channel:", error);
Expand Down
33 changes: 10 additions & 23 deletions dashboard/app/alerts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
} from "@/components/ui/dialog";

import { Alert as AlertType, ALERT_TYPE } from "@/lib/types";
import { alertService } from "@/lib/api-client";
import { withBasePath } from "@/lib/utils";

interface AlertWithNotification extends AlertType {
Expand Down Expand Up @@ -80,8 +81,7 @@ export default function AlertsPage() {

const fetchAlerts = useCallback(async (pageNum = 1, append = false, type = "all") => {
try {
const response = await fetch(withBasePath(`/api/alerts?page=${pageNum}&limit=50&type=${type}`));
const data = await response.json();
const data = await alertService.list(pageNum, 50, type);

if (append) {
setAlerts(prev => [...prev, ...(data.alerts || [])]);
Expand Down Expand Up @@ -131,17 +131,12 @@ export default function AlertsPage() {

setBulkLoading(true);
try {
const response = await fetch(withBasePath("/api/alerts/bulk-resolve"), {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
appendWarning: appendWarningOption,
limit: 100
}),
const data = await alertService.bulkResolve({
appendWarning: appendWarningOption,
limit: 100
});

if (response.ok) {
const data = await response.json();
if (data) {
// Refresh the list after bulk action
setPage(1);
await fetchAlerts(1, false);
Expand All @@ -161,15 +156,9 @@ export default function AlertsPage() {
const handleRetry = async (alertId: string, appendWarning: boolean) => {
setActionLoading(alertId);
try {
const response = await fetch(withBasePath(`/api/alerts/${alertId}/resolve`), {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
appendWarning
}),
});
const data = await alertService.resolve(alertId, { appendWarning });

if (response.ok) {
if (data) {
setAlerts((prev) => prev.filter((a) => a._id !== alertId));
setTotalCount((prev) => Math.max(0, prev - 1));
toast.success("Alert resolved and notification retried");
Expand All @@ -186,11 +175,9 @@ export default function AlertsPage() {
const handleDismiss = async (alertId: string) => {
setActionLoading(alertId);
try {
const response = await fetch(withBasePath(`/api/alerts/${alertId}`), {
method: "DELETE",
});
const data = await alertService.delete(alertId);

if (response.ok) {
if (data) {
setAlerts((prev) => prev.filter((a) => a._id !== alertId));
setTotalCount((prev) => Math.max(0, prev - 1));
}
Expand Down
5 changes: 2 additions & 3 deletions dashboard/app/analytics/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import {
Legend,
} from "recharts";
import type { DashboardStats } from "@/lib/types";
import { withBasePath } from "@/lib/utils";

const fetcher = (url: string) => fetch(withBasePath(url)).then((res) => res.json());
import { apiClient } from "@/lib/api-client";
const fetcher = <T,>(url: string): Promise<T> => apiClient.get(url) as unknown as Promise<T>;

const STATUS_COLORS = {
pending: "#fbbf24",
Expand Down
105 changes: 0 additions & 105 deletions dashboard/app/api/admin-channels/[id]/route.ts

This file was deleted.

34 changes: 0 additions & 34 deletions dashboard/app/api/admin-channels/providers/route.ts

This file was deleted.

93 changes: 0 additions & 93 deletions dashboard/app/api/admin-channels/route.ts

This file was deleted.

29 changes: 0 additions & 29 deletions dashboard/app/api/admin-channels/test/route.ts

This file was deleted.

Loading
Loading