import { AppSidebar } from "@/components/app-sidebar"; import { Breadcrumb, BreadcrumbItem, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from "@/components/ui/breadcrumb"; import { Separator } from "@/components/ui/separator"; import { SidebarInset, SidebarProvider, SidebarTrigger, } from "@/components/ui/sidebar"; import { Card, CardContent, CardHeader } from "@/components/ui/card"; import { useTheme } from "next-themes"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion" import { Input } from "@/components/ui/input" import { useEffect, useState } from "react"; import axios from "axios"; import Cookies from "js-cookie"; import { Button } from "@/components/ui/button"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" import { AlertCircle, Check, Palette, User, Bell } from "lucide-react"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog" import { Label } from "@/components/ui/label"; import { Checkbox } from "@/components/ui/checkbox"; interface NotificationsResponse { notifications: any[]; } export default function Settings() { const { theme, setTheme } = useTheme(); const [email, setEmail] = useState("") const [password, setPassword] = useState("") const [confirmPassword, setConfirmPassword] = useState("") const [oldPassword, setOldPassword] = useState("") const [emailError, setEmailError] = useState("") const [passwordError, setPasswordError] = useState("") const [emailErrorVisible, setEmailErrorVisible] = useState(false) const [passwordErrorVisible, setPasswordErrorVisible] = useState(false) const [passwordSuccess, setPasswordSuccess] = useState(false) const [emailSuccess, setEmailSuccess] = useState(false) const [notificationType, setNotificationType] = useState("") const [smtpHost, setSmtpHost] = useState("") const [smtpPort, setSmtpPort] = useState(0) const [smtpSecure, setSmtpSecure] = useState(false) const [smtpUsername, setSmtpUsername] = useState("") const [smtpPassword, setSmtpPassword] = useState("") const [smtpFrom, setSmtpFrom] = useState("") const [smtpTo, setSmtpTo] = useState("") const [telegramToken, setTelegramToken] = useState("") const [telegramChatId, setTelegramChatId] = useState("") const [discordWebhook, setDiscordWebhook] = useState("") const [notifications, setNotifications] = useState([]) const changeEmail = async () => { setEmailErrorVisible(false); setEmailSuccess(false); setEmailError(""); if (!email) { setEmailError("Email is required"); setEmailErrorVisible(true); setTimeout(() => { setEmailErrorVisible(false); setEmailError(""); } , 3000); return; } try { await axios.post('/api/auth/edit_email', { newEmail: email, jwtToken: Cookies.get('token') }); setEmailSuccess(true); setEmail(""); setTimeout(() => { setEmailSuccess(false); }, 3000); } catch (error: any) { setEmailError(error.response.data.error); setEmailErrorVisible(true); setTimeout(() => { setEmailErrorVisible(false); setEmailError(""); }, 3000); } } const changePassword = async () => { try { if (password !== confirmPassword) { setPasswordError("Passwords do not match"); setPasswordErrorVisible(true); setTimeout(() => { setPasswordErrorVisible(false); setPasswordError(""); }, 3000); return; } if (!oldPassword || !password || !confirmPassword) { setPasswordError("All fields are required"); setPasswordErrorVisible(true); setTimeout(() => { setPasswordErrorVisible(false); setPasswordError(""); }, 3000); return; } const response = await axios.post('/api/auth/edit_password', { oldPassword: oldPassword, newPassword: password, jwtToken: Cookies.get('token') }); if (response.status === 200) { setPasswordSuccess(true); setPassword(""); setOldPassword(""); setConfirmPassword(""); setTimeout(() => { setPasswordSuccess(false); }, 3000); } } catch (error: any) { setPasswordErrorVisible(true); setPasswordError(error.response.data.error); setTimeout(() => { setPasswordErrorVisible(false); setPasswordError(""); }, 3000); } } const addNotification = async () => { try { const response = await axios.post('/api/notifications/add', { type: notificationType, smtpHost: smtpHost, smtpPort: smtpPort, smtpSecure: smtpSecure, smtpUsername: smtpUsername, smtpPassword: smtpPassword, smtpFrom: smtpFrom, smtpTo: smtpTo, telegramToken: telegramToken, telegramChatId: telegramChatId, discordWebhook: discordWebhook }); getNotifications(); } catch (error: any) { alert(error.response.data.error); } } const deleteNotification = async (id: number) => { try { const response = await axios.post('/api/notifications/delete', { id: id }); if (response.status === 200) { getNotifications() } } catch (error: any) { alert(error.response.data.error); } } const getNotifications = async () => { try { const response = await axios.post('/api/notifications/get', {}); if (response.status === 200 && response.data) { setNotifications(response.data.notifications); } } catch (error: any) { alert(error.response.data.error); } } useEffect(() => { getNotifications() }, []) return (
/ Dashboard Settings
Settings

User Settings

Manage your user settings here. You can change your email, password, and other account settings.

Change Email

{emailErrorVisible && ( Error {emailError} )} {emailSuccess && ( Success Email changed successfully. )}
setEmail(e.target.value)} className="h-11" />

Change Password

{passwordErrorVisible && ( Error {passwordError} )} {passwordSuccess && ( Success Password changed successfully. )}
setOldPassword(e.target.value)} className="h-11" /> setPassword(e.target.value)} className="h-11" /> setConfirmPassword(e.target.value)} className="h-11" />

Theme Settings

Select a theme for the application. You can choose between light, dark, or system theme.

Notifications

Set up Notifications to get notified when an application goes offline or online.
Add Notification setSmtpHost(e.target.value)} />
setSmtpPort(Number(e.target.value))} />
setSmtpSecure(checked)} />
setSmtpUsername(e.target.value)} />
setSmtpPassword(e.target.value)} />
setSmtpFrom(e.target.value)} />
setSmtpTo(e.target.value)} />
)} {notificationType === "telegram" && (
setTelegramToken(e.target.value)} />
setTelegramChatId(e.target.value)} />
)} {notificationType === "discord" && (
setDiscordWebhook(e.target.value)} />
)} Cancel Add
{notifications.length > 0 ? ( notifications.map((notification) => (

{notification.type}

)) ) : (
No notifications configured
)}
) }