contentoh-components-library 21.3.45 → 21.3.47

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.
Files changed (24) hide show
  1. package/.env.development +2 -0
  2. package/dist/components/molecules/CarouselImagesLogin/index.js +1 -1
  3. package/dist/components/molecules/HeaderTop/index.js +68 -11
  4. package/dist/components/organisms/Chat/Chat.stories.js +21 -1
  5. package/dist/components/organisms/Chat/ContainerItems/index.js +1 -1
  6. package/dist/components/organisms/Chat/ContentChat/index.js +343 -191
  7. package/dist/components/organisms/Chat/Footer/index.js +48 -39
  8. package/dist/components/organisms/Chat/index.js +48 -3
  9. package/dist/components/pages/ProviderProductEdition/ProviderProductEdition.stories.js +2 -1
  10. package/dist/components/pages/ProviderProductEdition/index.js +2 -1
  11. package/dist/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +6 -2
  12. package/dist/components/pages/RetailerProductEdition/index.js +4 -2
  13. package/package.json +1 -1
  14. package/src/components/molecules/CarouselImagesLogin/index.js +1 -1
  15. package/src/components/molecules/HeaderTop/index.js +52 -6
  16. package/src/components/organisms/Chat/Chat.stories.js +21 -0
  17. package/src/components/organisms/Chat/ContainerItems/index.js +4 -1
  18. package/src/components/organisms/Chat/ContentChat/index.js +81 -6
  19. package/src/components/organisms/Chat/Footer/index.js +11 -0
  20. package/src/components/organisms/Chat/index.js +47 -3
  21. package/src/components/pages/ProviderProductEdition/ProviderProductEdition.stories.js +1 -0
  22. package/src/components/pages/ProviderProductEdition/index.js +1 -0
  23. package/src/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +5 -1
  24. package/src/components/pages/RetailerProductEdition/index.js +2 -0
@@ -100,6 +100,7 @@ export const ContentChat = (props) => {
100
100
  }
101
101
  if (chatType === "merchant_product") getInitialMerchantProduct();
102
102
  else if (chatType === "order_product") getInitialOrderProduct();
103
+ else if (chatType === "product_status") getInitialProductStatus();
103
104
  else getInitialTicket();
104
105
  }
