@pubuduth-aplicy/chat-ui 2.2.0 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pubuduth-aplicy/chat-ui",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -35,7 +35,8 @@ const CollapsibleSection = ({
35
35
  />
36
36
  </div>
37
37
  {isOpen && (
38
- <div className="p-2 text-gray-900 dark:text-gray-200">{children}</div>
38
+ <div className="p-2 text-gray-900 dark:text-gray-200"
39
+ style={{height:"400px"}}>{children}</div>
39
40
  )}
40
41
  </div>
41
42
  );
@@ -9,7 +9,6 @@ import { MessageStatus } from "../../types/type";
9
9
  import { Path } from "../../lib/api/endpoint";
10
10
  import { getChatConfig } from "../../Chat.config";
11
11
 
12
- const MAX_FILE_SIZE_MB = 5;
13
12
  const MAX_FILE_COUNT = 5;
14
13
  const ACCEPTED_IMAGE_TYPES = [
15
14
  "image/jpeg",
@@ -440,6 +439,8 @@ const MessageInput = () => {
440
439
  attachmentsRef.current = attachments;
441
440
  }, [attachments]);
442
441
 
442
+ {/* File attachment handlers */}
443
+
443
444
  // File attachment handlers
444
445
  const handleAttachmentClick = () => {
445
446
  setShowAttachmentOptions(!showAttachmentOptions);
@@ -466,45 +467,103 @@ const MessageInput = () => {
466
467
  }
467
468
  };
468
469
 
470
+ const FILE_SIZE_LIMITS_MB = {
471
+ image: 10,
472
+ video: 120,
473
+ document: 10,
474
+ } as const;
475
+
476
+ const getMaxSizeForType = (type: Attachment["type"] | null) => {
477
+ if (!type) return 0;
478
+ return FILE_SIZE_LIMITS_MB[type] * 1024 * 1024;
479
+ };
480
+
481
+ // const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
482
+ // const files = e.target.files;
483
+ // if (!files || files.length === 0) return;
484
+
485
+ // if (attachments.length + files.length > MAX_FILE_COUNT) {
486
+ // alert(`You can only attach up to ${MAX_FILE_COUNT} files`);
487
+ // return;
488
+ // }
489
+
490
+ // const newFilesSize = Array.from(files).reduce(
491
+ // (total, file) => total + file.size,
492
+ // 0
493
+ // );
494
+ // const currentAttachmentsSize = attachments.reduce(
495
+ // (total, att) => total + att.file.size,
496
+ // 0
497
+ // );
498
+
499
+ // if (
500
+ // currentAttachmentsSize + newFilesSize >
501
+ // MAX_FILE_SIZE_MB * 1024 * 1024
502
+ // ) {
503
+ // alert(`Total file size cannot exceed ${MAX_FILE_SIZE_MB}MB`);
504
+ // return;
505
+ // }
506
+
507
+ // const newAttachments: Attachment[] = [];
508
+
509
+ // for (let i = 0; i < files.length; i++) {
510
+ // const file = files[i];
511
+ // const fileType = getFileType(file.type);
512
+
513
+ // if (!fileType) {
514
+ // console.error(`Unsupported file type: ${file.type}`);
515
+ // continue;
516
+ // }
517
+
518
+ // if (file.size > MAX_FILE_SIZE_MB * 1024 * 1024) {
519
+ // console.error(`File too large: ${file.name}`);
520
+ // continue;
521
+ // }
522
+
523
+ // const previewUrl =
524
+ // fileType === "document"
525
+ // ? URL.createObjectURL(new Blob([""], { type: "application/pdf" }))
526
+ // : URL.createObjectURL(file);
527
+
528
+ // newAttachments.push({
529
+ // file,
530
+ // type: fileType,
531
+ // previewUrl,
532
+ // });
533
+ // }
534
+
535
+ // setAttachments((prev) => [...prev, ...newAttachments]);
536
+ // if (fileInputRef.current) {
537
+ // fileInputRef.current.value = "";
538
+ // }
539
+ // };
540
+
469
541
  const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
542
+ setInputError(null);
470
543
  const files = e.target.files;
471
544
  if (!files || files.length === 0) return;
472
545
 
473
- if (attachments.length + files.length > MAX_FILE_COUNT) {
474
- alert(`You can only attach up to ${MAX_FILE_COUNT} files`);
475
- return;
476
- }
546
+ const newAttachments: Attachment[] = [];
477
547
 
478
- const newFilesSize = Array.from(files).reduce(
479
- (total, file) => total + file.size,
480
- 0
481
- );
482
- const currentAttachmentsSize = attachments.reduce(
483
- (total, att) => total + att.file.size,
484
- 0
485
- );
486
-
487
- if (
488
- currentAttachmentsSize + newFilesSize >
489
- MAX_FILE_SIZE_MB * 1024 * 1024
490
- ) {
491
- alert(`Total file size cannot exceed ${MAX_FILE_SIZE_MB}MB`);
492
- return;
548
+ if (attachments.length + files.length > MAX_FILE_COUNT) {
549
+ return setInputError(`You can only attach up to ${MAX_FILE_COUNT} files`); // toast / inline message
493
550
  }
494
551
 
495
- const newAttachments: Attachment[] = [];
496
-
497
552
  for (let i = 0; i < files.length; i++) {
498
553
  const file = files[i];
499
554
  const fileType = getFileType(file.type);
500
555
 
501
556
  if (!fileType) {
502
- console.error(`Unsupported file type: ${file.type}`);
557
+ setInputError(`Unsupported file: ${file.name}`);
503
558
  continue;
504
559
  }
505
560
 
506
- if (file.size > MAX_FILE_SIZE_MB * 1024 * 1024) {
507
- console.error(`File too large: ${file.name}`);
561
+ const maxSize = getMaxSizeForType(fileType);
562
+
563
+ if (file.size > maxSize) {
564
+ setInputError(
565
+ `${file.name} exceeds ${FILE_SIZE_LIMITS_MB[fileType]}MB limit`
566
+ );
508
567
  continue;
509
568
  }
510
569
 
@@ -520,7 +579,11 @@ const MessageInput = () => {
520
579
  });
521
580
  }
522
581
 
523
- setAttachments((prev) => [...prev, ...newAttachments]);
582
+ if (newAttachments.length) {
583
+ setAttachments((prev) => [...prev, ...newAttachments]);
584
+ setInputError(null);
585
+ }
586
+
524
587
  if (fileInputRef.current) {
525
588
  fileInputRef.current.value = "";
526
589
  }
@@ -537,6 +600,7 @@ const MessageInput = () => {
537
600
  };
538
601
 
539
602
  const removeAttachment = (index: number) => {
603
+ setInputError(null);
540
604
  setAttachments((prev) => {
541
605
  const newAttachments = [...prev];
542
606
  URL.revokeObjectURL(newAttachments[index].previewUrl);
@@ -545,6 +609,8 @@ const MessageInput = () => {
545
609
  });
546
610
  };
547
611
 
612
+ {/* end of file attachment handlers */}
613
+
548
614
  return (
549
615
  <div className="message-input-container">
550
616
  {attachments.length > 0 && (
@@ -334,7 +334,7 @@ const Conversations = () => {
334
334
 
335
335
  {activeTab === "service" &&
336
336
  Object.entries(filteredGroupedServiceChats).length > 0 && (
337
- <div className="p-2">
337
+ <div className="p-2 h-[400px]">
338
338
  {Object.entries(filteredGroupedServiceChats).map(
339
339
  ([
340
340
  serviceId,