mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
65 lines
1.6 KiB
JavaScript
65 lines
1.6 KiB
JavaScript
import React from 'react';
|
|
import { DialogContent } from 'components';
|
|
import {
|
|
useCreditNote,
|
|
useReconcileCreditNote,
|
|
useCreateReconcileCreditNote,
|
|
} from 'hooks/query';
|
|
import { isEmpty } from 'lodash';
|
|
|
|
const ReconcileCreditNoteDialogContext = React.createContext();
|
|
|
|
/**
|
|
* Reconcile credit note provider.
|
|
*/
|
|
function ReconcileCreditNoteFormProvider({
|
|
creditNoteId,
|
|
dialogName,
|
|
...props
|
|
}) {
|
|
// Handle fetch reconcile credit note details.
|
|
const { isLoading: isReconcileCreditLoading, data: reconcileCreditNotes } =
|
|
useReconcileCreditNote(creditNoteId, {
|
|
enabled: !!creditNoteId,
|
|
});
|
|
|
|
// Handle fetch vendor credit details.
|
|
const { data: creditNote, isLoading: isCreditNoteLoading } = useCreditNote(
|
|
creditNoteId,
|
|
{
|
|
enabled: !!creditNoteId,
|
|
},
|
|
);
|
|
|
|
// Create reconcile credit note mutations.
|
|
const { mutateAsync: createReconcileCreditNoteMutate } =
|
|
useCreateReconcileCreditNote();
|
|
|
|
// Detarmines the datatable empty status.
|
|
const isEmptyStatus = isEmpty(reconcileCreditNotes);
|
|
|
|
// provider payload.
|
|
const provider = {
|
|
dialogName,
|
|
reconcileCreditNotes,
|
|
createReconcileCreditNoteMutate,
|
|
isEmptyStatus,
|
|
creditNote,
|
|
creditNoteId,
|
|
};
|
|
|
|
return (
|
|
<DialogContent
|
|
isLoading={isReconcileCreditLoading || isCreditNoteLoading}
|
|
name={'reconcile-credit-note'}
|
|
>
|
|
<ReconcileCreditNoteDialogContext.Provider value={provider} {...props} />
|
|
</DialogContent>
|
|
);
|
|
}
|
|
|
|
const useReconcileCreditNoteContext = () =>
|
|
React.useContext(ReconcileCreditNoteDialogContext);
|
|
|
|
export { ReconcileCreditNoteFormProvider, useReconcileCreditNoteContext };
|