refactoring(invoice drawer): invoice drawer.

This commit is contained in:
elforjani3
2021-03-06 20:29:32 +02:00
parent fe5fc80ecb
commit 252f3b4617
6 changed files with 109 additions and 21 deletions

View File

@@ -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 };