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"; import { toast } from "sonner";
interface Props { interface Props {
destinationId: string; notificationId: string;
} }
export const DeleteDestination = ({ destinationId }: Props) => { export const DeleteNotification = ({ notificationId }: Props) => {
const { mutateAsync, isLoading } = api.destination.remove.useMutation(); const { mutateAsync, isLoading } = api.notification.remove.useMutation();
const utils = api.useUtils(); const utils = api.useUtils();
return ( return (
<AlertDialog> <AlertDialog>
@@ -33,7 +33,7 @@ export const DeleteDestination = ({ destinationId }: Props) => {
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle> <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
<AlertDialogDescription> <AlertDialogDescription>
This action cannot be undone. This will permanently delete the This action cannot be undone. This will permanently delete the
destination notification
</AlertDialogDescription> </AlertDialogDescription>
</AlertDialogHeader> </AlertDialogHeader>
<AlertDialogFooter> <AlertDialogFooter>
@@ -41,14 +41,14 @@ export const DeleteDestination = ({ destinationId }: Props) => {
<AlertDialogAction <AlertDialogAction
onClick={async () => { onClick={async () => {
await mutateAsync({ await mutateAsync({
destinationId, notificationId,
}) })
.then(() => { .then(() => {
utils.destination.all.invalidate(); utils.notification.all.invalidate();
toast.success("Destination delete succesfully"); toast.success("Notification delete succesfully");
}) })
.catch(() => { .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 { api } from "@/utils/api";
import { BellRing } from "lucide-react"; import { BellRing } from "lucide-react";
import { AddNotification } from "./add-notification"; import { AddNotification } from "./add-notification";
import { DeleteNotification } from "./delete-notification";
export const ShowNotifications = () => { export const ShowNotifications = () => {
const { data } = api.notification.all.useQuery(); const { data } = api.notification.all.useQuery();
@@ -41,14 +42,14 @@ export const ShowNotifications = () => {
<span className="text-sm text-muted-foreground"> <span className="text-sm text-muted-foreground">
{index + 1}. {destination.name} {index + 1}. {destination.name}
</span> </span>
{/* <div className="flex flex-row gap-1"> <div className="flex flex-row gap-1">
<UpdateDestination {/* <UpdateDestination
destinationId={destination.destinationId} destinationId={destination.destinationId}
/> */}
<DeleteNotification
notificationId={destination.notificationId}
/> />
<DeleteDestination </div>
destinationId={destination.destinationId}
/>
</div> */}
</div> </div>
))} ))}
<div> <div>

View File

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