72 lines
2.3 KiB
JavaScript
72 lines
2.3 KiB
JavaScript
import { useQuery } from "@apollo/react-hooks";
|
|
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 { createStructuredSelector } from "reselect";
|
|
import AlertComponent from "../../components/alert/alert.component";
|
|
import PaymentsListPaginated from "../../components/payments-list-paginated/payment-list-paginated.component";
|
|
import RbacWrapper from "../../components/rbac-wrapper/rbac-wrapper.component";
|
|
import { QUERY_ALL_PAYMENTS_PAGINATED } from "../../graphql/payments.queries";
|
|
import { setBreadcrumbs } from "../../redux/application/application.actions";
|
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
bodyshop: selectBodyshop,
|
|
});
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
setBreadcrumbs: (breadcrumbs) => dispatch(setBreadcrumbs(breadcrumbs)),
|
|
});
|
|
|
|
export function AllJobs({ bodyshop, setBreadcrumbs }) {
|
|
const searchParams = queryString.parse(useLocation().search);
|
|
const { page, sortcolumn, sortorder, search } = searchParams;
|
|
|
|
const { loading, error, data, refetch } = useQuery(
|
|
QUERY_ALL_PAYMENTS_PAGINATED,
|
|
{
|
|
variables: {
|
|
search: search || "",
|
|
offset: page ? (page - 1) * 25 : 0,
|
|
limit: 25,
|
|
order: [
|
|
{
|
|
[sortcolumn || "created_at"]: sortorder
|
|
? sortorder === "descend"
|
|
? "desc"
|
|
: "asc"
|
|
: "desc",
|
|
},
|
|
],
|
|
},
|
|
}
|
|
);
|
|
const { t } = useTranslation();
|
|
|
|
useEffect(() => {
|
|
document.title = t("titles.payments-all");
|
|
setBreadcrumbs([
|
|
{ link: "/manage/payments", label: t("titles.bc.payments-all") },
|
|
]);
|
|
}, [t, setBreadcrumbs]);
|
|
|
|
if (error) return <AlertComponent message={error.message} type="error" />;
|
|
return (
|
|
<RbacWrapper action="payments:list">
|
|
<div>
|
|
<PaymentsListPaginated
|
|
refetch={refetch}
|
|
loading={loading}
|
|
searchParams={searchParams}
|
|
total={data ? data.search_payments_aggregate.aggregate.count : 0}
|
|
payments={data ? data.search_payments : []}
|
|
/>
|
|
</div>
|
|
</RbacWrapper>
|
|
);
|
|
}
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(AllJobs);
|