Can create inbox entries

This commit is contained in:
2025-05-10 18:37:51 +02:00
parent cceed381bd
commit 0b586039c3
8 changed files with 240 additions and 32 deletions

View File

@ -0,0 +1,75 @@
import RefreshIcon from "@mui/icons-material/Refresh";
import { Checkbox, FormControlLabel, IconButton, Tooltip } from "@mui/material";
import React from "react";
import { InboxApi, InboxEntry } from "../api/InboxApi";
import { useAlert } from "../hooks/context_providers/AlertDialogProvider";
import { useLoadingMessage } from "../hooks/context_providers/LoadingMessageProvider";
import { AsyncWidget } from "../widgets/AsyncWidget";
import { MoneyMgrWebRouteContainer } from "../widgets/MoneyMgrWebRouteContainer";
import { NewMovementWidget } from "../widgets/NewMovementWidget";
export function InboxRoute(): React.ReactElement {
const loadingMessage = useLoadingMessage();
const alert = useAlert();
const [entries, setEntries] = React.useState<InboxEntry[] | undefined>();
const [includeAttached, setIncludeAttached] = React.useState(false);
const loadKey = React.useRef(1);
const load = async () => {
setEntries(await InboxApi.GetList(includeAttached));
};
const reload = async (skipEntries: boolean) => {
try {
loadingMessage.show("Refreshing the list of inbox entries...");
// TODO : trigger reload number of inbox entries
if (!skipEntries) await load();
} catch (e) {
console.error("Failed to load list of inbox entries!", e);
alert(`Failed to refresh the list of inbox entries! ${e}`);
} finally {
loadingMessage.hide();
}
};
return (
<MoneyMgrWebRouteContainer
label={"Inbox"}
actions={
<span>
<FormControlLabel
checked={includeAttached}
control={
<Checkbox
onChange={(e) => {
setIncludeAttached(e.target.checked);
reload(false);
}}
/>
}
label="Include attached"
/>
<Tooltip title="Refresh table">
<IconButton onClick={() => reload(false)}>
<RefreshIcon />
</IconButton>
</Tooltip>
</span>
}
>
<div style={{ display: "flex", flexDirection: "column", flex: 1 }}>
<div style={{ flex: 1, display: "flex", flexDirection: "column" }}>
<AsyncWidget
loadKey={loadKey.current}
load={load}
errMsg="Failed to load the content of inbox!"
build={() => <>todo table</>}
/>
<NewMovementWidget isInbox onCreated={() => reload(false)} />
</div>
</div>
</MoneyMgrWebRouteContainer>
);
}