mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
feat: Bad Debt.
This commit is contained in:
46
src/containers/Dialogs/BadDebtDialog/BadDebtFormProvider.js
Normal file
46
src/containers/Dialogs/BadDebtDialog/BadDebtFormProvider.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import React from 'react';
|
||||
|
||||
import { DialogContent } from 'components';
|
||||
import {
|
||||
useAccounts,
|
||||
useInvoice,
|
||||
useCreateBadDebt,
|
||||
useCancelBadDebt,
|
||||
} from 'hooks/query';
|
||||
|
||||
const BadDebtContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Bad debt provider.
|
||||
*/
|
||||
function BadDebtFormProvider({ invoiceId, dialogName, ...props }) {
|
||||
// Handle fetch accounts data.
|
||||
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();
|
||||
|
||||
// Handle fetch invoice data.
|
||||
const { data: invoice, isLoading: isInvoiceLoading } = useInvoice(invoiceId, {
|
||||
enabled: !!invoiceId,
|
||||
});
|
||||
|
||||
// Create and cancel bad debt mutations.
|
||||
const { mutateAsync: createBadDebtMutate } = useCreateBadDebt();
|
||||
|
||||
// State provider.
|
||||
const provider = {
|
||||
accounts,
|
||||
invoice,
|
||||
invoiceId,
|
||||
dialogName,
|
||||
createBadDebtMutate,
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent isLoading={isAccountsLoading || isInvoiceLoading}>
|
||||
<BadDebtContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
const useBadDebtContext = () => React.useContext(BadDebtContext);
|
||||
|
||||
export { BadDebtFormProvider, useBadDebtContext };
|
||||
Reference in New Issue
Block a user