Commit 68ea51f6 authored by Merekeyev Dias's avatar Merekeyev Dias

added delete modal

parent 2c8b493e
...@@ -27,7 +27,7 @@ const App: React.FC = () => { ...@@ -27,7 +27,7 @@ const App: React.FC = () => {
<Route element={<AuthLayout />} > <Route element={<AuthLayout />} >
<Route path="/" element={<HomePage />} /> <Route path="/" element={<HomePage />} />
<Route path="/add" element={<AddPage />} /> <Route path="/add" element={<AddPage />} />
<Route path="/edit" element={<EditPage />} /> <Route path="/edit/:id" element={<EditPage />} />
<Route path="/requests" element={<RequestPage />} /> <Route path="/requests" element={<RequestPage />} />
</Route> </Route>
</Routes> </Routes>
......
import React from 'react'; import React, { useState } from 'react';
import { useNavigate } from 'react-router'; import { useNavigate } from 'react-router';
import { MaterialSymbol } from 'react-material-symbols'; import { MaterialSymbol } from 'react-material-symbols';
import { Button, Space, Spin, Table, Tag } from 'antd'; //Pagination import { Button, Pagination, Space, Spin, Table, Tag, Modal } from 'antd';
import type { TableProps } from 'antd'; import type { TableProps } from 'antd';
import './Homepage.css'; import './Homepage.css';
import { useGetOrganizationsQuery } from '../../features/api/apiSlice'; import { useGetOrganizationsQuery } from '../../features/api/apiSlice';
...@@ -29,40 +29,85 @@ const columns: TableProps<DataType>['columns'] = [ ...@@ -29,40 +29,85 @@ const columns: TableProps<DataType>['columns'] = [
{ {
title: "Код организации", title: "Код организации",
dataIndex: "organization_code", dataIndex: "organization_code",
key: "organization_code" key: "code"
}, },
{ {
title: "Наименование организации", title: "Наименование организации",
dataIndex: "organization_name", dataIndex: "organization_name",
key: "organization_name" key: "name"
},
{
title: "Адрес системы/хост",
dataIndex: "host",
key: "host"
}, },
{ {
title: "Статус", title: "Статус",
dataIndex: "status", dataIndex: "status",
key: "status", key: "status",
render: (_, record) => { render: (_, record) => {
const color = record.status === 'deleted' ? 'red' : record.status === 'blocked' ? 'orange' : 'green'; let color = record.status == '0' ? 'red' : record.status == '1' ? 'processing' : 'green';
return ( return (
<Tag color={color} style={{ fontSize: '14px' }}> <p>
{record.status === 'deleted' ? 'Удален' : record.status === 'blocked' ? 'Заблокирован' : 'Активен'} <Tag color={color} style={{ fontSize: '14px' }}>
</Tag> {record.status == '0' ? 'удален' : record.status == '1' ? 'заблокирован' : 'активен'}
); </Tag>
</p>
)
} }
}, },
{ {
title: "Действия", title: "Действия",
width: 60, width: 60,
render: (value) => { render: (_, record) => {
return ( return (
<Space> <ActionColumn data={record} />
<Button onClick={() => console.log(value)} icon={<MaterialSymbol icon='visibility' size={22} />} />
<Button onClick={() => console.log(value)} icon={<MaterialSymbol icon='delete' size={22} />} />
</Space>
) )
} }
} }
]
const ActionColumn: React.FC<{ data: any }> = ({ data }) => {
const [open, setOpen] = useState(false);
const navigate = useNavigate();
]; const showDeleteModal = () => {
setOpen(true);
};
const handleDeleteModalOk = () => {
setOpen(false);
};
const handleDeleteModalCancel = () => {
setOpen(false);
};
const handleEditClick = () => {
navigate(`/edit/${data.id}`);
}
return (
<Space>
<Button onClick={() => handleEditClick()} icon={<MaterialSymbol icon='visibility' size={22} />} />
<Button onClick={showDeleteModal} icon={<MaterialSymbol icon='delete' size={22} />} />
<Modal
open={open}
title={`Вы уверены в том, что хотите удалить ${data.organization_name}?`}
footer={() => {
return <div style={{textAlign: 'start', marginTop: '1rem'}}>
<Button key="submit" type="primary" danger onClick={handleDeleteModalOk} style={{marginRight: '.5rem'}}>
Удалить
</Button>
<Button key="back" onClick={handleDeleteModalCancel}>
Назад
</Button>
</div>;
}}
/>
</Space>
)
}
const HomePage: React.FC = () => { const HomePage: React.FC = () => {
const navigate = useNavigate(); const navigate = useNavigate();
...@@ -71,6 +116,10 @@ const HomePage: React.FC = () => { ...@@ -71,6 +116,10 @@ const HomePage: React.FC = () => {
navigate("/add"); navigate("/add");
}; };
const handlePaginationChange = (page: number | string | null) => {
console.log("Current page:", page);
};
const { const {
data: orgs = [], data: orgs = [],
isLoading, isLoading,
...@@ -82,12 +131,12 @@ const HomePage: React.FC = () => { ...@@ -82,12 +131,12 @@ const HomePage: React.FC = () => {
let table; let table;
if (isLoading) { if (isLoading) {
table = <Spin />; table = <Spin />
} else if (isSuccess) { } else if (isSuccess) {
const dataSource = orgs.map((org) => ({ ...org, key: org.id })); const dataSource = orgs.map((org) => ({ ...org, key: org.id }));
table = <Table dataSource={dataSource} columns={columns} pagination={false} />; table = <Table dataSource={dataSource} columns={columns} pagination={false} />
} else if (isError) { } else if (isError) {
table = <div>{error.toString()}</div>; table = <div>{error.toString()}</div>
} }
return ( return (
...@@ -101,12 +150,12 @@ const HomePage: React.FC = () => { ...@@ -101,12 +150,12 @@ const HomePage: React.FC = () => {
<div className="data"> <div className="data">
{table} {table}
</div> </div>
{/* <div className='pagination-container'> <div className='pagination-container'>
<Pagination current={1} defaultCurrent={1} pageSize={10} total={orgs.length} /> <Pagination current={1} defaultCurrent={1} pageSize={1} total={10} onChange={handlePaginationChange} />
</div> */} </div>
</section> </section>
</div> </div>
); );
}; }
export default HomePage; export default HomePage;
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment