code7-leia 0.1.48 → 0.1.52

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.
@@ -0,0 +1,131 @@
1
+ import React, { useCallback, useEffect, useState } from 'react';
2
+ import { getLanguage } from '../../../../utils/getLanguage'
3
+ import { useDropzone, FileRejection } from 'react-dropzone';
4
+ import PropTypes from 'prop-types';
5
+
6
+ import { Container} from './styles';
7
+
8
+ interface FileProperties {
9
+ id: number;
10
+ lastModified: number;
11
+ lastModifiedDate: Date;
12
+ name: string;
13
+ size: number;
14
+ type: string;
15
+ }
16
+
17
+ interface AreaUploadProps {
18
+ formatFile?: string;
19
+ multipleFile?: boolean;
20
+ initialFiles?: File[];
21
+ removeItem?: (file: FileProperties) => void;
22
+ setFile?: (file: { content: ArrayBuffer | string; properties: File }) => void;
23
+ onChange?: (files: File[]) => void;
24
+ hasListFiles?: boolean;
25
+ }
26
+
27
+ const AreaUpload: React.FC<AreaUploadProps> = ({
28
+ formatFile = 'application/pdf',
29
+ multipleFile = false,
30
+ initialFiles = [],
31
+ setFile = () => {},
32
+ onChange = () => {},
33
+ }) => {
34
+ const [myFiles, setMyFiles] = useState<File[]>([]);
35
+ const t = getLanguage('pt-br')
36
+
37
+ useEffect(() => {
38
+ setMyFiles([...initialFiles, ...myFiles]);
39
+ }, []);
40
+
41
+ const onDrop = useCallback(
42
+ (acceptedFiles: File[], fileRejections: FileRejection[]) => {
43
+ if (fileRejections && fileRejections.length > 0) {
44
+ console.error('Arquivos rejeitados:', fileRejections);
45
+ }
46
+
47
+ onChange(acceptedFiles);
48
+
49
+ const files = [...myFiles, ...acceptedFiles];
50
+ const filesWithId = files.map((item, index) => ({
51
+ id: index + 1,
52
+ lastModified: item.lastModified,
53
+ name: item.name,
54
+ size: item.size,
55
+ type: item.type,
56
+ }));
57
+ setMyFiles(filesWithId as unknown as File[]);
58
+
59
+ acceptedFiles.forEach((file) => {
60
+ const reader = new FileReader();
61
+
62
+ reader.onload = () => {
63
+ const binaryStr = reader.result;
64
+ setFile({ content: binaryStr as ArrayBuffer, properties: file });
65
+ };
66
+ reader.readAsArrayBuffer(file);
67
+ });
68
+ },
69
+ [myFiles]
70
+ );
71
+
72
+ const {
73
+ getRootProps,
74
+ getInputProps,
75
+ open,
76
+ isDragActive,
77
+ isDragAccept,
78
+ isDragReject,
79
+ } = useDropzone({
80
+ accept: formatFile as any,
81
+ noClick: true,
82
+ noKeyboard: true,
83
+ multiple: multipleFile,
84
+ onDrop,
85
+ });
86
+
87
+ return (
88
+ <>
89
+ {multipleFile || myFiles?.length === 0 ? (
90
+ <Container
91
+ {...getRootProps({ isDragActive, isDragAccept, isDragReject })}
92
+ >
93
+ <input {...getInputProps()} />
94
+
95
+ <span>
96
+ <p>
97
+ {t.fileArea.modal.descriptionUpload}
98
+ </p>
99
+ </span>
100
+ <button type="button" onClick={open}>
101
+ {t.fileArea.modal.chooseFile}
102
+ </button>
103
+ </Container>
104
+ ) : (
105
+ ''
106
+ )}
107
+ </>
108
+ );
109
+ };
110
+
111
+ AreaUpload.propTypes = {
112
+ formatFile: PropTypes.string,
113
+ multipleFile: PropTypes.bool,
114
+ initialFiles: PropTypes.arrayOf(PropTypes.object as any),
115
+ removeItem: PropTypes.func,
116
+ setFile: PropTypes.func,
117
+ onChange: PropTypes.func,
118
+ hasListFiles: PropTypes.bool,
119
+ };
120
+
121
+ AreaUpload.defaultProps = {
122
+ formatFile: 'application/json',
123
+ multipleFile: false,
124
+ initialFiles: [],
125
+ removeItem: () => {},
126
+ setFile: () => {},
127
+ onChange: () => {},
128
+ hasListFiles: true,
129
+ };
130
+
131
+ export default AreaUpload;
@@ -0,0 +1,75 @@
1
+ import styled from 'styled-components';
2
+
3
+ interface ContainerProps {
4
+ isDragAccept?: boolean;
5
+ isDragReject?: boolean;
6
+ isDragActive?: boolean;
7
+ }
8
+
9
+ const getColor = (props: ContainerProps) => {
10
+ if (props.isDragAccept) {
11
+ return '#6690ff';
12
+ }
13
+ if (props.isDragReject) {
14
+ return '#e18976';
15
+ }
16
+ if (props.isDragActive) {
17
+ return '#6690ff';
18
+ }
19
+ return '#979aa5';
20
+ };
21
+
22
+ export const Container = styled.div<ContainerProps>`
23
+ background-color: #f3f5f9;
24
+ flex: 1;
25
+ display: flex;
26
+ align-items: center;
27
+ justify-content: center;
28
+ flex-direction: column;
29
+ padding: 20px;
30
+ border-width: 2px;
31
+ border-radius: 4px;
32
+ border-color: var(${(props) => getColor(props)});
33
+ border-style: dashed;
34
+ color: #5a5d68;
35
+ outline: none;
36
+ transition: border 0.24s ease-in-out;
37
+
38
+ & > span {
39
+ margin: 8px 10px 0 0;
40
+ display: flex;
41
+ }
42
+
43
+ button {
44
+ padding: 8px 16px 8px 16px;
45
+ border-radius: 4px;
46
+ border: 2px #102693 solid;
47
+ margin-top: 10px;
48
+ }
49
+ `;
50
+
51
+ export const ListFiles = styled.div`
52
+ &.horizontal-itens {
53
+ display: flex;
54
+ flex-direction: row;
55
+ flex-wrap: wrap;
56
+
57
+ & button {
58
+ margin: 4px;
59
+ white-space: nowrap;
60
+ }
61
+
62
+ .tag-file {
63
+ display: flex;
64
+ gap: 8px;
65
+ padding: 10px 24px !important;
66
+ color: #102693 !important;
67
+ font-size: 14px;
68
+ letter-spacing: 0px;
69
+ }
70
+
71
+ .tag-icon {
72
+ cursor: pointer;
73
+ }
74
+ }
75
+ `;
@@ -1,11 +1,8 @@
1
1
  import React, { useEffect, useState} from 'react';
