fix: (*): fix currency code.

This commit is contained in:
elforjani3
2021-03-30 18:57:10 +02:00
parent 628d483813
commit 86a36f4044
32 changed files with 203 additions and 110 deletions

View File

@@ -6,20 +6,23 @@ import { defaultExpenseEntry } from './utils';
/**
* Expense form entries field.
*/
export default function ExpenseFormEntriesField({
linesNumber = 4,
}) {
export default function ExpenseFormEntriesField({ linesNumber = 4 }) {
return (
<FastField name={'categories'}>
{({ form, field: { value }, meta: { error, touched } }) => (
{({
form: { values, setFieldValue },
field: { value },
meta: { error, touched },
}) => (
<ExpenseFormEntriesTable
entries={value}
error={error}
onChange={(entries) => {
form.setFieldValue('categories', entries);
setFieldValue('categories', entries);
}}
defaultEntry={defaultExpenseEntry}
linesNumber={linesNumber}
currencyCode={values.currency_code}
/>
)}
</FastField>

View File

@@ -21,6 +21,7 @@ export default function ExpenseFormEntriesTable({
defaultEntry,
error,
onChange,
currencyCode,
}) {
// Expense form context.
const { accounts } = useExpenseFormContext();
@@ -69,6 +70,7 @@ export default function ExpenseFormEntriesTable({
updateData: handleUpdateData,
removeRow: handleRemoveRow,
autoFocus: ['expense_account_id', 0],
currencyCode
}}
footer={true}
/>

View File

@@ -1,7 +1,8 @@
import React from 'react';
import { Button, Tooltip, Intent, Position } from '@blueprintjs/core';
import { FormattedMessage as T, useIntl } from 'react-intl';
import { FormattedMessage as T } from 'react-intl';
import { Icon, Hint } from 'components';
import { formatMessage } from 'services/intl';
import {
InputGroupCell,
MoneyFieldCell,
@@ -51,9 +52,16 @@ const ActionsCellRenderer = ({
/**
* Amount footer cell.
*/
function AmountFooterCell({ rows }) {
function AmountFooterCell({ payload: { currencyCode }, rows }) {
const total = safeSumBy(rows, 'original.amount');
return <span>{formattedAmount(total, 'USD')}</span>;
return <span>{formattedAmount(total, currencyCode)}</span>;
}
/**
* Expense amount header cell.
*/
export function ExpenseAmountHeaderCell({ payload: { currencyCode } }) {
return formatMessage({ id: 'amount_currency' }, { currency: currencyCode });
}
/**
@@ -67,7 +75,6 @@ function ExpenseAccountFooterCell() {
* Retrieve expense form table entries columns.
*/
export function useExpenseFormTableColumns() {
const { formatMessage } = useIntl();
return React.useMemo(
() => [
@@ -92,7 +99,7 @@ export function useExpenseFormTableColumns() {
filterAccountsByRootTypes: ['expense'],
},
{
Header: formatMessage({ id: 'amount_currency' }, { currency: 'USD' }),
Header: ExpenseAmountHeaderCell,
accessor: 'amount',
Cell: MoneyFieldCell,
Footer: AmountFooterCell,