mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 07:40:32 +00:00
feat(OwnerContributionForm): add branch select.
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
|||||||
useCreateCashflowTransaction,
|
useCreateCashflowTransaction,
|
||||||
useAccount,
|
useAccount,
|
||||||
useAccounts,
|
useAccounts,
|
||||||
|
useBranches,
|
||||||
useCashflowAccounts,
|
useCashflowAccounts,
|
||||||
useSettingCashFlow,
|
useSettingCashFlow,
|
||||||
} from 'hooks/query';
|
} from 'hooks/query';
|
||||||
@@ -28,6 +29,13 @@ function MoneyInDialogProvider({
|
|||||||
enabled: !!accountId,
|
enabled: !!accountId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Fetches the branches list.
|
||||||
|
const {
|
||||||
|
data: branches,
|
||||||
|
isLoading: isBranchesLoading,
|
||||||
|
isSuccess: isBranchesSuccess,
|
||||||
|
} = useBranches();
|
||||||
|
|
||||||
// Fetch cash flow list .
|
// Fetch cash flow list .
|
||||||
const { data: cashflowAccounts, isLoading: isCashFlowAccountsLoading } =
|
const { data: cashflowAccounts, isLoading: isCashFlowAccountsLoading } =
|
||||||
useCashflowAccounts({}, { keepPreviousData: true });
|
useCashflowAccounts({}, { keepPreviousData: true });
|
||||||
@@ -49,9 +57,11 @@ function MoneyInDialogProvider({
|
|||||||
const provider = {
|
const provider = {
|
||||||
accounts,
|
accounts,
|
||||||
account,
|
account,
|
||||||
|
branches,
|
||||||
accountId,
|
accountId,
|
||||||
accountType,
|
accountType,
|
||||||
isAccountsLoading,
|
isAccountsLoading,
|
||||||
|
isBranchesSuccess,
|
||||||
|
|
||||||
cashflowAccounts,
|
cashflowAccounts,
|
||||||
|
|
||||||
@@ -66,7 +76,10 @@ function MoneyInDialogProvider({
|
|||||||
return (
|
return (
|
||||||
<DialogContent
|
<DialogContent
|
||||||
isLoading={
|
isLoading={
|
||||||
isAccountsLoading || isCashFlowAccountsLoading || isSettingsLoading
|
isAccountsLoading ||
|
||||||
|
isCashFlowAccountsLoading ||
|
||||||
|
isBranchesLoading ||
|
||||||
|
isSettingsLoading
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<MoneyInDialogContent.Provider value={provider} {...props} />
|
<MoneyInDialogContent.Provider value={provider} {...props} />
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ const defaultInitialValues = {
|
|||||||
credit_account_id: '',
|
credit_account_id: '',
|
||||||
currency_code: '',
|
currency_code: '',
|
||||||
description: '',
|
description: '',
|
||||||
|
branch_id: '',
|
||||||
publish: '',
|
publish: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const Schema = Yup.object().shape({
|
|||||||
reference_no: Yup.string(),
|
reference_no: Yup.string(),
|
||||||
credit_account_id: Yup.number().required(),
|
credit_account_id: Yup.number().required(),
|
||||||
cashflow_account_id: Yup.string().required(),
|
cashflow_account_id: Yup.string().required(),
|
||||||
|
branch_id: Yup.string(),
|
||||||
description: Yup.string()
|
description: Yup.string()
|
||||||
.min(3)
|
.min(3)
|
||||||
.max(DATATYPES_LENGTH.TEXT)
|
.max(DATATYPES_LENGTH.TEXT)
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ import {
|
|||||||
TextArea,
|
TextArea,
|
||||||
Position,
|
Position,
|
||||||
ControlGroup,
|
ControlGroup,
|
||||||
|
Button,
|
||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
|
import styled from 'styled-components';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import {
|
import {
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
@@ -21,6 +23,8 @@ import {
|
|||||||
If,
|
If,
|
||||||
InputPrependButton,
|
InputPrependButton,
|
||||||
ExchangeRateInputGroup,
|
ExchangeRateInputGroup,
|
||||||
|
BranchSelect,
|
||||||
|
FeatureCan,
|
||||||
} from 'components';
|
} from 'components';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { useAutofocus } from 'hooks';
|
import { useAutofocus } from 'hooks';
|
||||||
@@ -32,9 +36,13 @@ import {
|
|||||||
handleDateChange,
|
handleDateChange,
|
||||||
compose,
|
compose,
|
||||||
} from 'utils';
|
} from 'utils';
|
||||||
|
import { Features } from 'common';
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
|
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
|
||||||
import { useObserveTransactionNoSettings } from '../utils';
|
import {
|
||||||
|
useObserveTransactionNoSettings,
|
||||||
|
useSetPrimaryBranchToForm,
|
||||||
|
} from '../utils';
|
||||||
import withSettings from 'containers/Settings/withSettings';
|
import withSettings from 'containers/Settings/withSettings';
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
|
|
||||||
@@ -52,7 +60,8 @@ function OwnerContributionFormFields({
|
|||||||
transactionNextNumber,
|
transactionNextNumber,
|
||||||
}) {
|
}) {
|
||||||
// Money in dialog context.
|
// Money in dialog context.
|
||||||
const { accounts, account, isForeignCurrency } = useMoneyInDailogContext();
|
const { accounts, account, branches, isForeignCurrency } =
|
||||||
|
useMoneyInDailogContext();
|
||||||
|
|
||||||
const { values } = useFormikContext();
|
const { values } = useFormikContext();
|
||||||
|
|
||||||
@@ -83,8 +92,28 @@ function OwnerContributionFormFields({
|
|||||||
transactionNextNumber,
|
transactionNextNumber,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Sets the primary branch to form.
|
||||||
|
useSetPrimaryBranchToForm();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
<FeatureCan feature={Features.Branches}>
|
||||||
|
<BranchFieldsRow>
|
||||||
|
<Col xs={5}>
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'branch'} />}
|
||||||
|
className={classNames('form-group--select-list', Classes.FILL)}
|
||||||
|
>
|
||||||
|
<BranchSelect
|
||||||
|
name={'branch_id'}
|
||||||
|
branches={branches}
|
||||||
|
input={BranchSelectButton}
|
||||||
|
popoverProps={{ minimal: true }}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
</Col>
|
||||||
|
</BranchFieldsRow>
|
||||||
|
</FeatureCan>
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Date -----------*/}
|
{/*------------ Date -----------*/}
|
||||||
@@ -184,7 +213,6 @@ function OwnerContributionFormFields({
|
|||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
</Field>
|
</Field>
|
||||||
|
|
||||||
{/*------------ exchange rate -----------*/}
|
{/*------------ exchange rate -----------*/}
|
||||||
{/* <If
|
{/* <If
|
||||||
condition={isForeignCurrency(
|
condition={isForeignCurrency(
|
||||||
@@ -199,7 +227,6 @@ function OwnerContributionFormFields({
|
|||||||
formGroupProps={{ label: ' ', inline: false }}
|
formGroupProps={{ label: ' ', inline: false }}
|
||||||
/>
|
/>
|
||||||
{/* </If> */}
|
{/* </If> */}
|
||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ equity account -----------*/}
|
{/*------------ equity account -----------*/}
|
||||||
@@ -246,7 +273,6 @@ function OwnerContributionFormFields({
|
|||||||
</FastField>
|
</FastField>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
{/*------------ description -----------*/}
|
{/*------------ description -----------*/}
|
||||||
<FastField name={'description'}>
|
<FastField name={'description'}>
|
||||||
{({ field, meta: { error, touched } }) => (
|
{({ field, meta: { error, touched } }) => (
|
||||||
@@ -277,3 +303,12 @@ export default compose(
|
|||||||
transactionNumberPrefix: cashflowSetting?.numberPrefix,
|
transactionNumberPrefix: cashflowSetting?.numberPrefix,
|
||||||
})),
|
})),
|
||||||
)(OwnerContributionFormFields);
|
)(OwnerContributionFormFields);
|
||||||
|
|
||||||
|
function BranchSelectButton({ label }) {
|
||||||
|
return <Button text={label} minimal={false} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const BranchFieldsRow = styled(Row)`
|
||||||
|
margin-bottom: 10px;
|
||||||
|
border-bottom: 1px solid #e9e9e9;
|
||||||
|
`;
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useFormikContext } from 'formik';
|
import { useFormikContext } from 'formik';
|
||||||
import { transactionNumber } from 'utils';
|
import { transactionNumber } from 'utils';
|
||||||
|
import { sumBy, setWith, toSafeInteger, get, first } from 'lodash';
|
||||||
|
|
||||||
|
import { useMoneyInDailogContext } from './MoneyInDialogProvider';
|
||||||
|
|
||||||
export const useObserveTransactionNoSettings = (prefix, nextNumber) => {
|
export const useObserveTransactionNoSettings = (prefix, nextNumber) => {
|
||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
@@ -10,3 +13,18 @@ export const useObserveTransactionNoSettings = (prefix, nextNumber) => {
|
|||||||
setFieldValue('transacttion_numner', TransactionNo);
|
setFieldValue('transacttion_numner', TransactionNo);
|
||||||
}, [setFieldValue, prefix, nextNumber]);
|
}, [setFieldValue, prefix, nextNumber]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useSetPrimaryBranchToForm = () => {
|
||||||
|
const { setFieldValue } = useFormikContext();
|
||||||
|
const { branches, isBranchesSuccess } = useMoneyInDailogContext();
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (isBranchesSuccess) {
|
||||||
|
const primaryBranch = branches.find((b) => b.primary) || first(branches);
|
||||||
|
|
||||||
|
if (primaryBranch) {
|
||||||
|
setFieldValue('branch_id', primaryBranch.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [isBranchesSuccess, setFieldValue, branches]);
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user