mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 13:52:20 +00:00
A settings card under Integrations connects either system and tests it before saving. An import button beside Upload in Documents, on a condition's documents card, and beside Add in the visit and vaccination document pickers opens a sheet that searches by name with tag and date filters, shows what HealthLog already holds, and imports the ticked documents one at a time with a result per row. The buttons appear only for a person in their own record with a connection; strings in all seven languages.
74 lines
2.0 KiB
TypeScript
74 lines
2.0 KiB
TypeScript
"use client";
|
|
|
|
/**
|
|
* "Import from Paperless-ngx / Papra": the button that opens the document
|
|
* picker (#1038), for every place a document can be added or linked.
|
|
*
|
|
* Renders nothing unless the person, in their own record, has at least one
|
|
* usable connection: no connection, a delegate or guardian, the module off, or
|
|
* the operator's list unset all leave no trace, because a button that can only
|
|
* lead to a refusal advertises a feature that is not there. Connecting happens
|
|
* in Settings, not here.
|
|
*/
|
|
import { Import } from "lucide-react";
|
|
import { useState } from "react";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { useTranslations } from "@/lib/i18n/context";
|
|
import type { InboundDocumentKindValue } from "@/lib/validations/inbound-documents";
|
|
|
|
import {
|
|
DocumentSourcePicker,
|
|
type DocumentPickerLink,
|
|
} from "./document-source-picker";
|
|
import { systemName, useDocumentSourcesStatus } from "./use-document-sources";
|
|
|
|
export function ImportFromSourceButton({
|
|
link,
|
|
kind,
|
|
onImported,
|
|
className,
|
|
}: {
|
|
link?: DocumentPickerLink;
|
|
kind?: InboundDocumentKindValue;
|
|
onImported?: (documentIds: string[]) => void;
|
|
className?: string;
|
|
}) {
|
|
const { t } = useTranslations();
|
|
const { connected } = useDocumentSourcesStatus();
|
|
const [open, setOpen] = useState(false);
|
|
|
|
if (connected.length === 0) return null;
|
|
|
|
const label =
|
|
connected.length === 1
|
|
? t("documents.sourcePicker.openNamed", {
|
|
name: systemName(connected[0]),
|
|
})
|
|
: t("documents.sourcePicker.open");
|
|
|
|
return (
|
|
<>
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
size="sm"
|
|
className={className}
|
|
onClick={() => setOpen(true)}
|
|
data-slot="document-source-open"
|
|
>
|
|
<Import className="size-4" aria-hidden />
|
|
{label}
|
|
</Button>
|
|
<DocumentSourcePicker
|
|
open={open}
|
|
onOpenChange={setOpen}
|
|
systems={connected}
|
|
link={link}
|
|
kind={kind}
|
|
onImported={onImported}
|
|
/>
|
|
</>
|
|
);
|
|
}
|