mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
import React from 'react';
|
|
import { useAccount, useAccountTransactions } from 'hooks/query';
|
|
import { DrawerHeaderContent, DashboardInsider } from 'components';
|
|
|
|
const AccountDrawerContext = React.createContext();
|
|
|
|
/**
|
|
* Account drawer provider.
|
|
*/
|
|
function AccountDrawerProvider({ accountId, name, ...props }) {
|
|
// Fetches the specific account details.
|
|
const { data: account, isLoading: isAccountLoading } = useAccount(accountId, {
|
|
enabled: !!accountId,
|
|
});
|
|
|
|
// Load the specific account transactions.
|
|
const {
|
|
data: accounts,
|
|
isLoading: isAccountsLoading,
|
|
} = useAccountTransactions(accountId, {
|
|
enabled: !!accountId,
|
|
});
|
|
const drawerTitle = `${account.name} ${account.code}`;
|
|
|
|
// provider.
|
|
const provider = {
|
|
accountId,
|
|
account,
|
|
accounts,
|
|
drawerName: name,
|
|
};
|
|
|
|
return (
|
|
<DashboardInsider loading={isAccountLoading || isAccountsLoading}>
|
|
<DrawerHeaderContent name={'account-drawer'} title={drawerTitle} />
|
|
<AccountDrawerContext.Provider value={provider} {...props} />
|
|
</DashboardInsider>
|
|
);
|
|
}
|
|
|
|
const useAccountDrawerContext = () => React.useContext(AccountDrawerContext);
|
|
|
|
export { AccountDrawerProvider, useAccountDrawerContext };
|