tycho-components 0.0.15-SNAPSHOT-10 → 0.0.15-SNAPSHOT-12
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/AppDropzone/AppDropzone.d.ts +14 -0
- package/dist/AppDropzone/AppDropzone.js +43 -0
- package/dist/AppDropzone/UploadService.d.ts +6 -0
- package/dist/AppDropzone/UploadService.js +18 -0
- package/dist/AppDropzone/UploadedFile.d.ts +13 -0
- package/dist/AppDropzone/UploadedFile.js +1 -0
- package/dist/AppDropzone/index.d.ts +2 -0
- package/dist/AppDropzone/index.js +2 -0
- package/dist/AppDropzone/style.scss +35 -0
- package/dist/configs/Localization.d.ts +14 -0
- package/dist/configs/Localization.js +5 -2
- package/dist/configs/localization/UploadTexts.d.ts +23 -0
- package/dist/configs/localization/UploadTexts.js +23 -0
- package/dist/configs/useCorpusUtils.d.ts +1 -0
- package/dist/configs/useCorpusUtils.js +4 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/functions/CorpusUtils.d.ts +0 -5
- package/dist/functions/CorpusUtils.js +0 -7
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import './style.scss';
|
|
2
|
+
import { UploadedFile } from './UploadedFile';
|
|
3
|
+
type Props = {
|
|
4
|
+
folder: string;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
onSuccess: (response: UploadedFile) => void;
|
|
7
|
+
onError?: (err: any) => void;
|
|
8
|
+
accept: Record<string, string[]>;
|
|
9
|
+
onDrop?: () => void;
|
|
10
|
+
keepName?: boolean;
|
|
11
|
+
title?: string;
|
|
12
|
+
};
|
|
13
|
+
export default function AppDropzone({ folder, onClose, onSuccess, onError, accept, onDrop, keepName, title, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import Dropzone from 'react-dropzone';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import './style.scss';
|
|
6
|
+
import UploadService from './UploadService';
|
|
7
|
+
import { useMessageUtils } from '../configs/useMessageUtils';
|
|
8
|
+
import AppModal from '../AppModal';
|
|
9
|
+
export default function AppDropzone({ folder, onClose, onSuccess, onError, accept, onDrop, keepName, title, }) {
|
|
10
|
+
const { t } = useTranslation('upload');
|
|
11
|
+
const { dispatchError } = useMessageUtils();
|
|
12
|
+
const [file, setFile] = useState();
|
|
13
|
+
const [preview, setPreview] = useState();
|
|
14
|
+
const isImageFile = (file) => {
|
|
15
|
+
return file.type.startsWith('image/');
|
|
16
|
+
};
|
|
17
|
+
const handleDrop = async (files) => {
|
|
18
|
+
const file = files[0];
|
|
19
|
+
setFile(file);
|
|
20
|
+
if (isImageFile(file))
|
|
21
|
+
setPreview(URL.createObjectURL(file));
|
|
22
|
+
onDrop && onDrop();
|
|
23
|
+
};
|
|
24
|
+
const upload = async () => {
|
|
25
|
+
if (!file)
|
|
26
|
+
return;
|
|
27
|
+
const data = new FormData();
|
|
28
|
+
data.append('file', file);
|
|
29
|
+
data.append('folder', folder);
|
|
30
|
+
keepName && data.append('keepOriginalName', 'true');
|
|
31
|
+
UploadService.execute(data)
|
|
32
|
+
.then((r) => {
|
|
33
|
+
onSuccess(r.data);
|
|
34
|
+
})
|
|
35
|
+
.catch((err) => {
|
|
36
|
+
dispatchError({ err: 'error.uploading.image', t });
|
|
37
|
+
onError && onError(err);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
return (_jsx(AppModal, { title: title || t('modal.title'), className: "modal-upload", close: onClose, confirm: upload, children: _jsxs("div", { className: "dropzone-container", children: [!file && (_jsx(Dropzone, { onDrop: (acceptedFiles) => handleDrop(acceptedFiles), accept: accept, maxFiles: 1, children: ({ getRootProps, getInputProps }) => (_jsxs("div", { ...getRootProps(), className: "dropzone", children: [_jsx("input", { ...getInputProps() }), _jsx("span", { children: t('label.dropzone') })] })) })), file && preview && (_jsx("img", { className: "preview", src: preview, onLoad: () => {
|
|
41
|
+
URL.revokeObjectURL(preview);
|
|
42
|
+
} })), file && !preview && (_jsxs("div", { className: "uploaded-message", children: [_jsx("b", { children: t('label.uploaded.file') }), _jsx("span", { children: file.name }), _jsx("b", { children: t('label.confirm') })] }))] }) }));
|
|
43
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import Cookies from 'js-cookie';
|
|
3
|
+
const JWT_TOKEN = 'jwt_token_tycho';
|
|
4
|
+
const getJwtToken = () => {
|
|
5
|
+
const cookie = Cookies.get(JWT_TOKEN);
|
|
6
|
+
return cookie === 'undefined' ? '' : cookie;
|
|
7
|
+
};
|
|
8
|
+
function execute(data) {
|
|
9
|
+
const token = getJwtToken() || '';
|
|
10
|
+
const header = {
|
|
11
|
+
Authorization: `Bearer ${token}`,
|
|
12
|
+
};
|
|
13
|
+
return axios.post(import.meta.env.VITE_APP_UPLOAD_URL, data, {
|
|
14
|
+
headers: header,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
const UploadService = { execute };
|
|
18
|
+
export default UploadService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
.dropzone-container {
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
justify-content: center;
|
|
5
|
+
|
|
6
|
+
.dropzone {
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
text-align: center;
|
|
11
|
+
width: 100%;
|
|
12
|
+
padding: var(--spacing-700);
|
|
13
|
+
border-radius: var(--radius-100);
|
|
14
|
+
border: 2px dashed var(--border-subtle-3);
|
|
15
|
+
background-color: var(--layer-layer-2);
|
|
16
|
+
cursor: pointer;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.preview {
|
|
20
|
+
margin: 0 auto;
|
|
21
|
+
width: 400px;
|
|
22
|
+
height: 400px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.uploaded-message {
|
|
26
|
+
display: flex;
|
|
27
|
+
flex-direction: column;
|
|
28
|
+
width: 100%;
|
|
29
|
+
gap: 16px;
|
|
30
|
+
text-align: center;
|
|
31
|
+
border: 1px solid var(--border-subtle-3);
|
|
32
|
+
border-radius: var(--radius-100);
|
|
33
|
+
padding: 16px;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -121,6 +121,13 @@ export declare const commonResources: {
|
|
|
121
121
|
'platform.name': string;
|
|
122
122
|
'platform.desc': string;
|
|
123
123
|
};
|
|
124
|
+
upload: {
|
|
125
|
+
'label.dropzone': string;
|
|
126
|
+
'label.uploaded.file': string;
|
|
127
|
+
'label.confirm': string;
|
|
128
|
+
'modal.title': string;
|
|
129
|
+
'error.uploading.image': string;
|
|
130
|
+
};
|
|
124
131
|
};
|
|
125
132
|
'pt-BR': {
|
|
126
133
|
common: {
|
|
@@ -241,6 +248,13 @@ export declare const commonResources: {
|
|
|
241
248
|
'platform.name': string;
|
|
242
249
|
'platform.desc': string;
|
|
243
250
|
};
|
|
251
|
+
upload: {
|
|
252
|
+
'label.dropzone': string;
|
|
253
|
+
'label.uploaded.file': string;
|
|
254
|
+
'label.confirm': string;
|
|
255
|
+
'modal.title': string;
|
|
256
|
+
'error.uploading.image': string;
|
|
257
|
+
};
|
|
244
258
|
};
|
|
245
259
|
it: {
|
|
246
260
|
header: {
|
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import i18n from 'i18next';
|
|
2
2
|
import languageDetector from 'i18next-browser-languagedetector';
|
|
3
3
|
import { initReactI18next } from 'react-i18next';
|
|
4
|
-
import { ParticipantsTexts } from './localization/ParticipantsTexts';
|
|
5
|
-
import { CommonTexts } from './localization/CommonTexts';
|
|
6
4
|
import { CommentsTexts } from './localization/CommentsTexts';
|
|
5
|
+
import { CommonTexts } from './localization/CommonTexts';
|
|
7
6
|
import { HeaderTexts } from './localization/HeaderTexts';
|
|
7
|
+
import { ParticipantsTexts } from './localization/ParticipantsTexts';
|
|
8
|
+
import { UploadTexts } from './localization/UploadTexts';
|
|
8
9
|
export const commonResources = {
|
|
9
10
|
en: {
|
|
10
11
|
common: CommonTexts.en,
|
|
11
12
|
participants: ParticipantsTexts.en,
|
|
12
13
|
comments: CommentsTexts.en,
|
|
13
14
|
header: HeaderTexts.en,
|
|
15
|
+
upload: UploadTexts.en,
|
|
14
16
|
},
|
|
15
17
|
'pt-BR': {
|
|
16
18
|
common: CommonTexts['pt-BR'],
|
|
17
19
|
participants: ParticipantsTexts['pt-BR'],
|
|
18
20
|
comments: CommentsTexts['pt-BR'],
|
|
19
21
|
header: HeaderTexts['pt-BR'],
|
|
22
|
+
upload: UploadTexts['pt-BR'],
|
|
20
23
|
},
|
|
21
24
|
it: {
|
|
22
25
|
header: HeaderTexts.it,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const UploadTexts: {
|
|
2
|
+
en: {
|
|
3
|
+
'label.dropzone': string;
|
|
4
|
+
'label.uploaded.file': string;
|
|
5
|
+
'label.confirm': string;
|
|
6
|
+
'modal.title': string;
|
|
7
|
+
'error.uploading.image': string;
|
|
8
|
+
};
|
|
9
|
+
'pt-BR': {
|
|
10
|
+
'label.dropzone': string;
|
|
11
|
+
'label.uploaded.file': string;
|
|
12
|
+
'label.confirm': string;
|
|
13
|
+
'modal.title': string;
|
|
14
|
+
'error.uploading.image': string;
|
|
15
|
+
};
|
|
16
|
+
it: {
|
|
17
|
+
'label.dropzone': string;
|
|
18
|
+
'label.uploaded.file': string;
|
|
19
|
+
'label.confirm': string;
|
|
20
|
+
'modal.title': string;
|
|
21
|
+
'error.uploading.image': string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const UploadTexts = {
|
|
2
|
+
en: {
|
|
3
|
+
'label.dropzone': 'Drag and drop or click to upload a file',
|
|
4
|
+
'label.uploaded.file': 'You are uploading the following file',
|
|
5
|
+
'label.confirm': 'Press confirm to continue',
|
|
6
|
+
'modal.title': 'Upload a file',
|
|
7
|
+
'error.uploading.image': 'An error occurred while uploading a file. Contact the administrator.',
|
|
8
|
+
},
|
|
9
|
+
'pt-BR': {
|
|
10
|
+
'label.dropzone': 'Arraste e solte ou clique para enviar um arquivo.',
|
|
11
|
+
'label.uploaded.file': 'Você está enviando o seguinte arquivo',
|
|
12
|
+
'label.confirm': 'Pressione confirmar para continuar',
|
|
13
|
+
'modal.title': 'Upload de arquivo',
|
|
14
|
+
'error.uploading.image': 'Ocorreu um erro ao enviar o arquivo. Entre em contato com o administrador.',
|
|
15
|
+
},
|
|
16
|
+
it: {
|
|
17
|
+
'label.dropzone': 'Trascina e rilascia o clicca per caricare un file',
|
|
18
|
+
'label.uploaded.file': 'Stai caricando il seguente file',
|
|
19
|
+
'label.confirm': 'Premi conferma per continuare',
|
|
20
|
+
'modal.title': 'Carica un file',
|
|
21
|
+
'error.uploading.image': "Si è verificato un errore durante il caricamento del file. Contatta l'amministratore.",
|
|
22
|
+
},
|
|
23
|
+
};
|
|
@@ -13,9 +13,13 @@ export const useCorpusUtils = () => {
|
|
|
13
13
|
const hasCorpus = () => {
|
|
14
14
|
return state.corpus !== undefined;
|
|
15
15
|
};
|
|
16
|
+
const hasParameter = (corpus, param) => {
|
|
17
|
+
return corpus.parameters[param];
|
|
18
|
+
};
|
|
16
19
|
return {
|
|
17
20
|
getCorpus,
|
|
18
21
|
setCorpus,
|
|
19
22
|
hasCorpus,
|
|
23
|
+
hasParameter,
|
|
20
24
|
};
|
|
21
25
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as AppAnalytics } from './AppAnalytics';
|
|
2
2
|
export { default as AppColorpicker } from './AppColorpicker';
|
|
3
|
+
export { default as AppDropzone } from './AppDropzone';
|
|
3
4
|
export { default as AppEditable } from './AppEditable';
|
|
4
5
|
export { default as AppLoading } from './AppLoading';
|
|
5
6
|
export { default as AppModal } from './AppModal';
|
|
@@ -24,7 +25,6 @@ export { commonResources } from './configs/Localization';
|
|
|
24
25
|
export { KeyboardCustomLayouts } from './VirtualKeyboard/KeyboardCustomLayout';
|
|
25
26
|
export { CorpusImageTypeNames } from './configs/CorpusImage';
|
|
26
27
|
export { UserStatusNames } from './configs/User';
|
|
27
|
-
export { default as CorpusUtils } from './functions/CorpusUtils';
|
|
28
28
|
export { default as DateUtils } from './functions/DateUtils';
|
|
29
29
|
export { default as FormUtils } from './functions/FormUtils';
|
|
30
30
|
export { default as ImageUtils } from './functions/ImageUtils';
|
|
@@ -39,5 +39,6 @@ export type { Github } from './configs/Corpus';
|
|
|
39
39
|
export type { FormFieldOption } from './AppEditable/FormFieldOption';
|
|
40
40
|
export type { FieldOperations, FormField } from './AppEditable/FormField';
|
|
41
41
|
export type { KeyboardLayout } from './VirtualKeyboard/KeyboardCustomLayout';
|
|
42
|
+
export type { UploadedFile } from './AppDropzone/UploadedFile';
|
|
42
43
|
export type { User } from './configs/User';
|
|
43
44
|
export type { UserStatus } from './configs/User';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as AppAnalytics } from './AppAnalytics';
|
|
2
2
|
export { default as AppColorpicker } from './AppColorpicker';
|
|
3
|
+
export { default as AppDropzone } from './AppDropzone';
|
|
3
4
|
export { default as AppEditable } from './AppEditable';
|
|
4
5
|
export { default as AppLoading } from './AppLoading';
|
|
5
6
|
export { default as AppModal } from './AppModal';
|
|
@@ -24,7 +25,6 @@ export { commonResources } from './configs/Localization';
|
|
|
24
25
|
export { KeyboardCustomLayouts } from './VirtualKeyboard/KeyboardCustomLayout';
|
|
25
26
|
export { CorpusImageTypeNames } from './configs/CorpusImage';
|
|
26
27
|
export { UserStatusNames } from './configs/User';
|
|
27
|
-
export { default as CorpusUtils } from './functions/CorpusUtils';
|
|
28
28
|
export { default as DateUtils } from './functions/DateUtils';
|
|
29
29
|
export { default as FormUtils } from './functions/FormUtils';
|
|
30
30
|
export { default as ImageUtils } from './functions/ImageUtils';
|
package/package.json
CHANGED