@fctc/sme-widget-ui 1.8.7 → 1.8.9

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/dist/index.js CHANGED
@@ -10015,6 +10015,18 @@ var vi_default = {
10015
10015
  filter_by: "B\u1ED9 l\u1ECDc",
10016
10016
  group_by: "Nh\xF3m theo",
10017
10017
  or: "ho\u1EB7c",
10018
+ second_ago: "gi\xE2y tr\u01B0\u1EDBc",
10019
+ minute_ago: "ph\xFAt tr\u01B0\u1EDBc",
10020
+ hour_ago: "gi\u1EDD tr\u01B0\u1EDBc",
10021
+ day_ago: "ng\xE0y tr\u01B0\u1EDBc",
10022
+ month_ago: "th\xE1ng tr\u01B0\u1EDBc",
10023
+ year_ago: "n\u0103m tr\u01B0\u1EDBc",
10024
+ second_future: "gi\xE2y n\u1EEFa",
10025
+ minute_future: "ph\xFAt n\u1EEFa",
10026
+ hour_future: "gi\u1EDD n\u1EEFa",
10027
+ day_future: "ng\xE0y n\u1EEFa",
10028
+ month_future: "th\xE1ng n\u1EEFa",
10029
+ year_future: "n\u0103m n\u1EEFa",
10018
10030
  now: "B\xE2y gi\u1EDD",
10019
10031
  download_file: "T\u1EA3i xu\u1ED1ng t\u1EC7p n\xE0y",
10020
10032
  upload_success: "T\u1EA3i t\u1EC7p l\xEAn th\xE0nh c\xF4ng",
@@ -10052,6 +10064,18 @@ var en_default = {
10052
10064
  group_by: "Group By",
10053
10065
  or: "or",
10054
10066
  now: "Now",
10067
+ second_ago: "seconds ago",
10068
+ minute_ago: "minutes ago",
10069
+ hour_ago: "hours ago",
10070
+ day_ago: "days ago",
10071
+ month_ago: "months ago",
10072
+ year_ago: "years ago",
10073
+ second_future: "seconds",
10074
+ minute_future: "minutes",
10075
+ hour_future: "hours",
10076
+ day_future: "days",
10077
+ month_future: "months",
10078
+ year_future: "years",
10055
10079
  download_file: "Download this file",
10056
10080
  upload_success: "Upload file success",
10057
10081
  upload_failure: "Upload file failure",
@@ -16811,7 +16835,7 @@ var ButtonSelectFiles = ({
16811
16835
  id,
16812
16836
  widget,
16813
16837
  useUploadImage,
16814
- useUploadFileExcel
16838
+ useUploadFile
16815
16839
  }) => {
16816
16840
  const { t: t3 } = useI18n();
16817
16841
  const ALLOWED_TYPES = [
@@ -16826,42 +16850,8 @@ var ButtonSelectFiles = ({
16826
16850
  ];
16827
16851
  const MAX_FILE_SIZE = 10 * 1024 * 1024;
16828
16852
  const MAX_TOTAL_SIZE = 50 * 1024 * 1024;
16829
- const { mutate: onUploadImage, isPending } = useUploadImage();
16830
- const { mutate: onUploadFile } = useUploadFileExcel();
16831
- const handleUploadImage = async ({ formData }) => {
16832
- console.log("data", formData);
16833
- if (widget !== "many2many_binary") {
16834
- onUploadImage(
16835
- { formData },
16836
- {
16837
- onSuccess: (data) => {
16838
- const formatData = data?.data?.["ir.attachment"]?.[0];
16839
- const files = [...selectedFiles, formatData];
16840
- setSelectedFiles(files);
16841
- y2.success(t3("upload_success"));
16842
- },
16843
- onError: () => {
16844
- y2.error(t3("upload_failure"));
16845
- }
16846
- }
16847
- );
16848
- } else {
16849
- onUploadFile(
16850
- { formData },
16851
- {
16852
- onSuccess: (data) => {
16853
- const formatData = data?.data?.["ir.attachment"]?.[0];
16854
- const files = [...selectedFiles, formatData];
16855
- setSelectedFiles(files);
16856
- y2.success(t3("upload_success"));
16857
- },
16858
- onError: () => {
16859
- y2.error(t3("upload_failure"));
16860
- }
16861
- }
16862
- );
16863
- }
16864
- };
16853
+ const isBinary = widget === "many2many_binary";
16854
+ const { mutate, isPending } = isBinary ? useUploadFile() : useUploadImage();
16865
16855
  const validateFile = (file) => {
16866
16856
  if (!ALLOWED_TYPES.includes(file.type)) {
16867
16857
  setUploadError(t3("file_accept_single"));
@@ -16881,24 +16871,50 @@ var ButtonSelectFiles = ({
16881
16871
  }
16882
16872
  return true;
16883
16873
  };
16884
- const convertFileToBase64 = (file) => {
16885
- return new Promise((resolve, reject) => {
16886
- const reader = new FileReader();
16887
- reader.readAsDataURL(file);
16888
- reader.onload = () => resolve(reader.result);
16889
- reader.onerror = (error2) => reject(error2);
16890
- });
16874
+ const handleUpload = async (formData) => {
16875
+ mutate(
16876
+ { formData },
16877
+ {
16878
+ onSuccess: (data) => {
16879
+ let newFiles = [];
16880
+ if (isBinary) {
16881
+ newFiles = Array.isArray(data) ? data : [data];
16882
+ } else {
16883
+ const formatData = data?.data?.["ir.attachment"]?.[0];
16884
+ newFiles = formatData ? [formatData] : [];
16885
+ }
16886
+ setSelectedFiles((prev2) => {
16887
+ return [...prev2, ...newFiles];
16888
+ });
16889
+ y2.success(instance.t("upload_success"));
16890
+ },
16891
+ onError: () => {
16892
+ y2.error(instance.t("upload_failure"));
16893
+ }
16894
+ }
16895
+ );
16891
16896
  };
16892
16897
  const handleOnChange = async (event) => {
16893
16898
  const files = Array.from(event.target.files ?? []);
16899
+ setUploadError(void 0);
16894
16900
  event.target.value = "";
16895
16901
  if (files.length === 0) return;
16896
- const file = files[0];
16897
- try {
16898
- const base64 = await convertFileToBase64(file);
16899
- setSelectedFiles([...selectedFiles, { name: file.name, data: base64 }]);
16900
- } catch (error2) {
16901
- console.error("Error converting file:", error2);
16902
+ const validFiles = files.filter((file) => validateFile(file));
16903
+ if (validFiles.length === 0) return;
16904
+ if (isBinary) {
16905
+ const formData = new FormData();
16906
+ validFiles.forEach((file) => formData.append("ufile", file));
16907
+ formData.append("model", String(model));
16908
+ formData.append("id", id ? String(id) : String(0));
16909
+ await handleUpload(formData);
16910
+ } else {
16911
+ const file = validFiles[0];
16912
+ const formData = new FormData();
16913
+ formData.append("ufile", file);
16914
+ formData.append("thread_model", String(model));
16915
+ formData.append("thread_id", id ? String(id) : String(0));
16916
+ formData.append("is_pending", "true");
16917
+ await handleUpload(formData);
16902
16918
  }
16903
16919
  };
16904
16920
  return /* @__PURE__ */ (0, import_jsx_runtime69.jsxs)(import_jsx_runtime69.Fragment, { children: [
package/dist/index.mjs CHANGED
@@ -9893,6 +9893,18 @@ var vi_default = {
9893
9893
  filter_by: "B\u1ED9 l\u1ECDc",
9894
9894
  group_by: "Nh\xF3m theo",
9895
9895
  or: "ho\u1EB7c",
9896
+ second_ago: "gi\xE2y tr\u01B0\u1EDBc",
9897
+ minute_ago: "ph\xFAt tr\u01B0\u1EDBc",
9898
+ hour_ago: "gi\u1EDD tr\u01B0\u1EDBc",
9899
+ day_ago: "ng\xE0y tr\u01B0\u1EDBc",
9900
+ month_ago: "th\xE1ng tr\u01B0\u1EDBc",
9901
+ year_ago: "n\u0103m tr\u01B0\u1EDBc",
9902
+ second_future: "gi\xE2y n\u1EEFa",
9903
+ minute_future: "ph\xFAt n\u1EEFa",
9904
+ hour_future: "gi\u1EDD n\u1EEFa",
9905
+ day_future: "ng\xE0y n\u1EEFa",
9906
+ month_future: "th\xE1ng n\u1EEFa",
9907
+ year_future: "n\u0103m n\u1EEFa",
9896
9908
  now: "B\xE2y gi\u1EDD",
9897
9909
  download_file: "T\u1EA3i xu\u1ED1ng t\u1EC7p n\xE0y",
9898
9910
  upload_success: "T\u1EA3i t\u1EC7p l\xEAn th\xE0nh c\xF4ng",
@@ -9930,6 +9942,18 @@ var en_default = {
9930
9942
  group_by: "Group By",
9931
9943
  or: "or",
9932
9944
  now: "Now",
9945
+ second_ago: "seconds ago",
9946
+ minute_ago: "minutes ago",
9947
+ hour_ago: "hours ago",
9948
+ day_ago: "days ago",
9949
+ month_ago: "months ago",
9950
+ year_ago: "years ago",
9951
+ second_future: "seconds",
9952
+ minute_future: "minutes",
9953
+ hour_future: "hours",
9954
+ day_future: "days",
9955
+ month_future: "months",
9956
+ year_future: "years",
9933
9957
  download_file: "Download this file",
9934
9958
  upload_success: "Upload file success",
9935
9959
  upload_failure: "Upload file failure",
@@ -16689,7 +16713,7 @@ var ButtonSelectFiles = ({
16689
16713
  id,
16690
16714
  widget,
16691
16715
  useUploadImage,
16692
- useUploadFileExcel
16716
+ useUploadFile
16693
16717
  }) => {
16694
16718
  const { t: t3 } = useI18n();
16695
16719
  const ALLOWED_TYPES = [
@@ -16704,42 +16728,8 @@ var ButtonSelectFiles = ({
16704
16728
  ];
16705
16729
  const MAX_FILE_SIZE = 10 * 1024 * 1024;
16706
16730
  const MAX_TOTAL_SIZE = 50 * 1024 * 1024;
16707
- const { mutate: onUploadImage, isPending } = useUploadImage();
16708
- const { mutate: onUploadFile } = useUploadFileExcel();
16709
- const handleUploadImage = async ({ formData }) => {
16710
- console.log("data", formData);
16711
- if (widget !== "many2many_binary") {
16712
- onUploadImage(
16713
- { formData },
16714
- {
16715
- onSuccess: (data) => {
16716
- const formatData = data?.data?.["ir.attachment"]?.[0];
16717
- const files = [...selectedFiles, formatData];
16718
- setSelectedFiles(files);
16719
- y2.success(t3("upload_success"));
16720
- },
16721
- onError: () => {
16722
- y2.error(t3("upload_failure"));
16723
- }
16724
- }
16725
- );
16726
- } else {
16727
- onUploadFile(
16728
- { formData },
16729
- {
16730
- onSuccess: (data) => {
16731
- const formatData = data?.data?.["ir.attachment"]?.[0];
16732
- const files = [...selectedFiles, formatData];
16733
- setSelectedFiles(files);
16734
- y2.success(t3("upload_success"));
16735
- },
16736
- onError: () => {
16737
- y2.error(t3("upload_failure"));
16738
- }
16739
- }
16740
- );
16741
- }
16742
- };
16731
+ const isBinary = widget === "many2many_binary";
16732
+ const { mutate, isPending } = isBinary ? useUploadFile() : useUploadImage();
16743
16733
  const validateFile = (file) => {
16744
16734
  if (!ALLOWED_TYPES.includes(file.type)) {
16745
16735
  setUploadError(t3("file_accept_single"));
@@ -16759,24 +16749,50 @@ var ButtonSelectFiles = ({
16759
16749
  }
16760
16750
  return true;
16761
16751
  };
16762
- const convertFileToBase64 = (file) => {
16763
- return new Promise((resolve, reject) => {
16764
- const reader = new FileReader();
16765
- reader.readAsDataURL(file);
16766
- reader.onload = () => resolve(reader.result);
16767
- reader.onerror = (error2) => reject(error2);
16768
- });
16752
+ const handleUpload = async (formData) => {
16753
+ mutate(
16754
+ { formData },
16755
+ {
16756
+ onSuccess: (data) => {
16757
+ let newFiles = [];
16758
+ if (isBinary) {
16759
+ newFiles = Array.isArray(data) ? data : [data];
16760
+ } else {
16761
+ const formatData = data?.data?.["ir.attachment"]?.[0];
16762
+ newFiles = formatData ? [formatData] : [];
16763
+ }
16764
+ setSelectedFiles((prev2) => {
16765
+ return [...prev2, ...newFiles];
16766
+ });
16767
+ y2.success(instance.t("upload_success"));
16768
+ },
16769
+ onError: () => {
16770
+ y2.error(instance.t("upload_failure"));
16771
+ }
16772
+ }
16773
+ );
16769
16774
  };
16770
16775
  const handleOnChange = async (event) => {
16771
16776
  const files = Array.from(event.target.files ?? []);
16777
+ setUploadError(void 0);
16772
16778
  event.target.value = "";
16773
16779
  if (files.length === 0) return;
16774
- const file = files[0];
16775
- try {
16776
- const base64 = await convertFileToBase64(file);
16777
- setSelectedFiles([...selectedFiles, { name: file.name, data: base64 }]);
16778
- } catch (error2) {
16779
- console.error("Error converting file:", error2);
16780
+ const validFiles = files.filter((file) => validateFile(file));
16781
+ if (validFiles.length === 0) return;
16782
+ if (isBinary) {
16783
+ const formData = new FormData();
16784
+ validFiles.forEach((file) => formData.append("ufile", file));
16785
+ formData.append("model", String(model));
16786
+ formData.append("id", id ? String(id) : String(0));
16787
+ await handleUpload(formData);
16788
+ } else {
16789
+ const file = validFiles[0];
16790
+ const formData = new FormData();
16791
+ formData.append("ufile", file);
16792
+ formData.append("thread_model", String(model));
16793
+ formData.append("thread_id", id ? String(id) : String(0));
16794
+ formData.append("is_pending", "true");
16795
+ await handleUpload(formData);
16780
16796
  }
16781
16797
  };
16782
16798
  return /* @__PURE__ */ jsxs44(Fragment14, { children: [
package/dist/utils.js CHANGED
@@ -6830,6 +6830,18 @@ var vi_default = {
6830
6830
  filter_by: "B\u1ED9 l\u1ECDc",
6831
6831
  group_by: "Nh\xF3m theo",
6832
6832
  or: "ho\u1EB7c",
6833
+ second_ago: "gi\xE2y tr\u01B0\u1EDBc",
6834
+ minute_ago: "ph\xFAt tr\u01B0\u1EDBc",
6835
+ hour_ago: "gi\u1EDD tr\u01B0\u1EDBc",
6836
+ day_ago: "ng\xE0y tr\u01B0\u1EDBc",
6837
+ month_ago: "th\xE1ng tr\u01B0\u1EDBc",
6838
+ year_ago: "n\u0103m tr\u01B0\u1EDBc",
6839
+ second_future: "gi\xE2y n\u1EEFa",
6840
+ minute_future: "ph\xFAt n\u1EEFa",
6841
+ hour_future: "gi\u1EDD n\u1EEFa",
6842
+ day_future: "ng\xE0y n\u1EEFa",
6843
+ month_future: "th\xE1ng n\u1EEFa",
6844
+ year_future: "n\u0103m n\u1EEFa",
6833
6845
  now: "B\xE2y gi\u1EDD",
6834
6846
  download_file: "T\u1EA3i xu\u1ED1ng t\u1EC7p n\xE0y",
6835
6847
  upload_success: "T\u1EA3i t\u1EC7p l\xEAn th\xE0nh c\xF4ng",
@@ -6867,6 +6879,18 @@ var en_default = {
6867
6879
  group_by: "Group By",
6868
6880
  or: "or",
6869
6881
  now: "Now",
6882
+ second_ago: "seconds ago",
6883
+ minute_ago: "minutes ago",
6884
+ hour_ago: "hours ago",
6885
+ day_ago: "days ago",
6886
+ month_ago: "months ago",
6887
+ year_ago: "years ago",
6888
+ second_future: "seconds",
6889
+ minute_future: "minutes",
6890
+ hour_future: "hours",
6891
+ day_future: "days",
6892
+ month_future: "months",
6893
+ year_future: "years",
6870
6894
  download_file: "Download this file",
6871
6895
  upload_success: "Upload file success",
6872
6896
  upload_failure: "Upload file failure",
package/dist/utils.mjs CHANGED
@@ -6807,6 +6807,18 @@ var vi_default = {
6807
6807
  filter_by: "B\u1ED9 l\u1ECDc",
6808
6808
  group_by: "Nh\xF3m theo",
6809
6809
  or: "ho\u1EB7c",
6810
+ second_ago: "gi\xE2y tr\u01B0\u1EDBc",
6811
+ minute_ago: "ph\xFAt tr\u01B0\u1EDBc",
6812
+ hour_ago: "gi\u1EDD tr\u01B0\u1EDBc",
6813
+ day_ago: "ng\xE0y tr\u01B0\u1EDBc",
6814
+ month_ago: "th\xE1ng tr\u01B0\u1EDBc",
6815
+ year_ago: "n\u0103m tr\u01B0\u1EDBc",
6816
+ second_future: "gi\xE2y n\u1EEFa",
6817
+ minute_future: "ph\xFAt n\u1EEFa",
6818
+ hour_future: "gi\u1EDD n\u1EEFa",
6819
+ day_future: "ng\xE0y n\u1EEFa",
6820
+ month_future: "th\xE1ng n\u1EEFa",
6821
+ year_future: "n\u0103m n\u1EEFa",
6810
6822
  now: "B\xE2y gi\u1EDD",
6811
6823
  download_file: "T\u1EA3i xu\u1ED1ng t\u1EC7p n\xE0y",
6812
6824
  upload_success: "T\u1EA3i t\u1EC7p l\xEAn th\xE0nh c\xF4ng",
@@ -6844,6 +6856,18 @@ var en_default = {
6844
6856
  group_by: "Group By",
6845
6857
  or: "or",
6846
6858
  now: "Now",
6859
+ second_ago: "seconds ago",
6860
+ minute_ago: "minutes ago",
6861
+ hour_ago: "hours ago",
6862
+ day_ago: "days ago",
6863
+ month_ago: "months ago",
6864
+ year_ago: "years ago",
6865
+ second_future: "seconds",
6866
+ minute_future: "minutes",
6867
+ hour_future: "hours",
6868
+ day_future: "days",
6869
+ month_future: "months",
6870
+ year_future: "years",
6847
6871
  download_file: "Download this file",
6848
6872
  upload_success: "Upload file success",
6849
6873
  upload_failure: "Upload file failure",
@@ -497,7 +497,7 @@ declare const LoadingSmall: () => JSX.Element;
497
497
 
498
498
  declare const RenderFiles: ({ selectedFiles, setSelectedFiles, useGetImage }: any) => JSX.Element;
499
499
 
500
- declare const ButtonSelectFiles: ({ fileInputRef, selectedFiles, setSelectedFiles, setUploadError, model, id, widget, useUploadImage, useUploadFileExcel, }: any) => JSX.Element;
500
+ declare const ButtonSelectFiles: ({ fileInputRef, selectedFiles, setSelectedFiles, setUploadError, model, id, widget, useUploadImage, useUploadFile, }: any) => JSX.Element;
501
501
 
502
502
  interface VideoPlayerProps {
503
503
  src: string;
package/dist/widgets.d.ts CHANGED
@@ -497,7 +497,7 @@ declare const LoadingSmall: () => JSX.Element;
497
497
 
498
498
  declare const RenderFiles: ({ selectedFiles, setSelectedFiles, useGetImage }: any) => JSX.Element;
499
499
 
500
- declare const ButtonSelectFiles: ({ fileInputRef, selectedFiles, setSelectedFiles, setUploadError, model, id, widget, useUploadImage, useUploadFileExcel, }: any) => JSX.Element;
500
+ declare const ButtonSelectFiles: ({ fileInputRef, selectedFiles, setSelectedFiles, setUploadError, model, id, widget, useUploadImage, useUploadFile, }: any) => JSX.Element;
501
501
 
502
502
  interface VideoPlayerProps {
503
503
  src: string;
package/dist/widgets.js CHANGED
@@ -7754,6 +7754,18 @@ var vi_default = {
7754
7754
  filter_by: "B\u1ED9 l\u1ECDc",
7755
7755
  group_by: "Nh\xF3m theo",
7756
7756
  or: "ho\u1EB7c",
7757
+ second_ago: "gi\xE2y tr\u01B0\u1EDBc",
7758
+ minute_ago: "ph\xFAt tr\u01B0\u1EDBc",
7759
+ hour_ago: "gi\u1EDD tr\u01B0\u1EDBc",
7760
+ day_ago: "ng\xE0y tr\u01B0\u1EDBc",
7761
+ month_ago: "th\xE1ng tr\u01B0\u1EDBc",
7762
+ year_ago: "n\u0103m tr\u01B0\u1EDBc",
7763
+ second_future: "gi\xE2y n\u1EEFa",
7764
+ minute_future: "ph\xFAt n\u1EEFa",
7765
+ hour_future: "gi\u1EDD n\u1EEFa",
7766
+ day_future: "ng\xE0y n\u1EEFa",
7767
+ month_future: "th\xE1ng n\u1EEFa",
7768
+ year_future: "n\u0103m n\u1EEFa",
7757
7769
  now: "B\xE2y gi\u1EDD",
7758
7770
  download_file: "T\u1EA3i xu\u1ED1ng t\u1EC7p n\xE0y",
7759
7771
  upload_success: "T\u1EA3i t\u1EC7p l\xEAn th\xE0nh c\xF4ng",
@@ -7791,6 +7803,18 @@ var en_default = {
7791
7803
  group_by: "Group By",
7792
7804
  or: "or",
7793
7805
  now: "Now",
7806
+ second_ago: "seconds ago",
7807
+ minute_ago: "minutes ago",
7808
+ hour_ago: "hours ago",
7809
+ day_ago: "days ago",
7810
+ month_ago: "months ago",
7811
+ year_ago: "years ago",
7812
+ second_future: "seconds",
7813
+ minute_future: "minutes",
7814
+ hour_future: "hours",
7815
+ day_future: "days",
7816
+ month_future: "months",
7817
+ year_future: "years",
7794
7818
  download_file: "Download this file",
7795
7819
  upload_success: "Upload file success",
7796
7820
  upload_failure: "Upload file failure",
@@ -16217,7 +16241,7 @@ var ButtonSelectFiles = ({
16217
16241
  id,
16218
16242
  widget,
16219
16243
  useUploadImage,
16220
- useUploadFileExcel
16244
+ useUploadFile
16221
16245
  }) => {
16222
16246
  const { t: t3 } = useI18n();
16223
16247
  const ALLOWED_TYPES = [
@@ -16232,42 +16256,8 @@ var ButtonSelectFiles = ({
16232
16256
  ];
16233
16257
  const MAX_FILE_SIZE = 10 * 1024 * 1024;
16234
16258
  const MAX_TOTAL_SIZE = 50 * 1024 * 1024;
16235
- const { mutate: onUploadImage, isPending } = useUploadImage();
16236
- const { mutate: onUploadFile } = useUploadFileExcel();
16237
- const handleUploadImage = async ({ formData }) => {
16238
- console.log("data", formData);
16239
- if (widget !== "many2many_binary") {
16240
- onUploadImage(
16241
- { formData },
16242
- {
16243
- onSuccess: (data) => {
16244
- const formatData = data?.data?.["ir.attachment"]?.[0];
16245
- const files = [...selectedFiles, formatData];
16246
- setSelectedFiles(files);
16247
- y2.success(t3("upload_success"));
16248
- },
16249
- onError: () => {
16250
- y2.error(t3("upload_failure"));
16251
- }
16252
- }
16253
- );
16254
- } else {
16255
- onUploadFile(
16256
- { formData },
16257
- {
16258
- onSuccess: (data) => {
16259
- const formatData = data?.data?.["ir.attachment"]?.[0];
16260
- const files = [...selectedFiles, formatData];
16261
- setSelectedFiles(files);
16262
- y2.success(t3("upload_success"));
16263
- },
16264
- onError: () => {
16265
- y2.error(t3("upload_failure"));
16266
- }
16267
- }
16268
- );
16269
- }
16270
- };
16259
+ const isBinary = widget === "many2many_binary";
16260
+ const { mutate, isPending } = isBinary ? useUploadFile() : useUploadImage();
16271
16261
  const validateFile = (file) => {
16272
16262
  if (!ALLOWED_TYPES.includes(file.type)) {
16273
16263
  setUploadError(t3("file_accept_single"));
@@ -16287,24 +16277,50 @@ var ButtonSelectFiles = ({
16287
16277
  }
16288
16278
  return true;
16289
16279
  };
16290
- const convertFileToBase64 = (file) => {
16291
- return new Promise((resolve, reject) => {
16292
- const reader = new FileReader();
16293
- reader.readAsDataURL(file);
16294
- reader.onload = () => resolve(reader.result);
16295
- reader.onerror = (error2) => reject(error2);
16296
- });
16280
+ const handleUpload = async (formData) => {
16281
+ mutate(
16282
+ { formData },
16283
+ {
16284
+ onSuccess: (data) => {
16285
+ let newFiles = [];
16286
+ if (isBinary) {
16287
+ newFiles = Array.isArray(data) ? data : [data];
16288
+ } else {
16289
+ const formatData = data?.data?.["ir.attachment"]?.[0];
16290
+ newFiles = formatData ? [formatData] : [];
16291
+ }
16292
+ setSelectedFiles((prev2) => {
16293
+ return [...prev2, ...newFiles];
16294
+ });
16295
+ y2.success(instance.t("upload_success"));
16296
+ },
16297
+ onError: () => {
16298
+ y2.error(instance.t("upload_failure"));
16299
+ }
16300
+ }
16301
+ );
16297
16302
  };
16298
16303
  const handleOnChange = async (event) => {
16299
16304
  const files = Array.from(event.target.files ?? []);
16305
+ setUploadError(void 0);
16300
16306
  event.target.value = "";
16301
16307
  if (files.length === 0) return;
16302
- const file = files[0];
16303
- try {
16304
- const base64 = await convertFileToBase64(file);
16305
- setSelectedFiles([...selectedFiles, { name: file.name, data: base64 }]);
16306
- } catch (error2) {
16307
- console.error("Error converting file:", error2);
16308
+ const validFiles = files.filter((file) => validateFile(file));
16309
+ if (validFiles.length === 0) return;
16310
+ if (isBinary) {
16311
+ const formData = new FormData();
16312
+ validFiles.forEach((file) => formData.append("ufile", file));
16313
+ formData.append("model", String(model));
16314
+ formData.append("id", id ? String(id) : String(0));
16315
+ await handleUpload(formData);
16316
+ } else {
16317
+ const file = validFiles[0];
16318
+ const formData = new FormData();
16319
+ formData.append("ufile", file);
16320
+ formData.append("thread_model", String(model));
16321
+ formData.append("thread_id", id ? String(id) : String(0));
16322
+ formData.append("is_pending", "true");
16323
+ await handleUpload(formData);
16308
16324
  }
16309
16325
  };
16310
16326
  return /* @__PURE__ */ (0, import_jsx_runtime69.jsxs)(import_jsx_runtime69.Fragment, { children: [
package/dist/widgets.mjs CHANGED
@@ -7691,6 +7691,18 @@ var vi_default = {
7691
7691
  filter_by: "B\u1ED9 l\u1ECDc",
7692
7692
  group_by: "Nh\xF3m theo",
7693
7693
  or: "ho\u1EB7c",
7694
+ second_ago: "gi\xE2y tr\u01B0\u1EDBc",
7695
+ minute_ago: "ph\xFAt tr\u01B0\u1EDBc",
7696
+ hour_ago: "gi\u1EDD tr\u01B0\u1EDBc",
7697
+ day_ago: "ng\xE0y tr\u01B0\u1EDBc",
7698
+ month_ago: "th\xE1ng tr\u01B0\u1EDBc",
7699
+ year_ago: "n\u0103m tr\u01B0\u1EDBc",
7700
+ second_future: "gi\xE2y n\u1EEFa",
7701
+ minute_future: "ph\xFAt n\u1EEFa",
7702
+ hour_future: "gi\u1EDD n\u1EEFa",
7703
+ day_future: "ng\xE0y n\u1EEFa",
7704
+ month_future: "th\xE1ng n\u1EEFa",
7705
+ year_future: "n\u0103m n\u1EEFa",
7694
7706
  now: "B\xE2y gi\u1EDD",
7695
7707
  download_file: "T\u1EA3i xu\u1ED1ng t\u1EC7p n\xE0y",
7696
7708
  upload_success: "T\u1EA3i t\u1EC7p l\xEAn th\xE0nh c\xF4ng",
@@ -7728,6 +7740,18 @@ var en_default = {
7728
7740
  group_by: "Group By",
7729
7741
  or: "or",
7730
7742
  now: "Now",
7743
+ second_ago: "seconds ago",
7744
+ minute_ago: "minutes ago",
7745
+ hour_ago: "hours ago",
7746
+ day_ago: "days ago",
7747
+ month_ago: "months ago",
7748
+ year_ago: "years ago",
7749
+ second_future: "seconds",
7750
+ minute_future: "minutes",
7751
+ hour_future: "hours",
7752
+ day_future: "days",
7753
+ month_future: "months",
7754
+ year_future: "years",
7731
7755
  download_file: "Download this file",
7732
7756
  upload_success: "Upload file success",
7733
7757
  upload_failure: "Upload file failure",
@@ -16154,7 +16178,7 @@ var ButtonSelectFiles = ({
16154
16178
  id,
16155
16179
  widget,
16156
16180
  useUploadImage,
16157
- useUploadFileExcel
16181
+ useUploadFile
16158
16182
  }) => {
16159
16183
  const { t: t3 } = useI18n();
16160
16184
  const ALLOWED_TYPES = [
@@ -16169,42 +16193,8 @@ var ButtonSelectFiles = ({
16169
16193
  ];
16170
16194
  const MAX_FILE_SIZE = 10 * 1024 * 1024;
16171
16195
  const MAX_TOTAL_SIZE = 50 * 1024 * 1024;
16172
- const { mutate: onUploadImage, isPending } = useUploadImage();
16173
- const { mutate: onUploadFile } = useUploadFileExcel();
16174
- const handleUploadImage = async ({ formData }) => {
16175
- console.log("data", formData);
16176
- if (widget !== "many2many_binary") {
16177
- onUploadImage(
16178
- { formData },
16179
- {
16180
- onSuccess: (data) => {
16181
- const formatData = data?.data?.["ir.attachment"]?.[0];
16182
- const files = [...selectedFiles, formatData];
16183
- setSelectedFiles(files);
16184
- y2.success(t3("upload_success"));
16185
- },
16186
- onError: () => {
16187
- y2.error(t3("upload_failure"));
16188
- }
16189
- }
16190
- );
16191
- } else {
16192
- onUploadFile(
16193
- { formData },
16194
- {
16195
- onSuccess: (data) => {
16196
- const formatData = data?.data?.["ir.attachment"]?.[0];
16197
- const files = [...selectedFiles, formatData];
16198
- setSelectedFiles(files);
16199
- y2.success(t3("upload_success"));
16200
- },
16201
- onError: () => {
16202
- y2.error(t3("upload_failure"));
16203
- }
16204
- }
16205
- );
16206
- }
16207
- };
16196
+ const isBinary = widget === "many2many_binary";
16197
+ const { mutate, isPending } = isBinary ? useUploadFile() : useUploadImage();
16208
16198
  const validateFile = (file) => {
16209
16199
  if (!ALLOWED_TYPES.includes(file.type)) {
16210
16200
  setUploadError(t3("file_accept_single"));
@@ -16224,24 +16214,50 @@ var ButtonSelectFiles = ({
16224
16214
  }
16225
16215
  return true;
16226
16216
  };
16227
- const convertFileToBase64 = (file) => {
16228
- return new Promise((resolve, reject) => {
16229
- const reader = new FileReader();
16230
- reader.readAsDataURL(file);
16231
- reader.onload = () => resolve(reader.result);
16232
- reader.onerror = (error2) => reject(error2);
16233
- });
16217
+ const handleUpload = async (formData) => {
16218
+ mutate(
16219
+ { formData },
16220
+ {
16221
+ onSuccess: (data) => {
16222
+ let newFiles = [];
16223
+ if (isBinary) {
16224
+ newFiles = Array.isArray(data) ? data : [data];
16225
+ } else {
16226
+ const formatData = data?.data?.["ir.attachment"]?.[0];
16227
+ newFiles = formatData ? [formatData] : [];
16228
+ }
16229
+ setSelectedFiles((prev2) => {
16230
+ return [...prev2, ...newFiles];
16231
+ });
16232
+ y2.success(instance.t("upload_success"));
16233
+ },
16234
+ onError: () => {
16235
+ y2.error(instance.t("upload_failure"));
16236
+ }
16237
+ }
16238
+ );
16234
16239
  };
16235
16240
  const handleOnChange = async (event) => {
16236
16241
  const files = Array.from(event.target.files ?? []);
16242
+ setUploadError(void 0);
16237
16243
  event.target.value = "";
16238
16244
  if (files.length === 0) return;
16239
- const file = files[0];
16240
- try {
16241
- const base64 = await convertFileToBase64(file);
16242
- setSelectedFiles([...selectedFiles, { name: file.name, data: base64 }]);
16243
- } catch (error2) {
16244
- console.error("Error converting file:", error2);
16245
+ const validFiles = files.filter((file) => validateFile(file));
16246
+ if (validFiles.length === 0) return;
16247
+ if (isBinary) {
16248
+ const formData = new FormData();
16249
+ validFiles.forEach((file) => formData.append("ufile", file));
16250
+ formData.append("model", String(model));
16251
+ formData.append("id", id ? String(id) : String(0));
16252
+ await handleUpload(formData);
16253
+ } else {
16254
+ const file = validFiles[0];
16255
+ const formData = new FormData();
16256
+ formData.append("ufile", file);
16257
+ formData.append("thread_model", String(model));
16258
+ formData.append("thread_id", id ? String(id) : String(0));
16259
+ formData.append("is_pending", "true");
16260
+ await handleUpload(formData);
16245
16261
  }
16246
16262
  };
16247
16263
  return /* @__PURE__ */ jsxs44(Fragment14, { children: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fctc/sme-widget-ui",
3
- "version": "1.8.7",
3
+ "version": "1.8.9",
4
4
  "main": "dist/index.cjs",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",