code7-leia 0.1.113 → 0.1.115

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.
@@ -33,11 +33,40 @@ declare type TestArea = {
33
33
  description: string;
34
34
  };
35
35
  };
36
+ declare type Toast = {
37
+ deleteFile: {
38
+ success: {
39
+ title: String;
40
+ description: String;
41
+ };
42
+ fail: {
43
+ title: String;
44
+ description: String;
45
+ };
46
+ };
47
+ uploadFile: {
48
+ success: {
49
+ title: String;
50
+ description: String;
51
+ };
52
+ fail: {
53
+ title: String;
54
+ description: String;
55
+ };
56
+ };
57
+ Test: {
58
+ fail: {
59
+ title: String;
60
+ description: String;
61
+ };
62
+ };
63
+ };
36
64
  export declare type Language = {
37
65
  files: string;
38
66
  test: string;
39
67
  fileArea: FileArea;
40
68
  buttons: Buttons;
41
69
  testArea: TestArea;
70
+ toast: Toast;
42
71
  };
43
72
  export {};
@@ -1,7 +1,10 @@
1
1
  declare const store: import("redux").Store<{
2
2
  files: never[];
3
3
  message: string;
4
- }, any> & {
4
+ isLoading: boolean;
5
+ isChanging: boolean;
6
+ isOffline: boolean;
7
+ }, any, unknown> & {
5
8
  dispatch: unknown;
6
9
  };
7
10
  export default store;
@@ -10,11 +10,12 @@ export declare const getFilesActionSuccess: ({ files }: any) => {
10
10
  files: any;
11
11
  };
12
12
  };
