Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
okcodes committed Oct 16, 2020
1 parent 722810d commit 3ef1830
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {ChangeEvent, useEffect, useState} from 'react';
import Button from '@material-ui/core/Button';
import TextField from '@material-ui/core/TextField';
import Dialog from '@material-ui/core/Dialog';
Expand Down Expand Up @@ -58,20 +58,21 @@ type Props = {

export const FlowOperationFormDialog = ({open, handleClose, dropDownDataForCashAccounts, model}: Props) => {

const [dirty, setDirty] = React.useState<Omit<FlowOperationModel, 'amount'>>(model);
const [amount, setAmount] = React.useState(`${Math.abs(model.amount)}`);
const [type, setType] = React.useState<FlowType>(model.amount < 0 ? 'expense' : 'income');
const [dirty, setDirty] = useState<Omit<FlowOperationModel, 'amount'>>(model);
const [amount, setAmount] = useState(`${Math.abs(model.amount)}`);
const [type, setType] = useState<FlowType>(model.amount < 0 ? 'expense' : 'income');
const [showAccountPicker, setShowAccountPicker] = useState(false);

const amountAsNumber = () => {
const absAmount = Math.abs(accounting.unformat(amount, '.'));
return type === 'income' ? absAmount : -absAmount;
}

React.useEffect(() => {
useEffect(() => {
setDirty(model);
}, [model]);

React.useEffect(() => {
useEffect(() => {
setAmount(`${Math.abs(model.amount)}`);
setType(model.amount < 0 ? 'expense' : 'income');
}, [model.amount]);
Expand All @@ -80,7 +81,7 @@ export const FlowOperationFormDialog = ({open, handleClose, dropDownDataForCashA
setDirty({...dirty, [key]: value});
};

const onAmountChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const onAmountChange = (event: ChangeEvent<HTMLInputElement>) => {
setAmount(event.target.value);
};

Expand Down Expand Up @@ -131,7 +132,6 @@ export const FlowOperationFormDialog = ({open, handleClose, dropDownDataForCashA

const classes = useStyles();

console.log('%c Amount', 'background: white; color: black', {amount, 'model.amount': model.amount});
return (
<Dialog open={open} onClose={handleClose} aria-labelledby="form-dialog-title"
TransitionComponent={Transition}>
Expand All @@ -151,7 +151,7 @@ export const FlowOperationFormDialog = ({open, handleClose, dropDownDataForCashA
}}
/>
<Card className={classes.root}>
<CardContent>
<CardContent onClick={() => setShowAccountPicker(true)}>
<Typography className={classes.title} color="textSecondary" gutterBottom>
Account
</Typography>
Expand Down

0 comments on commit 3ef1830

Please sign in to comment.