From 07ee499742662b60a81cc0c4f7c7a0c9b66d747d Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 12 May 2025 19:40:05 +0200 Subject: [PATCH] Can display information about the movement attached to an inbox entry --- moneymgr_web/src/api/MovementsApi.ts | 11 ++++ moneymgr_web/src/routes/InboxRoute.tsx | 22 ++++++- moneymgr_web/src/widgets/MovementWidget.tsx | 63 +++++++++++++++++++++ 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 moneymgr_web/src/widgets/MovementWidget.tsx diff --git a/moneymgr_web/src/api/MovementsApi.ts b/moneymgr_web/src/api/MovementsApi.ts index 3674044..06fb2e7 100644 --- a/moneymgr_web/src/api/MovementsApi.ts +++ b/moneymgr_web/src/api/MovementsApi.ts @@ -59,6 +59,17 @@ export class MovementApi { ).data; } + /** + * Get a single movement information + */ static async GetSingleMovement(movement_id: number): Promise { + return ( + await APIClient.exec({ + uri: `/movement/${movement_id}`, + method: "GET", + }) + ).data; + } + /** * Update a movement information */ diff --git a/moneymgr_web/src/routes/InboxRoute.tsx b/moneymgr_web/src/routes/InboxRoute.tsx index 217d1ce..76e144d 100644 --- a/moneymgr_web/src/routes/InboxRoute.tsx +++ b/moneymgr_web/src/routes/InboxRoute.tsx @@ -10,6 +10,7 @@ import { AmountWidget } from "../widgets/AmountWidget"; import { AsyncWidget } from "../widgets/AsyncWidget"; import { DateWidget } from "../widgets/DateWidget"; import { MoneyMgrWebRouteContainer } from "../widgets/MoneyMgrWebRouteContainer"; +import { MovementWidget } from "../widgets/MovementWidget"; import { NewMovementWidget } from "../widgets/NewMovementWidget"; import { UploadedFileWidget } from "../widgets/UploadedFileWidget"; @@ -71,7 +72,13 @@ export function InboxRoute(): React.ReactElement { loadKey={loadKey.current + String(includeAttached)} load={load} errMsg="Failed to load the content of inbox!" - build={() => } + build={() => ( + + )} /> reload(false)} /> @@ -83,6 +90,7 @@ export function InboxRoute(): React.ReactElement { function InboxTable(p: { entries: InboxEntry[]; onReload: (skipEntries: boolean) => void; + showMovements?: boolean; }): React.ReactElement { const [rowSelectionModel, setRowSelectionModel] = React.useState([]); @@ -135,6 +143,16 @@ function InboxTable(p: { return ; }, }, + { + field: "movement_id", + headerName: "Movement", + editable: false, + flex: 3, + renderCell: (params) => { + if (params.row.movement_id) + return ; + }, + }, ]; return ( @@ -150,7 +168,7 @@ function InboxTable(p: { }, columns: { columnVisibilityModel: { - checked: false, + movement_id: p.showMovements!!, }, }, }} diff --git a/moneymgr_web/src/widgets/MovementWidget.tsx b/moneymgr_web/src/widgets/MovementWidget.tsx new file mode 100644 index 0000000..be54046 --- /dev/null +++ b/moneymgr_web/src/widgets/MovementWidget.tsx @@ -0,0 +1,63 @@ +import CallMadeIcon from "@mui/icons-material/CallMade"; +import CallReceivedIcon from "@mui/icons-material/CallReceived"; +import React from "react"; +import { Movement, MovementApi } from "../api/MovementsApi"; +import { useAccounts } from "../hooks/AccountsListProvider"; +import { AccountWidget } from "./AccountWidget"; +import { AmountWidget } from "./AmountWidget"; +import { AsyncWidget } from "./AsyncWidget"; + +export function MovementWidget(p: { id: number }): React.ReactElement { + const accounts = useAccounts(); + + const [movement, setMovement] = React.useState(); + + const load = async () => { + setMovement(await MovementApi.GetSingleMovement(p.id)); + }; + + return ( + ( + + {movement!.amount > 0 ? ( + + ) : ( + + )} + + + {movement?.label} + + + + + • + + + {accounts.get(movement!.account_id)?.name} + + + + )} + /> + ); +}