mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
feat: add refund credit & vendor dialogs.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import React from 'react';
|
||||
import { DialogContent } from 'components';
|
||||
import { pick } from 'lodash';
|
||||
|
||||
import {
|
||||
useAccounts,
|
||||
useCreditNote,
|
||||
useCreateRefundCreditNote,
|
||||
} from 'hooks/query';
|
||||
|
||||
const RefundCreditNoteContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Refund credit note form provider.
|
||||
*/
|
||||
function RefundCreditNoteFormProvider({ creditNoteId, dialogName, ...props }) {
|
||||
// Handle fetch accounts data.
|
||||
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();
|
||||
|
||||
// Handle fetch credit note data.
|
||||
const { data: creditNote, isLoading: isCreditNoteLoading } = useCreditNote(
|
||||
creditNoteId,
|
||||
{
|
||||
enabled: !!creditNoteId,
|
||||
},
|
||||
);
|
||||
// Create and edit credit note mutations.
|
||||
const { mutateAsync: createRefundCreditNoteMutate } =
|
||||
useCreateRefundCreditNote();
|
||||
|
||||
// State provider.
|
||||
const provider = {
|
||||
creditNote: {
|
||||
...pick(creditNote, ['id', 'formatted_amount', 'currency_code']),
|
||||
amount: creditNote.formatted_amount,
|
||||
},
|
||||
accounts,
|
||||
dialogName,
|
||||
createRefundCreditNoteMutate,
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent isLoading={isAccountsLoading || isCreditNoteLoading}>
|
||||
<RefundCreditNoteContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
const useRefundCreditNoteContext = () =>
|
||||
React.useContext(RefundCreditNoteContext);
|
||||
|
||||
export { RefundCreditNoteFormProvider, useRefundCreditNoteContext };
|
||||
Reference in New Issue
Block a user