mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
chrone: sperate client and server to different repos.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import React, { createContext } from 'react';
|
||||
import { DialogContent } from 'components';
|
||||
import {
|
||||
useItemCategory,
|
||||
useEditItemCategory,
|
||||
useCreateItemCategory,
|
||||
} from 'hooks/query';
|
||||
|
||||
const ItemCategoryContext = createContext();
|
||||
|
||||
/**
|
||||
* Accounts chart data provider.
|
||||
*/
|
||||
function ItemCategoryProvider({ itemCategoryId, dialogName, ...props }) {
|
||||
const { data: itemCategory, isFetching: isItemCategoryLoading } = useItemCategory(
|
||||
itemCategoryId,
|
||||
{
|
||||
enabled: !!itemCategoryId,
|
||||
},
|
||||
);
|
||||
// Create and edit item category mutations.
|
||||
const { mutateAsync: createItemCategoryMutate } = useCreateItemCategory();
|
||||
const { mutateAsync: editItemCategoryMutate } = useEditItemCategory();
|
||||
|
||||
// Detarmines whether the new mode form.
|
||||
const isNewMode = !itemCategoryId;
|
||||
const isEditMode = !isNewMode;
|
||||
|
||||
// Provider state.
|
||||
const provider = {
|
||||
itemCategoryId,
|
||||
dialogName,
|
||||
|
||||
itemCategory,
|
||||
isItemCategoryLoading,
|
||||
|
||||
createItemCategoryMutate,
|
||||
editItemCategoryMutate,
|
||||
|
||||
isNewMode,
|
||||
isEditMode
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent
|
||||
isLoading={isItemCategoryLoading}
|
||||
name={'item-category-form'}
|
||||
>
|
||||
<ItemCategoryContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
const useItemCategoryContext = () =>
|
||||
React.useContext(ItemCategoryContext);
|
||||
|
||||
export { ItemCategoryProvider, useItemCategoryContext };
|
||||
Reference in New Issue
Block a user