mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-18 07:56:57 +00:00
Set Notification Text Functionality
This commit is contained in:
parent
c1b62d8108
commit
70010ce8ee
@ -53,6 +53,9 @@ import { Textarea } from "@/components/ui/textarea";
|
|||||||
interface NotificationsResponse {
|
interface NotificationsResponse {
|
||||||
notifications: any[];
|
notifications: any[];
|
||||||
}
|
}
|
||||||
|
interface NotificationResponse {
|
||||||
|
notification_text?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export default function Settings() {
|
export default function Settings() {
|
||||||
const { theme, setTheme } = useTheme();
|
const { theme, setTheme } = useTheme();
|
||||||
@ -84,6 +87,8 @@ export default function Settings() {
|
|||||||
|
|
||||||
const [notifications, setNotifications] = useState<any[]>([])
|
const [notifications, setNotifications] = useState<any[]>([])
|
||||||
|
|
||||||
|
const [notificationText, setNotificationText] = useState<string>("")
|
||||||
|
|
||||||
const changeEmail = async () => {
|
const changeEmail = async () => {
|
||||||
setEmailErrorVisible(false);
|
setEmailErrorVisible(false);
|
||||||
setEmailSuccess(false);
|
setEmailSuccess(false);
|
||||||
@ -217,6 +222,35 @@ export default function Settings() {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
|
const getNotificationText = async () => {
|
||||||
|
try {
|
||||||
|
const response = await axios.post<NotificationResponse>('/api/settings/get_notification_text', {});
|
||||||
|
if (response.status === 200) {
|
||||||
|
if (response.data.notification_text) {
|
||||||
|
setNotificationText(response.data.notification_text);
|
||||||
|
} else {
|
||||||
|
setNotificationText("The application !name (!url) is now !status.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
alert(error.response.data.error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const editNotificationText = async () => {
|
||||||
|
try {
|
||||||
|
const response = await axios.post('/api/settings/notification_text', {
|
||||||
|
text: notificationText
|
||||||
|
});
|
||||||
|
} catch (error: any) {
|
||||||
|
alert(error.response.data.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getNotificationText()
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarProvider>
|
<SidebarProvider>
|
||||||
<AppSidebar />
|
<AppSidebar />
|
||||||
@ -531,16 +565,24 @@ export default function Settings() {
|
|||||||
<AlertDialogContent>
|
<AlertDialogContent>
|
||||||
<AlertDialogTitle>Customize Notification Text</AlertDialogTitle>
|
<AlertDialogTitle>Customize Notification Text</AlertDialogTitle>
|
||||||
<AlertDialogDescription>
|
<AlertDialogDescription>
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<Label htmlFor="text">Notification Text</Label>
|
<Label htmlFor="text">Notification Text</Label>
|
||||||
<Textarea id="text" placeholder="Type here..."/>
|
<Textarea id="text" placeholder="Type here..." value={notificationText} onChange={(e) => setNotificationText(e.target.value)} rows={4} />
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="pt-4 text-sm text-muted-foreground">
|
||||||
|
You can use the following placeholders in the text:
|
||||||
|
<ul className="list-disc list-inside space-y-1 pt-2">
|
||||||
|
<li><strong>!name</strong> - Application name</li>
|
||||||
|
<li><strong>!url</strong> - Application URL</li>
|
||||||
|
<li><strong>!status</strong> - Application status (online/offline)</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</AlertDialogDescription>
|
</AlertDialogDescription>
|
||||||
<AlertDialogFooter>
|
<AlertDialogFooter>
|
||||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||||
<AlertDialogAction onClick={addNotification}>
|
<AlertDialogAction onClick={editNotificationText}>
|
||||||
Save
|
Save
|
||||||
</AlertDialogAction>
|
</AlertDialogAction>
|
||||||
</AlertDialogFooter>
|
</AlertDialogFooter>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user