From 90953e490ceea8e5256fd564e4d220b2e7da50b3 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Thu, 19 Sep 2024 23:00:32 +0800 Subject: [PATCH] fix: fix website cannot delete problem #91 --- src/client/api/model/website.ts | 9 ------ src/client/components/CommonList.tsx | 4 ++- .../components/website/WebsiteConfig.tsx | 8 ++++-- src/client/components/website/WebsiteInfo.tsx | 14 ++++++++-- src/server/app.ts | 1 - src/server/model/workspace.ts | 14 ---------- src/server/router/workspace.ts | 23 --------------- src/server/trpc/routers/website.ts | 28 +++++++++++++++++++ 8 files changed, 47 insertions(+), 54 deletions(-) delete mode 100644 src/server/router/workspace.ts diff --git a/src/client/api/model/website.ts b/src/client/api/model/website.ts index cc154cd..ef17b95 100644 --- a/src/client/api/model/website.ts +++ b/src/client/api/model/website.ts @@ -4,15 +4,6 @@ import { AppRouterOutput } from '../trpc'; export type WebsiteInfo = NonNullable; -export async function deleteWorkspaceWebsite( - workspaceId: string, - websiteId: string -) { - await request.delete(`/api/workspace/${workspaceId}/website/${websiteId}`); - - queryClient.resetQueries(['websites', workspaceId]); -} - export function refreshWorkspaceWebsites(workspaceId: string) { queryClient.refetchQueries(['websites', workspaceId]); } diff --git a/src/client/components/CommonList.tsx b/src/client/components/CommonList.tsx index 4bdcd17..a9f4457 100644 --- a/src/client/components/CommonList.tsx +++ b/src/client/components/CommonList.tsx @@ -100,7 +100,9 @@ export const CommonList: React.FC = React.memo((props) => { }} >
-
{item.title}
+
+ {item.title} +
{item.number && item.number > 0 && ( diff --git a/src/client/components/website/WebsiteConfig.tsx b/src/client/components/website/WebsiteConfig.tsx index e611b14..c3eefcb 100644 --- a/src/client/components/website/WebsiteConfig.tsx +++ b/src/client/components/website/WebsiteConfig.tsx @@ -1,6 +1,5 @@ import { Form, Input, message } from 'antd'; import React from 'react'; -import { deleteWorkspaceWebsite } from '../../api/model/website'; import { useRequest } from '../../hooks/useRequest'; import { useCurrentWorkspaceId } from '../../store/user'; import { ErrorTip } from '../ErrorTip'; @@ -38,6 +37,9 @@ export const WebsiteConfig: React.FC<{ websiteId: string }> = React.memo( onSuccess: defaultSuccessHandler, onError: defaultErrorHandler, }); + const deleteMutation = trpc.website.delete.useMutation({ + onError: defaultErrorHandler, + }); const handleSave = useEvent( async (values: { name: string; domain: string; monitorId: string }) => { @@ -65,7 +67,7 @@ export const WebsiteConfig: React.FC<{ websiteId: string }> = React.memo( ); const [, handleDeleteWebsite] = useRequest(async () => { - await deleteWorkspaceWebsite(workspaceId, websiteId!); + await deleteMutation.mutateAsync({ workspaceId, websiteId }); message.success(t('Delete Success')); @@ -157,7 +159,7 @@ export const WebsiteConfig: React.FC<{ websiteId: string }> = React.memo(
handleDeleteWebsite()} >