mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
refactoring(accountant): accountant.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import React from 'react';
|
||||
import { LoadingIndicator } from 'components';
|
||||
import { useAccounts, useSaveSettings, useSettings } from 'hooks/query';
|
||||
|
||||
const AccountantFormContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Accountant data provider.
|
||||
*/
|
||||
function AccountantFormProvider({ ...props }) {
|
||||
// Fetches the accounts list.
|
||||
const { isFetching: isAccountsLoading, data: accounts } = useAccounts();
|
||||
|
||||
//Fetches Organization Settings.
|
||||
const { isFetching: isSettingsLoading } = useSettings();
|
||||
|
||||
// Save Organization Settings.
|
||||
const { mutateAsync: saveSettingMutate } = useSaveSettings();
|
||||
|
||||
// Provider state.
|
||||
const provider = {
|
||||
accounts,
|
||||
isAccountsLoading,
|
||||
saveSettingMutate,
|
||||
};
|
||||
|
||||
return (
|
||||
<LoadingIndicator loading={isSettingsLoading || isAccountsLoading}>
|
||||
<AccountantFormContext.Provider value={provider} {...props} />
|
||||
</LoadingIndicator>
|
||||
);
|
||||
}
|
||||
|
||||
const useAccountantFormContext = () => React.useContext(AccountantFormContext);
|
||||
export { AccountantFormProvider, useAccountantFormContext };
|
||||
Reference in New Issue
Block a user