Commit 41fd096a authored by Merekeyev Dias's avatar Merekeyev Dias

changed: pagin -> table pagin, datepicker -> datepicker.rangepicker

parent 3d69cbab
import React, { createRef, useEffect, useState } from 'react'; import React, { createRef, useEffect, useState } from 'react';
import { useNavigate } from 'react-router'; import { useNavigate } from 'react-router';
import { useSelector, useDispatch } from 'react-redux'; import { useSelector, useDispatch } from 'react-redux';
import { Button, message, Pagination, Space, Spin, Table } from 'antd'; import { Button, message, Space, Spin, Table } from 'antd';
import { TableRef } from 'antd/es/table'; import { TableRef } from 'antd/es/table';
import { useGetOrganizationsQuery } from '../../features/api/organizationApiSlice'; import { useGetOrganizationsQuery } from '../../features/api/organizationApiSlice';
...@@ -71,10 +71,20 @@ const HomePage: React.FC = () => { ...@@ -71,10 +71,20 @@ const HomePage: React.FC = () => {
} else if (isSuccess) { } else if (isSuccess) {
table = <Table table = <Table
dataSource={paginatedData(orgs)} dataSource={paginatedData(orgs)}
columns={columns} pagination={false} columns={columns}
rowKey="id" rowKey="id"
className='home_table' className='home_table'
ref={tableRef} ref={tableRef}
pagination={{
position: ['bottomCenter'],
defaultCurrent: 1,
current: currentPage,
pageSize: ORG_NUMBER_PER_PAGE,
total: totalOrgNumber,
onChange: handlePaginationChange,
hideOnSinglePage: true,
showSizeChanger: false
}}
/> />
} else if (isError) { } else if (isError) {
table = <div>{error.toString()}</div> table = <div>{error.toString()}</div>
...@@ -111,7 +121,6 @@ const HomePage: React.FC = () => { ...@@ -111,7 +121,6 @@ const HomePage: React.FC = () => {
disabled={syncBtnState} disabled={syncBtnState}
loading={isSyncLoading} loading={isSyncLoading}
icon={<span className='material-icons' style={{fontSize: 22, color: '#0E2B52'}}>sync</span>} icon={<span className='material-icons' style={{fontSize: 22, color: '#0E2B52'}}>sync</span>}
type='primary'
> >
Синхронизировать справочники Синхронизировать справочники
</Button> </Button>
...@@ -119,7 +128,7 @@ const HomePage: React.FC = () => { ...@@ -119,7 +128,7 @@ const HomePage: React.FC = () => {
<div className="data"> <div className="data">
{table} {table}
</div> </div>
<div className='pagination-container'> {/* <div className='pagination-container'>
<Pagination <Pagination
current={currentPage} current={currentPage}
defaultCurrent={1} defaultCurrent={1}
...@@ -129,7 +138,7 @@ const HomePage: React.FC = () => { ...@@ -129,7 +138,7 @@ const HomePage: React.FC = () => {
hideOnSinglePage={true} hideOnSinglePage={true}
showSizeChanger={false} showSizeChanger={false}
/> />
</div> </div> */}
</section> </section>
</div> </div>
); );
......
...@@ -7,13 +7,14 @@ ...@@ -7,13 +7,14 @@
} }
.form { .form {
margin: 10px 20px 80px 20px; margin: 10px 20px 50px;
padding-right: 20px; padding-right: 20px;
flex: 1; flex: 1;
overflow-y: auto; overflow-y: auto;
} }
.form-footer { .form-footer {
border-top: 1px solid #3333337c;
position: fixed; position: fixed;
bottom: 0; bottom: 0;
left: 0; left: 0;
......
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import { useNavigate, useParams } from 'react-router'; import { useNavigate, useParams } from 'react-router';
import { useSelector, useDispatch } from 'react-redux';
import { Form, Input, Button, Select, message } from 'antd'; import { Form, Input, Button, Select, message } from 'antd';
import { useAddNewOrganizationMutation, useEditOrganizationMutation, useGetOrganizationQuery, useGetOrganizationsQuery } from '../../features/api/organizationApiSlice'; import { useAddNewOrganizationMutation, useEditOrganizationMutation, useGetOrganizationQuery, useGetOrganizationsQuery } from '../../features/api/organizationApiSlice';
import { setTotalOrgNumber, setCurrentPage } from '../../features/pagination/mainPagination'; import { setTotalOrgNumber, setCurrentPage } from '../../features/pagination/mainPagination';
import { useSelector, useDispatch } from 'react-redux';
import './ManageOrganization.css'; import './ManageOrganization.css';
interface OrganizationValues { interface OrganizationValues {
...@@ -161,7 +162,11 @@ const ManageOrganization: React.FC = () => { ...@@ -161,7 +162,11 @@ const ManageOrganization: React.FC = () => {
</Item> </Item>
<div className='form-footer'> <div className='form-footer'>
<Item className='form-footer-item'> <Item className='form-footer-item'>
<Button type="default" style={{ marginRight: '8px' }} onClick={() => navigate("/")}> <Button
type="default"
style={{ marginRight: '8px' }}
onClick={() => navigate("/")}
>
Отмена Отмена
</Button> </Button>
<Button type="primary" htmlType="submit"> <Button type="primary" htmlType="submit">
......
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Button, Space, Tag, Modal, message } from 'antd'; import { Button, Tag, Modal, message } from 'antd';
import type { TableProps } from 'antd'; import type { TableProps } from 'antd';
import { getStatusText, getStatusColor, openXMLInNewPage, downloadXML } from './utils'; import { getStatusText, getStatusColor, openXMLInNewPage, downloadXML } from './utils';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
......
import React, { useEffect, useState, createRef } from 'react'; import React, { useEffect, useState, createRef } from 'react';
import dayjs, { Dayjs } from 'dayjs'; import dayjs, { Dayjs } from 'dayjs';
import isBetween from 'dayjs/plugin/isBetween'; import isBetween from 'dayjs/plugin/isBetween';
import { DatePicker, Select, Button, Pagination, Spin, Table } from 'antd'; import { DatePicker, Select, Button, Spin, Table } from 'antd';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { columns, DataType } from './Columns'; import { columns, DataType } from './Columns';
import { useGetRequestsQuery } from '../../features/api/requestApiSlice'; import { useGetRequestsQuery } from '../../features/api/requestApiSlice';
...@@ -10,8 +10,8 @@ import { TableRef } from 'antd/es/table'; ...@@ -10,8 +10,8 @@ import { TableRef } from 'antd/es/table';
import './RequestPage.css'; import './RequestPage.css';
dayjs.extend(isBetween); dayjs.extend(isBetween);
const dateFormat = 'YYYY-MM-DD'; const DATE_FORMAT = 'YYYY-MM-DD';
const defaultDates = { const DEFAULT_DATES = {
startDate: '2024/01/01', startDate: '2024/01/01',
endDate: '2024/12/31' endDate: '2024/12/31'
} }
...@@ -23,16 +23,17 @@ const RequestPage: React.FC = () => { ...@@ -23,16 +23,17 @@ const RequestPage: React.FC = () => {
const currentPage = useSelector((state: any) => state.reqPagination.currentPage); const currentPage = useSelector((state: any) => state.reqPagination.currentPage);
const REQ_NUMBER_PER_PAGE = useSelector((state: any) => state.reqPagination.REQ_NUMBER_PER_PAGE); const REQ_NUMBER_PER_PAGE = useSelector((state: any) => state.reqPagination.REQ_NUMBER_PER_PAGE);
const [startDate, setStartDate] = useState<Dayjs>(dayjs(defaultDates.startDate, dateFormat));
const [endDate, setEndDate] = useState<Dayjs>(dayjs(defaultDates.endDate, dateFormat));
const [data, setData] = useState<DataType[]>([]); const [data, setData] = useState<DataType[]>([]);
const [dates, setDates] = useState<[Dayjs | null, Dayjs | null]>([
dayjs(DEFAULT_DATES.startDate, DATE_FORMAT),
dayjs(DEFAULT_DATES.endDate, DATE_FORMAT),
]);
const [method, setMethod] = useState(''); const [method, setMethod] = useState('');
const [isTableLoading, setIsTableLoading] = useState(false);
const handlePaginationChange = (page: number) => { const handlePaginationChange = (page: number) => {
/* //scrollIntoView resets to the top of the table after changing the page with Pagination. But the bug was found - the div above the table scrolls to top of the page too, under the Header component. It happens because of overflow
scrollIntoView resets to the top of the table after changing the page with Pagination. But the bug was found - the div above the table scrolls to top of the page too, under the Header component. It happens because of overflow //tableRef.current?.nativeElement.scrollIntoView({ behavior: 'smooth' });
*/
// tableRef.current?.nativeElement.scrollIntoView({ behavior: 'smooth' });
dispatch(setCurrentPage(page)); dispatch(setCurrentPage(page));
}; };
...@@ -44,14 +45,13 @@ const RequestPage: React.FC = () => { ...@@ -44,14 +45,13 @@ const RequestPage: React.FC = () => {
const applyFilters = () => { const applyFilters = () => {
let filtered = reqs.list; let filtered = reqs.list;
/* //subtract and add methods are added because of the unique dates (hh:mm:ss = 00:00:00). The code below is the easiest way to deal with it, but it might be not the ideal form
subtract method is added because of the unique dates (hh:mm:ss = 00:00:00). The code below is the easiest way to deal with it, but it might be not the ideal form const adjustedStartDate = dates && dates[0] ? dayjs(dates[0]).subtract(1, 'day') : null;
*/ const adjustedEndDate = dates && dates[1] ? dayjs(dates[1]).subtract(1, 'day') : null;
const adjustedStartDate = dayjs(startDate).subtract(1, 'day'); if (dates && dates[0] && dates[1]) {
if (startDate && endDate) {
filtered = filtered.filter((req) => { filtered = filtered.filter((req) => {
const sendDate = dayjs(req.sendDate, dateFormat); const sendDate = dayjs(req.sendDate, DATE_FORMAT);
return sendDate.isBetween(adjustedStartDate, endDate, 'day', '[]'); return sendDate.isBetween(adjustedStartDate, adjustedEndDate, 'day', '[]');
}); });
} }
...@@ -64,14 +64,14 @@ const RequestPage: React.FC = () => { ...@@ -64,14 +64,14 @@ const RequestPage: React.FC = () => {
dispatch(setTotalReqNumber(filtered.length)); dispatch(setTotalReqNumber(filtered.length));
} }
const onSelectStartDate = (date: Dayjs) => { const onRangeChange = (dates: [Dayjs | null, Dayjs | null] | null) => {
setStartDate(date); if (dates) {
} setDates(dates);
} else {
const onSelectEndDate = (date: Dayjs) => { setDates([null, null]);
setEndDate(date); }
} };
const onSelectMethod = (method: string) => { const onSelectMethod = (method: string) => {
setMethod(method); setMethod(method);
} }
...@@ -88,12 +88,11 @@ const RequestPage: React.FC = () => { ...@@ -88,12 +88,11 @@ const RequestPage: React.FC = () => {
let min: number = Infinity; let min: number = Infinity;
let max: number = -Infinity; let max: number = -Infinity;
if (isLoading) { if (isSuccess) {
table = <Spin />;
} else if (isSuccess) {
reqs.list.forEach((req) => { reqs.list.forEach((req) => {
const dateValue = new Date(req.sendDate).valueOf(); const dateValue = new Date(req.sendDate).valueOf();
if (min > dateValue) { console.log(dateValue);
if (min > dateValue && dateValue!=0) {
min = dateValue; min = dateValue;
} }
if (max < dateValue) { if (max < dateValue) {
...@@ -103,7 +102,16 @@ const RequestPage: React.FC = () => { ...@@ -103,7 +102,16 @@ const RequestPage: React.FC = () => {
table = <Table table = <Table
dataSource={paginateData(data)} dataSource={paginateData(data)}
columns={columns} columns={columns}
pagination={false} loading={isTableLoading}
pagination={{
position: ['bottomCenter'],
current: currentPage,
defaultCurrent: 1,
pageSize: REQ_NUMBER_PER_PAGE,
total: totalReqNumber,
onChange: handlePaginationChange,
hideOnSinglePage: true
}}
rowKey="id" rowKey="id"
ref={tableRef} ref={tableRef}
/>; />;
...@@ -112,11 +120,13 @@ const RequestPage: React.FC = () => { ...@@ -112,11 +120,13 @@ const RequestPage: React.FC = () => {
} }
useEffect(() => { useEffect(() => {
if (isSuccess) { if (isLoading) {
setIsTableLoading(true);
} else if (isSuccess) {
setIsTableLoading(false);
setData(reqs.list); setData(reqs.list);
dispatch(setTotalReqNumber(reqs.list.length)); dispatch(setTotalReqNumber(reqs.list.length));
setStartDate(dayjs(min)); setDates([dayjs(min), dayjs(max)]);
setEndDate(dayjs(max));
} }
}, [isSuccess, reqs, dispatch]); }, [isSuccess, reqs, dispatch]);
...@@ -125,18 +135,13 @@ const RequestPage: React.FC = () => { ...@@ -125,18 +135,13 @@ const RequestPage: React.FC = () => {
<div className="filter"> <div className="filter">
<div className="fields"> <div className="fields">
<div className="dates"> <div className="dates">
<DatePicker <DatePicker.RangePicker
onChange={onSelectStartDate} onChange={onRangeChange}
format={dateFormat} defaultValue={[
defaultValue={startDate} dayjs(DEFAULT_DATES.startDate, DATE_FORMAT),
value={startDate} dayjs(DEFAULT_DATES.endDate, DATE_FORMAT),
style={{ marginRight: 14 }} ]}
/> value={dates}
<DatePicker
onChange={onSelectEndDate}
format={dateFormat}
defaultValue={endDate}
value={endDate}
/> />
</div> </div>
<div className="category"> <div className="category">
...@@ -173,16 +178,6 @@ const RequestPage: React.FC = () => { ...@@ -173,16 +178,6 @@ const RequestPage: React.FC = () => {
<div className="data"> <div className="data">
{table} {table}
</div> </div>
<div className="pagination_container">
<Pagination
current={currentPage}
defaultCurrent={1}
pageSize={REQ_NUMBER_PER_PAGE}
total={totalReqNumber}
onChange={handlePaginationChange}
hideOnSinglePage={true}
/>
</div>
</div> </div>
); );
}; };
......
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