mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
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 };
|