Can create inbox entries
This commit is contained in:
75
moneymgr_web/src/routes/InboxRoute.tsx
Normal file
75
moneymgr_web/src/routes/InboxRoute.tsx
Normal 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>
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user