"use client" import { useEffect, useState } from "react"; import { Textarea } from "../ui/textarea"; import { toast } from "../ui/use-toast"; import { SafetyNotes, fetchSafetyNote, updateSafetyNote } from "@/lib/db"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "../ui/card"; import { useSession } from "next-auth/react"; import dayjs from "dayjs"; import relativeTime from "dayjs/plugin/relativeTime"; dayjs.extend(relativeTime); export default function SafetyNotesCard({ objectId, type, title }: { objectId: string, type: SafetyNotes["_id"]["type"], title?: string }) { const session = useSession(); const [draft, setDraft] = useState(""); const [value, setValue] = useState(null); const [ready, setReady] = useState(false); const [error, setError] = useState(null); useEffect(() => { fetchSafetyNote(objectId, type) .then((note) => { setDraft(note?.text || ""); setValue(note); setReady(true); }) .catch((e) => { setError(String(e)); }); }, [objectId, type]); return ( {title ?? type.charAt(0).toUpperCase() + type.slice(1) + " notes"}