contentoh-components-library 21.2.84 → 21.2.85
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/.env.development +6 -1
- package/dist/assets/fonts/Roboto/Roboto-Medium.ttf +0 -0
- package/dist/assets/fonts/Roboto/Roboto-Regular.ttf +0 -0
- package/dist/assets/images/defaultImages/Spinner.gif +0 -0
- package/dist/assets/images/defaultImages/notFound.svg +124 -0
- package/dist/components/atoms/ButtonFileChooser/ButtonFileChooser.stories.js +72 -0
- package/dist/components/atoms/ButtonFileChooser/index.js +116 -0
- package/dist/components/atoms/ButtonFileChooser/styles.js +20 -0
- package/dist/components/atoms/ButtonV2/ButtonV2.stories.js +66 -0
- package/dist/components/atoms/ButtonV2/index.js +109 -0
- package/dist/components/atoms/ButtonV2/styles.js +53 -0
- package/dist/components/atoms/CustomIcon/CustomIcon.stories.js +50 -0
- package/dist/components/atoms/CustomIcon/index.js +38 -0
- package/dist/components/atoms/CustomIcon/styles.js +33 -0
- package/dist/components/atoms/IconFile/IconFile.stories.js +48 -0
- package/dist/components/atoms/IconFile/index.js +251 -0
- package/dist/components/atoms/IconFile/styles.js +23 -0
- package/dist/components/atoms/Image/Image.stories.js +63 -0
- package/dist/components/atoms/Image/index.js +72 -0
- package/dist/components/atoms/Image/styles.js +40 -0
- package/dist/components/atoms/ImageLink/ImageLink.stories.js +63 -0
- package/dist/components/atoms/ImageLink/index.js +75 -0
- package/dist/components/atoms/ImageLink/styles.js +40 -0
- package/dist/components/atoms/ImagePreview/ImagePreview.stories.js +70 -0
- package/dist/components/atoms/ImagePreview/index.js +220 -0
- package/dist/components/atoms/ImagePreview/styles.js +44 -0
- package/dist/components/atoms/InputText/InputText.stories.js +62 -0
- package/dist/components/atoms/InputText/index.js +64 -0
- package/dist/components/atoms/InputText/styles.js +32 -0
- package/dist/components/atoms/NotFound/NotFound.stories.js +36 -0
- package/dist/components/atoms/NotFound/index.js +73 -0
- package/dist/components/atoms/NotFound/styles.js +20 -0
- package/dist/components/atoms/Tooltip/Tooltip.stories.js +36 -6
- package/dist/components/atoms/Tooltip/index.js +41 -26
- package/dist/components/atoms/Tooltip/styles.js +3 -1
- package/dist/components/molecules/ButtonDownloadFile/DownloadFile.stories.js +66 -0
- package/dist/components/molecules/ButtonDownloadFile/index.js +179 -0
- package/dist/components/molecules/ButtonDownloadFile/styles.js +23 -0
- package/dist/components/molecules/CustomSelect/CustomSelect.stories.js +21 -22
- package/dist/components/molecules/CustomSelect/SelectItem.js +10 -1
- package/dist/components/molecules/HeaderTop/index.js +12 -5
- package/dist/components/molecules/HeaderTop/styles.js +1 -1
- package/dist/components/molecules/ImageTooltip/ImageTooltip.stories.js +72 -0
- package/dist/components/molecules/ImageTooltip/index.js +84 -0
- package/dist/components/molecules/ImageTooltip/styles.js +33 -0
- package/dist/components/organisms/Chat/Chat.stories.js +215 -0
- package/dist/components/organisms/Chat/ChatLists/ChatLists.stories.js +83 -0
- package/dist/components/organisms/Chat/ChatLists/index.js +158 -0
- package/dist/components/organisms/Chat/ChatLists/styles.js +29 -0
- package/dist/components/organisms/Chat/ContainerItems/ContainerItems.stories.js +176 -0
- package/dist/components/organisms/Chat/ContainerItems/index.js +570 -0
- package/dist/components/organisms/Chat/ContainerItems/styles.js +20 -0
- package/dist/components/organisms/Chat/ContentChat/ContentChat.stories.js +142 -0
- package/dist/components/organisms/Chat/ContentChat/index.js +1422 -0
- package/dist/components/organisms/Chat/ContentChat/styles.js +20 -0
- package/dist/components/organisms/Chat/Footer/Footer.stories.js +43 -0
- package/dist/components/organisms/Chat/Footer/index.js +983 -0
- package/dist/components/organisms/Chat/Footer/styles.js +32 -0
- package/dist/components/organisms/Chat/Header/Header.stories.js +96 -0
- package/dist/components/organisms/Chat/Header/index.js +84 -0
- package/dist/components/organisms/Chat/Header/styles.js +20 -0
- package/dist/components/organisms/Chat/index.js +325 -0
- package/dist/components/organisms/Chat/styles.js +29 -0
- package/dist/components/organisms/Modal/Modal.stories.js +66 -0
- package/dist/components/organisms/Modal/index.js +95 -0
- package/dist/components/organisms/Modal/styles.js +20 -0
- package/dist/components/pages/Dashboard/Dashboard.stories.js +16 -44
- package/dist/components/pages/Dashboard/index.js +10 -17
- package/dist/components/pages/ProviderProductEdition/index.js +3 -2
- package/dist/components/pages/RetailerProductEdition/index.js +4 -7
- package/dist/global-files/fonts.css +18 -0
- package/dist/global-files/handle_http.js +383 -0
- package/dist/global-files/utils.js +472 -0
- package/dist/global-files/variables.js +3 -1
- package/package.json +13 -1
- package/src/assets/fonts/Roboto/Roboto-Medium.ttf +0 -0
- package/src/assets/fonts/Roboto/Roboto-Regular.ttf +0 -0
- package/src/assets/images/chatPopup/Spinner.gif +0 -0
- package/src/assets/images/chatPopup/close.svg +3 -0
- package/src/assets/images/chatPopup/defaultImage.png +0 -0
- package/src/assets/images/chatPopup/defaultProfile.png +0 -0
- package/src/assets/images/chatPopup/doc.svg +1 -0
- package/src/assets/images/chatPopup/document.svg +1 -0
- package/src/assets/images/chatPopup/iconChat.svg +19 -0
- package/src/assets/images/chatPopup/iconPlus.svg +3 -0
- package/src/assets/images/chatPopup/pdf.svg +75 -0
- package/src/assets/images/chatPopup/remove.svg +4 -0
- package/src/assets/images/chatPopup/send.svg +3 -0
- package/src/assets/images/chatPopup/svgIcon.svg +109 -0
- package/src/assets/images/chatPopup/upload_file.svg +3 -0
- package/src/assets/images/chatPopup/xls.svg +53 -0
- package/src/assets/images/customSelect/starIcon.svg +14 -0
- package/src/assets/images/defaultImages/Spinner.gif +0 -0
- package/src/assets/images/defaultImages/notFound.svg +124 -0
- package/src/components/atoms/ButtonFileChooser/ButtonFileChooser.stories.js +47 -0
- package/src/components/atoms/ButtonFileChooser/index.js +70 -0
- package/src/components/atoms/ButtonFileChooser/styles.js +4 -0
- package/src/components/atoms/ButtonV2/ButtonV2.stories.js +50 -0
- package/src/components/atoms/ButtonV2/index.js +74 -0
- package/src/components/atoms/ButtonV2/styles.js +187 -0
- package/src/components/atoms/CustomIcon/CustomIcon.stories.js +36 -0
- package/src/components/atoms/CustomIcon/index.js +41 -0
- package/src/components/atoms/CustomIcon/styles.js +85 -0
- package/src/components/atoms/IconFile/IconFile.stories.js +35 -0
- package/src/components/atoms/IconFile/index.js +120 -0
- package/src/components/atoms/IconFile/styles.js +67 -0
- package/src/components/atoms/Image/Image.stories.js +43 -0
- package/src/components/atoms/Image/index.js +54 -0
- package/src/components/atoms/Image/styles.js +25 -0
- package/src/components/atoms/ImageLink/ImageLink.stories.js +43 -0
- package/src/components/atoms/ImageLink/index.js +58 -0
- package/src/components/atoms/ImageLink/styles.js +30 -0
- package/src/components/atoms/ImagePreview/ImagePreview.stories.js +52 -0
- package/src/components/atoms/ImagePreview/index.js +192 -0
- package/src/components/atoms/ImagePreview/styles.js +77 -0
- package/src/components/atoms/InputText/InputText.stories.js +40 -0
- package/src/components/atoms/InputText/index.js +63 -0
- package/src/components/atoms/InputText/styles.js +89 -0
- package/src/components/atoms/NotFound/NotFound.stories.js +19 -0
- package/src/components/atoms/NotFound/index.js +53 -0
- package/src/components/atoms/NotFound/styles.js +55 -0
- package/src/components/atoms/Tooltip/Tooltip.stories.js +51 -0
- package/src/components/atoms/Tooltip/index.js +59 -0
- package/src/components/atoms/Tooltip/styles.js +42 -0
- package/src/components/molecules/ButtonDownloadFile/DownloadFile.stories.js +54 -0
- package/src/components/molecules/ButtonDownloadFile/index.js +113 -0
- package/src/components/molecules/ButtonDownloadFile/styles.js +66 -0
- package/src/components/molecules/CustomSelect/CustomSelect.stories.js +20 -12
- package/src/components/molecules/CustomSelect/SelectItem.js +7 -0
- package/src/components/molecules/HeaderTop/index.js +11 -6
- package/src/components/molecules/HeaderTop/styles.js +4 -0
- package/src/components/molecules/ImageTooltip/ImageTooltip.stories.js +46 -0
- package/src/components/molecules/ImageTooltip/index.js +64 -0
- package/src/components/molecules/ImageTooltip/styles.js +18 -0
- package/src/components/organisms/Chat/Chat.stories.js +199 -0
- package/src/components/organisms/Chat/ChatLists/ChatLists.stories.js +65 -0
- package/src/components/organisms/Chat/ChatLists/Rotoplas.jpeg +0 -0
- package/src/components/organisms/Chat/ChatLists/THD.png +0 -0
- package/src/components/organisms/Chat/ChatLists/index.js +141 -0
- package/src/components/organisms/Chat/ChatLists/styles.js +162 -0
- package/src/components/organisms/Chat/ContainerItems/ContainerItems.stories.js +142 -0
- package/src/components/organisms/Chat/ContainerItems/index.js +551 -0
- package/src/components/organisms/Chat/ContainerItems/styles.js +336 -0
- package/src/components/organisms/Chat/ContentChat/ContentChat.stories.js +102 -0
- package/src/components/organisms/Chat/ContentChat/Rotoplas.jpeg +0 -0
- package/src/components/organisms/Chat/ContentChat/THD.png +0 -0
- package/src/components/organisms/Chat/ContentChat/index.js +900 -0
- package/src/components/organisms/Chat/ContentChat/styles.js +41 -0
- package/src/components/organisms/Chat/Footer/Footer.stories.js +22 -0
- package/src/components/organisms/Chat/Footer/index.js +669 -0
- package/src/components/organisms/Chat/Footer/styles.js +286 -0
- package/src/components/organisms/Chat/Header/Header.stories.js +66 -0
- package/src/components/organisms/Chat/Header/index.js +94 -0
- package/src/components/organisms/Chat/Header/styles.js +49 -0
- package/src/components/organisms/Chat/index.js +295 -0
- package/src/components/organisms/Chat/styles.js +42 -0
- package/src/components/organisms/Modal/Modal.stories.js +55 -0
- package/src/components/organisms/Modal/index.js +97 -0
- package/src/components/organisms/Modal/styles.js +103 -0
- package/src/components/pages/Dashboard/Dashboard.stories.js +16 -47
- package/src/components/pages/Dashboard/index.js +4 -13
- package/src/components/pages/ProviderProductEdition/index.js +6 -7
- package/src/components/pages/RetailerProductEdition/index.js +5 -4
- package/src/global-files/fonts.css +18 -0
- package/src/global-files/handle_http.js +231 -0
- package/src/global-files/utils.js +300 -0
- package/src/global-files/variables.js +2 -0
- package/dist/components/atoms/ChatPopUp/ChatPopUp.stories.js +0 -28
- package/dist/components/atoms/ChatPopUp/index.js +0 -841
- package/dist/components/atoms/ChatPopUp/styles.js +0 -27
- package/dist/components/atoms/ChatPopUp/utils/handlersChat.js +0 -182
- package/dist/components/atoms/StatusTag/StatusTag.stories.js +0 -48
- package/dist/components/atoms/StatusTag/index.js +0 -58
- package/dist/components/atoms/StatusTag/styles.js +0 -20
- package/dist/components/pages/RegistrationLoginFirstStep/RegistrationLoginFirstStep.stories.js +0 -37
- package/dist/components/pages/RegistrationLoginFirstStep/index.js +0 -269
- package/dist/components/pages/RegistrationLoginFirstStep/styles.js +0 -20
|
@@ -59,7 +59,7 @@ export const Dashboard = ({ jwt, user, company }) => {
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
const getRetailers = async () => {
|
|
62
|
-
const isTHDUser =
|
|
62
|
+
const isTHDUser = [657, 818, 819].includes(user.id_company);
|
|
63
63
|
const retailersResponse = await axios.get(
|
|
64
64
|
`${process.env.REACT_APP_RETAILER_ENDPOINT}`,
|
|
65
65
|
{
|
|
@@ -78,21 +78,13 @@ export const Dashboard = ({ jwt, user, company }) => {
|
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
const loadProductsByStatus = async (orderByStatus, filter) => {
|
|
81
|
-
const isTHDUser = user.is_retailer && company.retailers;
|
|
82
|
-
const isProvider = !user.is_retailer && user.id_role === 0;
|
|
83
|
-
const isCollaborator = user.id_role > 0;
|
|
84
81
|
const { ordersBydate, ordersByStatus } =
|
|
85
82
|
(await loadProductVersions(orderByStatus)) || {};
|
|
86
83
|
|
|
87
|
-
const { total = 0, R = 0, PA = 0, Ex = 0
|
|
88
|
-
let productsFinished = 0;
|
|
89
|
-
if (isTHDUser) productsFinished = Ex;
|
|
90
|
-
if (isProvider) productsFinished = ACA;
|
|
91
|
-
if (isCollaborator) productsFinished = Ex + ACA;
|
|
92
|
-
|
|
84
|
+
const { total = 0, R = 0, PA = 0, Ex = 0 } = ordersByStatus;
|
|
93
85
|
const inProcess = Object.keys(ordersByStatus).reduce(
|
|
94
86
|
(prev, curr) =>
|
|
95
|
-
!["total", "PA", "R", "Ex"
|
|
87
|
+
!["total", "PA", "R", "Ex"].includes(curr)
|
|
96
88
|
? prev + ordersByStatus[curr]
|
|
97
89
|
: prev,
|
|
98
90
|
0
|
|
@@ -102,12 +94,11 @@ export const Dashboard = ({ jwt, user, company }) => {
|
|
|
102
94
|
? metricsData[0]
|
|
103
95
|
: { label: "Productos totales", value: total },
|
|
104
96
|
];
|
|
105
|
-
|
|
106
97
|
metricsArray.push(
|
|
107
98
|
{ label: "Productos filtrados", value: total },
|
|
108
99
|
{ label: "Productos sin asignar", value: PA + R },
|
|
109
100
|
{ label: "Productos en proceso", value: inProcess },
|
|
110
|
-
{ label: "Productos terminados", value:
|
|
101
|
+
{ label: "Productos terminados", value: Ex }
|
|
111
102
|
);
|
|
112
103
|
setMetricsData(metricsArray);
|
|
113
104
|
setTotalCount(total);
|
|
@@ -45,7 +45,7 @@ import { useCloseModal } from "../../../global-files/customHooks";
|
|
|
45
45
|
import { CreateVersion } from "../../organisms/CreateVersion";
|
|
46
46
|
|
|
47
47
|
const reducerImages = (state, action) => {
|
|
48
|
-
let { values, attrForImgs, inputsByRetailer } = state;
|
|
48
|
+
let { values = [], attrForImgs, inputsByRetailer } = state;
|
|
49
49
|
switch (action.action) {
|
|
50
50
|
case "init":
|
|
51
51
|
const newInputsByRetailer = {};
|
|
@@ -100,7 +100,7 @@ const reducerImages = (state, action) => {
|
|
|
100
100
|
imageIdArray.includes(input.id)
|
|
101
101
|
);
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
if (orderedImages.length > 0) values = orderedImages;
|
|
104
104
|
} catch (error) {
|
|
105
105
|
console.log(error);
|
|
106
106
|
}
|
|
@@ -877,11 +877,10 @@ export const ProviderProductEdition = ({
|
|
|
877
877
|
const newProductEdit = productEdit;
|
|
878
878
|
newProductEdit.product[sectionStatusKey] = serviceStatus;
|
|
879
879
|
setProductEdit(newProductEdit);
|
|
880
|
-
const showSurveyByProvider =
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
showSurvey && showSurvey(showSurveyByProvider || showSurveyByRetailer);
|
|
880
|
+
const showSurveyByProvider = !user.is_retailer && orderStatus[orderId] === "AP";
|
|
881
|
+
const showSurveyByRetailer = user.is_retailer && orderStatus[orderId] === "ACA";
|
|
882
|
+
showSurvey &&
|
|
883
|
+
showSurvey(showSurveyByProvider || showSurveyByRetailer);
|
|
885
884
|
} else {
|
|
886
885
|
res = await axios.put(`${process.env.REACT_APP_SEND_EVAL}`, data, {
|
|
887
886
|
headers: {
|
|
@@ -35,7 +35,7 @@ import { useCloseModal } from "../../../global-files/customHooks";
|
|
|
35
35
|
import { CreateVersion } from "../../organisms/CreateVersion";
|
|
36
36
|
|
|
37
37
|
const reducerImages = (state, action) => {
|
|
38
|
-
let { values, attrForImgs, inputsByRetailer } = state;
|
|
38
|
+
let { values = [], attrForImgs, inputsByRetailer } = state;
|
|
39
39
|
switch (action.action) {
|
|
40
40
|
case "init":
|
|
41
41
|
const newInputsByRetailer = {};
|
|
@@ -80,9 +80,8 @@ const reducerImages = (state, action) => {
|
|
|
80
80
|
try {
|
|
81
81
|
const orderedImages = [];
|
|
82
82
|
const imageIdArray = [];
|
|
83
|
-
if (action?.retailerId && !inputsByRetailer[action.retailerId])
|
|
83
|
+
if (action?.retailerId && !inputsByRetailer[action.retailerId])
|
|
84
84
|
inputsByRetailer[action.retailerId] = [];
|
|
85
|
-
}
|
|
86
85
|
action.retailerId &&
|
|
87
86
|
inputsByRetailer[action.retailerId]?.filter((input) => {
|
|
88
87
|
imageIdArray.push(input.id_image);
|
|
@@ -90,10 +89,12 @@ const reducerImages = (state, action) => {
|
|
|
90
89
|
if (value.image_id === input.id_image) orderedImages.push(value);
|
|
91
90
|
});
|
|
92
91
|
});
|
|
92
|
+
|
|
93
93
|
inputs = inputsInitial?.filter((input) =>
|
|
94
94
|
imageIdArray.includes(input.id)
|
|
95
95
|
);
|
|
96
|
-
|
|
96
|
+
|
|
97
|
+
if (orderedImages.length > 0) values = orderedImages;
|
|
97
98
|
} catch (error) {
|
|
98
99
|
console.log(error);
|
|
99
100
|
}
|
|
@@ -43,3 +43,21 @@
|
|
|
43
43
|
src: url("../assets/fonts/raleway/Raleway-Black.ttf");
|
|
44
44
|
font-weight: 900;
|
|
45
45
|
}
|
|
46
|
+
|
|
47
|
+
@font-face {
|
|
48
|
+
font-family: "RobotoMedium";
|
|
49
|
+
src: url("../assets/fonts/Roboto/Roboto-Medium.ttf");
|
|
50
|
+
font-weight: 500;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@font-face {
|
|
54
|
+
font-family: "RobotoRegular";
|
|
55
|
+
src: url("../assets/fonts/Roboto/Roboto-Regular.ttf");
|
|
56
|
+
font-weight: 400;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.prueba {
|
|
60
|
+
color: #9e3e26;
|
|
61
|
+
color: #b42983;
|
|
62
|
+
color: #e7e7e7;
|
|
63
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
|
|
3
|
+
//============================================================
|
|
4
|
+
/**
|
|
5
|
+
* funcion que realiza un axios GET
|
|
6
|
+
*
|
|
7
|
+
* Si <body> es undefined significa que hubo error
|
|
8
|
+
|
|
9
|
+
* @returns { Promise<{
|
|
10
|
+
* body: {} | undefined ,
|
|
11
|
+
* message: string,
|
|
12
|
+
* errorDetail: string
|
|
13
|
+
* }> }
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
//============================================================
|
|
17
|
+
export const fetchGET = (
|
|
18
|
+
endpoint = "",
|
|
19
|
+
paramsQuery = {},
|
|
20
|
+
paramsHeaders = {}
|
|
21
|
+
) => {
|
|
22
|
+
return new Promise(async (response) => {
|
|
23
|
+
//console.log("======= fetchGET =========");
|
|
24
|
+
try {
|
|
25
|
+
let URL = endpoint;
|
|
26
|
+
const keysParamsQuery = Object.keys(paramsQuery);
|
|
27
|
+
// agregar cada param query a la URL
|
|
28
|
+
keysParamsQuery.forEach((key, index) => {
|
|
29
|
+
if (index == 0) {
|
|
30
|
+
URL += `?${key}=${paramsQuery[key]}`;
|
|
31
|
+
} else {
|
|
32
|
+
URL += `&${key}=${paramsQuery[key]}`;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
//console.log("URL:", URL);
|
|
36
|
+
const respHTTPjson = await axios.get(URL, { headers: paramsHeaders });
|
|
37
|
+
// verificar si existe un error en la peticion realizada
|
|
38
|
+
if (respHTTPjson.status !== 200) {
|
|
39
|
+
return response({
|
|
40
|
+
message: "No fue posible llevar a cabo la operación",
|
|
41
|
+
errorDetail: respHTTPjson.statusText,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
// obtener body backend
|
|
45
|
+
const body = JSON.parse(respHTTPjson.data.body);
|
|
46
|
+
|
|
47
|
+
// verificar si existe error desde el backend
|
|
48
|
+
if (respHTTPjson.data.statusCode !== 200) {
|
|
49
|
+
return response({
|
|
50
|
+
message: body.message ?? "",
|
|
51
|
+
errorDetail: body.errorDetail ?? "",
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
// success
|
|
55
|
+
return response({ body });
|
|
56
|
+
} catch (err) {
|
|
57
|
+
return response({
|
|
58
|
+
message: "Error al obtener los datos",
|
|
59
|
+
errorDetail: err.message,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
//============================================================
|
|
66
|
+
/**
|
|
67
|
+
* funcion que realiza un axios POST
|
|
68
|
+
*
|
|
69
|
+
* Si <body> es undefined significa que hubo error
|
|
70
|
+
|
|
71
|
+
* @returns { Promise<{
|
|
72
|
+
* body: {} | undefined ,
|
|
73
|
+
* message: string,
|
|
74
|
+
* errorDetail: string
|
|
75
|
+
* }> }
|
|
76
|
+
*
|
|
77
|
+
*/
|
|
78
|
+
//============================================================
|
|
79
|
+
export const fetchPOST = (
|
|
80
|
+
endpoint = "",
|
|
81
|
+
paramsBody = {},
|
|
82
|
+
paramsHeaders = {}
|
|
83
|
+
) => {
|
|
84
|
+
return new Promise(async (response) => {
|
|
85
|
+
//console.log("======= fetchPOST =========");
|
|
86
|
+
try {
|
|
87
|
+
const respHTTPjson = await axios.post(endpoint, paramsBody, {
|
|
88
|
+
headers: paramsHeaders,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// verificar si existe un error en la peticion realizada
|
|
92
|
+
if (respHTTPjson.status !== 200) {
|
|
93
|
+
return response({
|
|
94
|
+
message: "No fue posible llevar a cabo la operación",
|
|
95
|
+
errorDetail: respHTTPjson.statusText,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
// obtener body backend
|
|
99
|
+
const body = JSON.parse(respHTTPjson.data.body);
|
|
100
|
+
|
|
101
|
+
// verificar si existe error desde el backend
|
|
102
|
+
if (respHTTPjson.data.statusCode !== 200) {
|
|
103
|
+
console.log(body);
|
|
104
|
+
return response({
|
|
105
|
+
message: body.message ?? "",
|
|
106
|
+
errorDetail: body.errorDetail ?? "",
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
// success
|
|
110
|
+
return response({ body });
|
|
111
|
+
} catch (err) {
|
|
112
|
+
return response({
|
|
113
|
+
message: "Error al guardar los datos",
|
|
114
|
+
errorDetail: err.message,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
//============================================================
|
|
121
|
+
/**
|
|
122
|
+
* funcion que realiza un axios GET
|
|
123
|
+
*
|
|
124
|
+
* Si <body> es undefined significa que hubo error
|
|
125
|
+
|
|
126
|
+
* @returns { Promise<{
|
|
127
|
+
* body: {} | undefined ,
|
|
128
|
+
* message: string,
|
|
129
|
+
* errorDetail: string
|
|
130
|
+
* }> }
|
|
131
|
+
*
|
|
132
|
+
*/
|
|
133
|
+
//============================================================
|
|
134
|
+
export const fetchPUT = (
|
|
135
|
+
endpoint = "",
|
|
136
|
+
paramsBody = {},
|
|
137
|
+
paramsHeaders = {}
|
|
138
|
+
) => {
|
|
139
|
+
return new Promise(async (response) => {
|
|
140
|
+
//console.log("======= fetchPUT =========");
|
|
141
|
+
try {
|
|
142
|
+
const respHTTPjson = await axios.put(endpoint, paramsBody, {
|
|
143
|
+
headers: paramsHeaders,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// verificar si existe un error en la peticion realizada
|
|
147
|
+
if (respHTTPjson.status !== 200) {
|
|
148
|
+
return response({
|
|
149
|
+
message: "No fue posible llevar a cabo la operación",
|
|
150
|
+
errorDetail: respHTTPjson.statusText,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// obtener body backend
|
|
155
|
+
const body = JSON.parse(respHTTPjson.data.body);
|
|
156
|
+
|
|
157
|
+
// verificar si existe error desde el backend
|
|
158
|
+
if (respHTTPjson.data.statusCode !== 200) {
|
|
159
|
+
return response({
|
|
160
|
+
message: body.message ?? "",
|
|
161
|
+
errorDetail: body.errorDetail ?? "",
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// success
|
|
166
|
+
return response({ body });
|
|
167
|
+
} catch (err) {
|
|
168
|
+
return response({
|
|
169
|
+
message: "Error al actualizar los datos",
|
|
170
|
+
errorDetail: err.message,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
//============================================================
|
|
177
|
+
/**
|
|
178
|
+
* funcion que realiza un axios GET
|
|
179
|
+
*
|
|
180
|
+
* Si <body> es undefined significa que hubo error
|
|
181
|
+
|
|
182
|
+
* @returns { Promise<{
|
|
183
|
+
* body: {} | undefined ,
|
|
184
|
+
* message: string,
|
|
185
|
+
* errorDetail: string
|
|
186
|
+
* }> }
|
|
187
|
+
*
|
|
188
|
+
*/
|
|
189
|
+
//============================================================
|
|
190
|
+
export const fetchDELETE = (
|
|
191
|
+
endpoint = "",
|
|
192
|
+
paramsBody = {},
|
|
193
|
+
paramsHeaders = {}
|
|
194
|
+
) => {
|
|
195
|
+
return new Promise(async (response) => {
|
|
196
|
+
//console.log("======= fetchDELETE =========");
|
|
197
|
+
try {
|
|
198
|
+
const respHTTPjson = await axios.delete(endpoint, {
|
|
199
|
+
data: paramsBody,
|
|
200
|
+
headers: paramsHeaders,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// verificar si existe un error en la peticion realizada
|
|
204
|
+
if (respHTTPjson.status !== 200) {
|
|
205
|
+
return response({
|
|
206
|
+
message: "No fue posible llevar a cabo la operación",
|
|
207
|
+
errorDetail: respHTTPjson.statusText,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// obtener body backend
|
|
212
|
+
const body = JSON.parse(respHTTPjson.data.body);
|
|
213
|
+
|
|
214
|
+
// verificar si existe error desde el backend
|
|
215
|
+
if (respHTTPjson.data.statusCode !== 200) {
|
|
216
|
+
return response({
|
|
217
|
+
message: body.message ?? "",
|
|
218
|
+
errorDetail: body.errorDetail ?? "",
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// success
|
|
223
|
+
return response({ body });
|
|
224
|
+
} catch (err) {
|
|
225
|
+
return response({
|
|
226
|
+
message: "Error al actualizar los datos",
|
|
227
|
+
errorDetail: err.message,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
};
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { Base64 } from "js-base64";
|
|
2
|
+
import moment from "moment";
|
|
3
|
+
|
|
4
|
+
/*====================================================================
|
|
5
|
+
UTILERIAS PARA EL MANEJO DE ARCHIVOS
|
|
6
|
+
======================================================================*/
|
|
7
|
+
/*------------------------
|
|
8
|
+
devolver el base64
|
|
9
|
+
completo de un file
|
|
10
|
+
--------------------------*/
|
|
11
|
+
export const getBase64 = async (file) => {
|
|
12
|
+
return new Promise((success) => {
|
|
13
|
+
const reader = new FileReader();
|
|
14
|
+
reader.addEventListener("loadend", () => {
|
|
15
|
+
success(reader.result);
|
|
16
|
+
});
|
|
17
|
+
reader.readAsDataURL(file);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/*------------------------
|
|
22
|
+
devolver la data de un string base64
|
|
23
|
+
--------------------------*/
|
|
24
|
+
export const getDataBase64 = (base64Full) => {
|
|
25
|
+
//const base64 = reader.result.replace(/^data:\w+\/\w+.*;base64,/, "");
|
|
26
|
+
try {
|
|
27
|
+
const base64 = base64Full.split("base64,");
|
|
28
|
+
return base64.length ? base64[1] : undefined;
|
|
29
|
+
} catch (err) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/*------------------------
|
|
35
|
+
devolver un data Buffer a partir
|
|
36
|
+
de un data base64
|
|
37
|
+
--------------------------*/
|
|
38
|
+
export const getDataBuffer = (dataBase64) => {
|
|
39
|
+
try {
|
|
40
|
+
const dataBuffer = Buffer.from(dataBase64, "base64");
|
|
41
|
+
return dataBuffer;
|
|
42
|
+
} catch (err) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/*------------------------
|
|
48
|
+
devolver la extension de un file
|
|
49
|
+
a partir de un string: "name.ext"
|
|
50
|
+
--------------------------*/
|
|
51
|
+
export const getFileExtension = (fileName = "") => {
|
|
52
|
+
const nameParts = fileName.split(".");
|
|
53
|
+
let ext = "";
|
|
54
|
+
nameParts.forEach((part, index) => {
|
|
55
|
+
if (index !== 0) {
|
|
56
|
+
if (index + 1 === nameParts.length) ext += part;
|
|
57
|
+
else ext += part + ".";
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return ext === "" ? undefined : ext;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/*------------------------
|
|
64
|
+
devolver el nombre de un file
|
|
65
|
+
a partir de un string: "name.ext"
|
|
66
|
+
--------------------------*/
|
|
67
|
+
export const getFileName = (fileName = "") => {
|
|
68
|
+
const nameParts = fileName.split(".");
|
|
69
|
+
if (nameParts.length) return nameParts[0];
|
|
70
|
+
return undefined;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/*------------------------
|
|
74
|
+
obtener la URL de una imagen
|
|
75
|
+
con un peso mas pequeño al
|
|
76
|
+
peso original pasando como
|
|
77
|
+
parametros:
|
|
78
|
+
=> bucket: <string> bucket en donde se ecuentra la img
|
|
79
|
+
=> key: <string> ruta y nombre completa de la img (keyS3)
|
|
80
|
+
=> width: <number> largo de la img en px
|
|
81
|
+
=> height: <number> altura de la img en px
|
|
82
|
+
--------------------------*/
|
|
83
|
+
export const getImageURL = (bucket, key, width, height) => {
|
|
84
|
+
try {
|
|
85
|
+
const configAWS = {
|
|
86
|
+
bucket: bucket,
|
|
87
|
+
key: key,
|
|
88
|
+
edits: {
|
|
89
|
+
resize: {
|
|
90
|
+
width: width,
|
|
91
|
+
height: height,
|
|
92
|
+
fit: "contain",
|
|
93
|
+
background: { r: 255, g: 255, b: 255, alpha: 0 },
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
let url = "https://d24s337exbt5zr.cloudfront.net/";
|
|
98
|
+
url += Base64.encode(JSON.stringify(configAWS));
|
|
99
|
+
return url;
|
|
100
|
+
} catch (err) {
|
|
101
|
+
console.log(`ERROR al obtener la URL de la imagen (${key})`, err.message);
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/*------------------------
|
|
107
|
+
obtener la dimension de una imagen
|
|
108
|
+
a partir de un objeto <File>
|
|
109
|
+
retorno: {
|
|
110
|
+
=> width: <number> largo de la img en px
|
|
111
|
+
=> height: <number> altura de la img en px
|
|
112
|
+
}
|
|
113
|
+
NOTA regresa <undefined> si no se pudo
|
|
114
|
+
obtener la dimension de la imagen
|
|
115
|
+
--------------------------*/
|
|
116
|
+
export const getImageSize = (file) => {
|
|
117
|
+
return new Promise(async (response) => {
|
|
118
|
+
const img = new Image();
|
|
119
|
+
img.onload = () => response({ width: img.width, height: img.height });
|
|
120
|
+
img.onerror = () => response(undefined);
|
|
121
|
+
const base64 = await getBase64(file);
|
|
122
|
+
img.src = base64;
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/*------------------------
|
|
127
|
+
obtener una redimension (height) proporcional
|
|
128
|
+
a la dimension original (height) a partir de
|
|
129
|
+
un width deseado
|
|
130
|
+
retorno:
|
|
131
|
+
=> newHeight: <number> altura de la img en px
|
|
132
|
+
NOTA regresa <undefined> si no se pudo
|
|
133
|
+
obtener el nuevo <height> de la imagen
|
|
134
|
+
--------------------------*/
|
|
135
|
+
export const getResizeImgHeight = (originalWidth, originalHeight, newWidth) => {
|
|
136
|
+
/*
|
|
137
|
+
console.log(`==================
|
|
138
|
+
original width: ${originalWidth}
|
|
139
|
+
original height: ${originalHeight}
|
|
140
|
+
newWidth: ${newWidth}`);
|
|
141
|
+
*/
|
|
142
|
+
const scale = (newWidth * 100) / originalWidth / 100;
|
|
143
|
+
//console.log("scale:", scale);
|
|
144
|
+
return Math.ceil(originalHeight * scale);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/*====================================================================
|
|
148
|
+
UTILERIAS PARA EL MANEJO DE FECHAS
|
|
149
|
+
======================================================================*/
|
|
150
|
+
/*------------------------
|
|
151
|
+
nombres de los dias de la semana
|
|
152
|
+
--------------------------*/
|
|
153
|
+
const weekdayName = {
|
|
154
|
+
1: { short: "Dom", full: "Domingo" },
|
|
155
|
+
2: { short: "Lun", full: "Lunes" },
|
|
156
|
+
3: { short: "Mar", full: "Martes" },
|
|
157
|
+
4: { short: "Mié", full: "Miércoles" },
|
|
158
|
+
5: { short: "Jue", full: "Jueves" },
|
|
159
|
+
6: { short: "Vie", full: "Viernes" },
|
|
160
|
+
7: { short: "Sab", full: "Sabado" },
|
|
161
|
+
};
|
|
162
|
+
/*------------------------
|
|
163
|
+
nombres de los meses
|
|
164
|
+
--------------------------*/
|
|
165
|
+
const monthName = {
|
|
166
|
+
1: { short: "Ene", full: "Enero" },
|
|
167
|
+
2: { short: "Feb", full: "Febrero" },
|
|
168
|
+
3: { short: "Mar", full: "Marzo" },
|
|
169
|
+
4: { short: "Abr", full: "Abril" },
|
|
170
|
+
5: { short: "May", full: "Mayo" },
|
|
171
|
+
6: { short: "Jun", full: "Junio" },
|
|
172
|
+
7: { short: "Jul", full: "Julio" },
|
|
173
|
+
8: { short: "Ago", full: "Agosto" },
|
|
174
|
+
9: { short: "Sep", full: "Septiembre" },
|
|
175
|
+
10: { short: "Oct", full: "Octubre" },
|
|
176
|
+
11: { short: "Nov", full: "Noviembre" },
|
|
177
|
+
12: { short: "Dic", full: "Diciembre" },
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/*------------------------
|
|
181
|
+
Obtener una fecha a partir de
|
|
182
|
+
un objeto Date() en formato:
|
|
183
|
+
'DDD dd MMM aaaa'
|
|
184
|
+
ejemplo: 'Ene 12 Jul 2022'
|
|
185
|
+
--------------------------*/
|
|
186
|
+
export const getFullDate = (date = new Date()) => {
|
|
187
|
+
if (isNaN(date)) return undefined;
|
|
188
|
+
let dateString = `${weekdayName[date.getDay() + 1].short} `;
|
|
189
|
+
dateString += date.getDate() + " ";
|
|
190
|
+
dateString += `${monthName[date.getMonth() + 1].short} `;
|
|
191
|
+
dateString += date.getFullYear();
|
|
192
|
+
return dateString;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/*------------------------
|
|
196
|
+
Obtener una fecha a partir de
|
|
197
|
+
un objeto Date() en formato:
|
|
198
|
+
'dd de MMMM del aaaa'
|
|
199
|
+
ejemplo: '12 de octubre del 2022'
|
|
200
|
+
=> si es la fecha del dia actual:
|
|
201
|
+
devolvera 'Hoy'
|
|
202
|
+
=> si es la fecha del dia de ayer:
|
|
203
|
+
devolvera 'Ayer'
|
|
204
|
+
=> si es fecha del mismo año:
|
|
205
|
+
devolvera '12 de octubre'
|
|
206
|
+
--------------------------*/
|
|
207
|
+
export const getCustomDate = (date = new Date()) => {
|
|
208
|
+
if (isNaN(date)) return "";
|
|
209
|
+
let dateString = date.getDate() + " de ";
|
|
210
|
+
dateString += `${monthName[date.getMonth() + 1].full}`;
|
|
211
|
+
const today = new Date();
|
|
212
|
+
const yesterday = new Date();
|
|
213
|
+
yesterday.setDate(today.getDate() - 1);
|
|
214
|
+
|
|
215
|
+
// fecha de Hoy
|
|
216
|
+
if (
|
|
217
|
+
date.getDate() === today.getDate() &&
|
|
218
|
+
date.getMonth() === today.getMonth() &&
|
|
219
|
+
date.getFullYear() === today.getFullYear()
|
|
220
|
+
) {
|
|
221
|
+
return "Hoy";
|
|
222
|
+
}
|
|
223
|
+
// fecha de Ayer
|
|
224
|
+
if (
|
|
225
|
+
date.getDate() === yesterday.getDate() &&
|
|
226
|
+
date.getMonth() === yesterday.getMonth() &&
|
|
227
|
+
date.getFullYear() === yesterday.getFullYear()
|
|
228
|
+
) {
|
|
229
|
+
return "Ayer";
|
|
230
|
+
}
|
|
231
|
+
// fechas del mismo año
|
|
232
|
+
if (date.getFullYear() === today.getFullYear()) return dateString;
|
|
233
|
+
// fechas de diferente año
|
|
234
|
+
return dateString + " del " + date.getFullYear();
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/*------------------------
|
|
238
|
+
Obtener una hora a partir de
|
|
239
|
+
una fecha string (current_timestamp)
|
|
240
|
+
en formato: 'hh:mm PM/AM'
|
|
241
|
+
ejemplo: '12:34 PM'
|
|
242
|
+
--------------------------*/
|
|
243
|
+
export const getTime = (time = "") => {
|
|
244
|
+
if ([undefined, null, ""].includes(time))
|
|
245
|
+
return moment(new Date()).format("LT");
|
|
246
|
+
else return moment(time).format("LT");
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
/*====================================================================
|
|
250
|
+
UTILERIAS PARA EL MANEJO DE VALIDACIONES
|
|
251
|
+
======================================================================*/
|
|
252
|
+
/*------------------------
|
|
253
|
+
recibe un number o string
|
|
254
|
+
y determina si es numero natural
|
|
255
|
+
0,1,2,...
|
|
256
|
+
--------------------------*/
|
|
257
|
+
export const isValidNaturalNumber = (number) => {
|
|
258
|
+
if ([undefined, null, ""].includes(number)) return false;
|
|
259
|
+
if (!["string", "number"].includes(typeof number)) return false;
|
|
260
|
+
try {
|
|
261
|
+
const numberString = number + "";
|
|
262
|
+
for (let i = 0; i < numberString.length; i++) {
|
|
263
|
+
if ("0123456789".indexOf(numberString.charAt(i)) === -1) return false;
|
|
264
|
+
}
|
|
265
|
+
return true;
|
|
266
|
+
} catch (err) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
/*------------------------
|
|
272
|
+
recibe un array y determina si
|
|
273
|
+
el array esta vacio []
|
|
274
|
+
--------------------------*/
|
|
275
|
+
export const isArrayEmpty = (array) => {
|
|
276
|
+
if (Array.isArray(array) && array.length) return false;
|
|
277
|
+
return true;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/*------------------------
|
|
281
|
+
recibe un string y determina si
|
|
282
|
+
esta vacio ""
|
|
283
|
+
--------------------------*/
|
|
284
|
+
export const isStringEmpty = (cad) => {
|
|
285
|
+
if (cad && typeof cad === "string" && cad.trim().length !== 0) return false;
|
|
286
|
+
return true;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
/*------------------------
|
|
290
|
+
recibe un string JSON y lo
|
|
291
|
+
decodifica a su valor original
|
|
292
|
+
--------------------------*/
|
|
293
|
+
export const decodeJSON = (valueJSON) => {
|
|
294
|
+
try {
|
|
295
|
+
const decodeValue = JSON.parse(valueJSON);
|
|
296
|
+
return decodeValue;
|
|
297
|
+
} catch (err) {
|
|
298
|
+
return valueJSON;
|
|
299
|
+
}
|
|
300
|
+
};
|