feat(notifications): add delete notification modal

This commit is contained in:
Mauricio Siu
2024-07-09 01:16:06 -06:00
parent 680811357b
commit 342ff4b589
3 changed files with 16 additions and 15 deletions

View File

@@ -16,10 +16,10 @@ import { TrashIcon } from "lucide-react";
import { toast } from "sonner";
interface Props {
destinationId: string;
notificationId: string;
}
export const DeleteDestination = ({ destinationId }: Props) => {
const { mutateAsync, isLoading } = api.destination.remove.useMutation();
export const DeleteNotification = ({ notificationId }: Props) => {
const { mutateAsync, isLoading } = api.notification.remove.useMutation();
const utils = api.useUtils();
return (
<AlertDialog>
@@ -33,7 +33,7 @@ export const DeleteDestination = ({ destinationId }: Props) => {
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. This will permanently delete the
destination
notification
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
@@ -41,14 +41,14 @@ export const DeleteDestination = ({ destinationId }: Props) => {
<AlertDialogAction
onClick={async () => {
await mutateAsync({
destinationId,
notificationId,
})
.then(() => {
utils.destination.all.invalidate();
toast.success("Destination delete succesfully");
utils.notification.all.invalidate();
toast.success("Notification delete succesfully");
})
.catch(() => {
toast.error("Error to delete destination");
toast.error("Error to delete notification");
});
}}
>

View File

@@ -8,6 +8,7 @@ import {
import { api } from "@/utils/api";
import { BellRing } from "lucide-react";
import { AddNotification } from "./add-notification";
import { DeleteNotification } from "./delete-notification";
export const ShowNotifications = () => {
const { data } = api.notification.all.useQuery();
@@ -41,14 +42,14 @@ export const ShowNotifications = () => {
<span className="text-sm text-muted-foreground">
{index + 1}. {destination.name}
</span>
{/* <div className="flex flex-row gap-1">
<UpdateDestination
<div className="flex flex-row gap-1">
{/* <UpdateDestination
destinationId={destination.destinationId}
/> */}
<DeleteNotification
notificationId={destination.notificationId}
/>
<DeleteDestination
destinationId={destination.destinationId}
/>
</div> */}
</div>
</div>
))}
<div>

View File

@@ -78,7 +78,7 @@ export const notificationRouter = createTRPCRouter({
});
}
}),
removeNotification: adminProcedure
remove: adminProcedure
.input(apiFindOneNotification)
.mutation(async ({ input }) => {
try {