2
+ import { useDispatch, useSelector } from 'react-redux';
2
3
 
3
4
  import { FaUpload, FaList, FaPlus } from 'react-icons/fa';
4
5
 
5
- // import { formatAxios } from '../../utils/formatAxios'
6
-
7
- import { useLocation } from 'react-router-dom';
8
-
9
6
  import type { FileData } from '../../interface/FileData'
10
7
 
11
8
  import { getLanguage } from '../../utils/getLanguage'
@@ -18,14 +15,19 @@ import ModalFooter from './components/Modal/ModalFooter'
18
15
  import ModalContent from './components/Modal/ModalContent'
19
16
  import EmptyState from '../EmptyState';
20
17
  import Select from '../Select'
18
+ import AreaUpload from './components/AreaUpload';
19
+ import { useSharedProps } from '../../contexts/SharedPropsProvider';
20
+ import { getFilesAction } from '../../store/Files/Files.actions';
21
21
 
22
22
  export const FileArea = () => {
23
23
  const [files, setFiles] = useState<FileData[]>([]);
24
24
  const [initialFiles, setInitialFiles] = useState<FileData[]>([]);
25
- const { pathname } = useLocation();
25
+ const [uploadFile, setUploadFile] = useState<{ content: ArrayBuffer | string; properties: File }>();
26
26
  const [modal, setModal] = useState(false)
27
- const id = pathname.split('/')[4]
28
- const t = getLanguage('pt-br')
27
+ const { id, language } = useSharedProps();
28
+ const t = getLanguage(language)
29
+ const dispatch = useDispatch();
30
+ const initFiles = useSelector((state: any) => state.initFiles);
29
31
  const tags = [
30
32
  "pae",
31
33
  "boteria",
@@ -35,45 +37,16 @@ export const FileArea = () => {
35
37
  ]
36
38
 
37
39
  useEffect(() => {
38
- setFiles([
39
- {
40
- "name": "Documentação conceitual Code7_v3",
41
- "tags": "boteria, code7"
42
- },
43
- {
44
- "name": "PAE_Programa_Apoio_ao_Empregado",
45
- "tags": "pae, vr"
46
- },
47
- {
48
- "name": "Vidalink",
49
- "tags": "vidalink, vr"
50
- },
51
- {
52
- "name": "[GUIA PRÁTICO] Como criar o chatbot perfeito",
53
- "tags": "ebook, code7"
54
- }
55
- ])
56
-
57
- setInitialFiles([
58
- {
59
- "name": "Documentação conceitual Code7_v3",
60
- "tags": "boteria, code7"
61
- },
62
- {
63
- "name": "PAE_Programa_Apoio_ao_Empregado",
64
- "tags": "pae, vr"
65
- },
66
- {
67
- "name": "Vidalink",
68
- "tags": "vidalink, vr"
69
- },
70
- {
71
- "name": "[GUIA PRÁTICO] Como criar o chatbot perfeito",
72
- "tags": "ebook, code7"
73
- }
74
- ])
40
+ dispatch(getFilesAction(id))
75
41
  }, [])
76
42
 
43
+ useEffect(() => {
44
+ setFiles(initFiles)
45
+ setInitialFiles(initFiles)
46
+ }, [initFiles])
47
+
48
+
49
+
77
50
  useEffect(() => {
78
51
  console.log('files, id, t: ', files, id, t)
79
52
  }, [files])
@@ -99,6 +72,7 @@ export const FileArea = () => {
99
72
 
100
73
  const handleSelect = (value: string | number) => {
101
74
  console.log(value);
75
+ console.log(uploadFile);
102
76
  };
103
77
 
104
78
  const renderFiles = () => {
@@ -164,7 +138,9 @@ export const FileArea = () => {
164
138
  >
165
139
  <ModalContent>
166
140
  <div className='choose-file'>
167
- <input type="file" id="file" name="file" />
141
+ <AreaUpload
142
+ setFile={setUploadFile}
143
+ />
168
144
  </div>
169
145
  <div className='presset'>
170
146
  <p>Presset</p>
@@ -32,9 +32,9 @@ export const Container = styled.div`
32
32
  }
33
33
 
34
34
  .button {
35
- padding: 8px 16px 8px 16px
36
- border-radius: 4px
37
- gap: 10px
35
+ padding: 8px 16px 8px 16px;
36
+ border-radius: 4px;
37
+ gap: 10px;
38
38
  }
39
39
 
40
40
  .cancel {
@@ -46,6 +46,12 @@ export const Container = styled.div`
46
46
  background: #102693;
47
47
  color: white;
48
48
  }
49
+
50
+ .presset {
51
+ padding-top: 10px;
52
+ display: flex;
53
+ flex-direction: column;
54
+ }
49
55
  `;
50
56
 
51
57
  export const Header = styled.div`
@@ -0,0 +1,29 @@
1
+ import React, { createContext, useContext } from 'react';
2
+
3
+ interface Props {
4
+ id: string;
5
+ language: "en" | "pt-br" | "es";
6
+ children?: React.ReactNode;
7
+ }
8
+
9
+ interface SharedPropsContextType {
10
+ props: Props;
11
+ }
12
+
13
+ const SharedPropsContext = createContext<SharedPropsContextType | undefined>(undefined);
14
+
15
+ export const useSharedProps = () => {
16
+ const context = useContext(SharedPropsContext);
17
+ if (!context) {
18
+ throw new Error('useSharedProps deve ser usado dentro de um SharedPropsProvider');
19
+ }
20
+ return context.props;
21
+ };
22
+
23
+ export const SharedPropsProvider: React.FC<Props> = ({ children, ...props }) => {
24
+ return (
25
+ <SharedPropsContext.Provider value={{ props }}>
26
+ {children}
27
+ </SharedPropsContext.Provider>
28
+ );
29
+ };
@@ -0,0 +1,9 @@
1
+ import axios from 'axios';
2
+
3
+ export const API_TOKEN = 'API_TOKEN';
4
+
5
+ const url = process.env.REACT_APP_API_URL || 'http://localhost:5000/';
6
+
7
+ axios.defaults.baseURL = `${url}/`;
8
+
9
+ export default axios.create();
@@ -0,0 +1,8 @@
1
+ import api from '../Api'
2
+ import { FileData } from '../../interface/FileData'
3
+
4
+ export const getFiles = async (id: string) => {
5
+ const files:[FileData] = await api.get(`/files/${id}`)
6
+
7
+ return files
8
+ }
@@ -0,0 +1,8 @@
1
+ import { getFiles } from '../../service/Files/Files';
2
+
3
+ export function getFilesAction (id: string) {
4
+ return {
5
+ type: 'GET_FILES',
6
+ payload: getFiles(id)
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ export default function (state = [], action: any) {
2
+ switch (action.type) {
3
+ case 'GET_FILES':
4
+ return action.payload;
5
+ default:
6
+ return state;
7
+ }
8
+ }
@@ -0,0 +1,12 @@
1
+ import { createStore, combineReducers, applyMiddleware } from 'redux';
2
+ import reduxPromise from 'redux-promise';
3
+ import FilesReducer from './Files/Files.reducer';
4
+ import { FileData } from '../interface/FileData'
5
+
6
+ const rootReducer = combineReducers({
7
+ files: FilesReducer as unknown as [FileData],
8
+ });
9
+
10
+ const store = createStore(rootReducer, applyMiddleware(reduxPromise));
11
+
12
+ export default store;