diff --git a/packages/react/src/views/AttachmentPreview/AttachmentPreview.js b/packages/react/src/views/AttachmentPreview/AttachmentPreview.js
index 82ce58e818..b6e5246f3a 100644
--- a/packages/react/src/views/AttachmentPreview/AttachmentPreview.js
+++ b/packages/react/src/views/AttachmentPreview/AttachmentPreview.js
@@ -1,10 +1,18 @@
import React, { useContext, useState, useRef, useEffect } from 'react';
import { css } from '@emotion/react';
-import { Box, Icon, Button, Input, Modal } from '@embeddedchat/ui-elements';
+import {
+ Box,
+ Icon,
+ Button,
+ Input,
+ Modal,
+ useTheme,
+} from '@embeddedchat/ui-elements';
import useAttachmentWindowStore from '../../store/attachmentwindow';
import CheckPreviewType from './CheckPreviewType';
import RCContext from '../../context/RCInstance';
import { useMessageStore, useMemberStore } from '../../store';
+import useSettingsStore from '../../store/settingsStore';
import getAttachmentPreviewStyles from './AttachmentPreview.styles';
import { parseEmoji } from '../../lib/emoji';
import MembersList from '../Mentions/MembersList';
@@ -13,6 +21,7 @@ import useSearchMentionUser from '../../hooks/useSearchMentionUser';
const AttachmentPreview = () => {
const { RCInstance, ECOptions } = useContext(RCContext);
+ const { theme } = useTheme();
const styles = getAttachmentPreviewStyles();
const toggle = useAttachmentWindowStore((state) => state.toggle);
@@ -25,6 +34,7 @@ const AttachmentPreview = () => {
const [mentionIndex, setMentionIndex] = useState(-1);
const [startReadMentionUser, setStartReadMentionUser] = useState(false);
const [keyPressed, setKeyPressed] = useState(null);
+ const [isMsgLong, setIsMsgLong] = useState(false);
const [fileName, setFileName] = useState(data?.name);
@@ -46,12 +56,6 @@ const AttachmentPreview = () => {
setShowMembersList
);
- const handleFileDescription = (e) => {
- const description = e.target.value;
- messageRef.current.value = parseEmoji(description);
- searchMentionUser(description);
- };
-
const submit = async () => {
setIsPending(true);
await RCInstance.sendAttachment(
@@ -67,6 +71,27 @@ const AttachmentPreview = () => {
}
};
+ const msgMaxLength = useSettingsStore((state) => state.messageLimit);
+ const descAboveMaxLengthMsg = `Cannot upload file, description is over the ${msgMaxLength} character limit`;
+
+ const checkIfMsgLong = (description) => {
+ if (description.length > msgMaxLength) {
+ setIsMsgLong(true);
+ return;
+ }
+ submit();
+ };
+
+ const handleFileDescription = (e) => {
+ const description = e.target.value;
+ messageRef.current.value = parseEmoji(description);
+ if (isMsgLong) {
+ if (description.length <= msgMaxLength) {
+ setIsMsgLong(false);
+ }
+ }
+ searchMentionUser(description);
+ };
useEffect(() => {
const keyHandler = (e) => {
if (e.key === 'Enter') {
@@ -170,10 +195,29 @@ const AttachmentPreview = () => {
onChange={(e) => {
handleFileDescription(e);
}}
- css={styles.input}
+ css={css`
+ ${styles.input};
+ border-color: ${isMsgLong
+ ? theme.colors.destructive
+ : null};
+ color: ${isMsgLong ? theme.colors.destructive : null};
+ `}
placeholder="Description"
ref={messageRef}
/>
+
+ {isMsgLong && (
+
+ {descAboveMaxLengthMsg}
+
+ )}
+
@@ -191,7 +235,7 @@ const AttachmentPreview = () => {