@@ -1,45 +1,45 @@
|
||||
import React from "react";
|
||||
import VehiclesListComponent from "./vehicles-list.component";
|
||||
import { useQuery } from "@apollo/client";
|
||||
import {useQuery} from "@apollo/client";
|
||||
import AlertComponent from "../alert/alert.component";
|
||||
import { QUERY_ALL_VEHICLES_PAGINATED } from "../../graphql/vehicles.queries";
|
||||
import {QUERY_ALL_VEHICLES_PAGINATED} from "../../graphql/vehicles.queries";
|
||||
import queryString from "query-string";
|
||||
import { useLocation } from "react-router-dom";
|
||||
import {useLocation} from "react-router-dom";
|
||||
import {pageLimit} from "../../utils/config";
|
||||
|
||||
export default function VehiclesListContainer() {
|
||||
const searchParams = queryString.parse(useLocation().search);
|
||||
const { page, sortcolumn, sortorder, search } = searchParams;
|
||||
const searchParams = queryString.parse(useLocation().search);
|
||||
const {page, sortcolumn, sortorder, search} = searchParams;
|
||||
|
||||
const { loading, error, data, refetch } = useQuery(
|
||||
QUERY_ALL_VEHICLES_PAGINATED,
|
||||
{
|
||||
variables: {
|
||||
search: search || "",
|
||||
offset: page ? (page - 1) * pageLimit : 0,
|
||||
limit: pageLimit,
|
||||
order: [
|
||||
{
|
||||
[sortcolumn || "created_at"]: sortorder
|
||||
? sortorder === "descend"
|
||||
? "desc"
|
||||
: "asc"
|
||||
: "desc",
|
||||
},
|
||||
],
|
||||
},
|
||||
fetchPolicy: "network-only",
|
||||
nextFetchPolicy: "network-only",
|
||||
}
|
||||
);
|
||||
const {loading, error, data, refetch} = useQuery(
|
||||
QUERY_ALL_VEHICLES_PAGINATED,
|
||||
{
|
||||
variables: {
|
||||
search: search || "",
|
||||
offset: page ? (page - 1) * pageLimit : 0,
|
||||
limit: pageLimit,
|
||||
order: [
|
||||
{
|
||||
[sortcolumn || "created_at"]: sortorder
|
||||
? sortorder === "descend"
|
||||
? "desc"
|
||||
: "asc"
|
||||
: "desc",
|
||||
},
|
||||
],
|
||||
},
|
||||
fetchPolicy: "network-only",
|
||||
nextFetchPolicy: "network-only",
|
||||
}
|
||||
);
|
||||
|
||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||
return (
|
||||
<VehiclesListComponent
|
||||
loading={loading}
|
||||
vehicles={data ? data.search_vehicles : null}
|
||||
total={data ? data.search_vehicles_aggregate.aggregate.count : 0}
|
||||
refetch={refetch}
|
||||
/>
|
||||
);
|
||||
if (error) return <AlertComponent message={error.message} type="error"/>;
|
||||
return (
|
||||
<VehiclesListComponent
|
||||
loading={loading}
|
||||
vehicles={data ? data.search_vehicles : null}
|
||||
total={data ? data.search_vehicles_aggregate.aggregate.count : 0}
|
||||
refetch={refetch}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user