1
0
Fork 0

refactor: rows not cols

main
Paul Makles 2023-11-26 13:19:08 +00:00
parent 500f8b3e1c
commit 5cdb02b5bf
No known key found for this signature in database
GPG Key ID: 5059F398521BB0F6
3 changed files with 58 additions and 41 deletions

View File

@ -1,22 +1,33 @@
"use client" "use client";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { Textarea } from "../ui/textarea"; import { Textarea } from "../ui/textarea";
import { toast } from "../ui/use-toast"; import { toast } from "../ui/use-toast";
import { SafetyNotes, fetchSafetyNote, updateSafetyNote } from "@/lib/db"; 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 { useSession } from "next-auth/react";
import dayjs from "dayjs"; import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime"; import relativeTime from "dayjs/plugin/relativeTime";
import ReactMarkdown from 'react-markdown'; import ReactMarkdown from "react-markdown";
import remarkGfm from 'remark-gfm'; import remarkGfm from "remark-gfm";
dayjs.extend(relativeTime); dayjs.extend(relativeTime);
export default function SafetyNotesCard({ objectId, type, title }: { export default function SafetyNotesCard({
objectId: string, objectId,
type: SafetyNotes["_id"]["type"], type,
title?: string title,
}: {
objectId: string;
type: SafetyNotes["_id"]["type"];
title?: string;
}) { }) {
const session = useSession(); const session = useSession();
const [draft, setDraft] = useState(""); const [draft, setDraft] = useState("");
@ -40,18 +51,20 @@ export default function SafetyNotesCard({ objectId, type, title }: {
return ( return (
<Card> <Card>
<CardHeader> <CardHeader>
<CardTitle>{title ?? type.charAt(0).toUpperCase() + type.slice(1) + " notes"}</CardTitle> <CardTitle>
{title ?? type.charAt(0).toUpperCase() + type.slice(1) + " notes"}
</CardTitle>
</CardHeader> </CardHeader>
<CardContent> <CardContent>
{ {editing ? (
editing <Textarea
? <Textarea rows={8}
placeholder={ placeholder={
error error
? error ? error
: ready : ready
? "Enter notes here... (save on unfocus)" ? "Enter notes here... (save on unfocus)"
: "Fetching notes..." : "Fetching notes..."
} }
className="!min-h-[80px] max-h-[50vh]" className="!min-h-[80px] max-h-[50vh]"
disabled={!ready || error != null} disabled={!ready || error != null}
@ -83,33 +96,37 @@ export default function SafetyNotesCard({ objectId, type, title }: {
} }
}} }}
/> />
: <div onClick={() => setEditing(true)}> ) : (
{ <div onClick={() => setEditing(true)}>
error {error ? (
? <>{error}</> <>{error}</>
: value?.text ) : value?.text ? (
? <ReactMarkdown <ReactMarkdown
className="prose prose-a:text-[#fd6671] prose-img:max-h-96 max-w-none" className="prose prose-a:text-[#fd6671] prose-img:max-h-96 max-w-none"
remarkPlugins={[remarkGfm]} remarkPlugins={[remarkGfm]}
> >
{value.text} {value.text}
</ReactMarkdown> </ReactMarkdown>
: ready ) : ready ? (
? <i>Click to add a note</i> <i>Click to add a note</i>
: <i>Fetching notes...</i> ) : (
} <i>Fetching notes...</i>
)}
</div> </div>
} )}
</CardContent> </CardContent>
<CardFooter className="-my-2"> <CardFooter className="-my-2">
<CardDescription> <CardDescription>
{ {value ? (
value <>
? <>Last edited {dayjs(value.edited_at).fromNow()} by {value.edited_by}</> Last edited {dayjs(value.edited_at).fromNow()} by{" "}
: <>No object note set</> {value.edited_by}
} </>
</CardDescription> ) : (
<>No object note set</>
)}
</CardDescription>
</CardFooter> </CardFooter>
</Card> </Card>
) );
} }

View File

@ -17,7 +17,7 @@ export function CaseActions({ Case }: { Case: CaseDocument }) {
<CaseCard entry={Case} /> <CaseCard entry={Case} />
<Textarea <Textarea
cols={8} rows={8}
placeholder="Enter notes here... (save on unfocus)" placeholder="Enter notes here... (save on unfocus)"
className="!min-h-0 !h-[76px]" className="!min-h-0 !h-[76px]"
defaultValue={Case.notes} defaultValue={Case.notes}

View File

@ -89,7 +89,7 @@ export function ReportActions({
<ReportCard report={reportDraft} /> <ReportCard report={reportDraft} />
<Textarea <Textarea
cols={8} rows={8}
placeholder="Enter notes here... (save on unfocus)" placeholder="Enter notes here... (save on unfocus)"
className="!min-h-0 !h-[76px]" className="!min-h-0 !h-[76px]"
defaultValue={report.notes} defaultValue={report.notes}