105
106
  if (!showPopUpChat) {
@@ -126,6 +127,8 @@ export const ContentChat = (props) => {
126
127
  } else if (chatType === "order_product") {
127
128
  if (companies) getUpdateLatestOrderProduct(true);
128
129
  else getInitialOrderProduct();
130
+ } else if (chatType === "product_status") {
131
+ getInitialProductStatus();
129
132
  } else {
130
133
  if (singleChat.items) getUpdateLatestTicket(true);
131
134
  else getInitialTicket();
@@ -135,6 +138,47 @@ export const ContentChat = (props) => {
135
138
  /*=======================================================================
136
139
  PETICION GET INICIAL SEGUN EL TIPO DE CHAT
137
140
  ======================================================================= */
141
+ const getInitialProductStatus = async () => {
142
+ const paramsQuery = {
143
+ articleData: {
144
+ articleId: JSON.stringify(dataChat.id),
145
+ version: JSON.stringify(dataChat.version),
146
+ retailerId: JSON.stringify(dataChat.retailerId),
147
+ status: dataChat.status,
148
+ },
149
+ };
150
+ const paramsHeaders = { Authorization: dataChat.userToken };
151
+ const response = await fetchGET(
152
+ process.env.REACT_APP_READ_MESSAGES,
153
+ paramsQuery,
154
+ paramsHeaders
155
+ );
156
+ if (!response.body) {
157
+ setErrorChat({
158
+ existError: true,
159
+ code: 400,
160
+ message: response.message,
161
+ errorDetail: response.errorDetail,
162
+ });
163
+ setIsLoading(false);
164
+ return;
165
+ }
166
+ // success
167
+ setStartUpdate((prev) => prev + 1);
168
+ setCurrentUser({
169
+ id: response.body.data.currentUserId,
170
+ companyId: response.body.data.currentCompanyId,
171
+ });
172
+ setLastUpdateDate(response.body.data.lastUpdateDate);
173
+ setAllUsers(response.body.users);
174
+ setSingleChat({
175
+ items: response.body.items,
176
+ enabledLoadMore: response.body.items.length === 50,
177
+ });
178
+ setErrorChat({ existError: false });
179
+ setIsLoading(false);
180
+ };
181
+
138
182
  const getInitialMerchantProduct = async () => {
139
183
  const paramsQuery = {
140
184
  getType: "initial",
@@ -609,12 +653,14 @@ export const ContentChat = (props) => {
609
653
  // enviar items a la BD
610
654
  if (chatType === "merchant_product") {
611
655
  errorCreate = await createItemsMerchantProduct(items);
656
+ } else if (chatType === "product_status") {
657
+ errorCreate = await createItemsProductStatus(items);
612
658
  } else if (chatType === "order_product") {
613
659
  errorCreate = await createItemsOrderProduct(items);
614
660
  } else errorCreate = await createItemsTicket(items);
615
661
 
616
662
  // actualizar chat para que aparezcan los items enviados
617
- if (chatType === "merchant_product") {
663
+ if (["merchant_product", "product_status"].includes(chatType)) {
618
664
  await getUpdateLatestMerchantProduct();
619
665
  } else if (chatType === "order_product") {
620
666
  await getUpdateLatestOrderProduct();
@@ -627,9 +673,10 @@ export const ContentChat = (props) => {
627
673
  };
628
674
 
629
675
  const createItemsMerchantProduct = async (items = []) => {
630
- const { id, version } = dataChat;
676
+ const { id, version, orderId } = dataChat;
631
677
  const { id: retailerId } = activeRetailer;
632
678
  const paramsBody = { id, version, items, retailerId };
679
+ if (chatType === "product_status") paramsBody["orderId"] = orderId;
633
680
  const paramsHeaders = { Authorization: dataChat.userToken };
634
681
  const response = await fetchPOST(
635
682
  process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
@@ -643,6 +690,23 @@ export const ContentChat = (props) => {
643
690
  };
644
691
  }
645
692
  };
693
+ const createItemsProductStatus = async (items = []) => {
694
+ const { id, version, orderId, status } = dataChat;
695
+ const { id: retailerId } = activeRetailer;
696
+ const paramsBody = { id, version, items, retailerId, orderId, status };
697
+ const paramsHeaders = { Authorization: dataChat.userToken };
698
+ const response = await fetchPOST(
699
+ process.env.REACT_APP_CREATE_MESSAGES,
700
+ paramsBody,
701
+ paramsHeaders
702
+ );
703
+ if (!response.body) {
704
+ return {
705
+ message: response.message,
706
+ errorDetail: response.errorDetail,
707
+ };
708
+ }
709
+ };
646
710
 
647
711
  const createItemsOrderProduct = async (items = []) => {
648
712
  const paramsBody = {
@@ -690,7 +754,11 @@ export const ContentChat = (props) => {
690
754
  SECCION DE FUNCIONES
691
755
  ======================================================================= */
692
756
  const isSingleChat = () => {
693
- if (chatType === "merchant_product" || chatType === "ticket") {
757
+ if (
758
+ chatType === "merchant_product" ||
759
+ chatType === "ticket" ||
760
+ chatType === "product_status"
761
+ ) {
694
762
  return true;
695
763
  }
696
764
  if (companies && Object.keys(companies).length < 2) return true;
@@ -801,7 +869,7 @@ export const ContentChat = (props) => {
801
869
  // mostrar chat?
802
870
  let items;
803
871
  let enabledLoadMore;
804
- if (["merchant_product", "ticket"].includes(chatType)) {
872
+ if (["merchant_product", "ticket", "product_status"].includes(chatType)) {
805
873
  items = singleChat.items;
806
874
  enabledLoadMore = singleChat.enabledLoadMore;
807
875
  }
@@ -843,7 +911,9 @@ export const ContentChat = (props) => {
843
911
  activeCompanyId={activeCompanyId}
844
912
  ticketCompany={ticketCompany}
845
913
  currentUser={
846
- ["merchant_product", "order_product"].includes(chatType)
914
+ ["merchant_product", "order_product", "product_status"].includes(
915
+ chatType
916
+ )
847
917
  ? currentUser
848
918
  : dataChat.currentUser
849
919
  }
@@ -882,6 +952,12 @@ export const ContentChat = (props) => {
882
952
  ? { id: dataChat.id, version: currentArticle.version }
883
953
  : chatType === "ticket"
884
954
  ? { id: dataChat.id }
955
+ : chatType === "product_status"
956
+ ? {
957
+ id: dataChat.id,
958
+ version: dataChat.version,
959
+ retailerId: dataChat.retailerId,
960
+ }
885
961
  : undefined
886
962
  }
887
963
  chatCompany={getChatCompany()}
@@ -924,7 +1000,6 @@ export const ContentChat = (props) => {
924
1000
  }}
925
1001
  />
926
1002
  )}
927
-
928
1003
  {/* body */}
929
1004
  {renderBodyChat()}
930
1005
  </Container>
@@ -169,6 +169,17 @@ export const Footer = (props) => {
169
169
  errorMessage = "El ID del ticket no es valido";
170
170
  }
171
171
  break;
172
+ case "product_status":
173
+ if (
174
+ isValidNaturalNumber(dataChat?.id) &&
175
+ isValidNaturalNumber(dataChat?.version) &&
176
+ isValidNaturalNumber(dataChat?.retailerId)
177
+ ) {
178
+ fileKey += `productStatus/${dataChat.id}-${dataChat?.version}-${dataChat?.retailerId}/`;
179
+ } else {
180
+ errorMessage = "El ID del ticket no es valido";
181
+ }
182
+ break;
172
183
 
173
184
  default:
174
185
  errorMessage =
@@ -24,7 +24,7 @@ export const Chat = (props) => {
24
24
  const [showPopUpChat, setShowPopUpChat] = useState(false);
25
25
  const [data, setData] = useState();
26
26
 
27
- const { ticketCompany } = chatData || {};
27
+ const { ticketCompany, retailerId } = chatData || {};
28
28
 
29
29
  useEffect(() => {
30
30
  switch (chatType) {
@@ -37,6 +37,9 @@ export const Chat = (props) => {
37
37
  case "ticket":
38
38
  validateChatTicket();
39
39
  break;
40
+ case "product_status":
41
+ validateProductStatus();
42
+ break;
40
43
  default:
41
44
  setData({
42
45
  code: 404,
@@ -46,6 +49,45 @@ export const Chat = (props) => {
46
49
  }
47
50
  }, [chatType]);
48
51
 
52
+ const validateProductStatus = () => {
53
+ const {
54
+ userToken, // string
55
+ id, // number
56
+ version,
57
+ retailerId, // number
58
+ status,
59
+ orderId,
60
+ } = chatData;
61
+
62
+ if (!isValidGeneral(userToken, id)) return;
63
+
64
+ // validar el ID de la cadena asociada al producto en la OT
65
+ if (!isValidNaturalNumber(retailerId)) {
66
+ setDataError("La cadena relacionada al producto no es válida");
67
+ return;
68
+ }
69
+
70
+ // validar el ID de la version asociada al producto en la OT
71
+ if (!isValidNaturalNumber(version)) {
72
+ setDataError("La versión del producto no es válida");
73
+ return;
74
+ }
75
+
76
+ if (orderId && !isValidNaturalNumber(orderId)) {
77
+ setDataError("La orden del producto no es válida");
78
+ return;
79
+ }
80
+
81
+ setData({
82
+ userToken,
83
+ id,
84
+ version,
85
+ retailerId,
86
+ orderId,
87
+ status,
88
+ });
89
+ };
90
+
49
91
  const isValidGeneral = (userToken, id) => {
50
92
  // validar token del user
51
93
  if (isStringEmpty(userToken)) {
@@ -69,6 +111,8 @@ export const Chat = (props) => {
69
111
  retailerId, // number
70
112
  } = chatData;
71
113
 
114
+ console.log(chatData, "chatData");
115
+
72
116
  if (!isValidGeneral(userToken, id)) return;
73
117
 
74
118
  // validar el ID de la OT en donde se encuentra el producto
@@ -197,7 +241,7 @@ export const Chat = (props) => {
197
241
  dataChat={data}
198
242
  showBtnClose={false}
199
243
  ticketCompany={ticketCompany}
200
- activeRetailer={props.activeRetailer}
244
+ activeRetailer={props.activeRetailer || { id: retailerId }}
201
245
  />
202
246
  </ContainerFixed>
203
247
  );
@@ -230,7 +274,7 @@ export const Chat = (props) => {
230
274
  onClickBtnClose={() => {
231
275
  setShowPopUpChat(false);
232
276
  }}
233
- activeRetailer={props.activeRetailer}
277
+ activeRetailer={props.activeRetailer || { id: retailerId }}
234
278
  />
235
279
  </ContainerPopUp>
236
280
  </Slide>
@@ -138,6 +138,7 @@ ProviderProductEditionDefault.args = {
138
138
  hash: "",
139
139
  state: {
140
140
  withChat: true,
141
+ chatType: "product_status",
141
142
  },
142
143
  key: "24vwut",
143
144
  },
@@ -1294,6 +1294,7 @@ export const ProviderProductEdition = ({
1294
1294
  <HeaderTop
1295
1295
  setHeaderTop={setHeaderTop}
1296
1296
  withChat={location?.state?.withChat}
1297
+ chatType={location?.state?.chatType}
1297
1298
  productSelected={productSelected}
1298
1299
  token={token}
1299
1300
  activeRetailer={activeRetailer}
@@ -74,7 +74,11 @@ RetailerProductEditionDefault.args = {
74
74
  }
75
75
  },
76
76
  location: {
77
- product: { articleId: 39290, versionId: 7 },
77
+ product: { articleId: 354, versionId: 3 },
78
+ state: {
79
+ withChat: true,
80
+ chatType: "product_status",
81
+ },
78
82
  },
79
83
  user: {
80
84
  "id_user": 51,
@@ -1271,8 +1271,10 @@ export const RetailerProductEdition = ({
1271
1271
  setCompare={setCompare}
1272
1272
  isAuditor={[1, 6].includes(user.id_role)}
1273
1273
  withChat={location?.state?.withChat}
1274
+ chatType={location?.state?.chatType}
1274
1275
  productSelected={productSelected}
1275
1276
  token={token}
1277
+ activeRetailer={activeRetailer}
1276
1278
  />
1277
1279
  <div className="data-container">
1278
1280
  <div className="image-data-panel">