Files
triqura-ecd/components/rich-text-editor.tsx
colinislit ab2bec1260 fix: resolve TypeScript type errors across application
Fixed multiple TypeScript compilation errors that blocked production build:

Component Type Fixes:
- client-sidebar.tsx: Changed icon type from React.ElementType to
  React.ComponentType<{ className?: string }> for proper prop typing
- patient-form.tsx: Added type casting for FHIR extension property access
- page.tsx: Added explicit Intake[] type annotation
- document-card.tsx: Added null check for file_size property
- rich-text-editor.tsx: Removed invalid false parameter from setContent()

Data Model Fixes:
- actions.ts (intakes): Changed encounter status 'finished' to 'completed'
  (FHIR-compliant value)
- actions.ts (intakes): Set diagnosis clinical_status to always use 'active'
- actions.ts (intakes): Cast treatment_advice to Record<string, any>

Schema Extensions:
- lib/fhir/types/index.ts: Added extension property to FHIRPatient interface
  to support custom FHIR extensions (john-doe, insurance, GP, episode-status)

Validation Fixes:
- lib/types/intake.ts: Fixed Zod enum errorMap syntax (changed to message)

All changes ensure type safety while maintaining runtime functionality.
Build now completes successfully with zero TypeScript errors.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 12:20:14 +01:00

114 lines
3.8 KiB
TypeScript

'use client';
import { useEffect } from 'react';
import { EditorContent, useEditor } from '@tiptap/react';
import StarterKit from '@tiptap/starter-kit';
import Placeholder from '@tiptap/extension-placeholder';
import { Bold, Italic, List, ListOrdered, Quote } from 'lucide-react';
import { cn } from '@/lib/utils';
interface RichTextEditorProps {
value?: string;
onChange?: (value: string) => void;
placeholder?: string;
}
export function RichTextEditor({ value, onChange, placeholder }: RichTextEditorProps) {
const editor = useEditor({
extensions: [
StarterKit.configure({
heading: false,
bulletList: { keepMarks: true },
orderedList: { keepMarks: true },
}),
Placeholder.configure({ placeholder: placeholder || 'Schrijf iets...', includeChildren: true }),
],
content: value || '',
editorProps: {
attributes: {
class:
'prose prose-sm max-w-none focus:outline-none min-h-[160px] px-3 py-2 text-slate-800 bg-white',
},
},
onUpdate({ editor }) {
onChange?.(editor.getHTML());
},
immediatelyRender: false,
});
useEffect(() => {
if (!editor) return;
const html = value || '';
if (html !== editor.getHTML()) {
editor.commands.setContent(html);
}
}, [value, editor]);
if (!editor) {
return <div className="rounded-lg border border-slate-200 h-32 animate-pulse bg-slate-50" />;
}
const toggle = (command: () => void) => {
editor.chain().focus();
command();
};
return (
<div className="rounded-lg border border-slate-200 overflow-hidden">
<div className="flex items-center gap-1 border-b border-slate-200 bg-slate-50 px-2 py-1.5">
<button
type="button"
onClick={() => toggle(() => editor.chain().focus().toggleBold().run())}
className={cn(
'inline-flex h-7 w-7 items-center justify-center rounded-md text-xs text-slate-600 hover:bg-white',
editor.isActive('bold') && 'bg-white text-slate-900'
)}
>
<Bold className="h-4 w-4" />
</button>
<button
type="button"
onClick={() => toggle(() => editor.chain().focus().toggleItalic().run())}
className={cn(
'inline-flex h-7 w-7 items-center justify-center rounded-md text-xs text-slate-600 hover:bg-white',
editor.isActive('italic') && 'bg-white text-slate-900'
)}
>
<Italic className="h-4 w-4" />
</button>
<button
type="button"
onClick={() => toggle(() => editor.chain().focus().toggleBulletList().run())}
className={cn(
'inline-flex h-7 w-7 items-center justify-center rounded-md text-xs text-slate-600 hover:bg-white',
editor.isActive('bulletList') && 'bg-white text-slate-900'
)}
>
<List className="h-4 w-4" />
</button>
<button
type="button"
onClick={() => toggle(() => editor.chain().focus().toggleOrderedList().run())}
className={cn(
'inline-flex h-7 w-7 items-center justify-center rounded-md text-xs text-slate-600 hover:bg-white',
editor.isActive('orderedList') && 'bg-white text-slate-900'
)}
>
<ListOrdered className="h-4 w-4" />
</button>
<button
type="button"
onClick={() => toggle(() => editor.chain().focus().toggleBlockquote().run())}
className={cn(
'inline-flex h-7 w-7 items-center justify-center rounded-md text-xs text-slate-600 hover:bg-white',
editor.isActive('blockquote') && 'bg-white text-slate-900'
)}
>
<Quote className="h-4 w-4" />
</button>
</div>
<EditorContent editor={editor} />
</div>
);
}