@bjsdistribution/dms-client-return 0.0.3 → 0.0.4
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/README.md +1 -1
- package/dist/components/order-daily-overview/table/table-data/styles.d.ts +2 -0
- package/dist/components/order-view/generic-table/AuditLogs.d.ts +4 -0
- package/dist/components/order-view/hooks/useGetEventNotes.d.ts +2 -0
- package/dist/components/order-view/hooks/useGetSystemLogs.d.ts +2 -0
- package/dist/components/order-view/modalsPopup/CreateReturnModal.d.ts +4 -0
- package/dist/components/order-view/notes/logs/fakeData.d.ts +7 -7
- package/dist/components/order-view/store.d.ts +19 -1
- package/dist/components/order-view/system-event-logs/columns/Code.d.ts +3 -0
- package/dist/components/order-view/system-event-logs/columns/Date.d.ts +3 -0
- package/dist/components/order-view/system-event-logs/columns/Event.d.ts +3 -0
- package/dist/components/order-view/system-event-logs/columns/Note.d.ts +3 -0
- package/dist/components/order-view/system-event-logs/columns/index.d.ts +4 -0
- package/dist/components/order-view/system-event-logs/helper.d.ts +7 -0
- package/dist/dms-client-return.cjs.development.js +3232 -2176
- package/dist/dms-client-return.cjs.development.js.map +1 -1
- package/dist/dms-client-return.cjs.production.min.js +1 -1
- package/dist/dms-client-return.cjs.production.min.js.map +1 -1
- package/dist/dms-client-return.esm.js +3236 -2180
- package/dist/dms-client-return.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/common/expand-collapse/index.tsx +3 -3
- package/src/components/fakeData.ts +14 -23
- package/src/components/order-daily-overview/filters/Filters.tsx +6 -6
- package/src/components/order-daily-overview/header-filters/SelectionFilter.tsx +15 -6
- package/src/components/order-daily-overview/header-filters/Styledfilters.tsx +1 -0
- package/src/components/order-daily-overview/header-filters/filterStore.ts +1 -1
- package/src/components/order-daily-overview/index.tsx +36 -32
- package/src/components/order-daily-overview/return-after-table/ReturnAfterTable.tsx +8 -3
- package/src/components/order-daily-overview/return-after-table/table/OrderTable.tsx +25 -19
- package/src/components/order-daily-overview/return-after-table/table-filters/ReturnOrderFilter.tsx +17 -15
- package/src/components/order-daily-overview/return-order-table/ReturnTable.tsx +10 -3
- package/src/components/order-daily-overview/return-order-table/return-orders-filters/ReturnFilter.tsx +4 -0
- package/src/components/order-daily-overview/return-order-table/return-orders-filters/ReturnOrderTable.tsx +69 -19
- package/src/components/order-daily-overview/return-order-table/return-orders-filters/RightFilters.tsx +35 -38
- package/src/components/order-daily-overview/return-order-table/return-orders-filters/returnstyles.ts +7 -1
- package/src/components/order-daily-overview/table/ReturnTable.tsx +30 -92
- package/src/components/order-daily-overview/table/table-data/styles.ts +15 -0
- package/src/components/order-view/details-filters/DetailsFilters.tsx +2 -2
- package/src/components/order-view/details-filters/left-side-filters/dropdowns/DropDowns.tsx +0 -2
- package/src/components/order-view/details-filters/left-side-filters/dropdowns/PrintDropDown.tsx +2 -5
- package/src/components/order-view/generic-table/AuditLogs.tsx +96 -0
- package/src/components/order-view/hooks/useGetEventNotes.tsx +47 -0
- package/src/components/order-view/hooks/useGetSystemLogs.tsx +60 -0
- package/src/components/order-view/index.tsx +22 -3
- package/src/components/order-view/modalsPopup/CreateReturnModal.tsx +83 -0
- package/src/components/order-view/modalsPopup/ModalManager.tsx +49 -49
- package/src/components/order-view/notes/AddNote.tsx +127 -13
- package/src/components/order-view/notes/index.tsx +100 -3
- package/src/components/order-view/notes/logs/fakeData.ts +8 -48
- package/src/components/order-view/notes/logs/index.tsx +6 -45
- package/src/components/order-view/order-resources/collapsed-content/index.tsx +1 -1
- package/src/components/order-view/products-info/expanded-content/index.tsx +2 -2
- package/src/components/order-view/products-info/index.tsx +3 -2
- package/src/components/order-view/return-client-products/product-table/ReturnProductTable.tsx +29 -33
- package/src/components/order-view/store.ts +40 -2
- package/src/components/order-view/system-event-logs/collapsed-content/index.tsx +1 -1
- package/src/components/order-view/system-event-logs/columns/Code.tsx +17 -0
- package/src/components/order-view/system-event-logs/columns/Date.tsx +18 -0
- package/src/components/order-view/system-event-logs/columns/Event.tsx +26 -0
- package/src/components/order-view/system-event-logs/columns/Note.tsx +24 -0
- package/src/components/order-view/system-event-logs/columns/index.tsx +6 -0
- package/src/components/order-view/system-event-logs/expanded-content/index.tsx +34 -6
- package/src/components/order-view/system-event-logs/helper.ts +29 -0
- package/src/index.tsx +32 -5
- package/dist/components/order-view/system-event-logs/system-logs-table/SystemLogsTables.d.ts +0 -3
- package/dist/components/order-view/system-event-logs/system-logs-table/SytemLogsStyles.d.ts +0 -3
- package/src/components/order-view/system-event-logs/system-logs-table/SystemLogsTables.tsx +0 -59
- package/src/components/order-view/system-event-logs/system-logs-table/SytemLogsStyles.tsx +0 -239
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { getBaseEndpoint } from '@bjsdistribution/dms-component-library';
|
|
2
|
+
import { getCookie } from '../utils';
|
|
3
|
+
// import { useOrderDetails, useOrderProductSystemLogs } from '../store';
|
|
4
|
+
|
|
5
|
+
function useGetEventNotes() {
|
|
6
|
+
const ssoToken = getCookie('id_token');
|
|
7
|
+
|
|
8
|
+
const perform = async () => {
|
|
9
|
+
const endpoint = `${getBaseEndpoint()}/events/get/event_information/`;
|
|
10
|
+
// setLoading(true);
|
|
11
|
+
try {
|
|
12
|
+
const headers = {
|
|
13
|
+
accept: 'application/json',
|
|
14
|
+
'Content-Type': 'application/json',
|
|
15
|
+
Authorization: `Bearer ${ssoToken}`,
|
|
16
|
+
'x-pagination': JSON.stringify({
|
|
17
|
+
is_pagination: false,
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
const response = await fetch(endpoint, {
|
|
21
|
+
method: 'GET',
|
|
22
|
+
headers,
|
|
23
|
+
});
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
const json = await response.json();
|
|
26
|
+
const detail = json?.detail;
|
|
27
|
+
const msg = detail[0]?.msg;
|
|
28
|
+
console.error('Error response:', msg);
|
|
29
|
+
// setLoading(false);
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
const json = await response.json();
|
|
33
|
+
if (json.code === 200) {
|
|
34
|
+
return json?.data;
|
|
35
|
+
}
|
|
36
|
+
return [];
|
|
37
|
+
} catch (err) {
|
|
38
|
+
console.error('Error fetching data:', err);
|
|
39
|
+
return [];
|
|
40
|
+
} finally {
|
|
41
|
+
// setLoading(false);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return perform;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default useGetEventNotes;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { getBaseEndpoint } from '@bjsdistribution/dms-component-library';
|
|
2
|
+
import { getCookie } from '../utils';
|
|
3
|
+
import { useOrderDetails, useOrderProductSystemLogs } from '../store';
|
|
4
|
+
|
|
5
|
+
function useSystemLogs() {
|
|
6
|
+
const ssoToken = getCookie('id_token');
|
|
7
|
+
const [orderDetails] = useOrderDetails();
|
|
8
|
+
const gsitId = orderDetails?.gsit_order_id;
|
|
9
|
+
const [, setSystemLogsEvents] = useOrderProductSystemLogs();
|
|
10
|
+
|
|
11
|
+
const perform = async () => {
|
|
12
|
+
const endpoint = `${getBaseEndpoint()}/events/get/event/`;
|
|
13
|
+
// setLoading(true);
|
|
14
|
+
try {
|
|
15
|
+
const headers = {
|
|
16
|
+
accept: 'application/json',
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
Authorization: `Bearer ${ssoToken}`,
|
|
19
|
+
'x-pagination': JSON.stringify({
|
|
20
|
+
page: 1,
|
|
21
|
+
per_page: 100,
|
|
22
|
+
}),
|
|
23
|
+
'x-filters': JSON.stringify([
|
|
24
|
+
{
|
|
25
|
+
field: 'object_id',
|
|
26
|
+
op: '=',
|
|
27
|
+
value: `${gsitId}`,
|
|
28
|
+
},
|
|
29
|
+
]),
|
|
30
|
+
};
|
|
31
|
+
const response = await fetch(endpoint, {
|
|
32
|
+
method: 'GET',
|
|
33
|
+
headers,
|
|
34
|
+
});
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
const json = await response.json();
|
|
37
|
+
const detail = json?.detail;
|
|
38
|
+
const msg = detail[0]?.msg;
|
|
39
|
+
console.error('Error response:', msg);
|
|
40
|
+
// setLoading(false);
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
const json = await response.json();
|
|
44
|
+
if (json.code === 200) {
|
|
45
|
+
// setLoading(false);
|
|
46
|
+
setSystemLogsEvents(json.data);
|
|
47
|
+
return json.data;
|
|
48
|
+
}
|
|
49
|
+
return [];
|
|
50
|
+
} catch (err) {
|
|
51
|
+
console.error('Error fetching data:', err);
|
|
52
|
+
return [];
|
|
53
|
+
} finally {
|
|
54
|
+
// setLoading(false);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
return perform;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default useSystemLogs;
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
useOrderId,
|
|
22
22
|
useDepotOptions,
|
|
23
23
|
usePrevOrderDetails,
|
|
24
|
+
useOrderProductSystemLogs,
|
|
24
25
|
} from './store';
|
|
25
26
|
// import Loader from '../order-daily-overview/header/loader/Loader';
|
|
26
27
|
import { useLoading } from '../order-daily-overview/store/store';
|
|
@@ -30,6 +31,7 @@ import RouterHeader from '../order-daily-overview/header/route-header/RouterHead
|
|
|
30
31
|
// import HeaderFilter from '../order-daily-overview/Header-filters/HeaderFilter';
|
|
31
32
|
// import Filters from '../order-daily-overview/filters/Filters';
|
|
32
33
|
import DetailsFilters from './details-filters/DetailsFilters';
|
|
34
|
+
import useSystemLogs from './hooks/useGetSystemLogs';
|
|
33
35
|
|
|
34
36
|
interface ApiResponse {
|
|
35
37
|
message: string;
|
|
@@ -41,7 +43,7 @@ interface ApiResponse {
|
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
function OrderView() {
|
|
44
|
-
const [, setOrderId] = useOrderId();
|
|
46
|
+
const [orderId, setOrderId] = useOrderId();
|
|
45
47
|
|
|
46
48
|
const splitPath = (str: any) => {
|
|
47
49
|
const parts = str?.split('/')?.filter((part: any) => part !== ''); // Filter out empty parts
|
|
@@ -49,7 +51,7 @@ function OrderView() {
|
|
|
49
51
|
};
|
|
50
52
|
|
|
51
53
|
// For API Call
|
|
52
|
-
const [, setOrderDetails] = useOrderDetails();
|
|
54
|
+
const [orderDetails, setOrderDetails] = useOrderDetails();
|
|
53
55
|
const [, setPrevOrderDetails] = usePrevOrderDetails();
|
|
54
56
|
const [, setLoading] = useLoading();
|
|
55
57
|
const [, setOrderStaticData] = useOrderStaticData();
|
|
@@ -57,7 +59,6 @@ function OrderView() {
|
|
|
57
59
|
const [, setDepotOptions] = useDepotOptions();
|
|
58
60
|
const location = useLocation();
|
|
59
61
|
const paths = splitPath(location.pathname);
|
|
60
|
-
const orderId = 192;
|
|
61
62
|
|
|
62
63
|
const { data: fetchedData, loading, setShouldPerformAction } = useApiHook<{
|
|
63
64
|
data: OrdersType[];
|
|
@@ -154,6 +155,24 @@ function OrderView() {
|
|
|
154
155
|
}
|
|
155
156
|
}, [depotDataLoading]);
|
|
156
157
|
|
|
158
|
+
const gsitId = orderDetails?.gsit_order_id;
|
|
159
|
+
|
|
160
|
+
const systemLogsData = useSystemLogs();
|
|
161
|
+
const [, setSystemLogsEvents] = useOrderProductSystemLogs();
|
|
162
|
+
|
|
163
|
+
const fetchReminderData = async () => {
|
|
164
|
+
const result = await systemLogsData();
|
|
165
|
+
setSystemLogsEvents(result);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (gsitId) {
|
|
170
|
+
fetchReminderData();
|
|
171
|
+
|
|
172
|
+
console.log('Setting filters for gsitId:', gsitId);
|
|
173
|
+
}
|
|
174
|
+
}, [gsitId]);
|
|
175
|
+
|
|
157
176
|
return (
|
|
158
177
|
<>
|
|
159
178
|
<DashBoardWrapper>
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Alert, Checkbox } from '@bjsdistribution/dms-component-library';
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { useLocationData } from '../../store';
|
|
5
|
+
|
|
6
|
+
const CreateReturnModal = () => {
|
|
7
|
+
const [, setSelectedLocations] = useState<any[]>();
|
|
8
|
+
const [locationData] = useLocationData();
|
|
9
|
+
|
|
10
|
+
const handleSelectLocations = (id: any) => {
|
|
11
|
+
setSelectedLocations((prevSelectedLocations: any) => {
|
|
12
|
+
const isSelected = prevSelectedLocations?.some(
|
|
13
|
+
(location: any) => location.id === id
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
if (isSelected) {
|
|
17
|
+
return prevSelectedLocations.filter(
|
|
18
|
+
(invoice: any) => invoice.id !== id
|
|
19
|
+
);
|
|
20
|
+
} else {
|
|
21
|
+
return [...prevSelectedLocations, { id, status_id: 3 }];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
return (
|
|
26
|
+
<Wrapper>
|
|
27
|
+
<Alert
|
|
28
|
+
onClose={() => {}}
|
|
29
|
+
description=""
|
|
30
|
+
type="info"
|
|
31
|
+
title="Do you wish to proceed?"
|
|
32
|
+
showOkButton={false}
|
|
33
|
+
/>
|
|
34
|
+
<Container>
|
|
35
|
+
<ul style={{ listStyle: 'none', padding: 0 }}>
|
|
36
|
+
{locationData?.map((invoice: any) => (
|
|
37
|
+
<li
|
|
38
|
+
key={invoice.id}
|
|
39
|
+
style={{
|
|
40
|
+
marginBottom: '8px',
|
|
41
|
+
display: 'flex',
|
|
42
|
+
alignItems: 'center',
|
|
43
|
+
}}
|
|
44
|
+
>
|
|
45
|
+
<Checkbox
|
|
46
|
+
checked={true}
|
|
47
|
+
onChange={() => handleSelectLocations(invoice.id)}
|
|
48
|
+
/>
|
|
49
|
+
<StyledText style={{ marginLeft: '8px' }}>
|
|
50
|
+
{invoice.location_name}
|
|
51
|
+
</StyledText>
|
|
52
|
+
</li>
|
|
53
|
+
))}
|
|
54
|
+
</ul>
|
|
55
|
+
</Container>
|
|
56
|
+
</Wrapper>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const StyledText = styled.div`
|
|
61
|
+
color: #8d8f90;
|
|
62
|
+
font-family: Poppins;
|
|
63
|
+
font-size: 14px;
|
|
64
|
+
font-style: normal;
|
|
65
|
+
font-weight: 400;
|
|
66
|
+
`;
|
|
67
|
+
|
|
68
|
+
const Container = styled.div``;
|
|
69
|
+
|
|
70
|
+
export const Wrapper = styled.div`
|
|
71
|
+
display: flex;
|
|
72
|
+
padding: 15px;
|
|
73
|
+
flex-direction: column;
|
|
74
|
+
justify-content: center;
|
|
75
|
+
align-items: flex-start;
|
|
76
|
+
gap: 15px;
|
|
77
|
+
align-self: stretch;
|
|
78
|
+
border-radius: 8px;
|
|
79
|
+
background: #f8fafc;
|
|
80
|
+
box-shadow: 0px 1px 3px 0px rgba(16, 24, 40, 0.1);
|
|
81
|
+
`;
|
|
82
|
+
|
|
83
|
+
export default CreateReturnModal;
|
|
@@ -14,24 +14,24 @@ import {
|
|
|
14
14
|
} from '../store';
|
|
15
15
|
|
|
16
16
|
import ProductAction from './ProductAction';
|
|
17
|
-
import
|
|
18
|
-
import DeleteProduct from './DeleteProduct';
|
|
17
|
+
// import DeleteProduct from './DeleteProduct';
|
|
19
18
|
import AddProduct from './AddProduct';
|
|
20
19
|
import logsTable from './qclogs/logsTable';
|
|
21
20
|
import DefectsModal from './DefectsModal';
|
|
22
21
|
import repackModal from './RepackModal';
|
|
23
|
-
import { ApiResponse
|
|
22
|
+
import { ApiResponse } from '../types';
|
|
23
|
+
import CreateReturnModal from './CreateReturnModal';
|
|
24
24
|
const ModalManager = () => {
|
|
25
25
|
const [popupName, dispatch] = useAtom(countReducerAtom);
|
|
26
|
-
const [,
|
|
26
|
+
const [,] = useProductDetails();
|
|
27
27
|
const [orderProduct, setOrderProduct] = useCreateOrderProducts();
|
|
28
28
|
const [orderId] = useOrderId();
|
|
29
|
-
const [selectedRows
|
|
29
|
+
const [selectedRows] = useDeleteProdsID();
|
|
30
30
|
const [unRecieve, setUnRecieve] = useRecieveOrderProducts();
|
|
31
31
|
const [updateOrderProduct, setUpdateOrderProduct] = useUpdateOrderProducts();
|
|
32
32
|
const [selectedProductId] = useAtom(selectedProductIdAtom);
|
|
33
33
|
const [selectedTab] = useAtom(selectedTabKeyAtom);
|
|
34
|
-
const [
|
|
34
|
+
const [, setIsFormValid] = useState(false);
|
|
35
35
|
|
|
36
36
|
console.log(orderProduct, 'abcabcabcabcabcabcabcabcabcabcabc');
|
|
37
37
|
|
|
@@ -48,45 +48,45 @@ const ModalManager = () => {
|
|
|
48
48
|
setIsFormValid(validateForm());
|
|
49
49
|
}, [selectedRows]);
|
|
50
50
|
|
|
51
|
-
const payloads: DeleteProds[] = selectedRows?.map(row => ({
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}));
|
|
51
|
+
// const payloads: DeleteProds[] = selectedRows?.map(row => ({
|
|
52
|
+
// id: row.id,
|
|
53
|
+
// order_id: row.order_id,
|
|
54
|
+
// }));
|
|
55
55
|
|
|
56
|
-
const { data: isresponse, setShouldPerformAction: setaction } = useApiHook<{
|
|
57
|
-
|
|
58
|
-
}>({
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
56
|
+
// const { data: isresponse, setShouldPerformAction: setaction } = useApiHook<{
|
|
57
|
+
// data: ApiResponse[];
|
|
58
|
+
// }>({
|
|
59
|
+
// endpoint: `order/order_products/delete/`,
|
|
60
|
+
// method: 'DELETE',
|
|
61
|
+
// body: payloads,
|
|
62
|
+
// performAction: false,
|
|
63
|
+
// });
|
|
64
64
|
|
|
65
65
|
// Effect to handle API response
|
|
66
|
-
useEffect(() => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}, [isresponse]);
|
|
72
|
-
const onDeleteProducts = () => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
};
|
|
66
|
+
// useEffect(() => {
|
|
67
|
+
// if (isresponse && isresponse?.data) {
|
|
68
|
+
// handleRemoveRow();
|
|
69
|
+
// dispatch({ type: 'close' });
|
|
70
|
+
// }
|
|
71
|
+
// }, [isresponse]);
|
|
72
|
+
// const onDeleteProducts = () => {
|
|
73
|
+
// if (isFormValid) {
|
|
74
|
+
// setaction(true);
|
|
75
|
+
// } else {
|
|
76
|
+
// console.log('Please fill in all required fields before proceeding.');
|
|
77
|
+
// }
|
|
78
|
+
// };
|
|
79
79
|
|
|
80
|
-
const handleRemoveRow = () => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
};
|
|
80
|
+
// const handleRemoveRow = () => {
|
|
81
|
+
// if (selectedRows.length > 0) {
|
|
82
|
+
// setProductData((prevProductData: any) =>
|
|
83
|
+
// prevProductData.filter(
|
|
84
|
+
// (item: any) => !selectedRows.some(row => row.id === item.id)
|
|
85
|
+
// )
|
|
86
|
+
// );
|
|
87
|
+
// setSelectedRows([]);
|
|
88
|
+
// }
|
|
89
|
+
// };
|
|
90
90
|
|
|
91
91
|
// API block for creating product order
|
|
92
92
|
const {
|
|
@@ -226,13 +226,13 @@ const ModalManager = () => {
|
|
|
226
226
|
|
|
227
227
|
return (
|
|
228
228
|
<>
|
|
229
|
-
{popupName?.state == '
|
|
229
|
+
{popupName?.state == 'create-return' && (
|
|
230
230
|
<AntModal
|
|
231
|
-
openStatus={popupName?.state == '
|
|
231
|
+
openStatus={popupName?.state == 'create-return' ? true : false}
|
|
232
232
|
closeModal={() => closeModal()}
|
|
233
233
|
PopupHeader={{
|
|
234
|
-
heading: '
|
|
235
|
-
subHeading: '
|
|
234
|
+
heading: 'CONFIRM RETURN',
|
|
235
|
+
subHeading: '',
|
|
236
236
|
}}
|
|
237
237
|
PopupFooter={{
|
|
238
238
|
btns: [
|
|
@@ -245,13 +245,13 @@ const ModalManager = () => {
|
|
|
245
245
|
|
|
246
246
|
btnAlign: 'justifyEnd',
|
|
247
247
|
}}
|
|
248
|
-
BodyComponent={
|
|
249
|
-
width={
|
|
248
|
+
BodyComponent={CreateReturnModal}
|
|
249
|
+
width={800}
|
|
250
250
|
classNameAdd={'globalPopup'}
|
|
251
251
|
/>
|
|
252
252
|
)}
|
|
253
253
|
|
|
254
|
-
{popupName?.state === 'deleteProduct' && (
|
|
254
|
+
{/* {popupName?.state === 'deleteProduct' && (
|
|
255
255
|
<AntModal
|
|
256
256
|
openStatus={popupName?.state === 'deleteProduct'}
|
|
257
257
|
closeModal={closeModal}
|
|
@@ -275,7 +275,7 @@ const ModalManager = () => {
|
|
|
275
275
|
width={1104}
|
|
276
276
|
classNameAdd={'globalPopup'}
|
|
277
277
|
/>
|
|
278
|
-
)}
|
|
278
|
+
)} */}
|
|
279
279
|
|
|
280
280
|
{popupName?.state === 'addProduct' && (
|
|
281
281
|
<AntModal
|
|
@@ -1,27 +1,130 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Button,
|
|
3
3
|
Label,
|
|
4
|
-
|
|
4
|
+
// SelectDropdown,
|
|
5
5
|
} from '@bjsdistribution/dms-component-library';
|
|
6
|
-
import React from 'react';
|
|
6
|
+
import React, { useEffect, useState } from 'react';
|
|
7
7
|
import styled from 'styled-components';
|
|
8
|
+
// import NoteType from './NoteType';
|
|
9
|
+
import { getBaseEndpoint } from '@bjsdistribution/dms-component-library';
|
|
10
|
+
import { getCookie } from '../utils';
|
|
11
|
+
import { useLocation } from 'react-router-dom';
|
|
12
|
+
import {
|
|
13
|
+
useCallAPi,
|
|
14
|
+
usemoduleIds,
|
|
15
|
+
UseNotesLoading,
|
|
16
|
+
useOrderId,
|
|
17
|
+
} from '../store';
|
|
18
|
+
import { notification } from 'antd';
|
|
8
19
|
|
|
9
20
|
function AddNote() {
|
|
10
|
-
const
|
|
11
|
-
|
|
21
|
+
const [, setNoteLoadingStore] = UseNotesLoading();
|
|
22
|
+
const [noteText, setNoteText] = useState('');
|
|
23
|
+
const [orderId] = useOrderId();
|
|
24
|
+
|
|
25
|
+
const location = useLocation();
|
|
26
|
+
const pathname = location.pathname;
|
|
27
|
+
const orderIdLocaation = pathname.split('/')[1];
|
|
28
|
+
|
|
29
|
+
// const [note, setNote] = useState('');
|
|
30
|
+
const [, CallAPi] = useCallAPi();
|
|
31
|
+
const ssoToken = getCookie('id_token');
|
|
32
|
+
|
|
33
|
+
const [moduleIds] = usemoduleIds();
|
|
34
|
+
|
|
35
|
+
// Save New Note
|
|
36
|
+
|
|
37
|
+
const [notificationData, setNotificationData] = useState<{
|
|
38
|
+
type: 'success' | 'error';
|
|
39
|
+
message: string;
|
|
40
|
+
description: string;
|
|
41
|
+
} | null>(null);
|
|
42
|
+
|
|
43
|
+
const saveNote = async () => {
|
|
44
|
+
setNoteLoadingStore(true);
|
|
45
|
+
CallAPi(false);
|
|
46
|
+
|
|
47
|
+
if (!noteText) return;
|
|
48
|
+
const endpoint = `${getBaseEndpoint()}/audit_logs/orders/`;
|
|
49
|
+
const payload = {
|
|
50
|
+
audit_logs: [
|
|
51
|
+
{
|
|
52
|
+
parent_object_id: orderId || orderIdLocaation,
|
|
53
|
+
parent_module_id: moduleIds?.parentId,
|
|
54
|
+
module_id: moduleIds?.id,
|
|
55
|
+
module_object_id: orderId || orderIdLocaation,
|
|
56
|
+
action: 'create',
|
|
57
|
+
description: noteText,
|
|
58
|
+
data_dump: '{}',
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const response = await fetch(endpoint, {
|
|
65
|
+
method: 'POST',
|
|
66
|
+
headers: {
|
|
67
|
+
'Content-Type': 'application/json',
|
|
68
|
+
Authorization: `Bearer ${ssoToken}`,
|
|
69
|
+
},
|
|
70
|
+
body: JSON.stringify(payload),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// setNoteLoadingStore(false);
|
|
74
|
+
|
|
75
|
+
const { message, error }: any = response;
|
|
76
|
+
if (response) {
|
|
77
|
+
setNotificationData({
|
|
78
|
+
type: 'success',
|
|
79
|
+
message: 'Success',
|
|
80
|
+
description: message || 'Successfully Created Note.',
|
|
81
|
+
});
|
|
82
|
+
setNoteLoadingStore(true);
|
|
83
|
+
setNoteText('');
|
|
84
|
+
setNoteLoadingStore(false);
|
|
85
|
+
CallAPi(true);
|
|
86
|
+
} else if (error) {
|
|
87
|
+
// Error: Set error notification
|
|
88
|
+
setNotificationData({
|
|
89
|
+
type: 'error',
|
|
90
|
+
message: 'Error',
|
|
91
|
+
description: error || 'Something went wrong. Please try again.',
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error('Error saving note:', error);
|
|
96
|
+
alert('Failed to save note');
|
|
97
|
+
}
|
|
12
98
|
};
|
|
13
99
|
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (notificationData) {
|
|
102
|
+
const { type, message, description } = notificationData;
|
|
103
|
+
notification[type]({
|
|
104
|
+
message,
|
|
105
|
+
description,
|
|
106
|
+
duration: 5,
|
|
107
|
+
});
|
|
108
|
+
setNotificationData(null); // Clear notification data after showing
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Set top position for notifications
|
|
112
|
+
notification.config({
|
|
113
|
+
top: 80,
|
|
114
|
+
});
|
|
115
|
+
}, [notificationData]);
|
|
116
|
+
|
|
14
117
|
return (
|
|
15
118
|
<Container>
|
|
16
119
|
<Label label="Add New Note" />
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
120
|
+
<StyledTextArea
|
|
121
|
+
name="description"
|
|
122
|
+
placeholder="Enter your note here..."
|
|
123
|
+
value={noteText}
|
|
124
|
+
onChange={(e: any) => setNoteText(e.target.value)}
|
|
125
|
+
/>
|
|
23
126
|
<SaveNoteContainer>
|
|
24
|
-
<Button
|
|
127
|
+
<Button disabled={!noteText} onClick={saveNote}>
|
|
25
128
|
SAVE NOTE
|
|
26
129
|
</Button>
|
|
27
130
|
</SaveNoteContainer>
|
|
@@ -39,10 +142,21 @@ const Container = styled.div`
|
|
|
39
142
|
const SaveNoteContainer = styled.div`
|
|
40
143
|
display: inline-flex;
|
|
41
144
|
gap: 10px;
|
|
145
|
+
.disabled button {
|
|
146
|
+
opacity: 0.5;
|
|
147
|
+
cursor: default;
|
|
148
|
+
}
|
|
42
149
|
`;
|
|
43
150
|
|
|
44
|
-
const
|
|
45
|
-
|
|
151
|
+
const StyledTextArea = styled.textarea`
|
|
152
|
+
height: 57px;
|
|
153
|
+
border-radius: 12px;
|
|
154
|
+
background: #fff;
|
|
155
|
+
resize: none;
|
|
156
|
+
border-radius: 8px;
|
|
157
|
+
border: 1px solid var(--Neutral-Gray-Gray-100, #e0e2e7);
|
|
158
|
+
background: var(--Flowkit-White, #fff);
|
|
159
|
+
padding: 8px 12px;
|
|
46
160
|
`;
|
|
47
161
|
|
|
48
162
|
// const StyledSelectDropdown = styled(SelectDropdown)`
|
|
@@ -1,9 +1,107 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
import styled from 'styled-components';
|
|
3
3
|
import AddNote from './AddNote';
|
|
4
4
|
import AuditLogs from './logs';
|
|
5
|
-
|
|
5
|
+
import { useApiHook } from '@bjsdistribution/dms-component-library';
|
|
6
|
+
import {
|
|
7
|
+
useCallAPi,
|
|
8
|
+
usegetNotes,
|
|
9
|
+
usemoduleIds,
|
|
10
|
+
UseNotesLoading,
|
|
11
|
+
useOrderId,
|
|
12
|
+
} from '../store';
|
|
13
|
+
import { useLocation } from 'react-router-dom';
|
|
6
14
|
function Notes() {
|
|
15
|
+
const [moduleIds, setModuleIds] = usemoduleIds();
|
|
16
|
+
const [orderId] = useOrderId();
|
|
17
|
+
const location = useLocation();
|
|
18
|
+
const pathname = location.pathname;
|
|
19
|
+
const orderIdLocaation = pathname.split('/')[1];
|
|
20
|
+
const [, setNoteLoadingStore] = UseNotesLoading();
|
|
21
|
+
const [, setNotes] = usegetNotes();
|
|
22
|
+
const [loderStatus] = useCallAPi();
|
|
23
|
+
|
|
24
|
+
// Declare `allIds` state to store the comma-separated IDs
|
|
25
|
+
// const [allIds, setAllIds] = useState<string | null>(null);
|
|
26
|
+
|
|
27
|
+
// Fetch module IDs
|
|
28
|
+
const { data: fetchedData, loading: apiLoading } = useApiHook<{ data: any }>({
|
|
29
|
+
endpoint: 'audit_logs/modules/',
|
|
30
|
+
method: 'GET',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!apiLoading && fetchedData?.data) {
|
|
35
|
+
const modules =
|
|
36
|
+
fetchedData?.data
|
|
37
|
+
.filter((item: any) => item?.name === 'ORDER')
|
|
38
|
+
.flatMap((item: any) =>
|
|
39
|
+
item?.static_child_mappings?.map((child: any) => ({
|
|
40
|
+
id: child?.child_module?.id,
|
|
41
|
+
name: child?.child_module?.name,
|
|
42
|
+
parentId: child?.parent_module?.id,
|
|
43
|
+
parentName: child?.parent_module?.name,
|
|
44
|
+
}))
|
|
45
|
+
) || [];
|
|
46
|
+
|
|
47
|
+
// console.log(modules, 'modulesmodules');
|
|
48
|
+
|
|
49
|
+
// const ids = modules?.map((module: any) => module.id).join(',');
|
|
50
|
+
// setAllIds(ids);
|
|
51
|
+
|
|
52
|
+
// console.log(ids, 'allIds');
|
|
53
|
+
|
|
54
|
+
const orderNoteModule = modules?.find(
|
|
55
|
+
(module: any) => module?.name === 'ORDER-NOTE'
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
setModuleIds(orderNoteModule || modules[0] || null);
|
|
59
|
+
}
|
|
60
|
+
}, [apiLoading, fetchedData]);
|
|
61
|
+
|
|
62
|
+
// Fetch Notes Data when `allIds` is available
|
|
63
|
+
const {
|
|
64
|
+
data: NotesData,
|
|
65
|
+
loading: NotesLoading,
|
|
66
|
+
setShouldPerformAction,
|
|
67
|
+
} = useApiHook<{ data: any }>({
|
|
68
|
+
// Use `allIds` in the endpoint if it's set
|
|
69
|
+
endpoint: `audit_logs/?module_id=${
|
|
70
|
+
moduleIds?.parentId
|
|
71
|
+
}&module_object_id=${orderId || orderIdLocaation}
|
|
72
|
+
`,
|
|
73
|
+
method: 'GET',
|
|
74
|
+
performAction: false,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// &sub_module_ids=${allIds}
|
|
78
|
+
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
setNoteLoadingStore(true);
|
|
81
|
+
if (moduleIds) {
|
|
82
|
+
// Ensure `allIds` is set
|
|
83
|
+
setShouldPerformAction(true);
|
|
84
|
+
}
|
|
85
|
+
if (!NotesLoading && NotesData?.data) {
|
|
86
|
+
const updatedData = NotesData?.data
|
|
87
|
+
// .filter((item: any) => item['ORDER-NOTE'] || item['ORDER'])
|
|
88
|
+
// .map((item: any) => [item['ORDER-NOTE'], item['ORDER']])
|
|
89
|
+
.flat()
|
|
90
|
+
.filter(Boolean);
|
|
91
|
+
|
|
92
|
+
const combinedArray = updatedData.flat();
|
|
93
|
+
combinedArray.sort(
|
|
94
|
+
(a: any, b: any) =>
|
|
95
|
+
new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
|
|
96
|
+
);
|
|
97
|
+
setNotes(combinedArray);
|
|
98
|
+
setNoteLoadingStore(NotesLoading);
|
|
99
|
+
loderStatus
|
|
100
|
+
? setShouldPerformAction(true)
|
|
101
|
+
: setShouldPerformAction(false);
|
|
102
|
+
}
|
|
103
|
+
}, [moduleIds, NotesLoading, loderStatus]); // Add `allIds` to dependencies
|
|
104
|
+
|
|
7
105
|
return (
|
|
8
106
|
<Container>
|
|
9
107
|
<CardHeader>NOTES</CardHeader>
|
|
@@ -31,7 +129,6 @@ const CardHeader = styled.div`
|
|
|
31
129
|
text-transform: uppercase;
|
|
32
130
|
font-family: 'Roboto', sans-serif;
|
|
33
131
|
font-weight: 600;
|
|
34
|
-
|
|
35
132
|
`;
|
|
36
133
|
|
|
37
134
|
const CustomizedFormSection = styled.div`
|