Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Improve attachment component JSDoc

Anibal Svarcasb67f1b50d84d
diff --git a/src/components/atomic-crm/notes/AttachmentField.tsx b/src/components/atomic-crm/notes/AttachmentField.tsx
index d6863842..648c92b0 100644
--- a/src/components/atomic-crm/notes/AttachmentField.tsx
+++ b/src/components/atomic-crm/notes/AttachmentField.tsx
@@ -3,11 +3,14 @@ import type { FileFieldProps } from "@/components/admin";
import { cn } from "@/lib/utils";
/**
- * Displays a preview for a single note attachment in the edition form.
+ * Displays a preview for a single note attachment in the note edition form.
*
* This component is inspired by react-admin's `ImageField` and is intended for
- * use as the child of `<FileInput>` (which provides one attachment record at a time).
- * For note display outside forms, use `<NoteAttachments>`.
+ * usage inside a `<FileInput>`, where the current attachment is provided through
+ * the record context.
+ *
+ * @param props - Field props provided by react-admin file inputs.
+ * @returns An image preview for image attachments, or a regular link for other files.
*/
export const AttachmentField = (props: FileFieldProps) => {
const {
@@ -80,6 +83,12 @@ export const AttachmentField = (props: FileFieldProps) => {
);
};
+/**
+ * Checks whether a mime type corresponds to an image.
+ *
+ * @param mimeType - The attachment mime type.
+ * @returns `true` when the mime type starts with `image/`.
+ */
const isImageMimeType = (mimeType?: string): boolean => {
if (!mimeType) {
return false;
diff --git a/src/components/atomic-crm/notes/NoteAttachments.tsx b/src/components/atomic-crm/notes/NoteAttachments.tsx
index d8322f89..a30f2a50 100644
--- a/src/components/atomic-crm/notes/NoteAttachments.tsx
+++ b/src/components/atomic-crm/notes/NoteAttachments.tsx
@@ -5,8 +5,11 @@ import type { AttachmentNote, ContactNote, DealNote } from "../types";
/**
* Displays persisted note attachments in note show/list views.
*
- * Unlike `NoteAttachmentInputField`, this component receives a full note record
- * and renders all its attachments.
+ * This component receives a full note record and renders all attachments.
+ *
+ * @param props - Component props.
+ * @param props.note - Note record containing attachments to render.
+ * @returns `null` when there are no attachments, otherwise attachment previews and links.
*/
export const NoteAttachments = ({ note }: { note: ContactNote | DealNote }) => {
if (!note.attachments || note.attachments.length === 0) {
@@ -62,6 +65,12 @@ export const NoteAttachments = ({ note }: { note: ContactNote | DealNote }) => {
);
};
+/**
+ * Checks whether a mime type corresponds to an image.
+ *
+ * @param mimeType - The attachment mime type.
+ * @returns `true` when the mime type starts with `image/`.
+ */
const isImageMimeType = (mimeType?: string): boolean => {
if (!mimeType) {
return false;