BC-4: feat: base currency withCurrentOrganization

This commit is contained in:
elforjani3
2021-09-07 00:16:46 +02:00
parent 6401692903
commit 39ba31a842
31 changed files with 152 additions and 213 deletions

View File

@@ -20,14 +20,14 @@ import { ERROR } from 'common/errors';
import { useBillFormContext } from './BillFormProvider';
import { compose, orderingLinesIndexes, safeSumBy } from 'utils';
import { defaultBill, transformToEditForm } from './utils';
import withSettings from 'containers/Settings/withSettings';
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
/**
* Bill form.
*/
function BillForm({
// #withSettings
baseCurrency,
// #withCurrentOrganization
organization: { base_currency },
}) {
const history = useHistory();
@@ -41,14 +41,14 @@ function BillForm({
...(!isEmpty(bill)
? {
...transformToEditForm(bill),
currency_code: baseCurrency,
currency_code: base_currency,
}
: {
...defaultBill,
currency_code: baseCurrency,
currency_code: base_currency,
}),
}),
[bill, baseCurrency],
[bill, base_currency],
);
// Transform response error to fields.
@@ -142,8 +142,4 @@ function BillForm({
</div>
);
}
export default compose(
withSettings(({ organizationSettings }) => ({
baseCurrency: organizationSettings?.baseCurrency,
})),
)(BillForm);
export default compose(withCurrentOrganization())(BillForm);

View File

