feat: add refund credit & vendor dialogs.

This commit is contained in:
elforjani13
2021-12-05 19:29:39 +02:00
parent bf99bda616
commit ab48e6092a
20 changed files with 905 additions and 0 deletions

View File

@@ -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 };