forked from administration/panel
refactor: rows not cols
parent
500f8b3e1c
commit
5cdb02b5bf
|
@ -1,22 +1,33 @@
|
|||
"use client"
|
||||
"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 {
|
||||
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";
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
import ReactMarkdown from "react-markdown";
|
||||
import remarkGfm from "remark-gfm";
|
||||
|
||||
dayjs.extend(relativeTime);
|
||||
|
||||
export default function SafetyNotesCard({ objectId, type, title }: {
|
||||
objectId: string,
|
||||
type: SafetyNotes["_id"]["type"],
|
||||
title?: string
|
||||
export default function SafetyNotesCard({
|
||||
objectId,
|
||||
type,
|
||||
title,
|
||||
}: {
|
||||
objectId: string;
|
||||
type: SafetyNotes["_id"]["type"];
|
||||
title?: string;
|
||||
}) {
|
||||
const session = useSession();
|
||||
const [draft, setDraft] = useState("");
|
||||
|
@ -40,18 +51,20 @@ export default function SafetyNotesCard({ objectId, type, title }: {
|
|||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{title ?? type.charAt(0).toUpperCase() + type.slice(1) + " notes"}</CardTitle>
|
||||
<CardTitle>
|
||||
{title ?? type.charAt(0).toUpperCase() + type.slice(1) + " notes"}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{
|
||||
editing
|
||||
? <Textarea
|
||||
{editing ? (
|
||||
<Textarea
|
||||
rows={8}
|
||||
placeholder={
|
||||
error
|
||||
? error
|
||||
: ready
|
||||
? "Enter notes here... (save on unfocus)"
|
||||
: "Fetching notes..."
|
||||
? "Enter notes here... (save on unfocus)"
|
||||
: "Fetching notes..."
|
||||
}
|
||||
className="!min-h-[80px] max-h-[50vh]"
|
||||
disabled={!ready || error != null}
|
||||
|
@ -60,7 +73,7 @@ export default function SafetyNotesCard({ objectId, type, title }: {
|
|||
onChange={(e) => setDraft(e.currentTarget.value)}
|
||||
onBlur={async () => {
|
||||
if (draft === value?.text ?? "") return setEditing(false);
|
||||
|
||||
|
||||
try {
|
||||
await updateSafetyNote(objectId, type, draft);
|
||||
setValue({
|
||||
|
@ -83,33 +96,37 @@ export default function SafetyNotesCard({ objectId, type, title }: {
|
|||
}
|
||||
}}
|
||||
/>
|
||||
: <div onClick={() => setEditing(true)}>
|
||||
{
|
||||
error
|
||||
? <>{error}</>
|
||||
: value?.text
|
||||
? <ReactMarkdown
|
||||
className="prose prose-a:text-[#fd6671] prose-img:max-h-96 max-w-none"
|
||||
remarkPlugins={[remarkGfm]}
|
||||
>
|
||||
{value.text}
|
||||
</ReactMarkdown>
|
||||
: ready
|
||||
? <i>Click to add a note</i>
|
||||
: <i>Fetching notes...</i>
|
||||
}
|
||||
) : (
|
||||
<div onClick={() => setEditing(true)}>
|
||||
{error ? (
|
||||
<>{error}</>
|
||||
) : value?.text ? (
|
||||
<ReactMarkdown
|
||||
className="prose prose-a:text-[#fd6671] prose-img:max-h-96 max-w-none"
|
||||
remarkPlugins={[remarkGfm]}
|
||||
>
|
||||
{value.text}
|
||||
</ReactMarkdown>
|
||||
) : ready ? (
|
||||
<i>Click to add a note</i>
|
||||
) : (
|
||||
<i>Fetching notes...</i>
|
||||
)}
|
||||
</div>
|
||||
}
|
||||
)}
|
||||
</CardContent>
|
||||
<CardFooter className="-my-2">
|
||||
<CardDescription>
|
||||
{
|
||||
value
|
||||
? <>Last edited {dayjs(value.edited_at).fromNow()} by {value.edited_by}</>
|
||||
: <>No object note set</>
|
||||
}
|
||||
</CardDescription>
|
||||
<CardDescription>
|
||||
{value ? (
|
||||
<>
|
||||
Last edited {dayjs(value.edited_at).fromNow()} by{" "}
|
||||
{value.edited_by}
|
||||
</>
|
||||
) : (
|
||||
<>No object note set</>
|
||||
)}
|
||||
</CardDescription>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ export function CaseActions({ Case }: { Case: CaseDocument }) {
|
|||
<CaseCard entry={Case} />
|
||||
|
||||
<Textarea
|
||||
cols={8}
|
||||
rows={8}
|
||||
placeholder="Enter notes here... (save on unfocus)"
|
||||
className="!min-h-0 !h-[76px]"
|
||||
defaultValue={Case.notes}
|
||||
|
|
|
@ -89,7 +89,7 @@ export function ReportActions({
|
|||
<ReportCard report={reportDraft} />
|
||||
|
||||
<Textarea
|
||||
cols={8}
|
||||
rows={8}
|
||||
placeholder="Enter notes here... (save on unfocus)"
|
||||
className="!min-h-0 !h-[76px]"
|
||||
defaultValue={report.notes}
|
||||
|
|
Loading…
Reference in New Issue