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,
useVendorCredit,
useCreateRefundVendorCredit,
} from 'hooks/query';
const RefundVendorCreditContext = React.createContext();
function RefundVendorCreditFormProvider({
vendorCreditId,
dialogName,
...props
}) {
// Handle fetch accounts data.
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();
// Handle fetch vendor credit details.
const { data: vendorCredit, isLoading: isVendorCreditLoading } =
useVendorCredit(vendorCreditId, {
enabled: !!vendorCreditId,
});
// Create refund vendor credit mutations.
const { mutateAsync: createRefundVendorCreditMutate } =
useCreateRefundVendorCredit();
// State provider.
const provider = {
vendorCredit: {
...pick(vendorCredit, ['id', 'formatted_amount', 'currency_code']),
amount: vendorCredit.formatted_amount,
},
accounts,
dialogName,
createRefundVendorCreditMutate,
};
return (
<DialogContent isLoading={isAccountsLoading || isVendorCreditLoading}>
<RefundVendorCreditContext.Provider value={provider} {...props} />
</DialogContent>
);
}
const useRefundVendorCreditContext = () =>
React.useContext(RefundVendorCreditContext);
export { RefundVendorCreditFormProvider, useRefundVendorCreditContext };