@autobusal/common 1.3.1 → 1.3.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/Viewer/Items/TextareaHtml.tsx +10 -0
- package/Viewer/services.ts +24 -0
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ import { Editor } from '@tinymce/tinymce-react';
|
|
|
5
5
|
import { Editor as TinyMceEditor } from 'tinymce';
|
|
6
6
|
import { Validate } from '@autobusal/utilities/form';
|
|
7
7
|
import { Textarea } from './styles';
|
|
8
|
+
import { useFileUpload } from '../services';
|
|
8
9
|
|
|
9
10
|
interface Props {
|
|
10
11
|
name: string
|
|
@@ -18,10 +19,18 @@ interface Props {
|
|
|
18
19
|
const TextareaHtml = ({ name, value, validation, t, refs, onUpdate }: Props): JSX.Element => {
|
|
19
20
|
const editorRef = useRef<TinyMceEditor | null>(null);
|
|
20
21
|
|
|
22
|
+
const { mutateAsync: Upload } = useFileUpload();
|
|
23
|
+
|
|
21
24
|
const onChange = (content: string): void => {
|
|
22
25
|
onUpdate(name, content);
|
|
23
26
|
};
|
|
24
27
|
|
|
28
|
+
const onFileUpload = async (blobinfo: any): Promise<string> => {
|
|
29
|
+
const uploaded = await Upload(blobinfo);
|
|
30
|
+
|
|
31
|
+
return uploaded.filename;
|
|
32
|
+
};
|
|
33
|
+
|
|
25
34
|
return (
|
|
26
35
|
<div className="row-data">
|
|
27
36
|
<Editor
|
|
@@ -43,6 +52,7 @@ const TextareaHtml = ({ name, value, validation, t, refs, onUpdate }: Props): JS
|
|
|
43
52
|
'image media table | ' +
|
|
44
53
|
'removeformat | help'
|
|
45
54
|
),
|
|
55
|
+
images_upload_handler: onFileUpload,
|
|
46
56
|
content_style: 'body { font-family: Helvetica, Arial, sans-serif; font-size: 14px; }',
|
|
47
57
|
promotion: false,
|
|
48
58
|
highlight_on_focus: false
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { UseMutationResult, useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { apiClient } from '@autobusal/providers';
|
|
3
|
+
import { UploadData } from '@autobusal/providers/types';
|
|
4
|
+
|
|
5
|
+
export const useFileUpload = (): UseMutationResult<UploadData, Error, any, unknown> => (
|
|
6
|
+
useMutation({
|
|
7
|
+
mutationKey: ['textarea-html'],
|
|
8
|
+
mutationFn: async (blobData) => {
|
|
9
|
+
const formData = new FormData();
|
|
10
|
+
|
|
11
|
+
formData.append('image', blobData.blob(), blobData.filename());
|
|
12
|
+
|
|
13
|
+
return await apiClient
|
|
14
|
+
.post('/api/label/admin/upload', formData, {
|
|
15
|
+
headers: {
|
|
16
|
+
'Content-Type': 'multipart/form-data'
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
.then(response => (
|
|
20
|
+
response.data
|
|
21
|
+
))
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
);
|