@bjsdistribution/dms-client-return 0.1.58-prod → 0.1.59-prod

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.
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  interface IProps {
3
3
  collapsedContent: React.ReactNode;
4
4
  children: React.ReactNode;
5
+ extraActions?: React.ReactNode;
5
6
  }
6
7
  declare function CollapsableForm(props: IProps): React.JSX.Element;
7
8
  export default CollapsableForm;
@@ -7093,7 +7093,7 @@ function CollapsableForm(props) {
7093
7093
  var _useState = React.useState(true),
7094
7094
  isExpanded = _useState[0],
7095
7095
  setIsExpanded = _useState[1];
7096
- return React__default.createElement(MainContainer$3, null, React__default.createElement(CardHeader$1, null, React__default.createElement(CollapsedContent, null, props.collapsedContent, React__default.createElement(Container$F, null, React__default.createElement(Text$4, {
7096
+ return React__default.createElement(MainContainer$3, null, React__default.createElement(CardHeader$1, null, React__default.createElement(CollapsedContent, null, props.collapsedContent, React__default.createElement(Container$F, null, props == null ? void 0 : props.extraActions, React__default.createElement(Text$4, {
7097
7097
  onClick: function onClick() {
7098
7098
  return setIsExpanded(function (prev) {
7099
7099
  return !prev;
@@ -8244,25 +8244,58 @@ var Container$P = /*#__PURE__*/styled__default.div(_templateObject2$$ || (_templ
8244
8244
  var Items = /*#__PURE__*/styled__default.span(_templateObject3$w || (_templateObject3$w = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n font-family: 'Roboto', sans-serif;\n font-size: 14px;\n font-weight: 500;\n line-height: 24px;\n color: #8e8a85;\n text-transform: capitalize;\n color: #6a7378;\n"])));
8245
8245
 
8246
8246
  function ProductsInfo(_ref) {
8247
+ var _returnOrdersData$dat;
8247
8248
  var locationloading = _ref.locationloading;
8248
8249
  var _useOrderDetails = useOrderDetails(),
8249
8250
  data = _useOrderDetails[0];
8250
8251
  var returnOrder = data;
8252
+ var _useState = React.useState(false),
8253
+ spinLoading = _useState[0],
8254
+ setSpinLoading = _useState[1];
8255
+ // Export functionality
8256
+ var _useAxios = dmsComponentLibrary.useAxios({
8257
+ endpoint: "/v1/export/csv/" + (returnOrder == null ? void 0 : returnOrder.id),
8258
+ method: 'POST'
8259
+ }),
8260
+ callExportCSV = _useAxios.fetchData;
8261
+ var handleExportCSV = function handleExportCSV(e) {
8262
+ e.stopPropagation();
8263
+ setSpinLoading(true);
8264
+ callExportCSV().then(function (res) {
8265
+ var _res$data;
8266
+ var urlToDownload = (res == null || (_res$data = res.data) == null ? void 0 : _res$data.url) || (res == null ? void 0 : res.url);
8267
+ if (urlToDownload) {
8268
+ var a = document.createElement('a');
8269
+ a.href = urlToDownload;
8270
+ a.download = "products_export_" + (returnOrder == null ? void 0 : returnOrder.id) + ".csv";
8271
+ document.body.appendChild(a);
8272
+ a.click();
8273
+ document.body.removeChild(a);
8274
+ }
8275
+ setSpinLoading(false);
8276
+ })["catch"](function (err) {
8277
+ antd.notification.error({
8278
+ message: 'Failed to export csv',
8279
+ description: (err == null ? void 0 : err.message) || 'Export error'
8280
+ });
8281
+ setSpinLoading(false);
8282
+ });
8283
+ };
8251
8284
  // For API Call
8252
8285
  var _useProductDetails = useProductDetails(),
8253
8286
  setProductsData = _useProductDetails[1];
8254
8287
  var _useLoading = useLoading(),
8255
8288
  setLoading = _useLoading[1];
8256
- var _useAxios = dmsComponentLibrary.useAxios({
8289
+ var _useAxios2 = dmsComponentLibrary.useAxios({
8257
8290
  endpoint: "/v1/return/products/" + (returnOrder == null ? void 0 : returnOrder.id),
8258
8291
  method: 'GET',
8259
8292
  pagination: {
8260
8293
  is_pagination: false
8261
8294
  }
8262
8295
  }),
8263
- returnOrdersData = _useAxios.data,
8264
- loading = _useAxios.loading,
8265
- callReturnProducts = _useAxios.fetchData;
8296
+ returnOrdersData = _useAxios2.data,
8297
+ loading = _useAxios2.loading,
8298
+ callReturnProducts = _useAxios2.fetchData;
8266
8299
  React.useEffect(function () {
8267
8300
  if (returnOrder != null && returnOrder.id) {
8268
8301
  callReturnProducts();
@@ -8279,8 +8312,52 @@ function ProductsInfo(_ref) {
8279
8312
  }
8280
8313
  }
8281
8314
  }, [returnOrdersData, loading]);
8315
+ var isExportDisabled = !(returnOrdersData != null && returnOrdersData.data) || (returnOrdersData == null || (_returnOrdersData$dat = returnOrdersData.data) == null ? void 0 : _returnOrdersData$dat.length) === 0;
8282
8316
  return React__default.createElement(CollapsableForm, {
8283
- collapsedContent: React__default.createElement(CollapsedContent$1, null)
8317
+ collapsedContent: React__default.createElement(CollapsedContent$1, null),
8318
+ extraActions: React__default.createElement("div", {
8319
+ style: {
8320
+ display: 'flex',
8321
+ alignItems: 'center',
8322
+ cursor: isExportDisabled ? 'not-allowed' : 'pointer',
8323
+ opacity: isExportDisabled ? 0.5 : 1,
8324
+ marginRight: '16px',
8325
+ backgroundColor: 'rgb(243 243 243)',
8326
+ border: '1px solid #E2E8F0',
8327
+ padding: '6px 14px',
8328
+ borderRadius: '10px',
8329
+ boxShadow: '0 1px 2px rgba(0,0,0,0.05)',
8330
+ transition: 'background-color 0.2s'
8331
+ },
8332
+ onClick: function onClick(e) {
8333
+ if (isExportDisabled) return;
8334
+ handleExportCSV(e);
8335
+ },
8336
+ onMouseOver: function onMouseOver(e) {
8337
+ if (!isExportDisabled) e.currentTarget.style.backgroundColor = '#E2E8F0';
8338
+ },
8339
+ onMouseOut: function onMouseOut(e) {
8340
+ if (!isExportDisabled) e.currentTarget.style.backgroundColor = 'rgb(243 243 243)';
8341
+ }
8342
+ }, React__default.createElement("span", {
8343
+ style: {
8344
+ color: '#475569',
8345
+ fontFamily: 'Lato',
8346
+ fontSize: '13px',
8347
+ fontWeight: 600,
8348
+ whiteSpace: 'nowrap',
8349
+ letterSpacing: '0.3px'
8350
+ }
8351
+ }, "EXPORT CSV"), React__default.createElement("span", {
8352
+ style: {
8353
+ marginLeft: '6px',
8354
+ display: 'flex',
8355
+ alignItems: 'center'
8356
+ }
8357
+ }, React__default.createElement(antd.Spin, {
8358
+ spinning: spinLoading,
8359
+ size: "small"
8360
+ })))
8284
8361
  }, React__default.createElement(ExpandedContent$2, {
8285
8362
  callReturnProducts: callReturnProducts,
8286
8363
  loading: loading,