Repository: lesleyfon/chatapp
Pull request #23: Feat: Message Input as Image Dropzone 
Author: login: lesleyfon
Created: 2025-04-16T03:35:25Z | Merged: 2025-04-16T17:41:52Z



<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Added support for image uploads in chat messages with drag-and-drop, preview, and validation for file type and size.
  - Increased maximum upload file size to 5 MB.
  - Enabled sending images as files or base64 strings in private messages, including GIF conversion.
- **Bug Fixes**
  - Improved error handling for image uploads and private message creation with clearer feedback.
- **Other Improvements**
  - Updated types and interfaces to support image uploads and enhanced error handling.
  - Added default SVG placeholder and image-related constants for consistent file handling.
  - Integrated react-dropzone for improved drag-and-drop user experience.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->


Diff:
diff --git a/client/package.json b/client/package.json
index 9b873d0..d2f13ae 100644
--- a/client/package.json
+++ b/client/package.json
@@ -32,6 +32,7 @@
     "lucide-react": "^0.403.0",
     "react": "^18.3.1",
     "react-dom": "^18.3.1",
+    "react-dropzone": "^14.3.8",
     "react-hook-form": "^7.52.1",
     "react-icons": "^5.2.1",
     "react-router": "^6.24.1",
diff --git a/client/src/components/constants.ts b/client/src/components/constants.ts
index 137ec15..0262fcb 100644
--- a/client/src/components/constants.ts
+++ b/client/src/components/constants.ts
@@ -56,4 +56,22 @@ export const INPUT_NAME = "new-chat-name";
 /**
  * @description - The error field names for the new chat room.
  */
-export const ERROR_FIELD_NAMES = [INPUT_NAME, "new-chat-name-error", "new-chat-name-internal-error"];
\ No newline at end of file
+export const ERROR_FIELD_NAMES = [INPUT_NAME, "new-chat-name-error", "new-chat-name-internal-error"];
+
+/**
+ * @description - The accepted image types.
+ */
+export const ACCEPTED_IMAGE_TYPES = [
+  "image/png",
+  "image/jpeg",
+  "image/jpg",
+  "image/gif",
+  "image/webp",
+  "image/svg+xml",
+  "image/heic",
+  "image/heif"
+].join(", ");
+export const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB for example
+
+export const DEFAULT_SVG_URL =
+	"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IndoaXRlIiBzdHJva2Utd2lkdGg9IjEiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgY2xhc3M9Imx1Y2lkZSBsdWNpZGUtcGFwZXJjbGlwIj48cGF0aCBkPSJNMTMuMjM0IDIwLjI1MiAyMSAxMi4zIi8+PHBhdGggZD0ibTE2IDYtOC40MTQgOC41ODZhMiAyIDAgMCAwIDAgMi44MjggMiAyIDAgMCAwIDIuODI4IDBsOC40MTQtOC41ODZhNCA0IDAgMCAwIDAtNS42NTYgNCA0IDAgMCAwLTUuNjU2IDBsLTguNDE1IDguNTg1YTYgNiAwIDEgMCA4LjQ4NiA4LjQ4NiIvPjwvc3ZnPg==";
\ No newline at end of file
diff --git a/client/src/components/layout/chat-room/chat-room-message-input.tsx b/client/src/components/layout/chat-room/chat-room-message-input.tsx
index c05d4b5..cf3ce8e 100644
--- a/client/src/components/layout/chat-room/chat-room-message-input.tsx
+++ b/client/src/components/layout/chat-room/chat-room-message-input.tsx
@@ -1,25 +1,72 @@
 import EmojiPicker, { Theme } from "emoji-picker-react";
-import { SendIcon, SmileIcon } from "lucide-react";
+import { SendIcon, SmileIcon, ImageIcon } from "lucide-react";
 import { Button } from "../../ui/button";
-
-import { SubmitHandler, useForm } from "react-hook-form";
+import { useState, useCallback, useEffect } from "react";
+import { FileError, useDropzone } from "react-dropzone";
+import { SubmitErrorHandler, SubmitHandler, useForm } from "react-hook-form";
 import { useSendMessage } from "../../../hooks/useSendMessage";
 import { useSocket } from "../../../hooks/useSocket";
 import { cn, getCurrentDateTimeWithTimezone } from "../../../lib";
-import { type MessageInput } from "../../../types";
+import {
+	type MessageInputProps,
+	type ChatInputProps,
+	type ErrorMessagesProps,
+	type FileInputElementProps,
+} from "../../../types";
 import { Input } from "../../ui/input";
 import { Popover, PopoverContent, PopoverTrigger } from "../../ui/popover";
+import { ACCEPTED_IMAGE_TYPES, DEFAULT_SVG_URL, MAX_FILE_SIZE } from "../../constants";
 
-interface ChatInputProps {
-	chatId: string;
-	chatName: string;
-	isPrivateChat?: boolean;
-}
-// BUTTON Background Image
-const svgUrl =
-	"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IndoaXRlIiBzdHJva2Utd2lkdGg9IjEiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgY2xhc3M9Imx1Y2lkZSBsdWNpZGUtcGFwZXJjbGlwIj48cGF0aCBkPSJNMTMuMjM0IDIwLjI1MiAyMSAxMi4zIi8+PHBhdGggZD0ibTE2IDYtOC40MTQgOC41ODZhMiAyIDAgMCAwIDAgMi44MjggMiAyIDAgMCAwIDIuODI4IDBsOC40MTQtOC41ODZhNCA0IDAgMCAwIDAtNS42NTYgNCA0IDAgMCAwLTUuNjU2IDBsLTguNDE1IDguNTg1YTYgNiAwIDEgMCA4LjQ4NiA4LjQ4NiIvPjwvc3ZnPg==";
+const ErrorMessages = ({ errors }: ErrorMessagesProps) => (
+	<div className="flex flex-col">
+		{Object.keys(errors).map((error) => (
+			<p key={error} className="text-red-400 text-xs">
+				{errors[error as keyof MessageInputProps]?.message as string}
+			</p>
+		))}
+	</div>
+);
+
+const FileInputElement = ({
+	getRootProps,
+	errors,
+	svgUrl,
+	isDragActive,
+	getInputProps,
+}: FileInputElementProps) => {
+	return (
+		<div {...getRootProps()}>
+			<input {...getInputProps()} />
+			<Button
+				type="button"
+				variant="ghost"
+				size="icon"
+				className={cn(
+					"mr-2 cursor-pointer relative overflow-hidden",
+					errors?.message_img && "border-[1px] border-red-400",
+					isDragActive && "bg-gray-100 border-[1px] border-green-300"
+				)}
+			>
+				{svgUrl === DEFAULT_SVG_URL ? (
+					<ImageIcon className="h-5 w-5" />
+				) : (
+					<div
+						className="w-full h-full absolute inset-0"
+						style={{
+							backgroundImage: `url(${svgUrl})`,
+							backgroundRepeat: "no-repeat",
+							backgroundSize: "cover",
+							backgroundPosition: "center",
+						}}
+					/>
+				)}
+			</Button>
+		</div>
+	);
+};
 
