2023-09-06 06:14:12 +00:00
|
|
|
import { Button, Form, Input, message, Popconfirm, Tabs } from 'antd';
|
2023-09-05 07:32:16 +00:00
|
|
|
import React from 'react';
|
2023-09-06 06:14:12 +00:00
|
|
|
import { useNavigate, useParams } from 'react-router';
|
2023-11-14 16:34:50 +00:00
|
|
|
import { deleteWorkspaceWebsite } from '../../api/model/website';
|
|
|
|
import { useRequest } from '../../hooks/useRequest';
|
|
|
|
import { useCurrentWorkspaceId } from '../../store/user';
|
|
|
|
import { ErrorTip } from '../ErrorTip';
|
|
|
|
import { Loading } from '../Loading';
|
|
|
|
import { NoWorkspaceTip } from '../NoWorkspaceTip';
|
|
|
|
import { MonitorPicker } from '../monitor/MonitorPicker';
|
2023-10-14 17:01:34 +00:00
|
|
|
import {
|
|
|
|
defaultErrorHandler,
|
|
|
|
defaultSuccessHandler,
|
|
|
|
getQueryKey,
|
|
|
|
trpc,
|
2023-11-14 16:34:50 +00:00
|
|
|
} from '../../api/trpc';
|
2023-10-14 16:39:14 +00:00
|
|
|
import { useQueryClient } from '@tanstack/react-query';
|
2023-11-14 16:34:50 +00:00
|
|
|
import { useEvent } from '../../hooks/useEvent';
|
2024-01-03 07:37:28 +00:00
|
|
|
import { hostnameValidator } from '../../utils/validator';
|
2024-02-11 16:10:38 +00:00
|
|
|
import { useTranslation } from '@i18next-toolkit/react';
|
2023-09-05 07:32:16 +00:00
|
|
|
|
|
|
|
export const WebsiteInfo: React.FC = React.memo(() => {
|
2024-02-11 16:10:38 +00:00
|
|
|
const { t } = useTranslation();
|
2023-10-14 16:39:14 +00:00
|
|
|
const workspaceId = useCurrentWorkspaceId();
|
2023-09-05 07:32:16 +00:00
|
|
|
const { websiteId } = useParams<{
|
|
|
|
websiteId: string;
|
|
|
|
}>();
|
2023-09-06 06:14:12 +00:00
|
|
|
const navigate = useNavigate();
|
2023-10-14 16:39:14 +00:00
|
|
|
const queryClient = useQueryClient();
|
2023-09-05 07:32:16 +00:00
|
|
|
|
2023-10-14 17:01:34 +00:00
|
|
|
const { data: website, isLoading } = trpc.website.info.useQuery({
|
|
|
|
workspaceId,
|
|
|
|
websiteId: websiteId!,
|
|
|
|
});
|
|
|
|
|
2023-10-14 16:39:14 +00:00
|
|
|
const updateMutation = trpc.website.updateInfo.useMutation({
|
|
|
|
onSuccess: () => {
|
2023-10-14 17:01:34 +00:00
|
|
|
queryClient.resetQueries(getQueryKey(trpc.website.info));
|
2023-10-14 16:39:14 +00:00
|
|
|
defaultSuccessHandler();
|
|
|
|
},
|
|
|
|
onError: defaultErrorHandler,
|
|
|
|
});
|
|
|
|
|
|
|
|
const handleSave = useEvent(
|
2023-10-14 16:51:03 +00:00
|
|
|
async (values: { name: string; domain: string; monitorId: string }) => {
|
2023-10-14 16:39:14 +00:00
|
|
|
await updateMutation.mutateAsync({
|
|
|
|
workspaceId,
|
|
|
|
websiteId: websiteId!,
|
2023-09-05 07:32:16 +00:00
|
|
|
name: values.name,
|
|
|
|
domain: values.domain,
|
2023-10-14 16:51:03 +00:00
|
|
|
monitorId: values.monitorId,
|
2023-09-05 07:32:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2023-09-06 06:14:12 +00:00
|
|
|
const [, handleDeleteWebsite] = useRequest(async () => {
|
2023-10-14 16:39:14 +00:00
|
|
|
await deleteWorkspaceWebsite(workspaceId, websiteId!);
|
2023-09-06 06:14:12 +00:00
|
|
|
|
2024-02-11 16:10:38 +00:00
|
|
|
message.success(t('Delete Success'));
|
2023-09-06 06:14:12 +00:00
|
|
|
|
|
|
|
navigate('/settings/websites');
|
|
|
|
});
|
|
|
|
|
2023-10-14 16:39:14 +00:00
|
|
|
if (!workspaceId) {
|
2023-09-05 07:32:16 +00:00
|
|
|
return <NoWorkspaceTip />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!websiteId) {
|
|
|
|
return <ErrorTip />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
return <Loading />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!website) {
|
|
|
|
return <ErrorTip />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div className="h-24 flex items-center">
|
2024-02-11 16:10:38 +00:00
|
|
|
<div className="text-2xl flex-1">{t('Website Info')}</div>
|
2023-09-05 07:32:16 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div>
|
2023-09-06 06:14:12 +00:00
|
|
|
<Tabs>
|
|
|
|
<Tabs.TabPane key={'detail'} tab={'Detail'}>
|
|
|
|
<Form
|
|
|
|
layout="vertical"
|
|
|
|
initialValues={{
|
|
|
|
id: website.id,
|
|
|
|
name: website.name,
|
|
|
|
domain: website.domain,
|
2023-10-14 16:51:03 +00:00
|
|
|
monitorId: website.monitorId,
|
2023-09-06 06:14:12 +00:00
|
|
|
}}
|
|
|
|
onFinish={handleSave}
|
|
|
|
>
|
2024-02-11 16:10:38 +00:00
|
|
|
<Form.Item label={t('Website ID')} name="id">
|
2023-09-06 06:14:12 +00:00
|
|
|
<Input size="large" disabled={true} />
|
|
|
|
</Form.Item>
|
2024-02-11 16:10:38 +00:00
|
|
|
<Form.Item
|
|
|
|
label={t('Name')}
|
|
|
|
name="name"
|
|
|
|
rules={[{ required: true }]}
|
|
|
|
>
|
2023-09-06 06:14:12 +00:00
|
|
|
<Input size="large" />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
2024-02-11 16:10:38 +00:00
|
|
|
label={t('Domain')}
|
2023-09-06 06:14:12 +00:00
|
|
|
name="domain"
|
2024-01-03 07:37:28 +00:00
|
|
|
rules={[
|
|
|
|
{ required: true },
|
|
|
|
{
|
|
|
|
validator: hostnameValidator,
|
|
|
|
},
|
|
|
|
]}
|
2023-09-06 06:14:12 +00:00
|
|
|
>
|
|
|
|
<Input size="large" />
|
|
|
|
</Form.Item>
|
|
|
|
|
2023-11-14 16:34:50 +00:00
|
|
|
<Form.Item
|
2024-02-11 16:10:38 +00:00
|
|
|
label={t('Monitor')}
|
2023-11-14 16:34:50 +00:00
|
|
|
name="monitorId"
|
2024-02-11 16:10:38 +00:00
|
|
|
tooltip={t(
|
|
|
|
'You can bind a monitor which will display health status in website overview'
|
|
|
|
)}
|
2023-11-14 16:34:50 +00:00
|
|
|
>
|
2023-10-14 16:51:03 +00:00
|
|
|
<MonitorPicker size="large" allowClear={true} />
|
|
|
|
</Form.Item>
|
|
|
|
|
2023-09-06 06:14:12 +00:00
|
|
|
<Form.Item>
|
|
|
|
<Button size="large" htmlType="submit">
|
2024-02-11 16:10:38 +00:00
|
|
|
{t('Save')}
|
2023-09-06 06:14:12 +00:00
|
|
|
</Button>
|
|
|
|
</Form.Item>
|
|
|
|
</Form>
|
|
|
|
</Tabs.TabPane>
|
2023-09-05 07:32:16 +00:00
|
|
|
|
2023-09-06 06:14:12 +00:00
|
|
|
<Tabs.TabPane key={'data'} tab={'Data'}>
|
|
|
|
<Popconfirm
|
2024-02-11 16:10:38 +00:00
|
|
|
title={t('Delete Website')}
|
2023-09-06 06:14:12 +00:00
|
|
|
onConfirm={() => handleDeleteWebsite()}
|
|
|
|
>
|
|
|
|
<Button type="primary" danger={true}>
|
2024-02-11 16:10:38 +00:00
|
|
|
{t('Delete Website')}
|
2023-09-06 06:14:12 +00:00
|
|
|
</Button>
|
|
|
|
</Popconfirm>
|
|
|
|
</Tabs.TabPane>
|
|
|
|
</Tabs>
|
2023-09-05 07:32:16 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
WebsiteInfo.displayName = 'WebsiteInfo';
|