mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
import React from 'react';
|
|
import { FinancialHeaderLoadingSkeleton } from '../FinancialHeaderLoadingSkeleton';
|
|
import { useItems } from 'hooks/query';
|
|
|
|
const InventoryValuationGeneralPanelContext = React.createContext();
|
|
|
|
function InventoryValuationGeneralPanelProvider({ query, ...props }) {
|
|
// Handle fetching the items based on the given query.
|
|
const {
|
|
data: { items },
|
|
isLoading: isItemsLoading,
|
|
isFetching: isItemsFetching,
|
|
} = useItems({
|
|
stringified_filter_roles: JSON.stringify([
|
|
{ fieldKey: 'type', comparator: 'is', value: 'inventory', index: 1 },
|
|
]),
|
|
page_size: 10000,
|
|
});
|
|
|
|
// Provider data.
|
|
const provider = {
|
|
items,
|
|
isItemsFetching,
|
|
isItemsLoading,
|
|
};
|
|
|
|
const loading = isItemsLoading;
|
|
|
|
return loading ? (
|
|
<FinancialHeaderLoadingSkeleton />
|
|
) : (
|
|
<InventoryValuationGeneralPanelContext.Provider
|
|
value={provider}
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const useInventoryValuationGeneralPanelContext = () =>
|
|
React.useContext(InventoryValuationGeneralPanelContext);
|
|
|
|
export {
|
|
InventoryValuationGeneralPanelProvider,
|
|
useInventoryValuationGeneralPanelContext,
|
|
};
|