@@ -8,22 +8,24 @@ import { CLASSES } from 'common/classes';
import BillFormHeaderFields from './BillFormHeaderFields';
import { PageFormBigNumber } from 'components';
import withSettings from 'containers/Settings/withSettings';
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
import { compose } from 'redux';
/**
* Fill form header.
*/
function BillFormHeader({
// #withSettings
baseCurrency,
// #withCurrentOrganization
organization: { base_currency },
}) {
const { values } = useFormikContext();
// Calculate the total due amount of bill entries.
const totalDueAmount = useMemo(() => sumBy(values.entries, 'amount'), [
values.entries,
]);
const totalDueAmount = useMemo(
() => sumBy(values.entries, 'amount'),
[values.entries],
);
return (
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
@@ -31,13 +33,9 @@ function BillFormHeader({
<PageFormBigNumber
label={intl.get('due_amount')}
amount={totalDueAmount}
currencyCode={baseCurrency}
currencyCode={base_currency}
/>
</div>
);
}
export default compose(
withSettings(({ organizationSettings }) => ({
baseCurrency: organizationSettings?.baseCurrency,
})),
)(BillFormHeader);
export default compose(withCurrentOrganization())(BillFormHeader);

View File

@@ -11,7 +11,6 @@ import BillsEmptyStatus from './BillsEmptyStatus';
import withBills from './withBills';
import withBillActions from './withBillsActions';
import withSettings from 'containers/Settings/withSettings';
import withAlertsActions from 'containers/Alert/withAlertActions';
import withDialogActions from 'containers/Dialog/withDialogActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions';
@@ -33,7 +32,7 @@ function BillsDataTable({
// #withDialogActions
openDialog,
// #withDrawerActions
openDrawer,
}) {
@@ -127,7 +126,4 @@ export default compose(
withAlertsActions,
withDrawerActions,
withDialogActions,
withSettings(({ organizationSettings }) => ({
baseCurrency: organizationSettings?.baseCurrency,
})),
)(BillsDataTable);

View File

@@ -15,6 +15,8 @@ import PaymentMadeFormBody from './PaymentMadeFormBody';
import { PaymentMadeInnerProvider } from './PaymentMadeInnerProvider';
import withSettings from 'containers/Settings/withSettings';
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
import {
EditPaymentMadeFormSchema,
CreatePaymentMadeFormSchema,
@@ -29,7 +31,9 @@ import { defaultPaymentMade, transformToEditForm, ERRORS } from './utils';
function PaymentMadeForm({
// #withSettings
preferredPaymentAccount,
baseCurrency,
// #withCurrentOrganization
organization: { base_currency },
}) {
const history = useHistory();
@@ -54,7 +58,7 @@ function PaymentMadeForm({
: {
...defaultPaymentMade,
payment_account_id: defaultTo(preferredPaymentAccount),
currency_code: baseCurrency,
currency_code: base_currency,
entries: orderingLinesIndexes(defaultPaymentMade.entries),
}),
}),
@@ -156,10 +160,10 @@ function PaymentMadeForm({
}
export default compose(
withSettings(({ billPaymentSettings, organizationSettings }) => ({
withSettings(({ billPaymentSettings }) => ({
paymentNextNumber: billPaymentSettings?.next_number,
paymentNumberPrefix: billPaymentSettings?.number_prefix,
preferredPaymentAccount: parseInt(billPaymentSettings?.withdrawalAccount),
baseCurrency: organizationSettings?.baseCurrency,
})),
withCurrentOrganization(),
)(PaymentMadeForm);

View File

@@ -8,14 +8,14 @@ import { Money } from 'components';
import { FormattedMessage as T } from 'components';
import PaymentMadeFormHeaderFields from './PaymentMadeFormHeaderFields';
import withSettings from 'containers/Settings/withSettings';
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
/**
* Payment made header form.
*/
function PaymentMadeFormHeader({
// #withSettings
baseCurrency,
// #withCurrentOrganization
organization: { base_currency },
}) {
// Formik form context.
const {
@@ -36,7 +36,7 @@ function PaymentMadeFormHeader({
<T id={'amount_received'} />
</span>
<h1 class="big-amount__number">
<Money amount={amountPaid} currency={baseCurrency} />
<Money amount={amountPaid} currency={base_currency} />
</h1>
</div>
</div>
@@ -45,8 +45,4 @@ function PaymentMadeFormHeader({
);
}
export default compose(
withSettings(({ organizationSettings }) => ({
baseCurrency: organizationSettings?.baseCurrency,
})),
)(PaymentMadeFormHeader);
export default compose(withCurrentOrganization())(PaymentMadeFormHeader);

View File

@@ -23,7 +23,7 @@ import {
Icon,
MoneyInputGroup,
} from 'components';
import withSettings from 'containers/Settings/withSettings';
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
import { usePaymentMadeFormContext } from './PaymentMadeFormProvider';
import { ACCOUNT_TYPE } from 'common/accountTypes';
import {
@@ -41,7 +41,7 @@ import { accountsFieldShouldUpdate, vendorsFieldShouldUpdate } from './utils';
/**
* Payment made form header fields.
*/
function PaymentMadeFormHeaderFields({ baseCurrency }) {
function PaymentMadeFormHeaderFields({ organization: { base_currency } }) {
// Formik form context.
const {
values: { entries },
@@ -143,7 +143,7 @@ function PaymentMadeFormHeaderFields({ baseCurrency }) {
helperText={<ErrorMessage name="full_amount" />}
>
<ControlGroup>
<InputPrependText text={baseCurrency} />
<InputPrependText text={base_currency} />
<MoneyInputGroup
value={value}
onChange={(value) => {
@@ -160,7 +160,7 @@ function PaymentMadeFormHeaderFields({ baseCurrency }) {
minimal={true}
>
<T id={'receive_full_amount'} /> (
<Money amount={payableFullAmount} currency={baseCurrency} />)
<Money amount={payableFullAmount} currency={base_currency} />)
</Button>
</FormGroup>
)}
@@ -244,8 +244,4 @@ function PaymentMadeFormHeaderFields({ baseCurrency }) {
);
}
export default compose(
withSettings(({ organizationSettings }) => ({
baseCurrency: organizationSettings?.baseCurrency,
})),
)(PaymentMadeFormHeaderFields);
export default compose(withCurrentOrganization())(PaymentMadeFormHeaderFields);

View File

@@ -10,7 +10,8 @@ import TableSkeletonHeader from 'components/Datatable/TableHeaderSkeleton';
import withPaymentMadeActions from './withPaymentMadeActions';
import withPaymentMade from './withPaymentMade';
import withSettings from 'containers/Settings/withSettings';
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
import withAlertsActions from 'containers/Alert/withAlertActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { usePaymentMadesTableColumns, ActionsMenu } from './components';
@@ -109,7 +110,5 @@ export default compose(
withPaymentMade(({ paymentMadesTableState }) => ({ paymentMadesTableState })),
withAlertsActions,
withDrawerActions,
withSettings(({ organizationSettings }) => ({
baseCurrency: organizationSettings?.baseCurrency,
})),
withCurrentOrganization(),
)(PaymentMadesTable);