parent
69af4286a9
commit
a677a507b8
@ -0,0 +1,42 @@
|
|||||||
|
import Container from "components/services/widget/container";
|
||||||
|
import Block from "components/services/widget/block";
|
||||||
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||||
|
|
||||||
|
export default function Component({ service }) {
|
||||||
|
const { widget } = service;
|
||||||
|
|
||||||
|
const { data: inboxData, error: inboxError } = useWidgetAPI(widget, "inbox",
|
||||||
|
{
|
||||||
|
query: `tag:${widget.inboxTag}`,
|
||||||
|
format: "json",
|
||||||
|
fields: "count"
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const { data: documentData, error: documentError } = useWidgetAPI(widget, "documents",
|
||||||
|
{
|
||||||
|
fields: "count",
|
||||||
|
format: "json",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (inboxError || documentError) {
|
||||||
|
const finalError = inboxError ?? documentError;
|
||||||
|
return <Container error={finalError} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!inboxData || !documentData) {
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="paperlessngx.inbox" />
|
||||||
|
<Block label="paperlessngx.total" />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="paperlessngx.inbox" value={inboxData.count} />
|
||||||
|
<Block label="paperlessngx.total" value={documentData.count} />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
import genericProxyHandler from "utils/proxy/handlers/generic";
|
||||||
|
|
||||||
|
const widget = {
|
||||||
|
api: "{url}/api/{endpoint}",
|
||||||
|
proxyHandler: genericProxyHandler,
|
||||||
|
|
||||||
|
mappings: {
|
||||||
|
"inbox": {
|
||||||
|
endpoint: "documents/",
|
||||||
|
params: ["format", "query", "fields"],
|
||||||
|
validate: [
|
||||||
|
"count"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"documents": {
|
||||||
|
endpoint: "documents/",
|
||||||
|
params: ["format", "fields"],
|
||||||
|
validate: [
|
||||||
|
"count"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default widget;
|
Loading…
Reference in new issue