mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
import React, { createContext } from 'react';
|
|
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
|
import { useResourceViews, useResourceFields, usePaymentMades } from 'hooks/query';
|
|
|
|
const PaymentMadesContext = createContext();
|
|
|
|
/**
|
|
* Accounts chart data provider.
|
|
*/
|
|
function PaymentMadesProvider({ query, ...props }) {
|
|
// Fetch accounts resource views and fields.
|
|
const { data: paymentsViews, isFetching: isViewsLoading } = useResourceViews(
|
|
'bill_payments',
|
|
);
|
|
|
|
// Fetch the accounts resource fields.
|
|
const {
|
|
data: paymentsFields,
|
|
isFetching: isFieldsLoading,
|
|
} = useResourceFields('bill_payments');
|
|
|
|
// Fetch accounts list according to the given custom view id.
|
|
const {
|
|
data: { paymentMades, pagination },
|
|
isFetching: isPaymentsLoading,
|
|
} = usePaymentMades(query);
|
|
|
|
// Provider payload.
|
|
const provider = {
|
|
paymentMades,
|
|
pagination,
|
|
paymentsFields,
|
|
paymentsViews,
|
|
|
|
isPaymentsLoading,
|
|
isFieldsLoading,
|
|
isViewsLoading,
|
|
};
|
|
|
|
return (
|
|
<DashboardInsider
|
|
loading={isViewsLoading || isFieldsLoading}
|
|
name={'payment_made'}
|
|
>
|
|
<PaymentMadesContext.Provider value={provider} {...props} />
|
|
</DashboardInsider>
|
|
);
|
|
}
|
|
|
|
const usePaymentMadesContext = () => React.useContext(PaymentMadesContext);
|
|
|
|
export { PaymentMadesProvider, usePaymentMadesContext };
|