mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
refactoring(invoice drawer): invoice drawer.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import React, { createContext, useContext } from 'react';
|
||||
import { useInvoice } from 'hooks/query';
|
||||
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||
|
||||
const InvoiceDrawerContext = createContext();
|
||||
|
||||
/**
|
||||
* Invoice drawer provider.
|
||||
*/
|
||||
function InvoiceDrawerProvider({ invoiceId, ...props }) {
|
||||
// Fetch sale invoice details.
|
||||
const {
|
||||
data: { entries, ...invoice },
|
||||
isLoading: isInvoiceLoading,
|
||||
} = useInvoice(invoiceId, {
|
||||
enabled: !!invoiceId,
|
||||
});
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
invoiceId,
|
||||
invoice,
|
||||
entries,
|
||||
|
||||
isInvoiceLoading,
|
||||
};
|
||||
|
||||
return (
|
||||
<DashboardInsider loading={isInvoiceLoading}>
|
||||
<InvoiceDrawerContext.Provider value={provider} {...props} />
|
||||
</DashboardInsider>
|
||||
);
|
||||
}
|
||||
const useInvoiceDrawerContext = () => useContext(InvoiceDrawerContext);
|
||||
|
||||
export { InvoiceDrawerProvider, useInvoiceDrawerContext };
|
||||
Reference in New Issue
Block a user