diff --git a/moneymgr_web/src/dialogs/UpdateMovementDialog.tsx b/moneymgr_web/src/dialogs/UpdateMovementDialog.tsx index 0c00f33..57933ea 100644 --- a/moneymgr_web/src/dialogs/UpdateMovementDialog.tsx +++ b/moneymgr_web/src/dialogs/UpdateMovementDialog.tsx @@ -130,7 +130,7 @@ export function UpdateMovementDialog(p: { setMovement((m) => { return { ...m, - amount: m.amount, + amount: l, }; }) } diff --git a/moneymgr_web/src/widgets/SelectMovementWidget.tsx b/moneymgr_web/src/widgets/SelectMovementWidget.tsx index fcd8fdf..b6fec30 100644 --- a/moneymgr_web/src/widgets/SelectMovementWidget.tsx +++ b/moneymgr_web/src/widgets/SelectMovementWidget.tsx @@ -1,6 +1,15 @@ -import { ListItem, ListItemButton, Paper, Typography } from "@mui/material"; +import AddIcon from "@mui/icons-material/Add"; +import { + Fab, + ListItem, + ListItemButton, + Paper, + Tooltip, + Typography, +} from "@mui/material"; import React from "react"; import { Movement, MovementApi } from "../api/MovementsApi"; +import { UpdateMovementDialog } from "../dialogs/UpdateMovementDialog"; import { AsyncWidget } from "./AsyncWidget"; import { AccountInput } from "./forms/AccountInput"; import { AmountInput } from "./forms/AmountInput"; @@ -18,6 +27,8 @@ export function SelectMovementWidget(p: { label?: string; }; }): React.ReactElement { + const loadKey = React.useRef(1); + const [amount, setAmount] = React.useState( p.initialValues?.amount ); @@ -48,80 +59,143 @@ export function SelectMovementWidget(p: { else setList(undefined); }; + const [creating, setCreating] = React.useState(false); + + const handleStartCreateNewMovement = () => { + setCreating(true); + }; + + const handleCloseCreateNewMovement = () => { + setCreating(false); + }; + + const handleCreatedNewMovement = (m: Movement) => { + setAmount(m.amount); + setAccountId(m.account_id); + setTime(m.time); + setLabel(m.label); + p.onChange(m); + loadKey.current += 1; + setCreating(false); + }; + return ( - -
- - - - - - - -
- - { - if (list === null) - return ( - - Select an account to begin research. - - ); - if (list?.length === 0) - return ( - - No result. - - ); - - return ( - <> - {list?.map((entry) => ( - - p.onChange(entry)} - > - - - - ))} - - ); + <> + - + > +
+ + + + + + + +
+ +
+ { + if (list === null) + return ( + + Select an account to begin research. + + ); + if (list?.length === 0) + return ( + + No result. + + ); + + return ( + <> + {list?.map((entry) => ( + + p.onChange(entry)} + > + + + + ))} + + ); + }} + /> +
+ +
+ + + + + +
+
+ {creating && accountId && ( + + )} + ); }