- {/* ------------- Refund date ------------- */}
-
- {({ form, field: { value }, meta: { error, touched } }) => (
- }
- labelInfo={}
- className={classNames('form-group--select-list', CLASSES.FILL)}
- intent={inputIntent({ error, touched })}
- helperText={}
- >
- {
- form.setFieldValue('refund_date', formattedDate);
- })}
- popoverProps={{ position: Position.BOTTOM, minimal: true }}
- inputProps={{
- leftIcon: ,
- }}
- />
-
- )}
-
+
+
+
+ }
+ className={classNames('form-group--select-list', Classes.FILL)}
+ >
+
+
+
+
+
+
+
+
+ {/* ------------- Refund date ------------- */}
+
+ {({ form, field: { value }, meta: { error, touched } }) => (
+ }
+ labelInfo={}
+ className={classNames('form-group--select-list', CLASSES.FILL)}
+ intent={inputIntent({ error, touched })}
+ helperText={}
+ >
+ {
+ form.setFieldValue('refund_date', formattedDate);
+ })}
+ popoverProps={{ position: Position.BOTTOM, minimal: true }}
+ inputProps={{
+ leftIcon: ,
+ }}
+ />
+
+ )}
+
+
+
+
+ {/* ------------ Form account ------------ */}
+
+ {({ form, field: { value }, meta: { error, touched } }) => (
+
+ }
+ className={classNames(
+ 'form-group--deposit_account_id',
+ 'form-group--select-list',
+ CLASSES.FILL,
+ )}
+ labelInfo={}
+ intent={inputIntent({ error, touched })}
+ helperText={}
+ >
+
+ form.setFieldValue('deposit_account_id', id)
+ }
+ inputProps={{
+ placeholder: intl.get('select_account'),
+ }}
+ filterByTypes={[
+ ACCOUNT_TYPE.BANK,
+ ACCOUNT_TYPE.CASH,
+ ACCOUNT_TYPE.FIXED_ASSET,
+ ]}
+ />
+
+ )}
+
+
+
+
{/* ------------- Amount ------------- */}
{({
@@ -93,6 +173,19 @@ function RefundVendorCreditFormFields() {
)}
+
+
+ {/*------------ exchange rate -----------*/}
+
+
+
{/* ------------ Reference No. ------------ */}
{({ form, field, meta: { error, touched } }) => (
@@ -111,38 +204,6 @@ function RefundVendorCreditFormFields() {
)}
- {/* ------------ Form account ------------ */}
-
- {({ form, field: { value }, meta: { error, touched } }) => (
- }
- className={classNames(
- 'form-group--deposit_account_id',
- 'form-group--select-list',
- CLASSES.FILL,
- )}
- labelInfo={}
- intent={inputIntent({ error, touched })}
- helperText={}
- >
-
- form.setFieldValue('deposit_account_id', id)
- }
- inputProps={{
- placeholder: intl.get('select_account'),
- }}
- filterByTypes={[
- ACCOUNT_TYPE.BANK,
- ACCOUNT_TYPE.CASH,
- ACCOUNT_TYPE.FIXED_ASSET,
- ]}
- />
-
- )}
-
{/* --------- Statement --------- */}
{({ form, field, meta: { error, touched } }) => (
@@ -158,4 +219,10 @@ function RefundVendorCreditFormFields() {
);
}
-export default RefundVendorCreditFormFields;
+export default compose(withCurrentOrganization())(RefundVendorCreditFormFields);
+
+export const BranchRowDivider = styled.div`
+ height: 1px;
+ background: #ebf1f6;
+ margin-bottom: 13px;
+`;
diff --git a/src/containers/Dialogs/RefundVendorCreditDialog/RefundVendorCreditFormProvider.js b/src/containers/Dialogs/RefundVendorCreditDialog/RefundVendorCreditFormProvider.js
index 0f97aa814..c01e41565 100644
--- a/src/containers/Dialogs/RefundVendorCreditDialog/RefundVendorCreditFormProvider.js
+++ b/src/containers/Dialogs/RefundVendorCreditDialog/RefundVendorCreditFormProvider.js
@@ -5,6 +5,7 @@ import { pick } from 'lodash';
import {
useAccounts,
useVendorCredit,
+ useBranches,
useCreateRefundVendorCredit,
} from 'hooks/query';
@@ -18,6 +19,13 @@ function RefundVendorCreditFormProvider({
// Handle fetch accounts data.
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();
+ // Fetches the branches list.
+ const {
+ data: branches,
+ isLoading: isBranchesLoading,
+ isSuccess: isBranchesSuccess,
+ } = useBranches();
+
// Handle fetch vendor credit details.
const { data: vendorCredit, isLoading: isVendorCreditLoading } =
useVendorCredit(vendorCreditId, {
@@ -35,12 +43,18 @@ function RefundVendorCreditFormProvider({
amount: vendorCredit.credits_remaining,
},
accounts,
+ branches,
dialogName,
+ isBranchesSuccess,
createRefundVendorCreditMutate,
};
return (
-
+
);
diff --git a/src/containers/Dialogs/RefundVendorCreditDialog/utils.js b/src/containers/Dialogs/RefundVendorCreditDialog/utils.js
new file mode 100644
index 000000000..f2933a3a2
--- /dev/null
+++ b/src/containers/Dialogs/RefundVendorCreditDialog/utils.js
@@ -0,0 +1,20 @@
+import React from 'react';
+import { useFormikContext } from 'formik';
+import { first } from 'lodash';
+
+import { useRefundVendorCreditContext } from './RefundVendorCreditFormProvider';
+
+export const useSetPrimaryBranchToForm = () => {
+ const { setFieldValue } = useFormikContext();
+ const { branches, isBranchesSuccess } = useRefundVendorCreditContext();
+
+ React.useEffect(() => {
+ if (isBranchesSuccess) {
+ const primaryBranch = branches.find((b) => b.primary) || first(branches);
+
+ if (primaryBranch) {
+ setFieldValue('branch_id', primaryBranch.id);
+ }
+ }
+ }, [isBranchesSuccess, setFieldValue, branches]);
+};