-export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps) {
+export function ChatMessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps) {
+	const [svgUrl, setSvgUrl] = useState(DEFAULT_SVG_URL);
 	const socket = useSocket();
 	const { sendMessage, sendPrivateMessage } = useSendMessage({ socket });
 
@@ -32,18 +79,69 @@ export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps
 		setValue,
 		getValues,
 		setError,
+		clearErrors,
 		formState: { errors },
-	} = useForm<MessageInput>();
+	} = useForm<MessageInputProps>();
+
+	useEffect(() => {
+		return () => {
+			// Cleanup when component unmounts
+			if (svgUrl !== DEFAULT_SVG_URL) {
+				URL.revokeObjectURL(svgUrl);
+			}
+		};
+	}, [svgUrl]);
+
+	const validateFile = (file: File): FileError | null => {
+		const fileType = file.type;
+		if (file.size > MAX_FILE_SIZE) {
+			setError(FILE_INPUT_NAME, { message: "File size is too large" });
+			return { message: "File size is too large", code: "file-size-too-large" };
+		}
+		if (!ACCEPTED_IMAGE_TYPES.includes(fileType)) {
+			setError(FILE_INPUT_NAME, { message: "File type is not supported" });
+			return { message: "File type is not supported", code: "file-type-not-supported" };
+		}
+		return null;
+	};
+
+	const onDrop = useCallback(
+		(acceptedFiles: File[]) => {
+			if (!acceptedFiles.length) return;
+			const file = acceptedFiles[0];
 
-	const onSubmit: SubmitHandler<MessageInput> = (data) => {
+			if (file && !validateFile(file)) {
+				setValue(FILE_INPUT_NAME, file as unknown as string);
+				clearErrors(FILE_INPUT_NAME);
+				const filePreview = URL.createObjectURL(file);
+				setSvgUrl(filePreview);
+			}
+		},
+		// eslint-disable-next-line react-hooks/exhaustive-deps
+		[setValue]
+	);
+
+	const { getRootProps, getInputProps, isDragActive } = useDropzone({
+		onDrop,
+		accept: {
+			"image/*": ACCEPTED_IMAGE_TYPES.split(",")
+				.filter((type) => !type.includes("svg"))
+				.map((type) => `.${type.split("/")[1]}`),
+			"image/svg+xml": [".svg"],
+		},
+		maxSize: MAX_FILE_SIZE,
+		multiple: false,
+		validator: validateFile,
+	});
+
+	const onSubmit: SubmitHandler<MessageInputProps> = (data) => {
 		if (data.message_text.trim().length === 0) {
 			setError("message_text", {
 				message: "Can't submit an empty field",
 			});
 			return;
 		}
-		const message_img = data?.message_img?.[0] as unknown as HTMLImageElement;
-
+		const message_img = getValues(FILE_INPUT_NAME) as unknown as File;
 		if (isPrivateChat) {
 			sendPrivateMessage(
 				{
@@ -65,40 +163,51 @@ export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps
 				socket
 			);
 		}
+		// Clean up the file preview URL
+		if (svgUrl !== DEFAULT_SVG_URL) {
+			URL.revokeObjectURL(svgUrl);
+		}
 		setValue(INPUT_NAME, "");
+		setSvgUrl(DEFAULT_SVG_URL);
+		setValue(FILE_INPUT_NAME, undefined);
 	};
 
+	const onErrors: SubmitErrorHandler<MessageInputProps> = (errors) => {
+		if ("message_img" in errors) {
+			const message_img = getValues(FILE_INPUT_NAME) as unknown as File;
+			if (!message_img || !validateFile(message_img)) {
+				clearErrors(FILE_INPUT_NAME);
+				handleSubmit(onSubmit)();
+			}
+		}
+	};
 	return (
-		<div className="p-4 border-t">
-			<form onSubmit={handleSubmit(onSubmit)} className="flex items-center">
-				<Button
-					type="button"
-					variant="ghost"
-					size="icon"
-					className="mr-2 cursor-pointer"
-					style={{
-						backgroundImage: `url(${svgUrl})`,
-						backgroundRepeat: "no-repeat",
-						backgroundPositionX: "0",
-						backgroundSize: "24px",
-						backgroundPosition: "center",
+		<div className={cn("p-4 border-t", isDragActive && "bg-gray-100/10")}>
+			<form onSubmit={handleSubmit(onSubmit, onErrors)} className="flex items-center">
+				<FileInputElement
+					{...{
+						getRootProps,
+						errors,
+						svgUrl,
+						isDragActive,
+						getInputProps,
 					}}
-				>
+				/>
+
+				<div className="flex flex-col w-full" {...getRootProps()}>
 					<Input
-						{...register(FILE_INPUT_NAME)}
-						id="message-img"
-						type="file"
-						accept="image/png, image/jpeg"
-						className=" cursor-pointer opacity-0"
+						{...register(INPUT_NAME)}
+						type="text"
+						className={cn("flex-1", errors?.message_text ? "border-red-400" : "")}
+						placeholder="Type a message..."
+						onClick={(e) => {
+							// prevent opening file input since we are passing the getRootProps to the input wrapper
+							e.stopPropagation();
+						}}
 					/>
-				</Button>
-				<Input
-					{...register(INPUT_NAME)}
-					type="text"
-					className={cn("flex-1 ", errors?.message_text ? "border-red-400" : "")}
-					placeholder="Type a message..."
-					autoComplete="off"
-				/>
+					<ErrorMessages errors={errors} />
+				</div>
+
 				<Popover>
 					<PopoverTrigger>
 						<Button type="button" variant="ghost" size="icon" className="ml-2">
@@ -114,7 +223,6 @@ export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps
 							onEmojiClick={({ emoji }) => {
 								const currentMessageValue = getValues(INPUT_NAME);
 								const messageWithEmojiAttached = `${currentMessageValue}${emoji}`;
-
 								setValue(INPUT_NAME, messageWithEmojiAttached);
 							}}
 						/>
diff --git a/client/src/components/layout/chat-room/index.tsx b/client/src/components/layout/chat-room/index.tsx
index 3c5b9b9..8d394d5 100644
--- a/client/src/components/layout/chat-room/index.tsx
+++ b/client/src/components/layout/chat-room/index.tsx
@@ -3,7 +3,7 @@ import { ErrorResponse, SuccessResponse } from "../../../api/http-methods";
 import { SocketProvider } from "../../../context/socket.context";
 import useRoomData from "../../../hooks/useRoomData";
 import { Loader } from "../../loader";
-import { MessageInput } from "./chat-room-message-input";
+import { ChatMessageInput } from "./chat-room-message-input";
 import { ChatRoomSection } from "./chat-room-section";
 import { PrivateMessageSection } from "./private-chat-section";
 import { useLocation } from "react-router";
@@ -42,7 +42,7 @@ function ChatRoomLayout() {
 		return (
 			<section className="overflow-y-hidden grid grid-rows-[12fr_1fr] md:grid-rows-[11fr_1fr] ">
 				<PrivateMessageSection data={data ?? []} />
-				<MessageInput chatId={recipientId} chatName={""} isPrivateChat />
+				<ChatMessageInput chatId={recipientId} chatName={""} isPrivateChat />
 			</section>
 		);
 	}
@@ -51,7 +51,7 @@ function ChatRoomLayout() {
 		<section className="overflow-y-hidden grid grid-rows-[12fr_1fr] md:grid-rows-[11fr_1fr] ">
 			<ChatRoomSection data={chatData?.msg ?? []} />
 			{chatId && chatId.length > 0 ? (
-				<MessageInput chatId={chatId} chatName={roomName} />
+				<ChatMessageInput chatId={chatId} chatName={roomName} />
 			) : null}
 		</section>
 	);
diff --git a/client/src/hooks/useSendMessage.tsx b/client/src/hooks/useSendMessage.tsx
index bc43009..7941311 100644
--- a/client/src/hooks/useSendMessage.tsx
+++ b/client/src/hooks/useSendMessage.tsx
@@ -1,9 +1,27 @@
 import { Socket } from "socket.io-client";
 import useAuthStorage from "../store/useAuthStorage";
-import { MessageInput } from "./../types/index";
+import { MessageInputProps } from "./../types/index";
 import { useSocketAuth } from "./useSocketAuth";
 import { getBrowserTimeZone, getCurrentDateTimeWithTimezone } from "../lib";
 
+const convertGifToBase64 = (file: File): Promise<string> => {
+	return new Promise((resolve, reject) => {
+		const reader = new FileReader();
+		reader.onloadend = () => {
+			// Make sure the base64 string has the correct format
+			const result = reader.result as string;
+			if (!result.startsWith("data:image/gif;base64,")) {
+				// If it doesn't have the correct prefix, add it
+				resolve(`data:image/gif;base64,${result.replace(/^data:image\/gif;?base64,/, "")}`);
+			} else {
+				resolve(result);
+			}
+		};
+		reader.onerror = reject;
+		reader.readAsDataURL(file);
+	});
+};
+
 export const useSendMessage = ({ socket }: { socket: Socket | null }) => {
 	const { userId } = useAuthStorage((state) => state);
 
@@ -18,10 +36,10 @@ export const useSendMessage = ({ socket }: { socket: Socket | null }) => {
 	 *
 	 * @returns The original message payload if a socket is provided; otherwise, undefined.
 	 */
-	function sendPrivateMessage(
-		data: MessageInput & {
+	async function sendPrivateMessage(
+		data: MessageInputProps & {
 			recipientId: string;
-			imageFile?: HTMLImageElement;
+			imageFile?: HTMLImageElement | File | string;
 			imageName?: string;
 		},
 		socket: Socket | null
@@ -34,11 +52,22 @@ export const useSendMessage = ({ socket }: { socket: Socket | null }) => {
 		// If the socket is not connected, connect it
 		if (socket.connected === false) socket.connect();
 
+		/**
+		 * IF the imageFile is a gif, convert to base64
+		 */
+		let file = data?.imageFile;
+
+		if (file instanceof File) {
+			if (file.type === "image/gif") {
+				file = await convertGifToBase64(file);
+			}
+		}
+
 		socket.emit("add-private-message", {
 			recipientId: data.recipientId,
 			senderId: userId,
 			message: data.message_text,
-			imageFile: data?.imageFile,
+			imageFile: file,
 			imageName: data?.imageName,
 			created_at,
 			timezone,
@@ -56,7 +85,7 @@ export const useSendMessage = ({ socket }: { socket: Socket | null }) => {
 	 * @param data - An object containing the chat ID, chat name, and the message text to be sent.
 	 */
 	function sendMessage(
-		data: MessageInput & { chatId: string; chatName: string },
+		data: MessageInputProps & { chatId: string; chatName: string },
 		socket: Socket | null
 	) {
 		// If the socket is null, return early
diff --git a/client/src/types/index.ts b/client/src/types/index.ts
index b4fa8b9..e3a5763 100644
--- a/client/src/types/index.ts
+++ b/client/src/types/index.ts
@@ -1,4 +1,6 @@
 import { type LucideIcon } from "lucide-react";
+import { DropzoneInputProps, DropzoneRootProps } from "react-dropzone";
+import { FieldErrors } from "react-hook-form";
 
 export type ChatUserType = {
 	name: string | null;
@@ -105,7 +107,7 @@ export type PrivateChatResultType = {
   recipient: ChatUserType; 
 };
 
-export type MessageInput = {
+export type MessageInputProps = {
 	message_text: string;
 	message_img?:string
 	sent_at?:string
@@ -118,4 +120,20 @@ export interface SearchPrivateRoomProps {
 export interface CustomDialogTriggerProps {
 	triggerChild?: React.ReactNode;
 	openDialog: () => void;
-}
\ No newline at end of file
+}
+
+export interface ChatInputProps {
+	chatId: string;
+	chatName: string;
+	isPrivateChat?: boolean;
+}
+
+
+export type ErrorMessagesProps = { errors: FieldErrors<MessageInputProps> };
+export type FileInputElementProps = ErrorMessagesProps & {
+	svgUrl: string;
+	isDragActive: boolean;
+	errors: FieldErrors<MessageInputProps>;
+	getRootProps: <T extends DropzoneRootProps>(props?: T) => T;
+	getInputProps: <T extends DropzoneInputProps>(props?: T) => T;
+};
\ No newline at end of file
diff --git a/server/src/index.ts b/server/src/index.ts
index d98ed68..aebf231 100644
--- a/server/src/index.ts
+++ b/server/src/index.ts
@@ -61,7 +61,7 @@ class SocketServer {
   constructor(port: number, corsOptions: CorsOptions) {
     const upload = multer({
       dest: "uploads/", // TODO: DO WE NEED TO CHANGE THIS?
-      limits: { fileSize: 1024 * 1024 },
+      limits: { fileSize: 1024 * 1024 * 5 },
     });
 
     this.port = port;
diff --git a/server/src/model/QueryHandlers.model.ts b/server/src/model/QueryHandlers.model.ts
index 11c947d..9a7dc05 100644
--- a/server/src/model/QueryHandlers.model.ts
+++ b/server/src/model/QueryHandlers.model.ts
@@ -1,3 +1,4 @@
+import { File } from "buffer";
 import { and, asc, desc, eq, inArray, ne, or, sql } from "drizzle-orm";
 import { NodePgDatabase } from "drizzle-orm/node-postgres";
 import { connectToDB } from "../db";
@@ -992,9 +993,18 @@ export class QueryHandlers extends UserSchema {
     message: string;
     created_at: string;
     timezone: string;
-    imageFile?: Buffer;
+    imageFile?: Buffer | File | string;
     imageName?: string;
   }) {
+    try {
+      
+      if(imageFile instanceof File){
+        const arrayBuffer = await imageFile.arrayBuffer();
+        imageFile = Buffer.from(arrayBuffer);
+      } else if (typeof imageFile === "string") {
+        const cleanBase64 = imageFile.replace(/^data:image\/\w+;base64,/, '');
+        imageFile = Buffer.from(cleanBase64, "base64");
+      }
     return await this.db
       .insert(privateMessages)
       .values({
@@ -1016,6 +1026,14 @@ export class QueryHandlers extends UserSchema {
         image_file: privateMessages.image_file,
         image_name: privateMessages.image_name,
       });
+    } catch (err) {
+      // TODO: Add SENTRY logging
+      console.log(err);
+      return {
+        error: true,
+        reason: err.message,
+      };
+    }
   }
 }
 
diff --git a/server/src/types/index.ts b/server/src/types/index.ts
index 03914cf..b9bc501 100644
--- a/server/src/types/index.ts
+++ b/server/src/types/index.ts
@@ -1,3 +1,4 @@
+import { File } from "buffer";
 import { Request } from "express";
 
 export type RequestWithUser = Request & {
@@ -66,7 +67,7 @@ export interface MessageType extends MessageBase {
 
 export interface PrivateMessageBase extends MessageBase {
   fk_private_chat_id: number;
-  image_file: Buffer | string | null;
+  image_file: Buffer | File | string | null;
   image_name: string | null;
   timezone: string;
 }
@@ -124,3 +125,14 @@ export interface TypedMessage {
   messages: MessageBase | null;
   chat_user: UserBase | null;
 }
+
+
+export type AddPrivateMessageType = {
+  recipientId: number;
+  senderId: number;
+  message: string;
+  created_at: string;
+  timezone: string;
+  imageFile?: Buffer | File | string;
+  imageName?: string;
+}
\ No newline at end of file
diff --git a/server/src/web/socket.ts b/server/src/web/socket.ts
index 7727300..a06ea49 100644
--- a/server/src/web/socket.ts
+++ b/server/src/web/socket.ts
@@ -1,9 +1,14 @@
-import { Buffer } from "buffer";
+import { Buffer, File } from "buffer";
 import { StatusCodes } from "http-status-codes";
 import { Socket, Server as SocketIOServer } from "socket.io";
 import { ExtendedError } from "socket.io/dist/namespace";
 import { QueryHandlers } from "../model/QueryHandlers.model";
-import { type CbType, type ChatListType, type JWT_RETURN_USER } from "../types";
+import {
+  type CbType,
+  type ChatListType,
+  type JWT_RETURN_USER,
+  type AddPrivateMessageType,
+} from "../types";
 
 export class AppSocketBase extends QueryHandlers {
   io: SocketIOServer;
@@ -145,7 +150,7 @@ export class AppSocketBase extends QueryHandlers {
           });
 
           const chatId = insertIntoChatResponse[0].id;
-          
+
           // Add message to the message table - refactor this
           const messageResponse = await this.insertMessageToTable({
             chatId,
@@ -209,36 +214,26 @@ export class AppSocketBase extends QueryHandlers {
         message,
         imageFile,
         imageName,
-        created_at, 
-        timezone
-      }: {
-        recipientId: number;
-        senderId: number;
-        message: string;
-        created_at:string;
-        timezone:string;
-        imageFile?: Buffer;
-        imageName?: string;
-      }) => {
-      
-        if (!created_at || !timezone) {
-          return this.emitAddMessageErrorResponse(
-            null,
-            "created_at and timezone cannot be empty",
-          );
-        }
-
-        // Ensure that you do not return the passwords when selecting users
-        const [sender, receiver] = (
-          await this.getUserByUserIds({ userIdList: [senderId, recipientId] })
-        ).flat();
+        created_at,
+        timezone,
+      }: AddPrivateMessageType) => {
+        try {
+          if (!created_at || !timezone) {
+            return this.emitAddMessageErrorResponse(
+              null,
+              "created_at and timezone cannot be empty",
+            );
+          }
 
-        const privateChatsInsertResponse = (
-          await this.createPrivateChatEntry(sender, receiver)
-        )[0];
+          // Ensure that you do not return the passwords when selecting users
+          const [sender, receiver] = (
+            await this.getUserByUserIds({ userIdList: [senderId, recipientId] })
+          ).flat();
 
-        const privateMessageInsertResponse = (
-          await this.createPrivateMessage({
+          const privateChatsInsertResponse = (
+            await this.createPrivateChatEntry(sender, receiver)
+          )[0];
+          const response = await this.createPrivateMessage({
             privateChatsInsertResponse: {
               ...privateChatsInsertResponse,
               pk_private_chat_id: privateChatsInsertResponse.pk_private_chat_id,
@@ -247,64 +242,69 @@ export class AppSocketBase extends QueryHandlers {
             },
             senderId,
             message,
-            imageFile,
+            imageFile: imageFile,
             imageName,
             created_at,
             timezone,
-          })
-        )[0];
-
-        if (privateMessageInsertResponse?.image_file) {
-          // Convert Buffer to base64 string only if image_file exists and is a Buffer
-          if (Buffer.isBuffer(privateMessageInsertResponse.image_file)) {
-            const base64Image =
-              privateMessageInsertResponse.image_file.toString("base64");
-            // Cast to any to avoid type error when assigning string to Buffer type
-            (
-              privateMessageInsertResponse as unknown as { image_file: string }
-            ).image_file = base64Image;
+          });
+          if ("error" in response) {
+            return this.emitAddMessageErrorResponse(null, response.reason);
+          }
+          const privateMessageInsertResponse = response[0];
+          let base64Image: string | null = null
+          if (privateMessageInsertResponse?.image_file) {
+            // Convert Buffer to base64 string only if image_file exists and is a Buffer or a File
+            if (privateMessageInsertResponse.image_file instanceof File || Buffer.isBuffer(privateMessageInsertResponse.image_file) ) {
+              base64Image = privateMessageInsertResponse.image_file.toString("base64");
+            }else if ( typeof privateMessageInsertResponse?.image_file === "string") {
+              // If image_file is already a string, no need to convert to base64
+              // Just use it as-is since it's likely already in base64 format
+              base64Image = privateMessageInsertResponse.image_file;
+            }
           }
-        }
-
-        const addPrivateMessageSocketResponse = {
-          private_chat: {
-            pk_private_chat_id: privateChatsInsertResponse.pk_private_chat_id,
-            sender_id: privateChatsInsertResponse.sender_id,
-            recipient_id: privateChatsInsertResponse.recipient_id,
-            created_at: privateChatsInsertResponse.created_at,
-          },
-          chat_user: {
-            pk_user_id: sender.pk_user_id,
-            name: sender.name,
-            email: sender.email,
-            created_at: sender.created_at,
-          },
-          private_messages: {
-            id: privateMessageInsertResponse.id,
-            fk_private_chat_id: privateMessageInsertResponse.fk_private_chat_id,
-            fk_user_id: privateMessageInsertResponse.fk_user_id,
-            message_text: privateMessageInsertResponse.message_text,
-            sent_at: privateMessageInsertResponse.sent_at,
-            image_file: privateMessageInsertResponse.image_file,
-            image_name: privateMessageInsertResponse.image_name,
-            timezone: privateMessageInsertResponse.timezone,
-          },
-          recipient: {
-            pk_user_id: receiver.pk_user_id,
-            name: receiver.name,
-            email: receiver.email,
-          },
-        };
 
-        this.io.emit(
-          "add-private-message-response",
-          addPrivateMessageSocketResponse,
-        );
-        // Emits an event to display the most recent message sent
-        this.io.emit(
-          "get-latest-private-message-sent",
-          addPrivateMessageSocketResponse,
-        );
+          const addPrivateMessageSocketResponse = {
+            private_chat: {
+              pk_private_chat_id: privateChatsInsertResponse.pk_private_chat_id,
+              sender_id: privateChatsInsertResponse.sender_id,
+              recipient_id: privateChatsInsertResponse.recipient_id,
+              created_at: privateChatsInsertResponse.created_at,
+            },
+            chat_user: {
+              pk_user_id: sender.pk_user_id,
+              name: sender.name,
+              email: sender.email,
+              created_at: sender.created_at,
+            },
+            private_messages: {
+              id: privateMessageInsertResponse.id,
+              fk_private_chat_id: privateMessageInsertResponse.fk_private_chat_id,
+              fk_user_id: privateMessageInsertResponse.fk_user_id,
+              message_text: privateMessageInsertResponse.message_text,
+              sent_at: privateMessageInsertResponse.sent_at,
+              image_file: base64Image,
+              image_name: privateMessageInsertResponse.image_name,
+              timezone: privateMessageInsertResponse.timezone,
+            },
+            recipient: {
+              pk_user_id: receiver.pk_user_id,
+              name: receiver.name,
+              email: receiver.email,
+            },
+          };
+          this.io.emit(
+            "add-private-message-response",
+            addPrivateMessageSocketResponse,
+          );
+          // Emits an event to display the most recent message sent
+          this.io.emit(
+            "get-latest-private-message-sent",
+            addPrivateMessageSocketResponse,
+          );
+        } catch (error) {
+          // TODO: Add SENTRY logging
+          console.log(error);
+        }
       },
     );
   }


Reviews:
user: login: coderabbitai[bot]
body: **Actionable comments posted: 2**

<details>
<summary>🧹 Nitpick comments (3)</summary><blockquote>

<details>
<summary>client/src/hooks/useSendMessage.tsx (1)</summary><blockquote>

`58-61`: **Add more comprehensive file type handling**

The current implementation only handles GIF files specifically, but there could be a need to handle other image types differently in the future.

Consider making the file type handling more generic:

```diff
- let file = data?.imageFile;
- if (file instanceof File && file.type === "image/gif") {
-   file = await convertGifToBase64(file);
- }
+ let file = data?.imageFile;
+ if (file instanceof File) {
+   // Handle different file types as needed
+   if (file.type === "image/gif") {
+     file = await convertGifToBase64(file);
+   }
+   // Add more type-specific handling here if needed
+ }
```

</blockquote></details>
<details>
<summary>server/src/web/socket.ts (2)</summary><blockquote>

`253-280`: **Consider factoring out the repeated base64 logic.**  
The code handling `Buffer`, base64 strings, and `File` is correct but somewhat repetitive. A small helper function could simplify maintenance.

---

`322-324`: **Improve error handling.**  
You're logging errors to console with a TODO for Sentry. Implement full logging or open an issue to track robust error reporting.

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between f2a97d78b61ecc4de1b2aa04e4c706a5ea706849 and 68c68257eac0cb50c5e6e687fb7d4a85d428b242.

</details>

<details>
<summary>📒 Files selected for processing (8)</summary>

* `client/src/components/constants.ts` (1 hunks)
* `client/src/components/layout/chat-room/chat-room-message-input.tsx` (3 hunks)
* `client/src/hooks/useSendMessage.tsx` (3 hunks)
* `client/src/types/index.ts` (1 hunks)
* `server/src/index.ts` (1 hunks)
* `server/src/model/QueryHandlers.model.ts` (3 hunks)
* `server/src/types/index.ts` (3 hunks)
* `server/src/web/socket.ts` (4 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🧬 Code Graph Analysis (3)</summary>

<details>
<summary>server/src/web/socket.ts (1)</summary><blockquote>

<details>
<summary>server/src/types/index.ts (1)</summary>

* `AddPrivateMessageType` (130-138)

</details>

</blockquote></details>
<details>
<summary>client/src/hooks/useSendMessage.tsx (2)</summary><blockquote>

<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx (1)</summary>

* `MessageInput` (25-199)

</details>
<details>
<summary>client/src/types/index.ts (1)</summary>

* `MessageInput` (108-112)

</details>

</blockquote></details>
<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx (3)</summary><blockquote>

<details>
<summary>client/src/types/index.ts (2)</summary>

* `MessageInput` (108-112)
* `ChatInputProps` (123-127)

</details>
<details>
<summary>client/src/components/constants.ts (3)</summary>

* `DEFAULT_SVG_URL` (76-77)
* `MAX_FILE_SIZE` (74-74)
* `ACCEPTED_IMAGE_TYPES` (64-73)

</details>
<details>
<summary>client/src/lib/styles.ts (1)</summary>

* `cn` (5-7)

</details>

</blockquote></details>

</details><details>
<summary>🪛 Biome (1.9.4)</summary>

<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx</summary>

[error] 25-25: Shouldn't redeclare 'MessageInput'. Consider to delete it or rename it.

'MessageInput' is defined here:


(lint/suspicious/noRedeclare)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (40)</summary><blockquote>

<details>
<summary>server/src/index.ts (1)</summary>

`64-64`: **Increased file size limit matches client-side constant**

The maximum allowed file size for uploads was increased from 1MB to 5MB, which correctly aligns with the client-side `MAX_FILE_SIZE` constant defined in `client/src/components/constants.ts`.

</details>
<details>
<summary>client/src/types/index.ts (1)</summary>

`123-127`: **Well-structured interface for chat input props**

The new `ChatInputProps` interface properly defines the required properties for the chat input component with appropriate types. Making `isPrivateChat` optional is good design since not all chat contexts will be private.

</details>
<details>
<summary>client/src/components/constants.ts (1)</summary>

`64-77`: **Good range of supported image types and appropriate size limit**

The constants provide a comprehensive set of supported image types and a reasonable file size limit that matches the server-side configuration.

</details>
<details>
<summary>client/src/hooks/useSendMessage.tsx (4)</summary>

`7-23`: **Robust GIF to base64 conversion utility**

The `convertGifToBase64` function is well-implemented with proper error handling and ensures the correct data URL format for GIFs.

---

`39-43`: **Appropriate type extension for image files**

The function signature has been properly updated to handle various image file types with the union type `HTMLImageElement | File | string`, which provides good flexibility.

---

`55-61`: **Efficient conditional handling of GIF files**

The implementation correctly identifies GIF files and converts them to base64 format, which is necessary for proper socket transmission.

---

`63-67`: **Updated socket event with image file parameter**

The socket emit call correctly includes the potentially transformed image file.

</details>
<details>
<summary>server/src/types/index.ts (3)</summary>

`1-1`: **Verify Node.js environment support for the `File` import.**
If your environment is below Node 18, importing `File` from `"buffer"` could break. Ensure you're running a recent Node.js version that supports this feature.

---

`70-70`: **Union type for `image_file` looks good.**  
No issues with adding `File` to allow flexible image handling.

---

`128-138`: **New `AddPrivateMessageType` is consistent.**
The optional `imageFile` and `imageName` fields reflect your expanded image support. Looks good.

</details>
<details>
<summary>server/src/web/socket.ts (7)</summary>

`1-1`: **Check Node.js version for the `File` import.**  
Similar to other references, confirm the server runtime supports importing `File` from `"buffer"`.

---

`6-11`: **Imports for new types look correct.**  
The addition of `AddPrivateMessageType` aligns with your expanded image handling.

---

`217-226`: **Validation of `created_at` and `timezone` is appropriate.**  
Preventing empty timestamps/timezones for private messages ensures consistent data.

---

`230-235`: **Creating the private chat entry.**  
This new code properly retrieves sender/receiver before creating the chat entry. LGTM.

---

`245-245`: **Assigning `imageFile` is consistent.**  
No issues with passing `imageFile` to the next layer for processing.

---

`249-250`: **No concerns.**  
These lines are simply returning the database result. Looks good.

---

`282-321`: **Response object construction is clear.**  
Everything is well-defined and consistent with the new image support.

</details>
<details>
<summary>server/src/model/QueryHandlers.model.ts (4)</summary>

`1-1`: **Check compatibility for `File`;**  
Same note regarding Node.js environment support.

---

`996-997`: **Expanded `imageFile` type is consistent with the new approach.**  
Having a union of `Buffer | File | string` offers flexibility.

---

`999-1007`: **Base64 or `File` to `Buffer` conversion logic is correct.**  
Trimming the data URI prefix before decoding is a safe approach.

---

`1029-1036`: **Error handling strategy is clear.**  
FYI: returning an error object from the catch block is helpful; consider robust logging or instrumentation.

</details>
<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx (19)</summary>

`2-2`: **No issues with icon imports.**

---

`4-4`: **No issues with React imports.**

---

`5-5`: **Imports from `react-dropzone` are appropriate.**

---

`6-6`: **Hook form imports are valid.**

---

`10-10`: **Verify the static analysis note on 'MessageInput'.**  
A lint message states that re-declaring 'MessageInput' might be happening. Confirm there's no local definition overshadowing this import.

---

`13-13`: **Constants import is consistent with your file validation approach.**

---

`15-23`: **`ErrorMessages` component is well structured.**  
Effectively displays form errors.

---

`26-26`: **Default SVG state usage.**  
No issues.

---

`39-40`: **Clearing errors is fine.**

---

`43-61`: **File validation logic is solid.**  
It checks size and MIME type thoroughly.

---

`77-85`: **Drag-and-drop config matches validation constraints.**

---

`94-94`: **Casting file to `File` could cause runtime issues.**  
Confirm if you store an actual `File` object in form state or a string.

---

`118-119`: **Resetting fields on submission is appropriate.**

---

`121-126`: **Clearing `message_img` errors only if no file is fine.**

---

`128-128`: **No additional feedback.**

---

`130-156`: **Dropzone button and preview UI is well implemented.**

---

`158-158`: **No concerns with applying `getRootProps()` here.**

---

`160-167`: **Preventing click to open file dialog is appropriate.**

---

`169-170`: **Displaying error messages is handled properly.**

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-16T03:38:32Z
user: login: coderabbitai[bot]
body: **Actionable comments posted: 2**

<details>
<summary>🧹 Nitpick comments (2)</summary><blockquote>

<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx (2)</summary><blockquote>

`78-86`: **Watch out for possible mismatches in file extensions.**  
Splitting MIME types at `'/'` and tacking a dot (e.g. `"image/jpeg" → ".jpeg"`) is fine in many cases, but not all archives differentiate `.jpg` vs `.jpeg`. If you plan to support both forms, consider a more robust approach or allow `"image/*"`.

---

`123-131`: **Logic for clearing `message_img` errors could be consolidated.**  
You currently handle multiple scenarios in quick succession. Consider combining them for cleaner readability and maintenance.  

```diff
 if (isSubmitting && errors?.message_img) {
   const message_img = getValues(FILE_INPUT_NAME) as unknown as File;
-  if (!message_img) {
-    clearErrors(FILE_INPUT_NAME);
-  }
-  if (message_img || !validateFile(message_img)) {
-    clearErrors(FILE_INPUT_NAME);
-  }
+  if (!message_img || !validateFile(message_img)) {
+    clearErrors(FILE_INPUT_NAME);
+  }
 }
```

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between bff7e8a4b82dea5fede0525156ca56346b6915dc and 10d55891428e10b2af663168fe368ef491aacc60.

</details>

<details>
<summary>📒 Files selected for processing (4)</summary>

* `client/src/components/constants.ts` (1 hunks)
* `client/src/components/layout/chat-room/chat-room-message-input.tsx` (3 hunks)
* `client/src/hooks/useSendMessage.tsx` (3 hunks)
* `server/src/web/socket.ts` (4 hunks)

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (3)</summary>

* client/src/components/constants.ts
* server/src/web/socket.ts
* client/src/hooks/useSendMessage.tsx

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 Biome (1.9.4)</summary>

<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx</summary>

[error] 25-25: Shouldn't redeclare 'MessageInput'. Consider to delete it or rename it.

'MessageInput' is defined here:


(lint/suspicious/noRedeclare)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (4)</summary><blockquote>

<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx (4)</summary>

`2-13`: **All imports are well-structured.**  
No issues noted.

---

`15-23`: **Good addition of the `ErrorMessages` component.**  
Makes displaying form errors more manageable.

---

`43-61`: **Overall, file validation logic looks correct.**  
You gracefully check file size and MIME type, returning early on errors. This helps ensure consistent handling of invalid files.

---

`63-76`: **Condition ensures only valid files are set.**  
This reversed condition aligns properly with the desired logic of skipping invalid files.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-16T16:06:00Z
user: login: lesleyfon
state: COMMENTED
author_association: OWNER
submitted_at: 2025-04-16T16:07:27Z
user: login: coderabbitai[bot]
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-16T16:07:52Z
user: login: lesleyfon
state: COMMENTED
author_association: OWNER
submitted_at: 2025-04-16T16:11:53Z
user: login: coderabbitai[bot]
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-16T16:12:21Z
user: login: coderabbitai[bot]
body: **Actionable comments posted: 4**

<details>
<summary>♻️ Duplicate comments (1)</summary><blockquote>

<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx (1)</summary><blockquote>

`68-68`: **The `MessageInput` component name conflicts with the imported type.**

A type and a component share the same name (`MessageInput`), which can trigger linter errors and hamper readability, as noted in a previous comment. This naming collision should be resolved.


```diff
-export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps) {
+export function ChatMessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps) {
```

</blockquote></details>

</blockquote></details>

<details>
<summary>🧹 Nitpick comments (2)</summary><blockquote>

<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx (2)</summary><blockquote>

`86-104`: **Improve file validation with early returns for better readability.**

The current validation function builds up error state and then returns it at the end. Using early returns would make the code more readable and maintainable.


```diff
const validateFile = (file: File): FileError | null => {
-   let message = null;
-   let code = null;
    const fileType = file.type;

    if (file.size > MAX_FILE_SIZE) {
-       message = "File size is too large";
-       code = "file-size-too-large";
+       setError("message_img", { message: "File size is too large" });
+       return { message: "File size is too large", code: "file-size-too-large" };
    }
    if (!ACCEPTED_IMAGE_TYPES.includes(fileType)) {
-       message = "File type is not supported";
-       code = "file-type-not-supported";
+       setError("message_img", { message: "File type is not supported" });
+       return { message: "File type is not supported", code: "file-type-not-supported" };
    }
-   if (message && code) {
-       setError("message_img", { message });
-       return { message, code };
-   }
    return null;
};
```

---

`166-171`: **Improve error handling logic during submission.**

The current approach to clearing errors during submission is complex and may lead to unexpected behavior. Consider simplifying this logic.


```diff
-if (isSubmitting && errors?.message_img) {
-   const message_img = getValues(FILE_INPUT_NAME) as unknown as File;
-   if (!message_img || !validateFile(message_img)) {
-       clearErrors(FILE_INPUT_NAME);
-   }
-}
+// Instead, handle this in the onSubmit handler
+const onSubmit: SubmitHandler<MessageInputProps> = (data) => {
+   // ...existing code...
+   
+   // Clear image errors if there's no file or if file is valid
+   if (errors?.message_img) {
+       const message_img = getValues(FILE_INPUT_NAME) as unknown as File;
+       if (!message_img || !validateFile(message_img)) {
+           clearErrors(FILE_INPUT_NAME);
+       }
+   }
+   
+   // ...rest of the submission code...
+}
```

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 10d55891428e10b2af663168fe368ef491aacc60 and 679c8c2c36edd78029e8ed443a6a1fb5c194e357.

</details>

<details>
<summary>📒 Files selected for processing (2)</summary>

* `client/src/components/layout/chat-room/chat-room-message-input.tsx` (3 hunks)
* `client/src/types/index.ts` (3 hunks)

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary>

* client/src/types/index.ts

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🧠 Learnings (1)</summary>

<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx (1)</summary>

```
Learnt from: lesleyfon
PR: lesleyfon/chatapp#23
File: client/src/components/layout/chat-room/chat-room-message-input.tsx:135-163
Timestamp: 2025-04-16T16:12:20.124Z
Learning: In React Dropzone implementations, it's valid to apply `getRootProps()` to multiple sibling elements to create separate drop targets that all trigger the same `onDrop` callback. This pattern was intentionally used in the chat message input component to allow files to be dropped on either the image button or the text input area.
```

</details>

</details><details>
<summary>🧬 Code Graph Analysis (1)</summary>

<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx (5)</summary><blockquote>

<details>
<summary>client/src/types/index.ts (4)</summary>

* `ErrorMessagesProps` (132-132)
* `MessageInputProps` (110-114)
* `FileInputElementProps` (133-139)
* `ChatInputProps` (125-129)

</details>
<details>
<summary>client/src/components/ui/button.tsx (1)</summary>

* `Button` (53-53)

</details>
<details>
<summary>client/src/lib/styles.ts (1)</summary>

* `cn` (5-7)

</details>
<details>
<summary>client/src/components/constants.ts (3)</summary>

* `DEFAULT_SVG_URL` (76-77)
* `MAX_FILE_SIZE` (74-74)
* `ACCEPTED_IMAGE_TYPES` (64-73)

</details>
<details>
<summary>client/src/components/ui/input.tsx (1)</summary>

* `Input` (24-24)

</details>

</blockquote></details>

</details>

</details>

<details>
<summary>🔇 Additional comments (5)</summary><blockquote>

<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx (5)</summary>

`135-163`: **Good implementation of the form submission logic.**

The form submission logic correctly handles the chat message input with the new image upload functionality. It correctly differentiates between private and regular chats, and resets form state after submission.

---

`121-129`: **Well-configured React Dropzone.**

The dropzone configuration is well set up with appropriate options for file acceptance, size limits, and validation.

---

`173-198`: **Effective implementation of multiple dropzone targets.**

As noted in the retrieved learning, you've correctly implemented multiple dropzone targets by applying `getRootProps()` to sibling elements. This provides users with flexibility to drop files on either the image button or the text input area.

---

`30-66`: **Well-structured FileInputElement component.**

The FileInputElement component is well-structured and properly implements conditional rendering based on whether an image is selected. The styling also reacts appropriately to drag states and validation errors.

---

`20-28`: **Clean error message display component.**

The ErrorMessages component is clean and effectively renders error messages from the form state.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-16T16:37:37Z
user: login: lesleyfon
state: COMMENTED
author_association: OWNER
submitted_at: 2025-04-16T17:17:20Z
user: login: coderabbitai[bot]
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-16T17:18:19Z
user: login: coderabbitai[bot]
body: **Actionable comments posted: 0**

<details>
<summary>♻️ Duplicate comments (6)</summary><blockquote>

<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx (6)</summary><blockquote>

`11-15`: **Avoid type and component name collision.**

The `MessageInputProps` type is imported here, but the component is also named `MessageInput`, which can lead to naming conflicts and linter errors (as indicated by the Biome error in previous comments).


```diff
import {
	type MessageInputProps,
	type ChatInputProps,
	type ErrorMessagesProps,
	type FileInputElementProps,
} from "../../../types";
```

---

`68-68`: **Rename the component to avoid type name collision.**

The component name `MessageInput` conflicts with the imported type `MessageInputProps`. This has been flagged by linter (see previous Biome error).


```diff
-export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps) {
+export function ChatMessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps) {
```

---

`104-104`: **Use more explicit type handling for file input.**

Casting a `File` to `unknown` and then to `string` is error-prone. This approach bypasses type safety.


```diff
-setValue(FILE_INPUT_NAME, file as unknown as string);
+// Better approach would be to update MessageInputProps type to accept File
+setValue(FILE_INPUT_NAME, file);
```

---

`116-118`: **Use simplified image type acceptance pattern.**

Based on your previous feedback and the learning added, using `"image/*": []` is preferred over mapping MIME types to file extensions, especially for types like `image/svg+xml`.


```diff
accept: {
-	"image/*": ACCEPTED_IMAGE_TYPES.split(",").map((type) => `.${type.split("/")[1]}`),
+	"image/*": [], // Accept all image types and rely on validateFile function
},
```

---

`131-131`: **Add null check before using message_img.**

The image file is accessed without verifying its existence, which could lead to errors when no image is selected.


```diff
-const message_img = getValues(FILE_INPUT_NAME) as unknown as File;
+const message_img = getValues(FILE_INPUT_NAME) as unknown as File | undefined;
```

---

`69-69`: **Add useEffect cleanup for object URLs.**

While you've added cleanup in the onSubmit handler, you should also add a cleanup function in a useEffect to handle component unmount scenarios.


```diff
export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps) {
	const [svgUrl, setSvgUrl] = useState(DEFAULT_SVG_URL);
+	useEffect(() => {
+		return () => {
+			// Cleanup when component unmounts
+			if (svgUrl !== DEFAULT_SVG_URL) {
+				URL.revokeObjectURL(svgUrl);
+			}
+		};
+	}, [svgUrl]);
```

</blockquote></details>

</blockquote></details>

<details>
<summary>🧹 Nitpick comments (2)</summary><blockquote>

<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx (2)</summary><blockquote>

`4-5`: **Remember to import useEffect.**

If implementing the suggested cleanup effect, don't forget to add useEffect to your imports.


```diff
-import { useState, useCallback } from "react";
+import { useState, useCallback, useEffect } from "react";
```

---

`99-111`: **Consider adding safeguards for file handling in onDrop.**

The current implementation assumes files will always be present in the acceptedFiles array. Add a check to handle empty arrays gracefully.


```diff
const onDrop = useCallback(
	(acceptedFiles: File[]) => {
+		if (!acceptedFiles.length) return;
		const file = acceptedFiles[0];

		if (file && !validateFile(file)) {
			setValue(FILE_INPUT_NAME, file as unknown as string);
			clearErrors(FILE_INPUT_NAME);
			const filePreview = URL.createObjectURL(file);
			setSvgUrl(filePreview);
		}
	},
	// eslint-disable-next-line react-hooks/exhaustive-deps
	[setValue]
);
```

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between de6ac1cfa41f97b4e1731ffa477b4adadfa44a4f and 99242884278f3e36950014a4bf0679e1c8f3b2c3.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `client/src/components/layout/chat-room/chat-room-message-input.tsx` (3 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🧠 Learnings (1)</summary>

<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx (2)</summary>

```
Learnt from: lesleyfon
PR: lesleyfon/chatapp#23
File: client/src/components/layout/chat-room/chat-room-message-input.tsx:135-163
Timestamp: 2025-04-16T16:12:20.124Z
Learning: In React Dropzone implementations, it's valid to apply `getRootProps()` to multiple sibling elements to create separate drop targets that all trigger the same `onDrop` callback. This pattern was intentionally used in the chat message input component to allow files to be dropped on either the image button or the text input area.
```

```
Learnt from: lesleyfon
PR: lesleyfon/chatapp#23
File: client/src/components/layout/chat-room/chat-room-message-input.tsx:116-118
Timestamp: 2025-04-16T17:18:17.837Z
Learning: For the react-dropzone library's accept property, use `"image/*": []` instead of trying to map MIME types to file extensions (especially for types like image/svg+xml). This allows accepting all image types while relying on a separate validation function to enforce specific MIME type restrictions.
```

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (4)</summary><blockquote>

<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx (4)</summary>

`154-156`: **Good implementation of object URL cleanup.**

Proper cleanup of object URLs is essential to prevent memory leaks. Well done on implementing this in the submission handler.

---

`135-163`: **LGTM: The form submission logic looks good.**

The submission logic correctly handles both regular and private chat messages, including image file handling. The conditional URL revocation and state reset after submission are properly implemented.

---

`30-66`: **Well-structured FileInputElement component.**

Great job extracting the file input UI into a separate component with clear props. The conditional rendering between the icon and image preview is clean and the styling based on different states (drag active, errors) enhances user experience.

---

`184-196`: **Valid implementation of multiple dropzone targets.**

Using `getRootProps()` on multiple sibling elements is a valid approach with React Dropzone, allowing users to drop files on either the image button or the text input area. The `stopPropagation()` in the input's onClick handler is a nice touch to prevent the file dialog from opening when clicking the text input.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-16T17:23:22Z
user: login: lesleyfon
state: COMMENTED
author_association: OWNER
submitted_at: 2025-04-16T17:27:41Z
user: login: coderabbitai[bot]
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-16T17:28:13Z

Review comments:
diff_hunk: @@ -56,4 +56,22 @@ export const INPUT_NAME = "new-chat-name";
 /**
  * @description - The error field names for the new chat room.
  */
-export const ERROR_FIELD_NAMES = [INPUT_NAME, "new-chat-name-error", "new-chat-name-internal-error"];
\ No newline at end of file
+export const ERROR_FIELD_NAMES = [INPUT_NAME, "new-chat-name-error", "new-chat-name-internal-error"];
+
+/**
+ * @description - The accepted image types.
+ */
+export const ACCEPTED_IMAGE_TYPES = [
+  "image/png",
+  "image/jpeg",
+  "image/jpg",
+  "image/gif",
+  "image/webp",
+  "image/svg",
+  "image/heic",
+  "image/heif"
+].join(", ");
path: client/src/components/constants.ts
user: login: coderabbitai[bot]
body: _⚠️ Potential issue_

**Fix MIME type for SVG images**

The MIME type for SVG images should be "image/svg+xml" instead of "image/svg" to follow the standard specification.

```diff
-  "image/svg",
+  "image/svg+xml",
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
export const ACCEPTED_IMAGE_TYPES = [
  "image/png",
  "image/jpeg",
  "image/jpg",
  "image/gif",
  "image/webp",
  "image/svg+xml",
  "image/heic",
  "image/heif"
].join(", ");
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->

✅ Addressed in commits fc19609 to 10d5589
created_at: 2025-04-16T03:38:31Z
author_association: CONTRIBUTOR
diff_hunk: @@ -32,17 +36,62 @@ export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps
 		setValue,
 		getValues,
 		setError,
-		formState: { errors },
+		clearErrors,
+		formState: { errors, isSubmitting },
 	} = useForm<MessageInput>();
 
+	const validateFile = (file: File): FileError | null => {
+		let message = null;
+		let code = null;
+		const fileType = file.type;
+
+		if (file.size > MAX_FILE_SIZE) {
+			message = "File size is too large";
+			code = "file-size-too-large";
+		}
+		if (!ACCEPTED_IMAGE_TYPES.includes(fileType)) {
+			message = "File type is not supported";
+			code = "file-type-not-supported";
+		}
+		if (message && code) {
+			setError("message_img", { message });
+			return { message, code };
+		}
+		return null;
+	};
+
+	const onDrop = useCallback(
+		(acceptedFiles: File[]) => {
+			const file = acceptedFiles[0];
+
+			if (file && validateFile(file)) {
+				setValue(FILE_INPUT_NAME, file as unknown as string);
+				const filePreview = URL.createObjectURL(file);
+				setSvgUrl(filePreview);
+			}
+		},
+		// eslint-disable-next-line react-hooks/exhaustive-deps
+		[setValue]
+	);
path: client/src/components/layout/chat-room/chat-room-message-input.tsx
user: login: coderabbitai[bot]
body: _⚠️ Potential issue_

**Reverse the condition to skip setting invalid files.**
Currently, `if (file && validateFile(file)) { ... }` triggers on error. Use `if (file && !validateFile(file))` to only accept valid files and set the preview.  

```diff
-if (file && validateFile(file)) {
+if (file && !validateFile(file)) {
   setValue(FILE_INPUT_NAME, file as unknown as string);
   const filePreview = URL.createObjectURL(file);
   setSvgUrl(filePreview);
}
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
	const onDrop = useCallback(
		(acceptedFiles: File[]) => {
			const file = acceptedFiles[0];

			if (file && !validateFile(file)) {
				setValue(FILE_INPUT_NAME, file as unknown as string);
				const filePreview = URL.createObjectURL(file);
				setSvgUrl(filePreview);
			}
		},
		// eslint-disable-next-line react-hooks/exhaustive-deps
		[setValue]
	);
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->

✅ Addressed in commits fc19609 to 10d5589
created_at: 2025-04-16T03:38:31Z
author_association: CONTRIBUTOR
diff_hunk: @@ -66,39 +116,64 @@ export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps
 			);
 		}
 		setValue(INPUT_NAME, "");
+		setSvgUrl(DEFAULT_SVG_URL);
+		setValue(FILE_INPUT_NAME, undefined);
 	};
 
+	if (isSubmitting && errors?.message_img) {
+		const message_img = getValues(FILE_INPUT_NAME) as unknown as File;
+		if (!message_img) {
+			clearErrors(FILE_INPUT_NAME);
+		}
+		if (message_img || !validateFile(message_img)) {
+			clearErrors(FILE_INPUT_NAME);
+		}
+	}
 	return (
-		<div className="p-4 border-t">
+		<div className={cn("p-4 border-t", isDragActive && "bg-gray-100/10")}>
 			<form onSubmit={handleSubmit(onSubmit)} className="flex items-center">
-				<Button
-					type="button"
-					variant="ghost"
-					size="icon"
-					className="mr-2 cursor-pointer"
-					style={{
-						backgroundImage: `url(${svgUrl})`,
-						backgroundRepeat: "no-repeat",
-						backgroundPositionX: "0",
-						backgroundSize: "24px",
-						backgroundPosition: "center",
-					}}
-				>
+				<div {...getRootProps()}>
+					<input {...getInputProps()} />
+					<Button
+						type="button"
+						variant="ghost"
+						size="icon"
+						className={cn(
+							"mr-2 cursor-pointer relative overflow-hidden",
+							errors?.message_img && "border-[1px] border-red-400",
+							isDragActive && "bg-gray-100 border-[1px] border-green-300"
+						)}
+					>
+						{svgUrl === DEFAULT_SVG_URL ? (
+							<ImageIcon className="h-5 w-5" />
+						) : (
+							<div
+								className="w-full h-full absolute inset-0"
+								style={{
+									backgroundImage: `url(${svgUrl})`,
+									backgroundRepeat: "no-repeat",
+									backgroundSize: "cover",
+									backgroundPosition: "center",
+								}}
+							/>
+						)}
+					</Button>
+				</div>
+
+				<div className="flex flex-col w-full" {...getRootProps()}>
path: client/src/components/layout/chat-room/chat-room-message-input.tsx
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Avoid wrapping multiple elements with `getRootProps()`.**  
You’re applying `getRootProps()` to both the preview button container (line 135) and the input wrapper (line 163), which can lead to nested dropzones. Typically, React Dropzone expects a single root per drop area. Consider consolidating them into one container.

<!-- This is an auto-generated reply by CodeRabbit -->
created_at: 2025-04-16T16:05:59Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,25 +1,29 @@
 import EmojiPicker, { Theme } from "emoji-picker-react";
-import { SendIcon, SmileIcon } from "lucide-react";
+import { SendIcon, SmileIcon, ImageIcon } from "lucide-react";
 import { Button } from "../../ui/button";
-
-import { SubmitHandler, useForm } from "react-hook-form";
+import { useState, useCallback } from "react";
+import { FileError, useDropzone } from "react-dropzone";
+import { FieldErrors, SubmitHandler, useForm } from "react-hook-form";
 import { useSendMessage } from "../../../hooks/useSendMessage";
 import { useSocket } from "../../../hooks/useSocket";
 import { cn, getCurrentDateTimeWithTimezone } from "../../../lib";
-import { type MessageInput } from "../../../types";
+import { type MessageInput, type ChatInputProps } from "../../../types";
 import { Input } from "../../ui/input";
 import { Popover, PopoverContent, PopoverTrigger } from "../../ui/popover";
+import { ACCEPTED_IMAGE_TYPES, DEFAULT_SVG_URL, MAX_FILE_SIZE } from "../../constants";
 
-interface ChatInputProps {
-	chatId: string;
-	chatName: string;
-	isPrivateChat?: boolean;
-}
-// BUTTON Background Image
-const svgUrl =
-	"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IndoaXRlIiBzdHJva2Utd2lkdGg9IjEiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgY2xhc3M9Imx1Y2lkZSBsdWNpZGUtcGFwZXJjbGlwIj48cGF0aCBkPSJNMTMuMjM0IDIwLjI1MiAyMSAxMi4zIi8+PHBhdGggZD0ibTE2IDYtOC40MTQgOC41ODZhMiAyIDAgMCAwIDAgMi44MjggMiAyIDAgMCAwIDIuODI4IDBsOC40MTQtOC41ODZhNCA0IDAgMCAwIDAtNS42NTYgNCA0IDAgMCAwLTUuNjU2IDBsLTguNDE1IDguNTg1YTYgNiAwIDEgMCA4LjQ4NiA4LjQ4NiIvPjwvc3ZnPg==";
+const ErrorMessages = ({ errors }: { errors: FieldErrors<MessageInput> }) => (
+	<div className="flex flex-col">
+		{Object.keys(errors).map((error) => (
+			<p key={error} className="text-red-400 text-xs">
+				{errors[error as keyof MessageInput]?.message as string}
+			</p>
+		))}
+	</div>
+);
 
 export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps) {
path: client/src/components/layout/chat-room/chat-room-message-input.tsx
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Rename one of the `MessageInput` declarations to avoid confusion.**  
A type and a component share the same name, which can trigger linter errors and hamper readability.  

```diff
-export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps) {
+export function ChatMessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps) {
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
export function ChatMessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps) {
`````

</details>

<!-- suggestion_end -->

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Biome (1.9.4)</summary>

[error] 25-25: Shouldn't redeclare 'MessageInput'. Consider to delete it or rename it.

'MessageInput' is defined here:


(lint/suspicious/noRedeclare)

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit -->

✅ Addressed in commit 674aa88
created_at: 2025-04-16T16:05:59Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1016,6 +1026,14 @@ export class QueryHandlers extends UserSchema {
         image_file: privateMessages.image_file,
         image_name: privateMessages.image_name,
       });
+    } catch (err) {
+      // TODO: Add SENTRY logging
path: server/src/model/QueryHandlers.model.ts
user: login: lesleyfon
body: #24 Issue for adding logging. Thanks @coderabbitai
created_at: 2025-04-16T16:07:27Z
author_association: OWNER
diff_hunk: @@ -1016,6 +1026,14 @@ export class QueryHandlers extends UserSchema {
         image_file: privateMessages.image_file,
         image_name: privateMessages.image_name,
       });
+    } catch (err) {
+      // TODO: Add SENTRY logging
path: server/src/model/QueryHandlers.model.ts
user: login: coderabbitai[bot]
body: @lesleyfon You're welcome! Thanks for creating issue #24 to track the Sentry logging implementation. Good practice to separate concerns and handle it in a dedicated issue.


<!-- <agentComponentType>chat-answer</agentComponentType> -->

<!-- <rawResChunk><answer>@lesleyfon You're welcome! Thanks for creating issue #24 to track the Sentry logging implementation. Good practice to separate concerns and handle it in a dedicated issue.</answer></rawResChunk> -->

<!-- This is an auto-generated reply by CodeRabbit -->
created_at: 2025-04-16T16:07:52Z
author_association: CONTRIBUTOR
diff_hunk: @@ -66,39 +116,64 @@ export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps
 			);
 		}
 		setValue(INPUT_NAME, "");
+		setSvgUrl(DEFAULT_SVG_URL);
+		setValue(FILE_INPUT_NAME, undefined);
 	};
 
+	if (isSubmitting && errors?.message_img) {
+		const message_img = getValues(FILE_INPUT_NAME) as unknown as File;
+		if (!message_img) {
+			clearErrors(FILE_INPUT_NAME);
+		}
+		if (message_img || !validateFile(message_img)) {
+			clearErrors(FILE_INPUT_NAME);
+		}
+	}
 	return (
-		<div className="p-4 border-t">
+		<div className={cn("p-4 border-t", isDragActive && "bg-gray-100/10")}>
 			<form onSubmit={handleSubmit(onSubmit)} className="flex items-center">
-				<Button
-					type="button"
-					variant="ghost"
-					size="icon"
-					className="mr-2 cursor-pointer"
-					style={{
-						backgroundImage: `url(${svgUrl})`,
-						backgroundRepeat: "no-repeat",
-						backgroundPositionX: "0",
-						backgroundSize: "24px",
-						backgroundPosition: "center",
-					}}
-				>
+				<div {...getRootProps()}>
+					<input {...getInputProps()} />
+					<Button
+						type="button"
+						variant="ghost"
+						size="icon"
+						className={cn(
+							"mr-2 cursor-pointer relative overflow-hidden",
+							errors?.message_img && "border-[1px] border-red-400",
+							isDragActive && "bg-gray-100 border-[1px] border-green-300"
+						)}
+					>
+						{svgUrl === DEFAULT_SVG_URL ? (
+							<ImageIcon className="h-5 w-5" />
+						) : (
+							<div
+								className="w-full h-full absolute inset-0"
+								style={{
+									backgroundImage: `url(${svgUrl})`,
+									backgroundRepeat: "no-repeat",
+									backgroundSize: "cover",
+									backgroundPosition: "center",
+								}}
+							/>
+						)}
+					</Button>
+				</div>
+
+				<div className="flex flex-col w-full" {...getRootProps()}>
path: client/src/components/layout/chat-room/chat-room-message-input.tsx
user: login: lesleyfon
body: its not nested; it is two separate sibling elements 
created_at: 2025-04-16T16:11:53Z
author_association: OWNER
diff_hunk: @@ -66,39 +116,64 @@ export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps
 			);
 		}
 		setValue(INPUT_NAME, "");
+		setSvgUrl(DEFAULT_SVG_URL);
+		setValue(FILE_INPUT_NAME, undefined);
 	};
 
+	if (isSubmitting && errors?.message_img) {
+		const message_img = getValues(FILE_INPUT_NAME) as unknown as File;
+		if (!message_img) {
+			clearErrors(FILE_INPUT_NAME);
+		}
+		if (message_img || !validateFile(message_img)) {
+			clearErrors(FILE_INPUT_NAME);
+		}
+	}
 	return (
-		<div className="p-4 border-t">
+		<div className={cn("p-4 border-t", isDragActive && "bg-gray-100/10")}>
 			<form onSubmit={handleSubmit(onSubmit)} className="flex items-center">
-				<Button
-					type="button"
-					variant="ghost"
-					size="icon"
-					className="mr-2 cursor-pointer"
-					style={{
-						backgroundImage: `url(${svgUrl})`,
-						backgroundRepeat: "no-repeat",
-						backgroundPositionX: "0",
-						backgroundSize: "24px",
-						backgroundPosition: "center",
-					}}
-				>
+				<div {...getRootProps()}>
+					<input {...getInputProps()} />
+					<Button
+						type="button"
+						variant="ghost"
+						size="icon"
+						className={cn(
+							"mr-2 cursor-pointer relative overflow-hidden",
+							errors?.message_img && "border-[1px] border-red-400",
+							isDragActive && "bg-gray-100 border-[1px] border-green-300"
+						)}
+					>
+						{svgUrl === DEFAULT_SVG_URL ? (
+							<ImageIcon className="h-5 w-5" />
+						) : (
+							<div
+								className="w-full h-full absolute inset-0"
+								style={{
+									backgroundImage: `url(${svgUrl})`,
+									backgroundRepeat: "no-repeat",
+									backgroundSize: "cover",
+									backgroundPosition: "center",
+								}}
+							/>
+						)}
+					</Button>
+				</div>
+
+				<div className="flex flex-col w-full" {...getRootProps()}>
path: client/src/components/layout/chat-room/chat-room-message-input.tsx
user: login: coderabbitai[bot]
body: @lesleyfon You're absolutely right! I see now that they are indeed sibling elements, not nested. This is a valid approach with React Dropzone - having multiple elements with `getRootProps()` creates separate drop targets that all trigger the same `onDrop` callback. Thanks for the clarification.

---

<details>
<summary>✏️ Learnings added</summary>

```
Learnt from: lesleyfon
PR: lesleyfon/chatapp#23
File: client/src/components/layout/chat-room/chat-room-message-input.tsx:135-163
Timestamp: 2025-04-16T16:12:20.124Z
Learning: In React Dropzone implementations, it's valid to apply `getRootProps()` to multiple sibling elements to create separate drop targets that all trigger the same `onDrop` callback. This pattern was intentionally used in the chat message input component to allow files to be dropped on either the image button or the text input area.
```

> Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings).

</details>




<!-- <agentComponentType>chat-answer</agentComponentType> -->

<!-- <rawResChunk><answer>@lesleyfon You're absolutely right! I see now that they are indeed sibling elements, not nested. This is a valid approach with React Dropzone - having multiple elements with `getRootProps()` creates separate drop targets that all trigger the same `onDrop` callback. Thanks for the clarification.

---

<details>
<summary>✏️ Learnings added</summary>

```
Learnt from: lesleyfon
PR: lesleyfon/chatapp#23
File: client/src/components/layout/chat-room/chat-room-message-input.tsx:135-163
Timestamp: 2025-04-16T16:12:20.124Z
Learning: In React Dropzone implementations, it's valid to apply `getRootProps()` to multiple sibling elements to create separate drop targets that all trigger the same `onDrop` callback. This pattern was intentionally used in the chat message input component to allow files to be dropped on either the image button or the text input area.
```

> Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings).

</details>

</answer></rawResChunk> -->

<!-- This is an auto-generated reply by CodeRabbit -->
created_at: 2025-04-16T16:12:21Z
author_association: CONTRIBUTOR
diff_hunk: @@ -66,39 +159,44 @@ export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps
 			);
 		}
 		setValue(INPUT_NAME, "");
+		setSvgUrl(DEFAULT_SVG_URL);
+		setValue(FILE_INPUT_NAME, undefined);
path: client/src/components/layout/chat-room/chat-room-message-input.tsx
user: login: coderabbitai[bot]
body: _⚠️ Potential issue_

**Add cleanup for object URLs to prevent memory leaks.**

URLs created with `URL.createObjectURL()` should be revoked when no longer needed to prevent memory leaks.


```diff
const onSubmit: SubmitHandler<MessageInputProps> = (data) => {
  // existing code...
  
+  // Revoke the object URL to prevent memory leaks
+  if (svgUrl !== DEFAULT_SVG_URL) {
+    URL.revokeObjectURL(svgUrl);
+  }
  setSvgUrl(DEFAULT_SVG_URL);
  setValue(FILE_INPUT_NAME, undefined);
};
```

Also consider adding a cleanup function in a useEffect:

```jsx
useEffect(() => {
  return () => {
    // Cleanup when component unmounts
    if (svgUrl !== DEFAULT_SVG_URL) {
      URL.revokeObjectURL(svgUrl);
    }
  };
}, [svgUrl]);
```

<!-- This is an auto-generated comment by CodeRabbit -->

✅ Addressed in commit 9924288
created_at: 2025-04-16T16:37:36Z
author_association: CONTRIBUTOR
diff_hunk: @@ -32,17 +79,63 @@ export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps
 		setValue,
 		getValues,
 		setError,
-		formState: { errors },
-	} = useForm<MessageInput>();
+		clearErrors,
+		formState: { errors, isSubmitting },
+	} = useForm<MessageInputProps>();
+
+	const validateFile = (file: File): FileError | null => {
+		let message = null;
+		let code = null;
+		const fileType = file.type;
+
+		if (file.size > MAX_FILE_SIZE) {
+			message = "File size is too large";
+			code = "file-size-too-large";
+		}
+		if (!ACCEPTED_IMAGE_TYPES.includes(fileType)) {
+			message = "File type is not supported";
+			code = "file-type-not-supported";
+		}
+		if (message && code) {
+			setError("message_img", { message });
+			return { message, code };
+		}
+		return null;
+	};
 
-	const onSubmit: SubmitHandler<MessageInput> = (data) => {
+	const onDrop = useCallback(
+		(acceptedFiles: File[]) => {
+			const file = acceptedFiles[0];
+
+			if (file && !validateFile(file)) {
+				setValue(FILE_INPUT_NAME, file as unknown as string);
+				clearErrors(FILE_INPUT_NAME);
+				const filePreview = URL.createObjectURL(file);
+				setSvgUrl(filePreview);
+			}
+		},
+		// eslint-disable-next-line react-hooks/exhaustive-deps
+		[setValue]
+	);
+
+	const { getRootProps, getInputProps, isDragActive } = useDropzone({
+		onDrop,
+		accept: {
+			"image/*": ACCEPTED_IMAGE_TYPES.split(",").map((type) => `.${type.split("/")[1]}`),
+		},
path: client/src/components/layout/chat-room/chat-room-message-input.tsx
user: login: coderabbitai[bot]
body: _⚠️ Potential issue_

**Fix incorrect file type extension mapping.**

The current approach to map accepted MIME types to file extensions won't work as expected. MIME types like `image/svg+xml` will result in invalid extensions.


```diff
accept: {
-   "image/*": ACCEPTED_IMAGE_TYPES.split(",").map((type) => `.${type.split("/")[1]}`),
+   "image/*": [],  // This will accept all image types
},
```

Alternatively, if you need to restrict to specific types:

```diff
accept: {
-   "image/*": ACCEPTED_IMAGE_TYPES.split(",").map((type) => `.${type.split("/")[1]}`),
+   "image/*": [".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg", ".heic", ".heif"],
},
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
		accept: {
			"image/*": [".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg", ".heic", ".heif"],  // Only allow specific image types
		},
`````

`````suggestion
		accept: {
			"image/*": [],  // This will accept all image types
		},
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated reply by CodeRabbit -->

✅ Addressed in commit 674aa88

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-04-16T16:37:36Z
author_association: CONTRIBUTOR
diff_hunk: @@ -32,17 +79,63 @@ export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps
 		setValue,
 		getValues,
 		setError,
-		formState: { errors },
-	} = useForm<MessageInput>();
+		clearErrors,
+		formState: { errors, isSubmitting },
+	} = useForm<MessageInputProps>();
+
+	const validateFile = (file: File): FileError | null => {
+		let message = null;
+		let code = null;
+		const fileType = file.type;
+
+		if (file.size > MAX_FILE_SIZE) {
+			message = "File size is too large";
+			code = "file-size-too-large";
+		}
+		if (!ACCEPTED_IMAGE_TYPES.includes(fileType)) {
+			message = "File type is not supported";
+			code = "file-type-not-supported";
+		}
+		if (message && code) {
+			setError("message_img", { message });
+			return { message, code };
+		}
+		return null;
+	};
 
-	const onSubmit: SubmitHandler<MessageInput> = (data) => {
+	const onDrop = useCallback(
+		(acceptedFiles: File[]) => {
+			const file = acceptedFiles[0];
+
+			if (file && !validateFile(file)) {
+				setValue(FILE_INPUT_NAME, file as unknown as string);
+				clearErrors(FILE_INPUT_NAME);
+				const filePreview = URL.createObjectURL(file);
+				setSvgUrl(filePreview);
+			}
path: client/src/components/layout/chat-room/chat-room-message-input.tsx
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Use more explicit type handling for file input.**

The current approach of casting a `File` to `unknown` and then to `string` is error-prone. Consider updating the form's type definition or using a more explicit approach.


```diff
if (file && !validateFile(file)) {
-   setValue(FILE_INPUT_NAME, file as unknown as string);
+   // Better approach would be to update MessageInputProps type to accept File
+   setValue(FILE_INPUT_NAME, file);
    clearErrors(FILE_INPUT_NAME);
    const filePreview = URL.createObjectURL(file);
    setSvgUrl(filePreview);
}
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
			if (file && !validateFile(file)) {
				// Better approach would be to update MessageInputProps type to accept File
				setValue(FILE_INPUT_NAME, file);
				clearErrors(FILE_INPUT_NAME);
				const filePreview = URL.createObjectURL(file);
				setSvgUrl(filePreview);
			}
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->

✅ Addressed in commit 674aa88
created_at: 2025-04-16T16:37:36Z
author_association: CONTRIBUTOR
diff_hunk: @@ -32,17 +79,63 @@ export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps
 		setValue,
 		getValues,
 		setError,
-		formState: { errors },
-	} = useForm<MessageInput>();
+		clearErrors,
+		formState: { errors, isSubmitting },
+	} = useForm<MessageInputProps>();
+
+	const validateFile = (file: File): FileError | null => {
+		let message = null;
+		let code = null;
+		const fileType = file.type;
+
+		if (file.size > MAX_FILE_SIZE) {
+			message = "File size is too large";
+			code = "file-size-too-large";
+		}
+		if (!ACCEPTED_IMAGE_TYPES.includes(fileType)) {
+			message = "File type is not supported";
+			code = "file-type-not-supported";
+		}
+		if (message && code) {
+			setError("message_img", { message });
+			return { message, code };
+		}
+		return null;
+	};
 
-	const onSubmit: SubmitHandler<MessageInput> = (data) => {
+	const onDrop = useCallback(
+		(acceptedFiles: File[]) => {
+			const file = acceptedFiles[0];
+
+			if (file && !validateFile(file)) {
+				setValue(FILE_INPUT_NAME, file as unknown as string);
+				clearErrors(FILE_INPUT_NAME);
+				const filePreview = URL.createObjectURL(file);
+				setSvgUrl(filePreview);
+			}
+		},
+		// eslint-disable-next-line react-hooks/exhaustive-deps
+		[setValue]
+	);
+
+	const { getRootProps, getInputProps, isDragActive } = useDropzone({
+		onDrop,
+		accept: {
+			"image/*": ACCEPTED_IMAGE_TYPES.split(",").map((type) => `.${type.split("/")[1]}`),
+		},
+		maxSize: MAX_FILE_SIZE,
+		multiple: false,
+		validator: validateFile,
+	});
+
+	const onSubmit: SubmitHandler<MessageInputProps> = (data) => {
 		if (data.message_text.trim().length === 0) {
 			setError("message_text", {
 				message: "Can't submit an empty field",
 			});
 			return;
 		}
-		const message_img = data?.message_img?.[0] as unknown as HTMLImageElement;
+		const message_img = getValues(FILE_INPUT_NAME) as unknown as File;
path: client/src/components/layout/chat-room/chat-room-message-input.tsx
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Add null check before using message_img.**

You're accessing the image file directly without checking if it exists, which could cause errors when no image is selected.


```diff
-const message_img = getValues(FILE_INPUT_NAME) as unknown as File;
+const message_img = getValues(FILE_INPUT_NAME) as unknown as File | undefined;
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
		const message_img = getValues(FILE_INPUT_NAME) as unknown as File | undefined;
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-04-16T16:37:36Z
author_association: CONTRIBUTOR
diff_hunk: @@ -32,17 +79,63 @@ export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps
 		setValue,
 		getValues,
 		setError,
-		formState: { errors },
-	} = useForm<MessageInput>();
+		clearErrors,
+		formState: { errors, isSubmitting },
+	} = useForm<MessageInputProps>();
+
+	const validateFile = (file: File): FileError | null => {
+		let message = null;
+		let code = null;
+		const fileType = file.type;
+
+		if (file.size > MAX_FILE_SIZE) {
+			message = "File size is too large";
+			code = "file-size-too-large";
+		}
+		if (!ACCEPTED_IMAGE_TYPES.includes(fileType)) {
+			message = "File type is not supported";
+			code = "file-type-not-supported";
+		}
+		if (message && code) {
+			setError("message_img", { message });
+			return { message, code };
+		}
+		return null;
+	};
 
-	const onSubmit: SubmitHandler<MessageInput> = (data) => {
+	const onDrop = useCallback(
+		(acceptedFiles: File[]) => {
+			const file = acceptedFiles[0];
+
+			if (file && !validateFile(file)) {
+				setValue(FILE_INPUT_NAME, file as unknown as string);
+				clearErrors(FILE_INPUT_NAME);
+				const filePreview = URL.createObjectURL(file);
+				setSvgUrl(filePreview);
+			}
+		},
+		// eslint-disable-next-line react-hooks/exhaustive-deps
+		[setValue]
+	);
+
+	const { getRootProps, getInputProps, isDragActive } = useDropzone({
+		onDrop,
+		accept: {
+			"image/*": ACCEPTED_IMAGE_TYPES.split(",").map((type) => `.${type.split("/")[1]}`),
+		},
path: client/src/components/layout/chat-room/chat-room-message-input.tsx
user: login: lesleyfon
body: Since I want a single list/string to control all the mine types, I want to leave this as it is. Single source of truth
created_at: 2025-04-16T17:17:20Z
author_association: OWNER
diff_hunk: @@ -32,17 +79,63 @@ export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps
 		setValue,
 		getValues,
 		setError,
-		formState: { errors },
-	} = useForm<MessageInput>();
+		clearErrors,
+		formState: { errors, isSubmitting },
+	} = useForm<MessageInputProps>();
+
+	const validateFile = (file: File): FileError | null => {
+		let message = null;
+		let code = null;
+		const fileType = file.type;
+
+		if (file.size > MAX_FILE_SIZE) {
+			message = "File size is too large";
+			code = "file-size-too-large";
+		}
+		if (!ACCEPTED_IMAGE_TYPES.includes(fileType)) {
+			message = "File type is not supported";
+			code = "file-type-not-supported";
+		}
+		if (message && code) {
+			setError("message_img", { message });
+			return { message, code };
+		}
+		return null;
+	};
 
-	const onSubmit: SubmitHandler<MessageInput> = (data) => {
+	const onDrop = useCallback(
+		(acceptedFiles: File[]) => {
+			const file = acceptedFiles[0];
+
+			if (file && !validateFile(file)) {
+				setValue(FILE_INPUT_NAME, file as unknown as string);
+				clearErrors(FILE_INPUT_NAME);
+				const filePreview = URL.createObjectURL(file);
+				setSvgUrl(filePreview);
+			}
+		},
+		// eslint-disable-next-line react-hooks/exhaustive-deps
+		[setValue]
+	);
+
+	const { getRootProps, getInputProps, isDragActive } = useDropzone({
+		onDrop,
+		accept: {
+			"image/*": ACCEPTED_IMAGE_TYPES.split(",").map((type) => `.${type.split("/")[1]}`),
+		},
path: client/src/components/layout/chat-room/chat-room-message-input.tsx
user: login: coderabbitai[bot]
body: @lesleyfon I understand your preference for maintaining a single source of truth for MIME types. However, there's a technical issue with the current mapping: MIME types like `image/svg+xml` would incorrectly map to `.svg+xml` instead of `.svg`.

A simple solution that preserves your single source of truth approach would be:

```javascript
accept: {
    "image/*": [], // Accept all image types
},
```

This way:
1. ACCEPTED_IMAGE_TYPES remains your single source of truth
2. Your validateFile function (which already uses ACCEPTED_IMAGE_TYPES) handles the actual validation
3. You avoid the problematic MIME type → extension mapping

This approach simplifies the code while still respecting your design principle.

---

<details>
<summary>✏️ Learnings added</summary>

```
Learnt from: lesleyfon
PR: lesleyfon/chatapp#23
File: client/src/components/layout/chat-room/chat-room-message-input.tsx:116-118
Timestamp: 2025-04-16T17:18:17.837Z
Learning: For the react-dropzone library's accept property, use `"image/*": []` instead of trying to map MIME types to file extensions (especially for types like image/svg+xml). This allows accepting all image types while relying on a separate validation function to enforce specific MIME type restrictions.
```

> Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings).

</details>




<!-- <agentComponentType>chat-answer</agentComponentType> -->

<!-- <rawResChunk><answer>@lesleyfon I understand your preference for maintaining a single source of truth for MIME types. However, there's a technical issue with the current mapping: MIME types like `image/svg+xml` would incorrectly map to `.svg+xml` instead of `.svg`.

A simple solution that preserves your single source of truth approach would be:

```javascript
accept: {
    "image/*": [], // Accept all image types
},
```

This way:
1. ACCEPTED_IMAGE_TYPES remains your single source of truth
2. Your validateFile function (which already uses ACCEPTED_IMAGE_TYPES) handles the actual validation
3. You avoid the problematic MIME type → extension mapping

This approach simplifies the code while still respecting your design principle.

---

<details>
<summary>✏️ Learnings added</summary>

```
Learnt from: lesleyfon
PR: lesleyfon/chatapp#23
File: client/src/components/layout/chat-room/chat-room-message-input.tsx:116-118
Timestamp: 2025-04-16T17:18:17.837Z
Learning: For the react-dropzone library's accept property, use `"image/*": []` instead of trying to map MIME types to file extensions (especially for types like image/svg+xml). This allows accepting all image types while relying on a separate validation function to enforce specific MIME type restrictions.
```

> Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings).

</details>

</answer></rawResChunk> -->

<!-- This is an auto-generated reply by CodeRabbit -->
created_at: 2025-04-16T17:18:19Z
author_association: CONTRIBUTOR
diff_hunk: @@ -32,17 +79,63 @@ export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps
 		setValue,
 		getValues,
 		setError,
-		formState: { errors },
-	} = useForm<MessageInput>();
+		clearErrors,
+		formState: { errors, isSubmitting },
+	} = useForm<MessageInputProps>();
+
+	const validateFile = (file: File): FileError | null => {
+		let message = null;
+		let code = null;
+		const fileType = file.type;
+
+		if (file.size > MAX_FILE_SIZE) {
+			message = "File size is too large";
+			code = "file-size-too-large";
+		}
+		if (!ACCEPTED_IMAGE_TYPES.includes(fileType)) {
+			message = "File type is not supported";
+			code = "file-type-not-supported";
+		}
+		if (message && code) {
+			setError("message_img", { message });
+			return { message, code };
+		}
+		return null;
+	};
 
-	const onSubmit: SubmitHandler<MessageInput> = (data) => {
+	const onDrop = useCallback(
+		(acceptedFiles: File[]) => {
+			const file = acceptedFiles[0];
+
+			if (file && !validateFile(file)) {
+				setValue(FILE_INPUT_NAME, file as unknown as string);
+				clearErrors(FILE_INPUT_NAME);
+				const filePreview = URL.createObjectURL(file);
+				setSvgUrl(filePreview);
+			}
+		},
+		// eslint-disable-next-line react-hooks/exhaustive-deps
+		[setValue]
+	);
+
+	const { getRootProps, getInputProps, isDragActive } = useDropzone({
+		onDrop,
+		accept: {
+			"image/*": ACCEPTED_IMAGE_TYPES.split(",").map((type) => `.${type.split("/")[1]}`),
+		},
path: client/src/components/layout/chat-room/chat-room-message-input.tsx
user: login: lesleyfon
body: What do you think about this?
```
const { getRootProps, getInputProps, isDragActive } = useDropzone({
		onDrop,
		accept: {
			"image/*": ACCEPTED_IMAGE_TYPES.split(",")
				.filter((type) => !type.includes("svg"))
				.map((type) => `.${type.split("/")[1]}`),
			"image/svg+xml": [".svg"],
		},
		maxSize: MAX_FILE_SIZE,
		multiple: false,
		validator: validateFile,
	});
```
created_at: 2025-04-16T17:27:41Z
author_association: OWNER
diff_hunk: @@ -32,17 +79,63 @@ export function MessageInput({ chatId, chatName, isPrivateChat }: ChatInputProps
 		setValue,
 		getValues,
 		setError,
-		formState: { errors },
-	} = useForm<MessageInput>();
+		clearErrors,
+		formState: { errors, isSubmitting },
+	} = useForm<MessageInputProps>();
+
+	const validateFile = (file: File): FileError | null => {
+		let message = null;
+		let code = null;
+		const fileType = file.type;
+
+		if (file.size > MAX_FILE_SIZE) {
+			message = "File size is too large";
+			code = "file-size-too-large";
+		}
+		if (!ACCEPTED_IMAGE_TYPES.includes(fileType)) {
+			message = "File type is not supported";
+			code = "file-type-not-supported";
+		}
+		if (message && code) {
+			setError("message_img", { message });
+			return { message, code };
+		}
+		return null;
+	};
 
-	const onSubmit: SubmitHandler<MessageInput> = (data) => {
+	const onDrop = useCallback(
+		(acceptedFiles: File[]) => {
+			const file = acceptedFiles[0];
+
+			if (file && !validateFile(file)) {
+				setValue(FILE_INPUT_NAME, file as unknown as string);
+				clearErrors(FILE_INPUT_NAME);
+				const filePreview = URL.createObjectURL(file);
+				setSvgUrl(filePreview);
+			}
+		},
+		// eslint-disable-next-line react-hooks/exhaustive-deps
+		[setValue]
+	);
+
+	const { getRootProps, getInputProps, isDragActive } = useDropzone({
+		onDrop,
+		accept: {
+			"image/*": ACCEPTED_IMAGE_TYPES.split(",").map((type) => `.${type.split("/")[1]}`),
+		},
path: client/src/components/layout/chat-room/chat-room-message-input.tsx
user: login: coderabbitai[bot]
body: @lesleyfon Your solution would work correctly and specifically addresses the SVG extension issue! It's a clever approach that maintains your desire to use the MIME types from ACCEPTED_IMAGE_TYPES while properly handling the special case for SVG files.

That said, I still think the simpler approach I suggested earlier has some advantages:

```javascript
accept: {
  "image/*": [], // Accept all image types
},
```

**Comparing the approaches:**

Your solution:
- ✅ Correctly handles SVG extension
- ✅ More explicit about accepted formats in dropzone configuration
- ⚠️ More complex code to maintain
- ⚠️ Would need updates if more special MIME types are added in the future

Simpler approach:
- ✅ Handles all image types without special cases
- ✅ More maintainable (less code)
- ✅ Your validateFile function still enforces the exact MIME type restrictions
- ⚠️ Less explicit in the dropzone configuration itself

Since your validateFile function is already checking against ACCEPTED_IMAGE_TYPES, the accept property is somewhat redundant. But if you prefer the more explicit approach, your solution is definitely technically correct!

---

<details>
<summary>🧠 Learnings used</summary>

```
Learnt from: lesleyfon
PR: lesleyfon/chatapp#23
File: client/src/components/layout/chat-room/chat-room-message-input.tsx:116-118
Timestamp: 2025-04-16T17:18:17.837Z
Learning: For the react-dropzone library's accept property, use `"image/*": []` instead of trying to map MIME types to file extensions (especially for types like image/svg+xml). This allows accepting all image types while relying on a separate validation function to enforce specific MIME type restrictions.
```

---

```
Learnt from: lesleyfon
PR: lesleyfon/chatapp#23
File: client/src/components/layout/chat-room/chat-room-message-input.tsx:135-163
Timestamp: 2025-04-16T16:12:20.124Z
Learning: In React Dropzone implementations, it's valid to apply `getRootProps()` to multiple sibling elements to create separate drop targets that all trigger the same `onDrop` callback. This pattern was intentionally used in the chat message input component to allow files to be dropped on either the image button or the text input area.
```

</details>




<!-- <agentComponentType>chat-answer</agentComponentType> -->

<!-- <rawResChunk><answer>@lesleyfon Your solution would work correctly and specifically addresses the SVG extension issue! It's a clever approach that maintains your desire to use the MIME types from ACCEPTED_IMAGE_TYPES while properly handling the special case for SVG files.

That said, I still think the simpler approach I suggested earlier has some advantages:

```javascript
accept: {
  "image/*": [], // Accept all image types
},
```

**Comparing the approaches:**

Your solution:
- ✅ Correctly handles SVG extension
- ✅ More explicit about accepted formats in dropzone configuration
- ⚠️ More complex code to maintain
- ⚠️ Would need updates if more special MIME types are added in the future

Simpler approach:
- ✅ Handles all image types without special cases
- ✅ More maintainable (less code)
- ✅ Your validateFile function still enforces the exact MIME type restrictions
- ⚠️ Less explicit in the dropzone configuration itself

Since your validateFile function is already checking against ACCEPTED_IMAGE_TYPES, the accept property is somewhat redundant. But if you prefer the more explicit approach, your solution is definitely technically correct!

---

<details>
<summary>🧠 Learnings used</summary>

```
Learnt from: lesleyfon
PR: lesleyfon/chatapp#23
File: client/src/components/layout/chat-room/chat-room-message-input.tsx:116-118
Timestamp: 2025-04-16T17:18:17.837Z
Learning: For the react-dropzone library's accept property, use `"image/*": []` instead of trying to map MIME types to file extensions (especially for types like image/svg+xml). This allows accepting all image types while relying on a separate validation function to enforce specific MIME type restrictions.
```

---

```
Learnt from: lesleyfon
PR: lesleyfon/chatapp#23
File: client/src/components/layout/chat-room/chat-room-message-input.tsx:135-163
Timestamp: 2025-04-16T16:12:20.124Z
Learning: In React Dropzone implementations, it's valid to apply `getRootProps()` to multiple sibling elements to create separate drop targets that all trigger the same `onDrop` callback. This pattern was intentionally used in the chat message input component to allow files to be dropped on either the image button or the text input area.
```

</details>

</answer></rawResChunk> -->

<!-- This is an auto-generated reply by CodeRabbit -->
created_at: 2025-04-16T17:28:13Z
author_association: CONTRIBUTOR

PR comments:
user: login: vercel[bot]
created_at: 2025-04-16T03:35:31Z
body: [vc]: #B4Ta9NIHF/dLV852swpR+K56MQRK7CqJFibEssNI034=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJjaGF0YXBwIiwibGl2ZUZlZWRiYWNrIjp7InJlc29sdmVkIjowLCJ1bnJlc29sdmVkIjowLCJ0b3RhbCI6MCwibGluayI6ImNoYXRhcHAtZ2l0LWZlYXQtYWRkLW1lc3NhZ2UtZHJvcHpvbmUtbGVzbGV5LWJhbmFkemVtcy1wcm9qZWN0cy52ZXJjZWwuYXBwIn0sImluc3BlY3RvclVybCI6Imh0dHBzOi8vdmVyY2VsLmNvbS9sZXNsZXktYmFuYWR6ZW1zLXByb2plY3RzL2NoYXRhcHAvRGF6ZVRKNldNeXZKejY0YWdZdERzem9SdGJGZCIsInByZXZpZXdVcmwiOiJjaGF0YXBwLWdpdC1mZWF0LWFkZC1tZXNzYWdlLWRyb3B6b25lLWxlc2xleS1iYW5hZHplbXMtcHJvamVjdHMudmVyY2VsLmFwcCIsIm5leHRDb21taXRTdGF0dXMiOiJERVBMT1lFRCIsInJvb3REaXJlY3RvcnkiOiJjbGllbnQifV19
**The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)

| Name | Status | Preview | Comments | Updated (UTC) |
| :--- | :----- | :------ | :------- | :------ |
| **chatapp** | ✅ Ready ([Inspect](https://vercel.com/lesley-banadzems-projects/chatapp/DazeTJ6WMyvJz64agYtDszoRtbFd)) | [Visit Preview](https://chatapp-git-feat-add-message-dropzone-lesley-banadzems-projects.vercel.app) | 💬 [**Add feedback**](https://vercel.live/open-feedback/chatapp-git-feat-add-message-dropzone-lesley-banadzems-projects.vercel.app?via=pr-comment-feedback-link) | Apr 16, 2025 5:36pm |


author_association: NONE
user: login: coderabbitai[bot]
created_at: 2025-04-16T03:35:32Z
body: <!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- walkthrough_start -->

## Walkthrough

This update introduces image upload functionality to the chat message input, supporting drag-and-drop, file validation, and preview. New constants for accepted image types, file size limits, and a default SVG are added. The client-side message input now handles image files, validates them, and displays previews or errors. The message sending logic is updated to process image files, including GIF-to-base64 conversion. On the server, the allowed upload size is increased, and message handling is extended to accept and process images as Buffers, Files, or base64 strings, with improved error handling and type definitions. TypeScript interfaces and types are updated accordingly.

## Changes

| File(s)                                                                 | Change Summary                                                                                                                                                                                                                                                                                                                                                                         |
|-------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `client/src/components/constants.ts`                                    | Added new constants: `ACCEPTED_IMAGE_TYPES` (string of accepted image MIME types), `MAX_FILE_SIZE` (5 MB), and `DEFAULT_SVG_URL` (base64 SVG).                                                                                                                                                                                                                                        |
| `client/src/components/layout/chat-room/chat-room-message-input.tsx`    | Enhanced `MessageInput` to support drag-and-drop image upload with preview, validation (type and size), error handling, and integration with form state. Added `ErrorMessages` and `FileInputElement` components. Updated to use new constants and `useDropzone`.                                                                                                                     |
| `client/src/hooks/useSendMessage.tsx`                                   | Added `convertGifToBase64` helper. Updated `sendPrivateMessage` to accept `File` or `string` for `imageFile`, convert GIFs to base64, and handle async logic.                                                                                                                                                                                  |
| `client/src/types/index.ts`                                             | Renamed `MessageInput` to `MessageInputProps`. Added `ChatInputProps`, `ErrorMessagesProps`, and `FileInputElementProps` interfaces/types for enhanced typing of chat input, errors, and dropzone props.                                                                                                                                              |
| `client/package.json`                                                   | Added dependency `react-dropzone` version `^14.3.8`.                                                                                                                                                                                                                                                                                                  |
| `client/src/components/layout/chat-room/index.tsx`                      | Updated import and usage from `MessageInput` to `ChatMessageInput`.                                                                                                                                                                                                                                                                            |
| `server/src/index.ts`                                                   | Increased multer upload file size limit from 1 MB to 5 MB.                                                                                                                                                                                                                                                                                      |
| `server/src/model/QueryHandlers.model.ts`                               | Updated `createPrivateMessage` to accept `Buffer`, `File`, or `string` for `imageFile`. Added conversion logic for `File` and base64 strings. Added error handling (try-catch). Imported `File` from "buffer".                                                                                                                                |
| `server/src/types/index.ts`                                             | Imported `File` from "buffer". Modified `PrivateMessageBase.image_file` to accept `Buffer | File | string | null`. Added `AddPrivateMessageType` type for private message creation.                                                                                                                      |
| `server/src/web/socket.ts`                                              | Imported `File` and `AddPrivateMessageType`. Refactored `addPrivateMessage` event handler to use new type, added try-catch, improved image data handling for different formats, and error emission.                                                                                                      |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant User
    participant MessageInput
    participant useSendMessage
    participant SocketServer
    participant QueryHandlers
    participant Database

    User->>MessageInput: Drag-and-drop/select image, enter text
    MessageInput->>MessageInput: Validate image (type, size)
    MessageInput->>useSendMessage: Submit message with image file
    useSendMessage->>useSendMessage: Convert GIF to base64 if needed
    useSendMessage->>SocketServer: Emit message event with image (File/base64/Buffer)
    SocketServer->>QueryHandlers: createPrivateMessage with image data
    QueryHandlers->>QueryHandlers: Normalize image (Buffer/File/base64)
    QueryHandlers->>Database: Insert message and image
    Database-->>QueryHandlers: Success/error response
    QueryHandlers-->>SocketServer: Return result
    SocketServer-->>MessageInput: Emit response (success/error)
```

## Poem

> A bunny hops with pixel glee,  
> Now chat can share what eyes can see!  
> Drop your GIFs or JPEG dreams,  
> Previews pop with happy beams.  
> Five megabytes—no more fright—  
> Image magic, day or night!  
> 🐇✨

<!-- walkthrough_end -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 99242884278f3e36950014a4bf0679e1c8f3b2c3 and 674aa882578fd14b15983b5ca0bca6d9352a654c.

</details>

<details>
<summary>📒 Files selected for processing (2)</summary>

* `client/src/components/layout/chat-room/chat-room-message-input.tsx` (3 hunks)
* `client/src/components/layout/chat-room/index.tsx` (3 hunks)

</details>

<details>
<summary>✅ Files skipped from review due to trivial changes (1)</summary>

* client/src/components/layout/chat-room/index.tsx

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🧠 Learnings (1)</summary>

<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx (2)</summary>

```
Learnt from: lesleyfon
PR: lesleyfon/chatapp#23
File: client/src/components/layout/chat-room/chat-room-message-input.tsx:135-163
Timestamp: 2025-04-16T16:12:20.124Z
Learning: In React Dropzone implementations, it's valid to apply `getRootProps()` to multiple sibling elements to create separate drop targets that all trigger the same `onDrop` callback. This pattern was intentionally used in the chat message input component to allow files to be dropped on either the image button or the text input area.
```

```
Learnt from: lesleyfon
PR: lesleyfon/chatapp#23
File: client/src/components/layout/chat-room/chat-room-message-input.tsx:116-118
Timestamp: 2025-04-16T17:18:17.837Z
Learning: For the react-dropzone library's accept property, use `"image/*": []` instead of trying to map MIME types to file extensions (especially for types like image/svg+xml). This allows accepting all image types while relying on a separate validation function to enforce specific MIME type restrictions.
```

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (11)</summary><blockquote>

<details>
<summary>client/src/components/layout/chat-room/chat-room-message-input.tsx (11)</summary>

`4-5`: **Great addition of React Dropzone for file uploads.**

Adding `useDropzone` from `react-dropzone` is a good choice for implementing drag-and-drop file uploads with rich validation capabilities.

---

`18-18`: **Good use of constants for file validation.**

Centralizing file validation constants like `ACCEPTED_IMAGE_TYPES`, `MAX_FILE_SIZE`, and `DEFAULT_SVG_URL` in a separate constants file promotes maintainability and reusability.

---

`20-28`: **Nice extraction of error message display logic.**

Creating a separate `ErrorMessages` component keeps the main component cleaner and more focused on its primary responsibilities.

---

`30-66`: **Well-structured FileInputElement component with visual feedback.**

The `FileInputElement` component effectively implements:
- Dynamic styling based on drag and error states
- Conditional rendering between default icon and image preview
- Background image styling for previews that maintains the button dimensions

This approach cleanly separates the dropzone UI from the main component logic.

---

`86-93`: **Excellent implementation of cleanup for object URLs.**

The useEffect cleanup function properly prevents memory leaks by revoking object URLs when the component unmounts.

---

`95-106`: **Well-implemented file validation with clear error messages.**

The validation function properly checks both file size and type with appropriate error messages and error codes.

---

`124-135`: **Smart handling of file extension mapping with special case for SVG.**

Your solution to handle SVG files separately addresses the issue with mapping MIME types to file extensions. This ensures proper file filtering while maintaining the single source of truth for accepted image types.

---

`166-169`: **Proper resource cleanup in onSubmit.**

Revoking object URLs after form submission prevents memory leaks, which is a good practice.

---

`175-183`: **Clever error handling strategy for image submissions.**

The error handling approach allows submission to proceed if the image validation is the only issue, which provides a better user experience by not blocking submissions unnecessarily.

---

`185-195`: **Good visual feedback during file drag operations.**

The subtle background color change during drag operations provides good visual feedback to users without being distracting.

---

`197-208`: **Smart handling of click propagation in nested dropzones.**

Preventing event propagation on the text input click is crucial to avoid triggering the file dialog unintentionally when users try to type a message.

</details>

</blockquote></details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEejqANiS4AxEtS4BZaYjSlIASQzc86ZB+Y3EkgAEQp8bgAvfHJIAwA5bGYBSi4AJgBmAwBVRFTIK0QrWQAzGKN9Y3AoMnp8EpwCYjJlGnomVnYuXn5hUXEpGXkmJSpVdS0dSpMoOFRUTEbCUnIqNoVOjE5IKgB3SEQkwIp5OQVRlTVNbV0wQyrTAwYLeHYAekQKBjeO7hj2RA/GKIXCYXCIDTgjgGABEcIMAGIEZAAIIeZqrah0A5HNAnfgNBiwTCkRBmWDBbDcWhY9C0WjIcj7EgADz+FHWTAwILByAoJAsWPoBBQgXcxIwtBeGCI6ElkCUJTQ2AsuEgAGUAGoAcQV1DQGk8avgW3CtGwDGkkAABiiAMJ2gCiAAVoI6QgB9DyOFHax0e6AATWdjvV1r86A2gTAeW4eKFB1wFBNsvqkEc3sdkFwsm4VrKfDQDEt3HW8DFwQLg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EVgwMaecDenjWXKH1lKhrPHwlX2n4sNyMVDJsj4PBZQ1Oqs2anKiR9iGgOoy+GvvjUMTLgL+B/OsFaF2CT0TEBObYrDU57V0x+RWG2NvXtjqpaGrzYAESJvK4BYajnABKozEAyAJ6pBWAdPzyAQCfmO9NAUsh2A6Zp4qhSAGsInpoIN6gRMmpkhqhchxI22EoPHH2AXDjIpaOgPvRi4PCiqSzRLq8IaArdG0Hw2Qe2m+HP1X2aQu4A8BqA6dXeeAZYHTwCibBtgewashnh6EaQxgVwSYLcEMAzAow6gD0NwkQAeg8kNcOgB6B5AoxKgBgRMUpCWEMBCxaQN8AAHZSM4EBgAIDfBVi3wdeOvEsLLElABAZY2gFBDQBLC3w7YtIEsIEDQQ0g8Y/MdUEQjiMKxSwtAFBAEBLC0gSgNAG+AkZKBwIb4UsaBDfBKQYk64jIFBCUgCAlIAATjXG0BGo0wEcRBFoBvg3wSww8VBF7EkAII/YtACUCUhKQMgoEQsRIwyCFjl4UEQ8WgBBxKRwIQ4gsWWP3EMAixaQBgF+LoC0AyxSwyCPuJIBLC6AUEKCBkDQBKQ0AoEFsW+AYCgR9xUEEgBkHLHASRxaQBSGkFAgMBfxUEKsZOPfE0gyx4EVCS2LLFljMJoEAQOBHAgZBkJ9gfsfYFIkQAEumEvCQwCVBQRsJ+4ssQIEImgQyxb48RpOLYmySTIJkCSR2KggNBTxwk/cfuIHFLClht4uCSUAyBESDxtY8CHMMnECASg4EJSKBPvHgTTJ/YqCUJKgAOSOxnYmceWKWElBaAcwgQGuP3FLCMgNYmJOBAEAxIlItAfccRLSAYS3wUEE8T6OHHCSOg6hFMQyHTHDx8kWYrKvoCAA= -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details>
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---



<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=lesleyfon/chatapp&utm_content=23):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Generate unit testing code for this file.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai generate unit testing code for this file.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and generate unit testing code.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->
author_association: CONTRIBUTOR