13
- export declare const deleteFilesAction: (name: string, id: string) => {
13
+ export declare const deleteFilesAction: (name: string, id: string, language: string) => {
14
14
  type: string;
15
15
  payload: {
16
16
  name: string;
17
17
  id: string;
18
+ language: string;
18
19
  };
19
20
  };
20
21
  export declare const deleteFilesActionSuccess: ({ files }: any) => {
@@ -23,12 +24,13 @@ export declare const deleteFilesActionSuccess: ({ files }: any) => {
23
24
  files: any;
24
25
  };
25
26
  };
26
- export declare const uploadFilesAction: (file: any, id: string, pressets: [string]) => {
27
+ export declare const uploadFilesAction: (file: any, id: string, pressets: [string], language: string) => {
27
28
  type: string;
28
29
  payload: {
29
30
  file: any;
30
31
  id: string;
31
32
  pressets: [string];
33
+ language: string;
32
34
  };
33
35
  };
34
36
  export declare const uploadFilesActionSuccess: ({ files }: any) => {
@@ -52,3 +54,21 @@ export declare const testActionSuccess: ({ message }: any) => {
52
54
  message: any;
53
55
  };
54
56
  };
57
+ export declare const commonLoadingStart: () => {
58
+ type: string;
59
+ };
60
+ export declare const commonLoadingFinish: () => {
61
+ type: string;
62
+ };
63
+ export declare const commonChangingStart: () => {
64
+ type: string;
65
+ };
66
+ export declare const commonChangingFinish: () => {
67
+ type: string;
68
+ };
69
+ export declare const commonNetworkOnline: () => {
70
+ type: string;
71
+ };
72
+ export declare const commonNetworkOffline: () => {
73
+ type: string;
74
+ };
@@ -1,7 +1,13 @@
1
1
  export default function filesReducer(state: {
2
2
  files: never[];
3
3
  message: string;
4
+ isLoading: boolean;
5
+ isChanging: boolean;
6
+ isOffline: boolean;
4
7
  } | undefined, action: any): {
5
8
  files: never[];
6
9
  message: string;
10
+ isLoading: boolean;
11
+ isChanging: boolean;
12
+ isOffline: boolean;
7
13
  };
@@ -8,9 +8,6 @@ export declare function getFilesSaga(action: any): Generator<import("redux-saga/
8
8
  }>;
9
9
  export declare function deleteFilesSaga(action: any): Generator<import("redux-saga/effects").CallEffect<unknown> | import("redux-saga/effects").PutEffect<{
10
10
  type: string;
11
- payload: {
12
- files: any;
13
- };
14
11
  }>, void, {
15
12
  data: any;
16
13
  }>;
@@ -24,9 +21,6 @@ export declare function testSaga(action: any): Generator<import("redux-saga/effe
24
21
  }>;
25
22
  export declare function uploadFilesSaga(action: any): Generator<import("redux-saga/effects").CallEffect<unknown> | import("redux-saga/effects").PutEffect<{
26
23
  type: string;
27
- payload: {
28
- files: any;
29
- };
30
24
  }>, void, {
31
25
  data: any;
32
26
  }>;
@@ -7,5 +7,11 @@ declare const Types: {
7
7
  UPLOAD_FILES_SUCCESS: string;
8
8
  TEST_REQUEST: string;
9
9
  TEST_SUCCESS: string;
10
+ LOADING_START: string;
11
+ LOADING_FINISH: string;
12
+ CHANGING_START: string;
13
+ CHANGING_FINISH: string;
14
+ NETWORK_ONLINE: string;
15
+ NETWORK_OFFLINE: string;
10
16
  };
11
17
  export default Types;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.113",
2
+ "version": "0.1.115",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -75,6 +75,7 @@
75
75
  "react-icons": "^5.0.1",
76
76
  "react-redux": "^7.2.2",
77
77
  "react-router-dom": ">=5",
78
+ "react-toastify": "^10.0.5",
78
79
  "redux": "^4.0.5",
79
80
  "redux-persist": "^6.0.0",
80
81
  "redux-promise": "^0.6.0",
@@ -0,0 +1,62 @@
1
+ import React from 'react';
2
+ import { toast as reactToast } from 'react-toastify';
3
+
4
+ import { CustomContainerToast } from './styles';
5
+
6
+ interface CustomToastContentProps {
7
+ title: String;
8
+ description?: String;
9
+ }
10
+
11
+ const CustomToastContent: React.FC<CustomToastContentProps> = ({
12
+ title,
13
+ description
14
+ }) => {
15
+ return (
16
+ <>
17
+ <div className="custom-toastify-content">
18
+ <strong className="custom-toastify-title">{title}</strong>
19
+ {description && (
20
+ <p className="custom-toastify-description">{description}</p>
21
+ )}
22
+ </div>
23
+ </>
24
+ );
25
+ };
26
+
27
+ const toast = {
28
+ default: ({ title, description }: CustomToastContentProps) =>
29
+ reactToast(
30
+ <CustomToastContent
31
+ title={title}
32
+ description={description}
33
+ />
34
+ ),
35
+ success: ({ title, description }: CustomToastContentProps) =>
36
+ reactToast.success(
37
+ <CustomToastContent
38
+ title={title}
39
+ description={description}
40
+ />
41
+ ),
42
+ error: ({ title, description }: CustomToastContentProps) =>
43
+ reactToast.error(
44
+ <CustomToastContent
45
+ title={title}
46
+ description={description}
47
+ />
48
+ ),
49
+ warn: ({ title, description }: CustomToastContentProps) =>
50
+ reactToast.warn(
51
+ <CustomToastContent
52
+ title={title}
53
+ description={description}
54
+ />
55
+ ),
56
+ };
57
+
58
+ const ContainerToast: React.FC = () => {
59
+ return <CustomContainerToast autoClose={4000} />;
60
+ };
61
+
62
+ export { ContainerToast, toast };
@@ -0,0 +1,73 @@
1
+ import styled from 'styled-components';
2
+ import { ToastContainer } from 'react-toastify';
3
+ import 'react-toastify/dist/ReactToastify.css';
4
+
5
+ interface CustomContainerToastProps {
6
+ }
7
+
8
+ export const CustomContainerToast = styled(ToastContainer)<CustomContainerToastProps>`
9
+ .Toastify__toast {
10
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto',
11
+ 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans',
12
+ 'Helvetica Neue', sans-serif;
13
+ padding: 6px 12px;
14
+ border-radius: 5px;
15
+
16
+ .custom-toastify-content {
17
+ display: flex;
18
+ flex-direction: column;
19
+ }
20
+ .custom-toastify-icon {
21
+ margin-right: 10px;
22
+ }
23
+ .custom-toastify-title {
24
+ color: #3d4859;
25
+ font-size: 0.875rem;
26
+ margin-bottom: 2px;
27
+ }
28
+ .custom-toastify-description {
29
+ color: #5a5d68;
30
+ font-size: 0.813rem;
31
+ margin-bottom: 2px;
32
+ }
33
+ .custom-toastify-action {
34
+ margin-top: 14px;
35
+ }
36
+ }
37
+
38
+ .Toastify__toast--default {
39
+ background: #fff;
40
+ border-left: 5px solid #3366FF;
41
+ }
42
+
43
+ .Toastify__toast--success {
44
+ background: #fff;
45
+ border-left: 5px solid #3366FF;
46
+ }
47
+
48
+ .Toastify__toast--error {
49
+ background: #fff;
50
+ border-left: 5px solid #f9675b;
51
+ }
52
+
53
+ .Toastify__toast--warning {
54
+ border-left: 5px solid #f9a75b;
55
+ background: #fff;
56
+ }
57
+
58
+ .Toastify__close-button {
59
+ color: #858f9e;
60
+ }
61
+
62
+ .Toastify__toast-body {
63
+ margin: auto 0px;
64
+ font-size: 1rem;
65
+ flex: 1 1 0%;
66
+ display: flex;
67
+ align-items: center;
68
+ }
69
+
70
+ .Toastify__progress-bar {
71
+ background: #3d48593d;
72
+ }
73
+ `;
@@ -31,6 +31,7 @@ export const FileArea = () => {
31
31
  const t = getLanguage(language)
32
32
  const dispatch = useDispatch();
33
33
  const initFiles = useSelector((state: any) => state.files);
34
+ const isLoading = useSelector((state: any) => state.isLoading);
34
35
  const tags = propTags ? propTags.tags : [];
35
36
 
36
37
  useEffect(() => {
@@ -41,6 +42,8 @@ export const FileArea = () => {
41
42
  if(!!initFiles){
42
43
  setFiles(initFiles)
43
44
  setInitialFiles(initFiles)
45
+ setModal(false)
46
+ setModalDelete(false)
44
47
  }
45
48
  }, [initFiles])
46
49
 
@@ -66,20 +69,20 @@ export const FileArea = () => {
66
69
  const handleOpenModalDelete = (name: string) => {
67
70
  setFileDelete(name + '.pdf')
68
71
  setModalDelete(!modalDelete)
69
-
70
72
  }
71
73
 
72
74
  const deleteFile = () => {
73
- dispatch(deleteFilesAction(fileDelete, id))
75
+ dispatch(deleteFilesAction(fileDelete, id, language))
74
76
  }
75
77
 
76
78
  const handleUploadFile = () => {
77
- dispatch(uploadFilesAction(uploadFile, id, [presset]))
79
+ dispatch(uploadFilesAction(uploadFile, id, [presset], language))
78
80
  };
79
81
 
80
82
  const renderFiles = () => {
81
83
  return (
82
- <S.Container>
84
+ <S.Container isLoading={isLoading}>
85
+ <div id='loading' />
83
86
  <S.Header>
84
87
  <div className='infos'>
85
88
  <h2>{t.files}</h2>
@@ -1,6 +1,43 @@
1
- import styled from 'styled-components';
1
+ import styled, { css } from 'styled-components';
2
+
3
+ interface ContainerProps {
4
+ isLoading?: boolean;
5
+ }
6
+
7
+ export const Container = styled.div<ContainerProps>`
8
+ ${(props) =>
9
+ props.isLoading &&
10
+ css`
11
+ #loading {
12
+ position: fixed;
13
+ top: 0;
14
+ left: 0;
15
+ width: 100%;
16
+ height: 100%;
17
+ background-color: #979aa5;
18
+ display: flex;
19
+ justify-content: center;
20
+ align-items: center;
21
+ z-index: 9999;
22
+ }
23
+
24
+ #loading::after {
25
+ content: "";
26
+ border: 4px solid #f3f3f3; /* Cor do símbolo de carregamento */
27
+ border-top: 4px solid #3498db; /* Cor do símbolo de carregamento */
28
+ border-radius: 50%;
29
+ width: 30px;
30
+ height: 30px;
31
+ animation: spin 1s linear infinite;
32
+ }
33
+
34
+ @keyframes spin {
35
+ 0% { transform: rotate(0deg); }
36
+ 100% { transform: rotate(360deg); }
37
+ }
38
+ `}
39
+
2
40
 
3
- export const Container = styled.div`
4
41
  .tag {
5
42
  padding: 4px 8px 4px 8px;
6
43
  background: #C7F9ED;
@@ -36,10 +36,40 @@ type TestArea = {
36
36
  };
37
37
  };
38
38
 
39
+ type Toast = {
40
+ deleteFile: {
41
+ success: {
42
+ title: String,
43
+ description: String
44
+ },
45
+ fail: {
46
+ title: String,
47
+ description: String
48
+ }
49
+ },
50
+ uploadFile: {
51
+ success: {
52
+ title: String,
53
+ description: String
54
+ },
55
+ fail: {
56
+ title: String,
57
+ description: String
58
+ }
59
+ },
60
+ Test: {
61
+ fail: {
62
+ title: String,
63
+ description: String
64
+ }
65
+ }
66
+ }
67
+
39
68
  export type Language = {
40
69
  files: string;
41
70
  test: string;
42
71
  fileArea: FileArea;
43
72
  buttons: Buttons;
44
73
  testArea: TestArea;
74
+ toast: Toast
45
75
  };
@@ -14,10 +14,10 @@ export const getFilesActionSuccess = ({ files }: any) => {
14
14
  }
15
15
  }
16
16
 
17
- export const deleteFilesAction = (name: string, id: string) => {
17
+ export const deleteFilesAction = (name: string, id: string, language: string) => {
18
18
  return {
19
19
  type: types.DELETE_FILES_REQUEST,
20
- payload: { name, id }
20
+ payload: { name, id, language }
21
21
  }
22
22
  }
23
23
 
@@ -28,10 +28,10 @@ export const deleteFilesActionSuccess = ({ files }: any) => {
28
28
  }
29
29
  }
30
30
 
31
- export const uploadFilesAction = (file: any, id: string, pressets: [string]) => {
31
+ export const uploadFilesAction = (file: any, id: string, pressets: [string], language: string) => {
32
32
  return {
33
33
  type: types.UPLOAD_FILES_REQUEST,
34
- payload: { file, id, pressets }
34
+ payload: { file, id, pressets, language }
35
35
  }
36
36
  }
37
37
 
@@ -54,4 +54,28 @@ export const testActionSuccess = ({ message }: any) => {
54
54
  type: types.TEST_SUCCESS,
55
55
  payload: { message }
56
56
  }
57
- }
57
+ }
58
+
59
+ export const commonLoadingStart = () => ({
60
+ type: types.LOADING_START,
61
+ });
62
+
63
+ export const commonLoadingFinish = () => ({
64
+ type: types.LOADING_FINISH,
65
+ });
66
+
67
+ export const commonChangingStart = () => ({
68
+ type: types.CHANGING_START,
69
+ });
70
+
71
+ export const commonChangingFinish = () => ({
72
+ type: types.CHANGING_FINISH,
73
+ });
74
+
75
+ export const commonNetworkOnline = () => ({
76
+ type: types.NETWORK_ONLINE,
77
+ });
78
+
79
+ export const commonNetworkOffline = () => ({
80
+ type: types.NETWORK_OFFLINE,
81
+ });
@@ -3,7 +3,10 @@ import types from './types'
3
3
 
4
4
  const INITIAL_STATE = {
5
5
  files: [],
6
- message: ''
6
+ message: '',
7
+ isLoading: false,
8
+ isChanging: false,
9
+ isOffline: true,
7
10
  }
8
11
 
9
12
  export default function filesReducer(state = INITIAL_STATE, action: any) {
@@ -18,6 +21,24 @@ export default function filesReducer(state = INITIAL_STATE, action: any) {
18
21
  case types.TEST_SUCCESS:
19
22
  draft.message = action.payload.message;
20
23
  break;
24
+ case types.LOADING_START:
25
+ draft.isLoading = true;
26
+ break;
27
+ case types.LOADING_FINISH:
28
+ draft.isLoading = false;
29
+ break;
30
+ case types.CHANGING_START:
31
+ draft.isChanging = true;
32
+ break;
33
+ case types.CHANGING_FINISH:
34
+ draft.isChanging = false;
35
+ break;
36
+ case types.NETWORK_ONLINE:
37
+ draft.isOffline = false;
38
+ break;
39
+ case types.NETWORK_OFFLINE:
40
+ draft.isOffline = true;
41
+ break;
21
42
  default:
22
43
  return action.payload;
23
44
  }
@@ -1,7 +1,14 @@
1
1
  import { takeLatest, all, put, call } from 'redux-saga/effects';
2
2
  import api from '../../service/Api'
3
3
  import Types from './types'
4
- import { getFilesActionSuccess, deleteFilesActionSuccess, testActionSuccess, uploadFilesActionSuccess } from './actions'
4
+ import { getFilesActionSuccess,
5
+ deleteFilesActionSuccess,
6
+ testActionSuccess,
7
+ uploadFilesActionSuccess,
8
+ commonLoadingStart,
9
+ commonLoadingFinish, } from './actions'
10
+ import { toast } from '../../components/CustomToast'
11
+ import { getLanguage } from '../../utils/getLanguage'
5
12
 
6
13
  export function* getFilesSaga(action: any) {
7
14
  try {
@@ -14,13 +21,19 @@ export function* getFilesSaga(action: any) {
14
21
  }
15
22
 
16
23
  export function* deleteFilesSaga(action: any) {
24
+ const t = getLanguage(action.payload.language)
17
25
  try {
26
+ yield put(commonLoadingStart());
18
27
  const { id, name } = action.payload
28
+
19
29
  yield call(api.delete, `/delete/${id}/${name}`);
20
30
  const { data } = yield call(api.get, `/files/${id}`);
21
- yield put(deleteFilesActionSuccess({ files: data.files }));
31
+ yield put(deleteFilesActionSuccess({ files: data.files, success: true }));
22
32
  } catch (error) {
33
+ toast.error({title: t.toast.deleteFile.fail.title, description: t.toast.deleteFile.fail.description});
23
34
  console.log('-----------deleteFilesSaga.error------------------->', error);
35
+ } finally {
36
+ yield put(commonLoadingFinish());
24
37
  }
25
38
  }
26
39
 
@@ -35,12 +48,14 @@ export function* testSaga(action: any) {
35
48
  }
36
49
 
37
50
  export function* uploadFilesSaga(action: any) {
51
+ const t = getLanguage(action.payload.language)
38
52
  try {
53
+ yield put(commonLoadingStart());
39
54
  const { id, file, pressets } = action.payload;
40
55
  const tags = pressets.join(',');
41
56
 
42
57
  const blob = new Blob([file.content]);
43
-
58
+
44
59
  const formData = new FormData();
45
60
  formData.append('file', blob, file.properties.path);
46
61
 
@@ -55,7 +70,10 @@ export function* uploadFilesSaga(action: any) {
55
70
  const { data } = yield call(api.get, `/files/${id}`);
56
71
  yield put(uploadFilesActionSuccess({ files: data.files }));
57
72
  } catch (error) {
73
+ toast.error({title: t.toast.uploadFile.fail.title, description: t.toast.uploadFile.fail.description});
58
74
  console.log('-----------uploadFilesSaga.error------------------->', error);
75
+ } finally {
76
+ yield put(commonLoadingFinish());
59
77
  }
60
78
  }
61
79
 
@@ -6,7 +6,13 @@ const Types = {
6
6
  UPLOAD_FILES_REQUEST: 'UPLOAD_FILES_REQUEST',
7
7
  UPLOAD_FILES_SUCCESS: 'UPLOAD_FILES_SUCCESS',
8
8
  TEST_REQUEST: 'TEST_REQUEST',
9
- TEST_SUCCESS: 'TEST_SUCCESS'
9
+ TEST_SUCCESS: 'TEST_SUCCESS',
10
+ LOADING_START: 'LOADING_START',
11
+ LOADING_FINISH: 'LOADING_FINISH',
12
+ CHANGING_START: 'CHANGING_START',
13
+ CHANGING_FINISH: 'CHANGING_FINISH',
14
+ NETWORK_ONLINE: 'NETWORK_ONLINE',
15
+ NETWORK_OFFLINE: 'NETWORK_OFFLINE',
10
16
  };
11
17
 
12
18
  export default Types;