feat(user notifications): added the ability for users to sub to notifications and add multi email

This commit is contained in:
2026-04-06 09:29:46 -05:00
parent 3ecf5fb916
commit 637de857f9
7 changed files with 207 additions and 16 deletions

View File

@@ -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 (
<div>
<Card className="p-3 w-lg">