mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
22 lines
658 B
TypeScript
22 lines
658 B
TypeScript
// @ts-nocheck
|
|
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]);
|
|
};
|