@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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.58-prod",
2
+ "version": "0.1.59-prod",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -5,6 +5,7 @@ import ChevronUp from '../../assets/icons/ChevronUp';
5
5
  interface IProps {
6
6
  collapsedContent: React.ReactNode;
7
7
  children: React.ReactNode;
8
+ extraActions?: React.ReactNode;
8
9
  }
9
10
 
10
11
  function CollapsableForm(props: IProps) {
@@ -15,6 +16,7 @@ function CollapsableForm(props: IProps) {
15
16
  <CollapsedContent>
16
17
  {props.collapsedContent}
17
18
  <Container>
19
+ {props?.extraActions}
18
20
  <Text onClick={() => setIsExpanded(prev => !prev)}>
19
21
  {isExpanded ? 'COLLAPSE' : 'SHOW'}
20
22
  </Text>
@@ -5,6 +5,8 @@ import CollapsableForm from '../../../common/expand-collapse';
5
5
  import { useOrderDetails, useProductDetails } from '../store';
6
6
  import { useLoading } from '../../order-daily-overview/store/store';
7
7
  import { useAxios } from '@bjsdistribution/dms-component-library';
8
+ import { notification, Spin } from 'antd';
9
+ import { useState } from 'react';
8
10
 
9
11
  interface ApiResponse {
10
12
  message: string;
@@ -19,6 +21,40 @@ function ProductsInfo({ locationloading }: any) {
19
21
  const [data] = useOrderDetails();
20
22
  const returnOrder = data;
21
23
 
24
+ const [spinLoading, setSpinLoading] = useState<boolean>(false);
25
+
26
+ // Export functionality
27
+ const { fetchData: callExportCSV } = useAxios<any>({
28
+ endpoint: `/v1/export/csv/${returnOrder?.id}`,
29
+ method: 'POST',
30
+ });
31
+
32
+ const handleExportCSV = (e: React.MouseEvent) => {
33
+ e.stopPropagation();
34
+ setSpinLoading(true);
35
+
36
+ callExportCSV()
37
+ .then((res: any) => {
38
+ const urlToDownload = res?.data?.url || res?.url;
39
+ if (urlToDownload) {
40
+ const a = document.createElement('a');
41
+ a.href = urlToDownload;
42
+ a.download = `products_export_${returnOrder?.id}.csv`;
43
+ document.body.appendChild(a);
44
+ a.click();
45
+ document.body.removeChild(a);
46
+ }
47
+ setSpinLoading(false);
48
+ })
49
+ .catch(err => {
50
+ notification.error({
51
+ message: 'Failed to export csv',
52
+ description: err?.message || 'Export error',
53
+ });
54
+ setSpinLoading(false);
55
+ });
56
+ };
57
+
22
58
  // For API Call
23
59
  const [, setProductsData] = useProductDetails();
24
60
  const [, setLoading] = useLoading();
@@ -52,8 +88,46 @@ function ProductsInfo({ locationloading }: any) {
52
88
  }
53
89
  }, [returnOrdersData, loading]);
54
90
 
91
+ const isExportDisabled = !returnOrdersData?.data || returnOrdersData?.data?.length === 0;
92
+
55
93
  return (
56
- <CollapsableForm collapsedContent={<CollapsedContent />}>
94
+ <CollapsableForm
95
+ collapsedContent={<CollapsedContent />}
96
+ extraActions={
97
+ <div
98
+ style={{
99
+ display: 'flex',
100
+ alignItems: 'center',
101
+ cursor: isExportDisabled ? 'not-allowed' : 'pointer',
102
+ opacity: isExportDisabled ? 0.5 : 1,
103
+ marginRight: '16px',
104
+ backgroundColor: 'rgb(243 243 243)',
105
+ border: '1px solid #E2E8F0',
106
+ padding: '6px 14px',
107
+ borderRadius: '10px',
108
+ boxShadow: '0 1px 2px rgba(0,0,0,0.05)',
109
+ transition: 'background-color 0.2s',
110
+ }}
111
+ onClick={(e) => {
112
+ if (isExportDisabled) return;
113
+ handleExportCSV(e);
114
+ }}
115
+ onMouseOver={(e) => {
116
+ if (!isExportDisabled) e.currentTarget.style.backgroundColor = '#E2E8F0';
117
+ }}
118
+ onMouseOut={(e) => {
119
+ if (!isExportDisabled) e.currentTarget.style.backgroundColor = 'rgb(243 243 243)';
120
+ }}
121
+ >
122
+ <span style={{ color: '#475569', fontFamily: 'Lato', fontSize: '13px', fontWeight: 600, whiteSpace: 'nowrap', letterSpacing: '0.3px' }}>
123
+ EXPORT CSV
124
+ </span>
125
+ <span style={{ marginLeft: '6px', display: 'flex', alignItems: 'center' }}>
126
+ <Spin spinning={spinLoading} size="small" />
127
+ </span>
128
+ </div>
129
+ }
130
+ >
57
131
  <ExpandedContent
58
132
  callReturnProducts={callReturnProducts}
59
133
  loading={loading}