fix :default currency in make journal form.

This commit is contained in:
elforjani3
2020-11-15 19:03:26 +02:00
parent e7bded2e6a
commit 9d1cb8791f
3 changed files with 56 additions and 9 deletions

View File

@@ -126,6 +126,7 @@ function MakeJournalEntriesForm({
date: Yup.date() date: Yup.date()
.required() .required()
.label(formatMessage({ id: 'date' })), .label(formatMessage({ id: 'date' })),
currency_code: Yup.string(),
reference: Yup.string().min(1).max(255), reference: Yup.string().min(1).max(255),
description: Yup.string().min(1).max(1024), description: Yup.string().min(1).max(1024),
entries: Yup.array().of( entries: Yup.array().of(
@@ -172,6 +173,7 @@ function MakeJournalEntriesForm({
date: moment(new Date()).format('YYYY-MM-DD'), date: moment(new Date()).format('YYYY-MM-DD'),
description: '', description: '',
reference: '', reference: '',
currency_code: '',
entries: [...repeatValue(defaultEntry, 4)], entries: [...repeatValue(defaultEntry, 4)],
}), }),
[defaultEntry, journalNumber], [defaultEntry, journalNumber],
@@ -442,11 +444,12 @@ function MakeJournalEntriesForm({
}, },
[changePageSubtitle], [changePageSubtitle],
); );
console.log(values, 'Val');
return ( return (
<div class="make-journal-entries"> <div class="make-journal-entries">
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
<MakeJournalEntriesHeader <MakeJournalEntriesHeader
manualJournal={manualJournalId}
errors={errors} errors={errors}
touched={touched} touched={touched}
values={values} values={values}

View File

@@ -1,4 +1,4 @@
import React, { useMemo, useCallback } from 'react'; import React, { useMemo, useState, useCallback } from 'react';
import { import {
InputGroup, InputGroup,
FormGroup, FormGroup,
@@ -15,16 +15,18 @@ import classNames from 'classnames';
import { CLASSES } from 'common/classes'; import { CLASSES } from 'common/classes';
import { momentFormatter, tansformDateValue, saveInvoke } from 'utils'; import { momentFormatter, tansformDateValue, saveInvoke } from 'utils';
import { import {
CurrenciesSelectList,
ErrorMessage, ErrorMessage,
Hint, Hint,
FieldHint, FieldHint,
FieldRequiredHint, FieldRequiredHint,
Icon, Icon,
InputPrependButton, InputPrependButton,
CurrencySelectList,
} from 'components'; } from 'components';
import withDialogActions from 'containers/Dialog/withDialogActions'; import withDialogActions from 'containers/Dialog/withDialogActions';
import withCurrencies from 'containers/Currencies/withCurrencies';
import withSettings from 'containers/Settings/withSettings';
import { compose } from 'utils'; import { compose } from 'utils';
@@ -36,11 +38,20 @@ function MakeJournalEntriesHeader({
getFieldProps, getFieldProps,
// #ownProps // #ownProps
manualJournal,
onJournalNumberChanged, onJournalNumberChanged,
// #withSettings
baseCurrency,
// #withCurrencies
currenciesList,
// #withDialog // #withDialog
openDialog, openDialog,
}) { }) {
const [selectedItems, setSelectedItems] = useState({});
const handleDateChange = useCallback( const handleDateChange = useCallback(
(date) => { (date) => {
const formatted = moment(date).format('YYYY-MM-DD'); const formatted = moment(date).format('YYYY-MM-DD');
@@ -57,6 +68,19 @@ function MakeJournalEntriesHeader({
saveInvoke(onJournalNumberChanged, event.currentTarget.value); saveInvoke(onJournalNumberChanged, event.currentTarget.value);
}; };
const onItemsSelect = useCallback(
(filedName) => {
return (filed) => {
setSelectedItems({
...selectedItems,
[filedName]: filed,
});
setFieldValue(filedName, filed.currency_code);
};
},
[setFieldValue, selectedItems],
);
return ( return (
<div class="make-journal-entries__header"> <div class="make-journal-entries__header">
<Row> <Row>
@@ -197,7 +221,12 @@ function MakeJournalEntriesHeader({
CLASSES.FILL, CLASSES.FILL,
)} )}
> >
<CurrenciesSelectList /> <CurrencySelectList
currenciesList={currenciesList}
selectedCurrencyCode={values.currency_code}
onCurrencySelected={onItemsSelect('currency_code')}
defaultSelectText={baseCurrency}
/>
</FormGroup> </FormGroup>
</Col> </Col>
</Row> </Row>
@@ -205,4 +234,12 @@ function MakeJournalEntriesHeader({
); );
} }
export default compose(withDialogActions)(MakeJournalEntriesHeader); export default compose(
withDialogActions,
withSettings(({ organizationSettings }) => ({
baseCurrency: organizationSettings?.baseCurrency,
})),
withCurrencies(({ currenciesList }) => ({
currenciesList,
})),
)(MakeJournalEntriesHeader);

View File

@@ -8,6 +8,7 @@ import DashboardInsider from 'components/Dashboard/DashboardInsider';
import withCustomersActions from 'containers/Customers/withCustomersActions'; import withCustomersActions from 'containers/Customers/withCustomersActions';
import withAccountsActions from 'containers/Accounts/withAccountsActions'; import withAccountsActions from 'containers/Accounts/withAccountsActions';
import withManualJournalsActions from 'containers/Accounting/withManualJournalsActions'; import withManualJournalsActions from 'containers/Accounting/withManualJournalsActions';
import withCurrenciesActions from 'containers/Currencies/withCurrenciesActions';
import withSettingsActions from 'containers/Settings/withSettingsActions'; import withSettingsActions from 'containers/Settings/withSettingsActions';
import { compose } from 'utils'; import { compose } from 'utils';
@@ -22,6 +23,9 @@ function MakeJournalEntriesPage({
// #withManualJournalActions // #withManualJournalActions
requestFetchManualJournal, requestFetchManualJournal,
// #wihtCurrenciesActions
requestFetchCurrencies,
// #withSettingsActions // #withSettingsActions
requestFetchOptions, requestFetchOptions,
}) { }) {
@@ -36,11 +40,12 @@ function MakeJournalEntriesPage({
requestFetchCustomers(), requestFetchCustomers(),
); );
const fetchSettings = useQuery( const fetchCurrencies = useQuery('currencies', () =>
['settings'], requestFetchCurrencies(),
() => requestFetchOptions({}),
); );
const fetchSettings = useQuery(['settings'], () => requestFetchOptions({}));
const fetchJournal = useQuery( const fetchJournal = useQuery(
['manual-journal', id], ['manual-journal', id],
(key, journalId) => requestFetchManualJournal(journalId), (key, journalId) => requestFetchManualJournal(journalId),
@@ -63,6 +68,7 @@ function MakeJournalEntriesPage({
loading={ loading={
fetchJournal.isFetching || fetchJournal.isFetching ||
fetchAccounts.isFetching || fetchAccounts.isFetching ||
fetchCurrencies.isFetching ||
fetchCustomers.isFetching fetchCustomers.isFetching
} }
name={'make-journal-page'} name={'make-journal-page'}
@@ -80,5 +86,6 @@ export default compose(
withAccountsActions, withAccountsActions,
withCustomersActions, withCustomersActions,
withManualJournalsActions, withManualJournalsActions,
withSettingsActions withCurrenciesActions,
withSettingsActions,
)(MakeJournalEntriesPage); )(MakeJournalEntriesPage);