fix: fix website cannot delete problem #91
This commit is contained in:
parent
32adb75e9a
commit
90953e490c
@ -4,15 +4,6 @@ import { AppRouterOutput } from '../trpc';
|
||||
|
||||
export type WebsiteInfo = NonNullable<AppRouterOutput['website']['info']>;
|
||||
|
||||
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]);
|
||||
}
|
||||
|
@ -100,7 +100,9 @@ export const CommonList: React.FC<CommonListProps> = React.memo((props) => {
|
||||
}}
|
||||
>
|
||||
<div className="flex w-full items-center justify-between gap-1">
|
||||
<div className="font-semibold">{item.title}</div>
|
||||
<div className="overflow-hidden text-ellipsis font-semibold">
|
||||
{item.title}
|
||||
</div>
|
||||
|
||||
{item.number && item.number > 0 && (
|
||||
<span className="opacity-60" title={String(item.number)}>
|
||||
|
@ -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(
|
||||
<CardContent>
|
||||
<div>
|
||||
<AlertConfirm
|
||||
title={t('Delete Website')}
|
||||
title={t('Delete Website') + ' ' + website.name}
|
||||
onConfirm={() => handleDeleteWebsite()}
|
||||
>
|
||||
<Button variant="destructive">
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { Button, Form, Input, message, Popconfirm, Tabs } from 'antd';
|
||||
import React from 'react';
|
||||
import { useNavigate, useParams } from 'react-router';
|
||||
import { deleteWorkspaceWebsite } from '../../api/model/website';
|
||||
import { useRequest } from '../../hooks/useRequest';
|
||||
import { useCurrentWorkspaceId } from '../../store/user';
|
||||
import { ErrorTip } from '../ErrorTip';
|
||||
@ -27,6 +26,7 @@ export const WebsiteInfo: React.FC = React.memo(() => {
|
||||
}>();
|
||||
const navigate = useNavigate();
|
||||
const queryClient = useQueryClient();
|
||||
const trpcUtils = trpc.useUtils();
|
||||
|
||||
const { data: website, isLoading } = trpc.website.info.useQuery({
|
||||
workspaceId,
|
||||
@ -40,6 +40,9 @@ export const WebsiteInfo: React.FC = React.memo(() => {
|
||||
},
|
||||
onError: defaultErrorHandler,
|
||||
});
|
||||
const deleteMutation = trpc.website.delete.useMutation({
|
||||
onError: defaultErrorHandler,
|
||||
});
|
||||
|
||||
const handleSave = useEvent(
|
||||
async (values: { name: string; domain: string; monitorId: string }) => {
|
||||
@ -54,7 +57,12 @@ export const WebsiteInfo: React.FC = React.memo(() => {
|
||||
);
|
||||
|
||||
const [, handleDeleteWebsite] = useRequest(async () => {
|
||||
await deleteWorkspaceWebsite(workspaceId, websiteId!);
|
||||
if (!websiteId) {
|
||||
return;
|
||||
}
|
||||
|
||||
await deleteMutation.mutateAsync({ workspaceId, websiteId });
|
||||
await trpcUtils.website.all.refetch({ workspaceId });
|
||||
|
||||
message.success(t('Delete Success'));
|
||||
|
||||
@ -139,7 +147,7 @@ export const WebsiteInfo: React.FC = React.memo(() => {
|
||||
|
||||
<Tabs.TabPane key={'data'} tab={'Data'}>
|
||||
<Popconfirm
|
||||
title={t('Delete Website')}
|
||||
title={t('Delete Website') + ' ' + website.name}
|
||||
onConfirm={() => handleDeleteWebsite()}
|
||||
>
|
||||
<Button type="primary" danger={true}>
|
||||
|
@ -50,7 +50,6 @@ app.use(
|
||||
app.use('/health', healthRouter);
|
||||
app.use('/api/auth/*', ExpressAuth(authConfig));
|
||||
app.use('/api/website', websiteRouter);
|
||||
app.use('/api/workspace', workspaceRouter);
|
||||
app.use('/monitor', monitorRouter);
|
||||
app.use('/telemetry', telemetryRouter);
|
||||
app.use('/serverStatus', serverStatusRouter);
|
||||
|
@ -47,20 +47,6 @@ export async function getWorkspaceWebsites(workspaceId: string) {
|
||||
return workspace?.websites ?? [];
|
||||
}
|
||||
|
||||
export async function deleteWorkspaceWebsite(
|
||||
workspaceId: string,
|
||||
websiteId: string
|
||||
) {
|
||||
const website = await prisma.website.delete({
|
||||
where: {
|
||||
id: websiteId,
|
||||
workspaceId,
|
||||
},
|
||||
});
|
||||
|
||||
return website;
|
||||
}
|
||||
|
||||
export async function getWorkspaceWebsiteDateRange(websiteId: string) {
|
||||
const { params } = await parseWebsiteFilters(websiteId, {
|
||||
startDate: new Date(DEFAULT_RESET_DATE),
|
||||
|
@ -1,23 +0,0 @@
|
||||
import { Router } from 'express';
|
||||
import { auth } from '../middleware/auth.js';
|
||||
import { param, validate } from '../middleware/validate.js';
|
||||
import { workspacePermission } from '../middleware/workspace.js';
|
||||
import { deleteWorkspaceWebsite } from '../model/workspace.js';
|
||||
import { ROLES } from '@tianji/shared';
|
||||
|
||||
export const workspaceRouter = Router();
|
||||
|
||||
workspaceRouter.delete(
|
||||
'/:workspaceId/website/:websiteId',
|
||||
validate(param('workspaceId').isString(), param('websiteId').isString()),
|
||||
auth(),
|
||||
workspacePermission([ROLES.owner]),
|
||||
async (req, res) => {
|
||||
const workspaceId = req.params.workspaceId;
|
||||
const websiteId = req.params.websiteId;
|
||||
|
||||
const website = await deleteWorkspaceWebsite(workspaceId, websiteId);
|
||||
|
||||
res.json({ website });
|
||||
}
|
||||
);
|
@ -522,6 +522,34 @@ export const websiteRouter = router({
|
||||
|
||||
return website;
|
||||
}),
|
||||
delete: workspaceOwnerProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'DELETE',
|
||||
tags: [OPENAPI_TAG.WEBSITE],
|
||||
protect: true,
|
||||
path: `/workspace/{workspaceId}/website/{websiteId}`,
|
||||
},
|
||||
})
|
||||
.input(
|
||||
z.object({
|
||||
websiteId: z.string(),
|
||||
})
|
||||
)
|
||||
.output(websiteInfoSchema)
|
||||
.mutation(async ({ input }) => {
|
||||
const { workspaceId, websiteId } = input;
|
||||
|
||||
const website = await prisma.website.delete({
|
||||
where: {
|
||||
id: websiteId,
|
||||
workspaceId,
|
||||
},
|
||||
});
|
||||
|
||||
return website;
|
||||
}),
|
||||
|
||||
updateInfo: workspaceOwnerProcedure
|
||||
.meta(
|
||||
buildWebsiteOpenapi({
|
||||
|
Loading…
Reference in New Issue
Block a user