test(notification): added framework for managment tab
This commit is contained in:
@@ -1,8 +1,22 @@
|
|||||||
|
import { getnotifications } from "@/utils/querys/admin/notifications";
|
||||||
|
import { notifyColumns } from "@/utils/tableData/notifications/notifyColumns";
|
||||||
|
import { NotifyTable } from "@/utils/tableData/notifications/notifyData";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
|
||||||
export default function NotificationMGT() {
|
export default function NotificationMGT() {
|
||||||
|
const { data, isError, isLoading } = useQuery(getnotifications());
|
||||||
|
|
||||||
|
if (isLoading) return <div>Loading adjustmnet data...</div>;
|
||||||
|
if (isError) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p>There was an error getting the adjustments.</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
Manage all notifications from here instad of going to the db,
|
<NotifyTable columns={notifyColumns} data={data} />
|
||||||
locking some items that are auto updated on server restarts
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
import { createRootRoute, Link, Outlet } from "@tanstack/react-router";
|
import {
|
||||||
|
createRootRoute,
|
||||||
|
Link,
|
||||||
|
Outlet,
|
||||||
|
useLocation,
|
||||||
|
} from "@tanstack/react-router";
|
||||||
//import {TanStackRouterDevtools} from "@tanstack/router-devtools";
|
//import {TanStackRouterDevtools} from "@tanstack/router-devtools";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import { SidebarProvider } from "../components/ui/sidebar";
|
import { SidebarProvider } from "../components/ui/sidebar";
|
||||||
@@ -17,11 +22,12 @@ import {
|
|||||||
import { SessionProvider } from "../components/providers/Providers";
|
import { SessionProvider } from "../components/providers/Providers";
|
||||||
import { Toaster } from "sonner";
|
import { Toaster } from "sonner";
|
||||||
//import { Button } from "../components/ui/button";
|
//import { Button } from "../components/ui/button";
|
||||||
|
|
||||||
import { useSessionStore } from "../lib/store/sessionStore";
|
import { useSessionStore } from "../lib/store/sessionStore";
|
||||||
import { useSession } from "@/hooks/useSession";
|
import { useSession } from "@/hooks/useSession";
|
||||||
import { useLogout } from "@/hooks/useLogout";
|
import { useLogout } from "@/hooks/useLogout";
|
||||||
|
import ExportInventoryData from "@/components/logistics/warehouse/ExportInventoryData";
|
||||||
import { AddCards } from "@/components/dashboard/AddCards";
|
import { AddCards } from "@/components/dashboard/AddCards";
|
||||||
|
//import { AddCards } from "@/components/dashboard/AddCards";
|
||||||
|
|
||||||
// same as the layout
|
// same as the layout
|
||||||
export const Route = createRootRoute({
|
export const Route = createRootRoute({
|
||||||
@@ -30,16 +36,20 @@ export const Route = createRootRoute({
|
|||||||
const { session } = useSession();
|
const { session } = useSession();
|
||||||
const { user } = useSessionStore();
|
const { user } = useSessionStore();
|
||||||
const logout = useLogout();
|
const logout = useLogout();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="overflow-hidden">
|
||||||
<SessionProvider>
|
<SessionProvider>
|
||||||
<ThemeProvider>
|
<ThemeProvider>
|
||||||
<nav className="flex justify-end">
|
<nav className="flex justify-end w-full shadow ">
|
||||||
<div className="m-2 flex flex-row">
|
<div className="m-2 flex flex-row">
|
||||||
<div className="m-auto pr-2">
|
{location.pathname === "/" && (
|
||||||
<AddCards />
|
<div className="m-auto pr-2 flex flex-row gap-2">
|
||||||
</div>
|
<ExportInventoryData />
|
||||||
|
<AddCards />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div className="m-1">
|
<div className="m-1">
|
||||||
<ModeToggle />
|
<ModeToggle />
|
||||||
</div>
|
</div>
|
||||||
@@ -88,16 +98,18 @@ export const Route = createRootRoute({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<SidebarProvider defaultOpen={sidebarState}>
|
<main>
|
||||||
<AppSidebar />
|
<SidebarProvider defaultOpen={sidebarState}>
|
||||||
<Toaster expand={true} richColors closeButton />
|
<AppSidebar />
|
||||||
<Outlet />
|
<Toaster expand={true} richColors closeButton />
|
||||||
</SidebarProvider>
|
<Outlet />
|
||||||
|
</SidebarProvider>
|
||||||
|
</main>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</SessionProvider>
|
</SessionProvider>
|
||||||
|
|
||||||
{/* <TanStackRouterDevtools position="bottom-right" /> */}
|
{/* <TanStackRouterDevtools position="bottom-right" /> */}
|
||||||
</>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
26
frontend/src/utils/querys/admin/notifications.tsx
Normal file
26
frontend/src/utils/querys/admin/notifications.tsx
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { queryOptions } from "@tanstack/react-query";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
export function getnotifications() {
|
||||||
|
const token = localStorage.getItem("auth_token");
|
||||||
|
return queryOptions({
|
||||||
|
queryKey: ["getNotifications"],
|
||||||
|
queryFn: () => fetchUsers(token),
|
||||||
|
enabled: !!token, // Prevents query if token is null
|
||||||
|
staleTime: 1000,
|
||||||
|
refetchInterval: 2 * 2000,
|
||||||
|
refetchOnWindowFocus: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchUsers = async (token: string | null) => {
|
||||||
|
const { data } = await axios.get(`/api/notify/notifications`, {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// if we are not localhost ignore the devDir setting.
|
||||||
|
//const url: string = window.location.host.split(":")[0];
|
||||||
|
return data.data ?? [];
|
||||||
|
};
|
||||||
30
server/services/notifications/controller/getNotifications.ts
Normal file
30
server/services/notifications/controller/getNotifications.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { and, desc, eq, gte, inArray, lte, sql } from "drizzle-orm";
|
||||||
|
import { db } from "../../../../database/dbclient.js";
|
||||||
|
import { logs } from "../../../../database/schema/logs.js";
|
||||||
|
import { createLog } from "../../logger/logger.js";
|
||||||
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
|
import { notifications } from "../../../../database/schema/notifications.js";
|
||||||
|
|
||||||
|
export const getNotifications = async () => {
|
||||||
|
const { data, error } = await tryCatch(db.select().from(notifications));
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
createLog(
|
||||||
|
"error",
|
||||||
|
"notify",
|
||||||
|
"notify",
|
||||||
|
`Error getting notifications: ${error}`
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Error getting notifications.",
|
||||||
|
data: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
sucess: true,
|
||||||
|
message: "Current notifications.",
|
||||||
|
data: data,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -11,10 +11,11 @@ import { startNotificationMonitor } from "./utils/processNotifications.js";
|
|||||||
import notifyStats from "./routes/getActiveNotifications.js";
|
import notifyStats from "./routes/getActiveNotifications.js";
|
||||||
import tiTrigger from "./routes/manualTiggerTi.js";
|
import tiTrigger from "./routes/manualTiggerTi.js";
|
||||||
import blocking from "./routes/qualityBlocking.js";
|
import blocking from "./routes/qualityBlocking.js";
|
||||||
|
import notify from "./routes/getNotifications.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
const routes = [sendemail, notifyStats, tiTrigger, blocking] as const;
|
const routes = [sendemail, notifyStats, tiTrigger, blocking, notify] as const;
|
||||||
|
|
||||||
const appRoutes = routes.forEach((route) => {
|
const appRoutes = routes.forEach((route) => {
|
||||||
app.route("/notify", route);
|
app.route("/notify", route);
|
||||||
|
|||||||
44
server/services/notifications/routes/getNotifications.ts
Normal file
44
server/services/notifications/routes/getNotifications.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
// an external way to creating logs
|
||||||
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
|
//import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
|
import { getNotifications } from "../controller/getNotifications.js";
|
||||||
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
|
|
||||||
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
|
app.openapi(
|
||||||
|
createRoute({
|
||||||
|
tags: ["notify"],
|
||||||
|
summary: "Gets notifications.",
|
||||||
|
method: "get",
|
||||||
|
path: "/notifications",
|
||||||
|
// description:
|
||||||
|
// "This might be a temp soltuin during the transtion between versions",
|
||||||
|
responses: responses(),
|
||||||
|
}),
|
||||||
|
async (c: any) => {
|
||||||
|
//apiHit(c, { endpoint: `api/logger/logs` });
|
||||||
|
const { data, error } = await tryCatch(getNotifications());
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return c.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "There was an error clearing the log.",
|
||||||
|
data: error,
|
||||||
|
},
|
||||||
|
400
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return c.json(
|
||||||
|
{
|
||||||
|
success: data?.success,
|
||||||
|
message: data?.message,
|
||||||
|
data: data?.data,
|
||||||
|
},
|
||||||
|
200
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
export default app;
|
||||||
Reference in New Issue
Block a user