Files
bigcapital/src/containers/Drawers/BillDrawer/BillDrawerProvider.js
2021-12-27 14:44:04 +02:00

46 lines
1.2 KiB
JavaScript

import React from 'react';
import intl from 'react-intl-universal';
import { DrawerHeaderContent, DrawerLoading } from 'components';
import { useBill, useBillLocatedLandedCost } from 'hooks/query';
const BillDrawerContext = React.createContext();
/**
* Bill drawer provider.
*/
function BillDrawerProvider({ billId, ...props }) {
// Handle fetch bill details.
const { isLoading: isBillLoading, data: bill } = useBill(billId, {
enabled: !!billId,
});
// Handle fetch bill located landed cost transaction.
const { isLoading: isLandedCostLoading, data: transactions } =
useBillLocatedLandedCost(billId, {
enabled: !!billId,
});
//provider.
const provider = {
billId,
transactions,
bill,
};
const loading = isLandedCostLoading || isBillLoading;
return (
<DrawerLoading loading={loading}>
<DrawerHeaderContent
name="bill-drawer"
title={intl.get('bill.details.drawer.title')}
/>
<BillDrawerContext.Provider value={provider} {...props} />
</DrawerLoading>
);
}
const useBillDrawerContext = () => React.useContext(BillDrawerContext);
export { BillDrawerProvider, useBillDrawerContext };