{option.label}
diff --git a/frontend/src/routes/(auth)/-components/NotificationsSubCard.tsx b/frontend/src/routes/(auth)/-components/NotificationsSubCard.tsx
index 6d4eb40..ffe4b78 100644
--- a/frontend/src/routes/(auth)/-components/NotificationsSubCard.tsx
+++ b/frontend/src/routes/(auth)/-components/NotificationsSubCard.tsx
@@ -1,4 +1,6 @@
import { useSuspenseQuery } from "@tanstack/react-query";
+import axios from "axios";
+import { toast } from "sonner";
import {
Card,
CardContent,
@@ -12,15 +14,29 @@ import { notifications } from "../../../lib/queries/notifications";
export default function NotificationsSubCard({ user }: any) {
const { data } = useSuspenseQuery(notifications());
- const { data: ns } = useSuspenseQuery(notificationSubs(user.id));
+ const { data: ns, refetch } = useSuspenseQuery(notificationSubs(user.id));
const form = useAppForm({
defaultValues: {
notificationId: "",
emails: [user.email],
},
onSubmit: async ({ value }) => {
+ if (value.notificationId === "") {
+ toast.error("Please select a notification before trying to subscribe.");
+ return;
+ }
const postD = { ...value, userId: user.id };
- console.log(postD);
+
+ try {
+ const res = await axios.post("/lst/api/notification/sub", postD, {
+ withCredentials: true,
+ });
+
+ refetch();
+ form.reset();
+ } catch (error) {
+ console.error(error);
+ }
},
});
@@ -32,8 +48,6 @@ export default function NotificationsSubCard({ user }: any) {
}));
}
- console.log(ns);
-
return (
diff --git a/frontend/src/routes/(auth)/-components/NotificationsTable.tsx b/frontend/src/routes/(auth)/-components/NotificationsTable.tsx
new file mode 100644
index 0000000..16e3a70
--- /dev/null
+++ b/frontend/src/routes/(auth)/-components/NotificationsTable.tsx
@@ -0,0 +1,120 @@
+import { useSuspenseQuery } from "@tanstack/react-query";
+import { createColumnHelper } from "@tanstack/react-table";
+import axios from "axios";
+import { Trash } from "lucide-react";
+import { toast } from "sonner";
+import { Button } from "../../../components/ui/button";
+import { Card, CardContent, CardHeader } from "../../../components/ui/card";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from "../../../components/ui/tooltip";
+import { notificationSubs } from "../../../lib/queries/notificationSubs";
+import { notifications } from "../../../lib/queries/notifications";
+import LstTable from "../../../lib/tableStuff/LstTable";
+import SearchableHeader from "../../../lib/tableStuff/SearchableHeader";
+
+type Notifications = {
+ id: string;
+ name: string;
+ emails: string;
+ description: string;
+ remove: unknown;
+};
+
+export default function NotificationsTable({ userId }: any) {
+ const { data: subs, refetch } = useSuspenseQuery(notificationSubs(userId));
+ const { data: note } = useSuspenseQuery(notifications());
+ const columnHelper = createColumnHelper();
+
+ // filter out the current
+ const notificationMap = Object.fromEntries(note.map((n: any) => [n.id, n]));
+
+ const data = subs.map((sub: any) => ({
+ ...sub,
+ name: notificationMap[sub.notificationId].name || null,
+ description: notificationMap[sub.notificationId].description || null,
+ emails: sub.emails ? sub.emails.join(",") : null,
+ }));
+
+ const removeNotification = async (ns: any) => {
+ try {
+ const res = await axios.delete(`/lst/api/notification/sub`, {
+ withCredentials: true,
+ data: {
+ userId: ns.userId,
+ notificationId: ns.notificationId,
+ },
+ });
+
+ if (res.data.success) {
+ toast.success(`Subscription removed`);
+ refetch();
+ } else {
+ console.info(res);
+ toast.error(res.data.message);
+ }
+ } catch {
+ toast.error(`There was an error removing subscription.`);
+ }
+ };
+
+ const column = [
+ columnHelper.accessor("name", {
+ header: ({ column }) => (
+
+ ),
+ filterFn: "includesString",
+ cell: (i) => i.getValue(),
+ }),
+ columnHelper.accessor("description", {
+ header: ({ column }) => (
+
+ ),
+ cell: (i) => (
+
+
+ {i.getValue()?.length > 25 ? (
+ {i.getValue().slice(0, 25)}...
+ ) : (
+ {i.getValue()}
+ )}
+
+ {i.getValue()}
+
+ ),
+ }),
+ columnHelper.accessor("emails", {
+ header: ({ column }) => (
+
+ ),
+ filterFn: "includesString",
+ cell: (i) => i.getValue(),
+ }),
+ columnHelper.accessor("remove", {
+ header: ({ column }) => (
+
+ ),
+ filterFn: "includesString",
+ cell: (i) => {
+ return (
+
+ );
+ },
+ }),
+ ];
+ return (
+
+ Subscriptions
+
+
+
+
+ );
+}
diff --git a/frontend/src/routes/(auth)/user.profile.tsx b/frontend/src/routes/(auth)/user.profile.tsx
index 6d1380b..19ecf9b 100644
--- a/frontend/src/routes/(auth)/user.profile.tsx
+++ b/frontend/src/routes/(auth)/user.profile.tsx
@@ -13,6 +13,7 @@ import { useAppForm } from "@/lib/formSutff";
import { Spinner } from "../../components/ui/spinner";
import ChangePassword from "./-components/ChangePassword";
import NotificationsSubCard from "./-components/NotificationsSubCard";
+import NotificationsTable from "./-components/NotificationsTable";
export const Route = createFileRoute("/(auth)/user/profile")({
beforeLoad: async () => {
@@ -119,11 +120,24 @@ function RouteComponent() {
-
-
- You are not subscribed to any notifications.
-
-
+
+
+ Subscriptions
+
+
+
+
+
+ }
+ >
+ {session && }
+
);