Files
temetro/.agents/skills/ai-elements/scripts/web-preview.tsx
T
Khalid Abdi 929bec8f31 feat: AI-added records save with placeholders + "Added by AI" provenance
Stop blocking AI imports/proposals on missing non-critical fields. Records
the chat agent drafts now save with safe placeholders, auto-generated file
numbers, and a source="ai" marker that surfaces an "Added by AI" badge so a
clinician can review/edit them later.

Backend:
- add `source` (manual|ai) column to patients/appointments/prescriptions
  (migration 0014) + canonical types, services, validation schemas
- relax patient/appointment validation: empty file number allowed, demographic
  + type/provider/initials fall back to placeholders (initials derived from name)
- patients.generateFileNumber() auto-assigns an MRN when one is missing
- proposeAppointment accepts a name when no file number resolves; AI commits +
  /api/ai/import stamp source="ai"

Frontend:
- `source` on Appointment/Patient/Prescription types; AI commits send source="ai"
- reusable <AiBadge> shown on the Patients table/detail and prescriptions list

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-14 19:27:17 +03:00

116 lines
2.8 KiB
TypeScript

"use client";
import {
WebPreview,
WebPreviewBody,
WebPreviewConsole,
WebPreviewNavigation,
WebPreviewNavigationButton,
WebPreviewUrl,
} from "@/components/ai-elements/web-preview";
import {
ArrowLeftIcon,
ArrowRightIcon,
ExternalLinkIcon,
Maximize2Icon,
MousePointerClickIcon,
RefreshCcwIcon,
} from "lucide-react";
import { useCallback, useState } from "react";
const handleUrlChange = (url: string) => {
console.log("URL changed to:", url);
};
const handleGoBack = () => {
console.log("Go back");
};
const handleGoForward = () => {
console.log("Go forward");
};
const handleReload = () => {
console.log("Reload");
};
const handleSelect = () => {
console.log("Select");
};
const handleOpenInNewTab = () => {
console.log("Open in new tab");
};
const exampleLogs = [
{
level: "log" as const,
message: "Page loaded successfully",
timestamp: new Date(Date.now() - 10_000),
},
{
level: "warn" as const,
message: "Deprecated API usage detected",
timestamp: new Date(Date.now() - 5000),
},
{
level: "error" as const,
message: "Failed to load resource",
timestamp: new Date(),
},
];
const Example = () => {
const [_fullscreen, setFullscreen] = useState(false);
const handleToggleFullscreen = useCallback(
() => setFullscreen((prev) => !prev),
[]
);
return (
<WebPreview
defaultUrl="/"
onUrlChange={handleUrlChange}
style={{ height: "400px" }}
>
<WebPreviewNavigation>
<WebPreviewNavigationButton onClick={handleGoBack} tooltip="Go back">
<ArrowLeftIcon className="size-4" />
</WebPreviewNavigationButton>
<WebPreviewNavigationButton
onClick={handleGoForward}
tooltip="Go forward"
>
<ArrowRightIcon className="size-4" />
</WebPreviewNavigationButton>
<WebPreviewNavigationButton onClick={handleReload} tooltip="Reload">
<RefreshCcwIcon className="size-4" />
</WebPreviewNavigationButton>
<WebPreviewUrl />
<WebPreviewNavigationButton onClick={handleSelect} tooltip="Select">
<MousePointerClickIcon className="size-4" />
</WebPreviewNavigationButton>
<WebPreviewNavigationButton
onClick={handleOpenInNewTab}
tooltip="Open in new tab"
>
<ExternalLinkIcon className="size-4" />
</WebPreviewNavigationButton>
<WebPreviewNavigationButton
onClick={handleToggleFullscreen}
tooltip="Maximize"
>
<Maximize2Icon className="size-4" />
</WebPreviewNavigationButton>
</WebPreviewNavigation>
<WebPreviewBody src="https://preview-v0me-kzml7zc6fkcvbyhzrf47.vusercontent.net/" />
<WebPreviewConsole logs={exampleLogs} />
</WebPreview>
);
};
export default Example;