fix(cashflow): labels of Add money in/out don't appear.

This commit is contained in:
a.bouhuolia
2023-01-25 00:14:11 +02:00
parent 806e4fb54c
commit 96ac46ca64
5 changed files with 35 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
// @ts-nocheck // @ts-nocheck
import intl from 'react-intl-universal'; import intl from 'react-intl-universal';
export const addMoneyIn = [ export const getAddMoneyInOptions = () => [
{ {
name: intl.get('cash_flow.owner_contribution'), name: intl.get('cash_flow.owner_contribution'),
value: 'owner_contribution', value: 'owner_contribution',
@@ -16,7 +16,7 @@ export const addMoneyIn = [
}, },
]; ];
export const addMoneyOut = [ export const getAddMoneyOutOptions = () => [
{ {
name: intl.get('cash_flow.owner_drawings'), name: intl.get('cash_flow.owner_drawings'),
value: 'OwnerDrawing', value: 'OwnerDrawing',

View File

@@ -1,5 +1,5 @@
// @ts-nocheck // @ts-nocheck
import React from 'react'; import React, { useMemo } from 'react';
import { import {
Button, Button,
NavbarGroup, NavbarGroup,
@@ -15,7 +15,10 @@ import {
} from '@/components'; } from '@/components';
import { CashFlowMenuItems } from './utils'; import { CashFlowMenuItems } from './utils';
import { addMoneyIn, addMoneyOut } from '@/constants/cashflowOptions'; import {
getAddMoneyOutOptions,
getAddMoneyInOptions,
} from '@/constants/cashflowOptions';
import { useRefreshCashflowTransactionsInfinity } from '@/hooks/query'; import { useRefreshCashflowTransactionsInfinity } from '@/hooks/query';
import { useAccountTransactionsContext } from './AccountTransactionsProvider'; import { useAccountTransactionsContext } from './AccountTransactionsProvider';
@@ -41,6 +44,10 @@ function AccountTransactionsActionsBar({
}; };
const { accountId } = useAccountTransactionsContext(); const { accountId } = useAccountTransactionsContext();
// Retrieves the money in/out buttons options.
const addMoneyInOptions = useMemo(() => getAddMoneyInOptions(), []);
const addMoneyOutOptions = useMemo(() => getAddMoneyOutOptions(), []);
// Handle money in form // Handle money in form
const handleMoneyInFormTransaction = (account) => { const handleMoneyInFormTransaction = (account) => {
openDialog('money-in', { openDialog('money-in', {
@@ -69,7 +76,7 @@ function AccountTransactionsActionsBar({
<DashboardActionsBar> <DashboardActionsBar>
<NavbarGroup> <NavbarGroup>
<CashFlowMenuItems <CashFlowMenuItems
items={addMoneyIn} items={addMoneyInOptions}
onItemSelect={handleMoneyInFormTransaction} onItemSelect={handleMoneyInFormTransaction}
text={<T id={'cash_flow.label.add_money_in'} />} text={<T id={'cash_flow.label.add_money_in'} />}
buttonProps={{ buttonProps={{
@@ -77,7 +84,7 @@ function AccountTransactionsActionsBar({
}} }}
/> />
<CashFlowMenuItems <CashFlowMenuItems
items={addMoneyOut} items={addMoneyOutOptions}
onItemSelect={handlMoneyOutFormTransaction} onItemSelect={handlMoneyOutFormTransaction}
text={<T id={'cash_flow.label.add_money_out'} />} text={<T id={'cash_flow.label.add_money_out'} />}
buttonProps={{ buttonProps={{

View File

@@ -1,5 +1,5 @@
// @ts-nocheck // @ts-nocheck
import React from 'react'; import React, { useMemo } from 'react';
import intl from 'react-intl-universal'; import intl from 'react-intl-universal';
import styled from 'styled-components'; import styled from 'styled-components';
import { isNull, isEmpty } from 'lodash'; import { isNull, isEmpty } from 'lodash';
@@ -22,7 +22,10 @@ import withAlertsActions from '@/containers/Alert/withAlertActions';
import withDialogActions from '@/containers/Dialog/withDialogActions'; import withDialogActions from '@/containers/Dialog/withDialogActions';
import { safeCallback } from '@/utils'; import { safeCallback } from '@/utils';
import { addMoneyIn, addMoneyOut } from '@/constants/cashflowOptions'; import {
getAddMoneyInOptions,
getAddMoneyOutOptions,
} from '@/constants/cashflowOptions';
const CASHFLOW_SKELETON_N = 4; const CASHFLOW_SKELETON_N = 4;
@@ -183,8 +186,10 @@ function CashflowAccountMoneyInContextMenu({ onClick }) {
const handleItemClick = curry((transactionType, event) => { const handleItemClick = curry((transactionType, event) => {
onClick && onClick(transactionType, event); onClick && onClick(transactionType, event);
}); });
// Retreives the add money in button options.
const addMoneyInOptions = useMemo(() => getAddMoneyInOptions(), []);
return addMoneyIn.map((option) => ( return addMoneyInOptions.map((option) => (
<MenuItem text={option.name} onClick={handleItemClick(option.value)} /> <MenuItem text={option.name} onClick={handleItemClick(option.value)} />
)); ));
} }
@@ -196,8 +201,10 @@ function CashflowAccountMoneyOutContextMenu({ onClick }) {
const handleItemClick = curry((transactionType, event) => { const handleItemClick = curry((transactionType, event) => {
onClick && onClick(transactionType, event); onClick && onClick(transactionType, event);
}); });
// Retreives the add money out button options.
const addMoneyOutOptions = useMemo(() => getAddMoneyOutOptions(), []);
return addMoneyOut.map((option) => ( return addMoneyOutOptions.map((option) => (
<MenuItem text={option.name} onClick={handleItemClick(option.value)} /> <MenuItem text={option.name} onClick={handleItemClick(option.value)} />
)); ));
} }

View File

@@ -1,5 +1,5 @@
// @ts-nocheck // @ts-nocheck
import React from 'react'; import React, { useMemo } from 'react';
import { FastField, Field, ErrorMessage } from 'formik'; import { FastField, Field, ErrorMessage } from 'formik';
import { FormGroup } from '@blueprintjs/core'; import { FormGroup } from '@blueprintjs/core';
import classNames from 'classnames'; import classNames from 'classnames';
@@ -12,7 +12,7 @@ import {
Row, Row,
} from '@/components'; } from '@/components';
import { inputIntent } from '@/utils'; import { inputIntent } from '@/utils';
import { CLASSES, addMoneyIn } from '@/constants'; import { CLASSES, getAddMoneyInOptions } from '@/constants';
import { useMoneyInDailogContext } from './MoneyInDialogProvider'; import { useMoneyInDailogContext } from './MoneyInDialogProvider';
@@ -23,6 +23,9 @@ export default function TransactionTypeFields() {
// Money in dialog context. // Money in dialog context.
const { cashflowAccounts } = useMoneyInDailogContext(); const { cashflowAccounts } = useMoneyInDailogContext();
// Retrieves the add money in button options.
const addMoneyInOptions = useMemo(() => getAddMoneyInOptions(), []);
return ( return (
<div className="trasnaction-type-fileds"> <div className="trasnaction-type-fileds">
<Row> <Row>
@@ -73,7 +76,7 @@ export default function TransactionTypeFields() {
)} )}
> >
<ListSelect <ListSelect
items={addMoneyIn} items={addMoneyInOptions}
onItemSelect={(type) => { onItemSelect={(type) => {
setFieldValue('transaction_type', type.value); setFieldValue('transaction_type', type.value);
}} }}

View File

@@ -1,5 +1,5 @@
// @ts-nocheck // @ts-nocheck
import React from 'react'; import React, { useMemo } from 'react';
import { FastField, Field, ErrorMessage } from 'formik'; import { FastField, Field, ErrorMessage } from 'formik';
import { FormGroup } from '@blueprintjs/core'; import { FormGroup } from '@blueprintjs/core';
import classNames from 'classnames'; import classNames from 'classnames';
@@ -14,7 +14,7 @@ import {
import { inputIntent } from '@/utils'; import { inputIntent } from '@/utils';
import { CLASSES } from '@/constants/classes'; import { CLASSES } from '@/constants/classes';
import { addMoneyOut } from '@/constants/cashflowOptions'; import { getAddMoneyOutOptions } from '@/constants/cashflowOptions';
import { useMoneyOutDialogContext } from './MoneyOutDialogProvider'; import { useMoneyOutDialogContext } from './MoneyOutDialogProvider';
@@ -25,6 +25,8 @@ function TransactionTypeFields() {
// Money in dialog context. // Money in dialog context.
const { cashflowAccounts } = useMoneyOutDialogContext(); const { cashflowAccounts } = useMoneyOutDialogContext();
const addMoneyOutOptions = useMemo(() => getAddMoneyOutOptions(), []);
return ( return (
<div className="trasnaction-type-fileds"> <div className="trasnaction-type-fileds">
<Row> <Row>
@@ -75,7 +77,7 @@ function TransactionTypeFields() {
)} )}
> >
<ListSelect <ListSelect
items={addMoneyOut} items={addMoneyOutOptions}
onItemSelect={(type) => { onItemSelect={(type) => {
setFieldValue('transaction_type', type.value); setFieldValue('transaction_type', type.value);
}} }}