@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.
@@ -7085,7 +7085,7 @@ function CollapsableForm(props) {
7085
7085
  var _useState = useState(true),
7086
7086
  isExpanded = _useState[0],
7087
7087
  setIsExpanded = _useState[1];
7088
- return React.createElement(MainContainer$3, null, React.createElement(CardHeader$1, null, React.createElement(CollapsedContent, null, props.collapsedContent, React.createElement(Container$F, null, React.createElement(Text$4, {
7088
+ return React.createElement(MainContainer$3, null, React.createElement(CardHeader$1, null, React.createElement(CollapsedContent, null, props.collapsedContent, React.createElement(Container$F, null, props == null ? void 0 : props.extraActions, React.createElement(Text$4, {
7089
7089
  onClick: function onClick() {
7090
7090
  return setIsExpanded(function (prev) {
7091
7091
  return !prev;
@@ -8236,25 +8236,58 @@ var Container$P = /*#__PURE__*/styled.div(_templateObject2$$ || (_templateObject
8236
8236
  var Items = /*#__PURE__*/styled.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"])));
8237
8237
 
8238
8238
  function ProductsInfo(_ref) {
8239
+ var _returnOrdersData$dat;
8239
8240
  var locationloading = _ref.locationloading;
8240
8241
  var _useOrderDetails = useOrderDetails(),
8241
8242
  data = _useOrderDetails[0];
8242
8243
  var returnOrder = data;
8244
+ var _useState = useState(false),
8245
+ spinLoading = _useState[0],
8246
+ setSpinLoading = _useState[1];
8247
+ // Export functionality
8248
+ var _useAxios = useAxios({
8249
+ endpoint: "/v1/export/csv/" + (returnOrder == null ? void 0 : returnOrder.id),
8250
+ method: 'POST'
8251
+ }),
8252
+ callExportCSV = _useAxios.fetchData;
8253
+ var handleExportCSV = function handleExportCSV(e) {
8254
+ e.stopPropagation();
8255
+ setSpinLoading(true);
8256
+ callExportCSV().then(function (res) {
8257
+ var _res$data;
8258
+ var urlToDownload = (res == null || (_res$data = res.data) == null ? void 0 : _res$data.url) || (res == null ? void 0 : res.url);
8259
+ if (urlToDownload) {
8260
+ var a = document.createElement('a');
8261
+ a.href = urlToDownload;
8262
+ a.download = "products_export_" + (returnOrder == null ? void 0 : returnOrder.id) + ".csv";
8263
+ document.body.appendChild(a);
8264
+ a.click();
8265
+ document.body.removeChild(a);
8266
+ }
8267
+ setSpinLoading(false);
8268
+ })["catch"](function (err) {
8269
+ notification.error({
8270
+ message: 'Failed to export csv',
8271
+ description: (err == null ? void 0 : err.message) || 'Export error'
8272
+ });
8273
+ setSpinLoading(false);
8274
+ });
8275
+ };
8243
8276
  // For API Call
8244
8277
  var _useProductDetails = useProductDetails(),
8245
8278
  setProductsData = _useProductDetails[1];
8246
8279
  var _useLoading = useLoading(),
8247
8280
  setLoading = _useLoading[1];
8248
- var _useAxios = useAxios({
8281
+ var _useAxios2 = useAxios({
8249
8282
  endpoint: "/v1/return/products/" + (returnOrder == null ? void 0 : returnOrder.id),
8250
8283
  method: 'GET',
8251
8284
  pagination: {
8252
8285
  is_pagination: false
8253
8286
  }
8254
8287
  }),
8255
- returnOrdersData = _useAxios.data,
8256
- loading = _useAxios.loading,
8257
- callReturnProducts = _useAxios.fetchData;
8288
+ returnOrdersData = _useAxios2.data,
8289
+ loading = _useAxios2.loading,
8290
+ callReturnProducts = _useAxios2.fetchData;
8258
8291
  useEffect(function () {
8259
8292
  if (returnOrder != null && returnOrder.id) {
8260
8293
  callReturnProducts();
@@ -8271,8 +8304,52 @@ function ProductsInfo(_ref) {
8271
8304
  }
8272
8305
  }
8273
8306
  }, [returnOrdersData, loading]);
8307
+ var isExportDisabled = !(returnOrdersData != null && returnOrdersData.data) || (returnOrdersData == null || (_returnOrdersData$dat = returnOrdersData.data) == null ? void 0 : _returnOrdersData$dat.length) === 0;
8274
8308
  return React.createElement(CollapsableForm, {
8275
- collapsedContent: React.createElement(CollapsedContent$1, null)
8309
+ collapsedContent: React.createElement(CollapsedContent$1, null),
8310
+ extraActions: React.createElement("div", {
8311
+ style: {
8312
+ display: 'flex',
8313
+ alignItems: 'center',
8314
+ cursor: isExportDisabled ? 'not-allowed' : 'pointer',
8315
+ opacity: isExportDisabled ? 0.5 : 1,
8316
+ marginRight: '16px',
8317
+ backgroundColor: 'rgb(243 243 243)',
8318
+ border: '1px solid #E2E8F0',
8319
+ padding: '6px 14px',
8320
+ borderRadius: '10px',
8321
+ boxShadow: '0 1px 2px rgba(0,0,0,0.05)',
8322
+ transition: 'background-color 0.2s'
8323
+ },
8324
+ onClick: function onClick(e) {
8325
+ if (isExportDisabled) return;
8326
+ handleExportCSV(e);
8327
+ },
8328
+ onMouseOver: function onMouseOver(e) {
8329
+ if (!isExportDisabled) e.currentTarget.style.backgroundColor = '#E2E8F0';
8330
+ },
8331
+ onMouseOut: function onMouseOut(e) {
8332
+ if (!isExportDisabled) e.currentTarget.style.backgroundColor = 'rgb(243 243 243)';
8333
+ }
8334
+ }, React.createElement("span", {
8335
+ style: {
8336
+ color: '#475569',
8337
+ fontFamily: 'Lato',
8338
+ fontSize: '13px',
8339
+ fontWeight: 600,
8340
+ whiteSpace: 'nowrap',
8341
+ letterSpacing: '0.3px'
8342
+ }
8343
+ }, "EXPORT CSV"), React.createElement("span", {
8344
+ style: {
8345
+ marginLeft: '6px',
8346
+ display: 'flex',
8347
+ alignItems: 'center'
8348
+ }
8349
+ }, React.createElement(Spin, {
8350
+ spinning: spinLoading,
8351
+ size: "small"
8352
+ })))
8276
8353
  }, React.createElement(ExpandedContent$2, {
8277
8354
  callReturnProducts: callReturnProducts,
8278
8355
  loading: loading,