2023-09-02 07:40:38 +00:00
|
|
|
import {
|
|
|
|
BarChartOutlined,
|
|
|
|
EditOutlined,
|
|
|
|
PlusOutlined,
|
|
|
|
} from '@ant-design/icons';
|
|
|
|
import { Button, Form, Input, Modal, Table } from 'antd';
|
|
|
|
import { ColumnsType } from 'antd/es/table';
|
|
|
|
import React, { useMemo, useState } from 'react';
|
2023-09-04 17:18:43 +00:00
|
|
|
import {
|
|
|
|
addWorkspaceWebsite,
|
|
|
|
refreshWorkspaceWebsites,
|
|
|
|
useWorspaceWebsites,
|
|
|
|
WebsiteInfo,
|
|
|
|
} from '../api/model/website';
|
|
|
|
import { Loading } from '../components/Loading';
|
|
|
|
import { NoWorkspaceTip } from '../components/NoWorkspaceTip';
|
|
|
|
import { useRequest } from '../hooks/useRequest';
|
|
|
|
import { useUserStore } from '../store/user';
|
2023-08-31 16:11:47 +00:00
|
|
|
|
|
|
|
export const Website: React.FC = React.memo(() => {
|
2023-09-02 07:40:38 +00:00
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
2023-09-04 17:18:43 +00:00
|
|
|
const currentWorkspace = useUserStore(
|
|
|
|
(state) => state.info?.currentWorkspace
|
|
|
|
);
|
|
|
|
const [form] = Form.useForm();
|
2023-09-02 07:40:38 +00:00
|
|
|
|
2023-09-04 17:18:43 +00:00
|
|
|
const [{ loading }, handleAddWebsite] = useRequest(async () => {
|
|
|
|
await form.validateFields();
|
|
|
|
const values = form.getFieldsValue();
|
|
|
|
|
|
|
|
await addWorkspaceWebsite(currentWorkspace!.id, values.name, values.domain);
|
|
|
|
refreshWorkspaceWebsites(currentWorkspace!.id);
|
2023-09-02 07:40:38 +00:00
|
|
|
setIsModalOpen(false);
|
2023-09-04 17:18:43 +00:00
|
|
|
|
|
|
|
form.resetFields();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!currentWorkspace) {
|
|
|
|
return <NoWorkspaceTip />;
|
|
|
|
}
|
2023-09-02 07:40:38 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div className="h-24 flex items-center">
|
2023-09-04 17:18:43 +00:00
|
|
|
<div className="text-2xl flex-1">Websites</div>
|
2023-09-02 07:40:38 +00:00
|
|
|
<div>
|
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
icon={<PlusOutlined />}
|
|
|
|
size="large"
|
|
|
|
onClick={() => setIsModalOpen(true)}
|
|
|
|
>
|
|
|
|
Add Website
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-09-04 17:18:43 +00:00
|
|
|
<WebsiteList workspaceId={currentWorkspace.id} />
|
2023-09-02 07:40:38 +00:00
|
|
|
|
|
|
|
<Modal
|
|
|
|
title="Add Server"
|
|
|
|
open={isModalOpen}
|
2023-09-04 17:18:43 +00:00
|
|
|
okButtonProps={{
|
|
|
|
loading,
|
|
|
|
}}
|
|
|
|
onOk={() => handleAddWebsite()}
|
2023-09-02 07:40:38 +00:00
|
|
|
onCancel={() => setIsModalOpen(false)}
|
|
|
|
>
|
2023-09-04 17:18:43 +00:00
|
|
|
<Form layout="vertical" form={form}>
|
|
|
|
<Form.Item
|
|
|
|
label="Server Name"
|
|
|
|
name="name"
|
|
|
|
rules={[{ required: true }]}
|
|
|
|
>
|
2023-09-02 07:40:38 +00:00
|
|
|
<Input />
|
|
|
|
</Form.Item>
|
2023-09-04 17:18:43 +00:00
|
|
|
<Form.Item label="Domain" name="domain" rules={[{ required: true }]}>
|
2023-09-02 07:40:38 +00:00
|
|
|
<Input />
|
|
|
|
</Form.Item>
|
|
|
|
</Form>
|
|
|
|
</Modal>
|
|
|
|
</div>
|
|
|
|
);
|
2023-08-31 16:11:47 +00:00
|
|
|
});
|
|
|
|
Website.displayName = 'Website';
|
2023-09-02 07:40:38 +00:00
|
|
|
|
2023-09-04 17:18:43 +00:00
|
|
|
const WebsiteList: React.FC<{ workspaceId: string }> = React.memo((props) => {
|
|
|
|
const { websites, isLoading } = useWorspaceWebsites(props.workspaceId);
|
2023-09-02 07:40:38 +00:00
|
|
|
|
2023-09-04 17:18:43 +00:00
|
|
|
const columns = useMemo((): ColumnsType<WebsiteInfo> => {
|
2023-09-02 07:40:38 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
dataIndex: 'name',
|
|
|
|
title: 'Name',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
dataIndex: 'domain',
|
|
|
|
title: 'Domain',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'action',
|
|
|
|
render: () => {
|
|
|
|
return (
|
|
|
|
<div className="flex gap-2 justify-end">
|
|
|
|
<Button icon={<EditOutlined />}>Edit</Button>
|
|
|
|
<Button icon={<BarChartOutlined />}>View</Button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}, []);
|
|
|
|
|
2023-09-04 17:18:43 +00:00
|
|
|
if (isLoading) {
|
|
|
|
return <Loading />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return <Table columns={columns} dataSource={websites} pagination={false} />;
|
2023-09-02 07:40:38 +00:00
|
|
|
});
|
|
|
|
WebsiteList.displayName = 'WebsiteList';
|