From 3ef1830dde7e68ed670939366dc1ceaf57a57d34 Mon Sep 17 00:00:00 2001 From: okcodes Date: Fri, 16 Oct 2020 03:19:30 -0500 Subject: [PATCH] Refactor --- .../components/FlowOperationFormDialog.tsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/views/FlowOperationList/components/FlowOperationFormDialog.tsx b/src/views/FlowOperationList/components/FlowOperationFormDialog.tsx index 1b3cc68..7d16fb1 100644 --- a/src/views/FlowOperationList/components/FlowOperationFormDialog.tsx +++ b/src/views/FlowOperationList/components/FlowOperationFormDialog.tsx @@ -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'; @@ -58,20 +58,21 @@ type Props = { export const FlowOperationFormDialog = ({open, handleClose, dropDownDataForCashAccounts, model}: Props) => { - const [dirty, setDirty] = React.useState>(model); - const [amount, setAmount] = React.useState(`${Math.abs(model.amount)}`); - const [type, setType] = React.useState(model.amount < 0 ? 'expense' : 'income'); + const [dirty, setDirty] = useState>(model); + const [amount, setAmount] = useState(`${Math.abs(model.amount)}`); + const [type, setType] = useState(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]); @@ -80,7 +81,7 @@ export const FlowOperationFormDialog = ({open, handleClose, dropDownDataForCashA setDirty({...dirty, [key]: value}); }; - const onAmountChange = (event: React.ChangeEvent) => { + const onAmountChange = (event: ChangeEvent) => { setAmount(event.target.value); }; @@ -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 ( @@ -151,7 +151,7 @@ export const FlowOperationFormDialog = ({open, handleClose, dropDownDataForCashA }} /> - + setShowAccountPicker(true)}> Account