add delete function

This commit is contained in:
Brandon Egger 2023-09-05 20:38:05 -05:00
parent f66c35a225
commit 2ef07fd37a
2 changed files with 26 additions and 2 deletions

View File

@ -95,6 +95,15 @@ const ResourceViewPage = () => {
}
);
const { mutate: mutateDelete } = api.auditoryResource.delete.useMutation({
onSuccess: async () => {
await router.push(`/resources`);
},
onError: (error) => {
console.error(error);
},
});
const ConditionalView = (data: AuditoryResource) => {
return (
<div className="mx-auto flex max-w-2xl flex-col flex-col-reverse divide-x py-4 sm:flex-row">
@ -138,8 +147,9 @@ const ResourceViewPage = () => {
label="Delete"
symbol={<TrashIcon className="w-4" />}
onConfirm={() => {
// todo
console.log("deleting");
mutateDelete({
id,
});
}}
/>,
]}

View File

@ -89,6 +89,20 @@ export const auditoryResourceRouter = createTRPCRouter({
});
}),
delete: protectedProcedure
.input(
z.object({
id: z.string(),
})
)
.mutation(async ({ input, ctx }) => {
return await ctx.prisma.auditoryResource.delete({
where: {
id: input.id,
},
});
}),
update: protectedProcedure
.input(AuditoryResourceSchema.partial().extend({ id: z.string() }))
.mutation(async ({ input, ctx }) => {