refactoring: WIP payment receive and made form.

This commit is contained in:
a.bouhuolia
2021-02-16 14:03:43 +02:00
parent f6456db592
commit a75177b9d1
47 changed files with 1331 additions and 1723 deletions

View File

@@ -0,0 +1,91 @@
import React, { createContext, useContext } from 'react';
import {
useAccounts,
useVendors,
useItems,
usePaymentMade,
useSettings,
useCreatePaymentMade,
useEditPaymentMade
} from 'hooks/query';
import { DashboardInsider } from 'components';
// Payment made form context.
const PaymentMadeFormContext = createContext();
/**
* Payment made form provider.
*/
function PaymentMadeFormProvider({ paymentMadeId, ...props }) {
// Handle fetch accounts data.
const { data: accounts, isFetching: isAccountsFetching } = useAccounts();
// Handle fetch Items data table or list.
const {
data: { items },
isFetching: isItemsFetching,
isLoading: isItemsLoading,
} = useItems();
// Handle fetch venders data table or list.
const {
data: { vendors },
isFetching: isVendorsFetching,
} = useVendors();
// Handle fetch specific payment made details.
const {
data: { paymentMade, payableBills, paymentBills },
isFetching: isPaymentFetching,
isLoading: isPaymentLoading,
} = usePaymentMade(paymentMadeId, {
enabled: !!paymentMadeId,
});
// Fetch payment made settings.
useSettings();
// Create and edit payment made mutations.
const { mutateAsync: createPaymentMadeMutate } = useCreatePaymentMade();
const { mutateAsync: editPaymentMadeMutate } = useEditPaymentMade();
// Provider payload.
const provider = {
paymentMadeId,
accounts,
paymentMade,
payableBills,
paymentBills,
vendors,
items,
isAccountsFetching,
isItemsFetching,
isItemsLoading,
isVendorsFetching,
isPaymentFetching,
isPaymentLoading,
createPaymentMadeMutate,
editPaymentMadeMutate,
};
return (
<DashboardInsider
loading={
isVendorsFetching ||
isItemsFetching ||
isAccountsFetching ||
isPaymentFetching ||
isPaymentLoading
}
name={'payment-made'}
>
<PaymentMadeFormContext.Provider value={provider} {...props} />
</DashboardInsider>
);
}
const usePaymentMadeFormContext = () => useContext(PaymentMadeFormContext);
export { PaymentMadeFormProvider, usePaymentMadeFormContext };