mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 04:10:32 +00:00
40 lines
1010 B
JavaScript
40 lines
1010 B
JavaScript
import React from 'react';
|
|
import { DrawerHeaderContent, DrawerLoading } from 'components';
|
|
import { useCustomer } from 'hooks/query';
|
|
|
|
const ContactDetailDrawerContext = React.createContext();
|
|
|
|
/**
|
|
* Contact detail provider.
|
|
*/
|
|
function CustomerDetailsDrawerProvider({ customerId, ...props }) {
|
|
// Handle fetch customer details.
|
|
const { data: customer, isLoading: isCustomerLoading } = useCustomer(
|
|
customerId,
|
|
{
|
|
enabled: !!customerId,
|
|
},
|
|
);
|
|
// Provider.
|
|
const provider = {
|
|
customer,
|
|
customerId,
|
|
isCustomerLoading,
|
|
};
|
|
|
|
return (
|
|
<DrawerLoading loading={isCustomerLoading}>
|
|
<DrawerHeaderContent
|
|
name="customer-details-drawer"
|
|
title={customer?.display_name}
|
|
/>
|
|
<ContactDetailDrawerContext.Provider value={provider} {...props} />
|
|
</DrawerLoading>
|
|
);
|
|
}
|
|
|
|
const useCustomerDetailsDrawerContext = () =>
|
|
React.useContext(ContactDetailDrawerContext);
|
|
|
|
export { CustomerDetailsDrawerProvider, useCustomerDetailsDrawerContext };
|