feat: add delete notification function

This commit is contained in:
moonrailgun 2023-09-27 20:45:19 +08:00
parent 52255690cb
commit 324edc2d88
2 changed files with 40 additions and 5 deletions

View File

@ -1,5 +1,5 @@
import { EditOutlined, PlusOutlined } from '@ant-design/icons';
import { Button, List } from 'antd';
import { DeleteOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons';
import { Button, List, Popconfirm } from 'antd';
import React, { useState } from 'react';
import { trpc } from '../../api/trpc';
import {
@ -21,10 +21,10 @@ export const NotificationList: React.FC = React.memo(() => {
NotificationFormValues | undefined
>(undefined);
const mutation = trpc.notification.upsert.useMutation();
const upsertMutation = trpc.notification.upsert.useMutation();
const deleteMutation = trpc.notification.delete.useMutation();
const handleOpenModal = useEvent((initValues?: NotificationFormValues) => {
console.log('initValues', initValues);
setEditingFormData(initValues);
setOpen(true);
});
@ -35,7 +35,7 @@ export const NotificationList: React.FC = React.memo(() => {
});
const handleSubmit = useEvent(async (values: NotificationFormValues) => {
await mutation.mutateAsync({
await upsertMutation.mutateAsync({
workspaceId: currentWorkspaceId!,
...values,
});
@ -43,6 +43,14 @@ export const NotificationList: React.FC = React.memo(() => {
refetch();
});
const handleDelete = useEvent(async (notificationId: string) => {
await deleteMutation.mutateAsync({
workspaceId: currentWorkspaceId!,
id: notificationId,
});
refetch();
});
if (!currentWorkspaceId) {
return <NoWorkspaceTip />;
}
@ -84,6 +92,17 @@ export const NotificationList: React.FC = React.memo(() => {
>
Edit
</Button>,
<Popconfirm
title="Is delete this item?"
okButtonProps={{
danger: true,
}}
onConfirm={() => {
handleDelete(item.id);
}}
>
<Button danger={true} icon={<DeleteOutlined />} />
</Popconfirm>,
]}
>
<List.Item.Meta title={item.name} />

View File

@ -49,4 +49,20 @@ export const notificationRouter = router({
});
}
}),
delete: workspaceOwnerProcedure
.input(
z.object({
id: z.string(),
})
)
.mutation(async ({ input }) => {
const { id, workspaceId } = input;
return await prisma.notification.delete({
where: {
workspaceId,
id,
},
});
}),
});