IO-899 Refactor ccc paginated query
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
import { useQuery } from "@apollo/client";
|
||||
import queryString from "query-string";
|
||||
import React, { useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { useLocation } from "react-router-dom";
|
||||
import AlertComponent from "../../components/alert/alert.component";
|
||||
import RbacWrapper from "../../components/rbac-wrapper/rbac-wrapper.component";
|
||||
import { QUERY_ACTIVE_CONTRACTS_PAGINATED } from "../../graphql/cccontracts.queries";
|
||||
import {
|
||||
setBreadcrumbs,
|
||||
setSelectedHeader,
|
||||
} from "../../redux/application/application.actions";
|
||||
import ContractsPageComponent from "./contracts.page.component";
|
||||
import queryString from "query-string";
|
||||
import { useLocation } from "react-router-dom";
|
||||
import moment from "moment";
|
||||
import RbacWrapper from "../../components/rbac-wrapper/rbac-wrapper.component";
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
setBreadcrumbs: (breadcrumbs) => dispatch(setBreadcrumbs(breadcrumbs)),
|
||||
@@ -21,17 +20,13 @@ const mapDispatchToProps = (dispatch) => ({
|
||||
|
||||
export function ContractsPageContainer({ setBreadcrumbs, setSelectedHeader }) {
|
||||
const searchParams = queryString.parse(useLocation().search);
|
||||
const { page, sortcolumn, sortorder, start, end } = searchParams;
|
||||
const { search, page, sortcolumn, sortorder } = searchParams;
|
||||
|
||||
const { loading, error, data, refetch } = useQuery(
|
||||
QUERY_ACTIVE_CONTRACTS_PAGINATED,
|
||||
{
|
||||
variables: {
|
||||
//search: search || "",
|
||||
start: start
|
||||
? moment(start)
|
||||
: moment().startOf("week").subtract(7, "days"),
|
||||
end: end ? moment(end) : moment().endOf("week"),
|
||||
search: search || "",
|
||||
offset: page ? (page - 1) * 25 : 0,
|
||||
limit: 25,
|
||||
order: [
|
||||
@@ -62,14 +57,12 @@ export function ContractsPageContainer({ setBreadcrumbs, setSelectedHeader }) {
|
||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||
return (
|
||||
<RbacWrapper action="contracts:list">
|
||||
<div>
|
||||
<ContractsPageComponent
|
||||
loading={loading}
|
||||
refetch={refetch}
|
||||
data={data ? data.cccontracts : []}
|
||||
total={data ? data.cccontracts_aggregate.aggregate.count : 0}
|
||||
/>
|
||||
</div>
|
||||
<ContractsPageComponent
|
||||
loading={loading}
|
||||
refetch={refetch}
|
||||
data={data ? data.search_cccontracts : []}
|
||||
total={data ? data.search_cccontracts_aggregate.aggregate.count : 0}
|
||||
/>
|
||||
</RbacWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user