Commit 53baecd5 authored by Merekeyev Dias's avatar Merekeyev Dias

added requests in apislice

parent f0caf0ca
...@@ -3,20 +3,48 @@ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' ...@@ -3,20 +3,48 @@ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
interface Organizations { interface Organizations {
id: number; id: number;
bin: string; bin: string;
code: string; organization_code: string;
name: string; organization_name: string;
status: string; status: string;
host: string; login: string;
} }
export const apiSlice = createApi({ export const apiSlice = createApi({
reducerPath: 'api', reducerPath: 'api',
baseQuery: fetchBaseQuery({ baseUrl: "https://669f8d88b132e2c136fe5106.mockapi.io/api/v1" }), baseQuery: fetchBaseQuery({ baseUrl: "https://669f8d88b132e2c136fe5106.mockapi.io/api/v1" }),
endpoints: (builder) => ({ endpoints: (builder) => ({
getOrganization: builder.query<Organizations[], void>({ getOrganizations: builder.query<Organizations[], void>({
query: () => '/organizations' query: () => '/organizations'
}),
getOrganization: builder.query({
query: orgId => `/organizations/${orgId}`
}),
addNewOrganization: builder.query({
query: initialOrg => ({
url: '/organizations',
method: 'POST',
body: initialOrg
})
}),
editOrganization: builder.query({
query: org => ({
url: `/organizations/${org.id}`,
method: 'PUT',
body: org
})
}),
deleteOrganization: builder.query({
query: orgId => ({
url: `organizations/${orgId}`,
method: "DELETE",
})
}) })
}) })
}) })
export const { useGetOrganizationQuery } = apiSlice; export const {
\ No newline at end of file useGetOrganizationsQuery,
useGetOrganizationQuery,
useAddNewOrganizationQuery,
useEditOrganizationQuery,
useDeleteOrganizationQuery } = apiSlice;
\ No newline at end of file
import React from 'react'; import React 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, Pagination, Spin, Table } from 'antd'; import { Button, Pagination, Space, Spin, Table } from 'antd';
import type { TableProps } from 'antd'; import type { TableProps } from 'antd';
import './Homepage.css'; import './Homepage.css';
import { useGetOrganizationQuery } from '../../features/api/apiSlice'; import { useGetOrganizationsQuery } from '../../features/api/apiSlice';
interface DataType { interface DataType {
id: number; id: number;
bin: string; bin: string;
code: string; organization_code: string;
name: string; organization_name: string;
status: string; status: string;
host: string; login: string;
} }
const columns: TableProps<DataType>['columns'] = [ const columns: TableProps<DataType>['columns'] = [
...@@ -28,17 +28,17 @@ const columns: TableProps<DataType>['columns'] = [ ...@@ -28,17 +28,17 @@ const columns: TableProps<DataType>['columns'] = [
}, },
{ {
title: "Код организации", title: "Код организации",
dataIndex: "code", dataIndex: "organization_code",
key: "code" key: "code"
}, },
{ {
title: "Наименование организации", title: "Наименование организации",
dataIndex: "name", dataIndex: "organization_name",
key: "name" key: "name"
}, },
{ {
title: "Адрес системы/хост", title: "Адрес системы/хост",
dataIndex: "host", dataIndex: "",
key: "host" key: "host"
}, },
{ {
...@@ -54,11 +54,14 @@ const columns: TableProps<DataType>['columns'] = [ ...@@ -54,11 +54,14 @@ const columns: TableProps<DataType>['columns'] = [
} }
}, },
{ {
title: "act", title: "Действия",
width: 60, width: 60,
render: (value ) => { render: (value ) => {
return ( return (
<Button onClick={() => console.log(value)} icon={<MaterialSymbol>delete</MaterialSymbol>} /> <Space>
<Button onClick={() => console.log(value)} icon={<MaterialSymbol icon='visibility' size={22} />} />
<Button onClick={() => console.log(value)} icon={<MaterialSymbol icon='delete' size={22} />} />
</Space>
) )
} }
} }
...@@ -81,7 +84,7 @@ const HomePage: React.FC = () => { ...@@ -81,7 +84,7 @@ const HomePage: React.FC = () => {
isSuccess, isSuccess,
isError, isError,
error error
} = useGetOrganizationQuery(); } = useGetOrganizationsQuery();
let table; let table;
...@@ -89,7 +92,7 @@ const HomePage: React.FC = () => { ...@@ -89,7 +92,7 @@ const HomePage: React.FC = () => {
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} /> table = <Table dataSource={dataSource} columns={columns} pagination={false} />
} else if (isError) { } else if (isError) {
table = <div>{error.toString()}</div> table = <div>{error.toString()}</div>
} }
...@@ -105,9 +108,9 @@ const HomePage: React.FC = () => { ...@@ -105,9 +108,9 @@ 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={1} total={10} onChange={handlePaginationChange} /> <Pagination current={1} defaultCurrent={1} pageSize={1} total={10} onChange={handlePaginationChange} />
</div> */} </div>
</section> </section>
</div> </div>
); );
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
.data { .data {
flex: 1; flex: 1;
overflow-y: auto; overflow-y: auto;
margin-bottom: 75px;
} }
.data-table { .data-table {
......
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