mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
refactoring: WIP payment receive and made form.
This commit is contained in:
@@ -6,7 +6,8 @@ import {
|
||||
usePaymentMade,
|
||||
useSettings,
|
||||
useCreatePaymentMade,
|
||||
useEditPaymentMade
|
||||
useEditPaymentMade,
|
||||
useDueBills,
|
||||
} from 'hooks/query';
|
||||
import { DashboardInsider } from 'components';
|
||||
|
||||
@@ -17,6 +18,9 @@ const PaymentMadeFormContext = createContext();
|
||||
* Payment made form provider.
|
||||
*/
|
||||
function PaymentMadeFormProvider({ paymentMadeId, ...props }) {
|
||||
const [submitPayload, setSubmitPayload] = React.useState({});
|
||||
const [paymentVendorId, setPaymentVendorId] = React.useState(null);
|
||||
|
||||
// Handle fetch accounts data.
|
||||
const { data: accounts, isFetching: isAccountsFetching } = useAccounts();
|
||||
|
||||
@@ -42,6 +46,13 @@ function PaymentMadeFormProvider({ paymentMadeId, ...props }) {
|
||||
enabled: !!paymentMadeId,
|
||||
});
|
||||
|
||||
// Retrieve the due bills of the given vendor.
|
||||
const {
|
||||
data: dueBills,
|
||||
isLoading: isDueBillsLoading,
|
||||
isFetching: isDueBillsFetching,
|
||||
} = useDueBills(paymentVendorId, { enabled: !!paymentVendorId });
|
||||
|
||||
// Fetch payment made settings.
|
||||
useSettings();
|
||||
|
||||
@@ -49,6 +60,8 @@ function PaymentMadeFormProvider({ paymentMadeId, ...props }) {
|
||||
const { mutateAsync: createPaymentMadeMutate } = useCreatePaymentMade();
|
||||
const { mutateAsync: editPaymentMadeMutate } = useEditPaymentMade();
|
||||
|
||||
const isNewMode = !paymentMadeId;
|
||||
|
||||
// Provider payload.
|
||||
const provider = {
|
||||
paymentMadeId,
|
||||
@@ -58,16 +71,25 @@ function PaymentMadeFormProvider({ paymentMadeId, ...props }) {
|
||||
paymentBills,
|
||||
vendors,
|
||||
items,
|
||||
dueBills,
|
||||
submitPayload,
|
||||
paymentVendorId,
|
||||
|
||||
isNewMode,
|
||||
isAccountsFetching,
|
||||
isItemsFetching,
|
||||
isItemsLoading,
|
||||
isVendorsFetching,
|
||||
isPaymentFetching,
|
||||
isPaymentLoading,
|
||||
isDueBillsLoading,
|
||||
isDueBillsFetching,
|
||||
|
||||
createPaymentMadeMutate,
|
||||
editPaymentMadeMutate,
|
||||
|
||||
setSubmitPayload,
|
||||
setPaymentVendorId,
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user