feat(invoice detail): add exchange rate detail.

This commit is contained in:
elforjani13
2022-02-27 14:23:57 +02:00
parent a3c79d98b0
commit 01db5a2faa

View File

@@ -1,33 +1,34 @@
import React from 'react';
import { DetailItem } from 'components';
import intl from 'react-intl-universal';
import { useSelector } from 'react-redux';
import { createSelector } from 'reselect';
import * as R from 'ramda';
import { DetailItem } from 'components';
import { isEqual } from 'lodash';
const organizationBaseCurrecy = createSelector(
(state) => {
const tenantId = state.authentication.tenantId;
return state.organizations.data[tenantId];
},
(organization) => organization?.base_currency,
);
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
export function ExchangeRateDetailItem({
// #ownProps
/**
* Detail exchange rate item.
* @param {*} param0
* @param {*} param1
* @returns
*/
function DetailExchangeRate({
exchangeRate,
toCurrency,
// #withCurrentOrganization
organization: { base_currency },
}) {
const fromCurrency = useSelector(organizationBaseCurrecy);
if (isEqual(fromCurrency, toCurrency)) {
if (isEqual(base_currency, toCurrency)) {
return null;
}
return (
<DetailItem label={intl.get('invoice.details.exchange_rate')}>
1 {fromCurrency} = {exchangeRate} {toCurrency}
1 {base_currency} = {exchangeRate} {toCurrency}
</DetailItem>
);
}
export const ExchangeRateDetailItem = R.compose(withCurrentOrganization())(
DetailExchangeRate,
);