@bjsdistribution/dms-client-return 0.0.58 → 0.0.59

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.0.58",
2
+ "version": "0.0.59",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -9,7 +9,7 @@ import styled from 'styled-components';
9
9
  import { getBaseEndpoint } from '@bjsdistribution/dms-component-library';
10
10
  import { getCookie } from '../utils';
11
11
  import { useLocation } from 'react-router-dom';
12
- import { usemoduleIds, UseNotesLoading, useOrderId } from '../store';
12
+ import { useGlobalStateHitAuditLog, usemoduleIds, useOrderId } from '../store';
13
13
  import { notification } from 'antd';
14
14
 
15
15
  function AddNote() {
@@ -22,8 +22,8 @@ function AddNote() {
22
22
 
23
23
  const ssoToken = getCookie('id_token');
24
24
  const [moduleIds] = usemoduleIds();
25
+ const [, setRecallAuditLog] = useGlobalStateHitAuditLog();
25
26
 
26
- const [NoteLoadingStore, setNoteLoadingStore] = UseNotesLoading();
27
27
 
28
28
  // Save New Note
29
29
 
@@ -34,6 +34,7 @@ function AddNote() {
34
34
  } | null>(null);
35
35
 
36
36
  const saveNote = async () => {
37
+ setRecallAuditLog(false);
37
38
  if (!noteText) return;
38
39
  const endpoint = `${getBaseEndpoint()}/audit_logs/orders/`;
39
40
  const payload = {
@@ -63,30 +64,23 @@ function AddNote() {
63
64
 
64
65
  // setNoteLoadingStore(false);
65
66
 
66
- const { message, error }: any = response;
67
- if (response) {
68
- setNotificationData({
69
- type: 'success',
67
+ if (response.ok) {
68
+ notification.success({
70
69
  message: 'Success',
71
- description: message || 'Successfully Created Note.',
70
+ description: 'Note saved successfully.',
72
71
  });
73
- setNoteLoadingStore(!NoteLoadingStore);
74
72
  setNoteText('');
75
- } else if (error) {
76
- // Error: Set error notification
77
- setNotificationData({
78
- type: 'error',
73
+ setRecallAuditLog(true);
74
+ } else {
75
+ notification.error({
79
76
  message: 'Error',
80
- description: error || 'Something went wrong. Please try again.',
77
+ description: 'Failed to save note.',
81
78
  });
82
79
  }
83
80
  } catch (error) {
84
- // console.error('Error saving note:', error);
85
- // alert('Failed to save note');
86
81
  notification.error({
87
82
  message: 'Error',
88
- description:
89
- `${error}` || 'An error has occurred. Please try again later.',
83
+ description: 'Failed to save note due to an error.',
90
84
  });
91
85
  }
92
86
  };
@@ -4,24 +4,27 @@ import AddNote from './AddNote';
4
4
  import AuditLogs from './logs';
5
5
  import { useApiHook } from '@bjsdistribution/dms-component-library';
6
6
  import {
7
- SeteauditLogToggle,
7
+ useAuditLogLoadingState,
8
8
  // useCallAPi,
9
9
  usegetNotes,
10
+ useGlobalStateHitAuditLog,
10
11
  usemoduleIds,
11
- UseNotesLoading,
12
12
  useOrderId,
13
13
  } from '../store';
14
- import { useLocation } from 'react-router-dom';
14
+ // import { useLocation } from 'react-router-dom';
15
15
  function Notes() {
16
16
  const [moduleIds, setModuleIds] = usemoduleIds();
17
17
  const [orderId] = useOrderId();
18
- const location = useLocation();
19
- const pathname = location.pathname;
20
- const orderIdLocaation = pathname.split('/')[1];
21
- const [apiBaseLoading] = UseNotesLoading();
18
+ // const location = useLocation();
19
+ // const pathname = location.pathname;
20
+ // const orderIdLocaation = pathname.split('/')[1];
21
+
22
+ const[recallAuditLog] = useGlobalStateHitAuditLog()
23
+
24
+ const [,setAuditLogLoading] = useAuditLogLoadingState()
25
+
22
26
  const [, setNotes] = usegetNotes();
23
27
  // const [loderStatus] = useCallAPi();
24
- const [auditState] = SeteauditLogToggle();
25
28
 
26
29
  // Fetch module IDs
27
30
  const { data: fetchedData, loading: apiLoading } = useApiHook<{ data: any }>({
@@ -58,15 +61,14 @@ function Notes() {
58
61
  } = useApiHook<{ data: any }>({
59
62
  endpoint: `audit_logs/?module_id=${
60
63
  moduleIds?.parentId
61
- }&module_object_id=${orderId || orderIdLocaation}`,
64
+ }&module_object_id=${orderId}`,
62
65
  method: 'GET',
63
66
  performAction: false,
64
67
  });
65
68
 
66
69
  useEffect(() => {
67
- let combinedArray = [];
68
-
69
- if (moduleIds && orderId) {
70
+ if (moduleIds && orderId ) {
71
+
70
72
  setShouldPerformAction(true);
71
73
  }
72
74
  if (!NotesLoading && NotesData?.data) {
@@ -75,14 +77,21 @@ function Notes() {
75
77
  .map((item: any) => [item['ORDER-NOTE'], item['ORDER']])
76
78
  .flat()
77
79
  .filter(Boolean);
78
- combinedArray = updatedData.flat();
80
+
81
+ // const orderData = NotesData?.data[0]?.ORDER || [];
82
+ // const orderNotesData = NotesData?.data[1]?.['ORDER-NOTE'] || [];
83
+ // const allNotes = [...orderData, ...orderNotesData];
84
+ const combinedArray = updatedData.flat();
79
85
  combinedArray.sort(
80
86
  (a: any, b: any) =>
81
87
  new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
82
88
  );
89
+ setNotes(combinedArray);
90
+ recallAuditLog ? setShouldPerformAction(true) : setShouldPerformAction(false)
91
+
83
92
  }
84
- setNotes({ data: combinedArray, loading: NotesLoading });
85
- }, [moduleIds, NotesLoading, auditState, apiBaseLoading]);
93
+ setAuditLogLoading(NotesLoading)
94
+ }, [moduleIds,orderId,NotesLoading,recallAuditLog]);
86
95
 
87
96
  return (
88
97
  <Container>
@@ -163,7 +163,7 @@ function useIsOnHoldOrder() {
163
163
  }
164
164
  //value
165
165
  const orderId = atom<any>(undefined);
166
- export const useOrderId = () => {
166
+ export const useOrderId = () => { //dddddddddddd
167
167
  return useAtom(orderId);
168
168
  };
169
169
 
@@ -366,10 +366,6 @@ export {
366
366
  useClientData,
367
367
  };
368
368
 
369
- const NotesLoading = atom<boolean>(true);
370
- export const UseNotesLoading = () => {
371
- return useAtom(NotesLoading);
372
- };
373
369
 
374
370
  const notes = atom<any>([]);
375
371
 
@@ -443,11 +439,6 @@ export function useApiCalling() {
443
439
  return useAtom(apiCalling);
444
440
  }
445
441
 
446
- const globalStateHitAuditLog = atom<boolean>(false);
447
- export function useGlobalStateHitAuditLog() {
448
- return useAtom(globalStateHitAuditLog);
449
- }
450
-
451
442
 
452
443
  const liveRecalling = atom<boolean>(false);
453
444
 
@@ -463,10 +454,19 @@ export const letselectedProductIdAtom = atom<number | null>(null);
463
454
  // return useAtom(BulkUPdateDisabledState);
464
455
  // };
465
456
 
466
- const auditLogToggle = atom<boolean>(true);
467
- export const SeteauditLogToggle = () => {
468
- return useAtom(auditLogToggle);
469
- };
457
+
458
+ const auditLogLoadingState = atom<boolean>(true);
459
+ export function useAuditLogLoadingState() {
460
+ return useAtom(auditLogLoadingState);
461
+ }
462
+
463
+
464
+ const globalStateHitAuditLog = atom<boolean>(false);
465
+ export function useGlobalStateHitAuditLog() {
466
+ return useAtom(globalStateHitAuditLog);
467
+ }
468
+
469
+
470
470
 
471
471
  // Popup state Manage
472
472
  const initialState = null;