@bjsdistribution/dms-client-return 0.0.94-prod → 0.0.95-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.
Files changed (138) hide show
  1. package/dist/assets/icons/ArrowDownIcon.d.ts +6 -0
  2. package/dist/assets/icons/DeliverProductIcon.d.ts +3 -0
  3. package/dist/assets/icons/ReturnProductIcon.d.ts +3 -0
  4. package/dist/common/checkbox/index.d.ts +2 -0
  5. package/dist/common/modals/order-action-modal/OrderActionModal.d.ts +3 -1
  6. package/dist/components/order-view/details-filters/left-side-filters/dropdowns/DropDowns.d.ts +1 -0
  7. package/dist/components/order-view/details-filters/left-side-filters/dropdowns/MenuDropDown.d.ts +2 -2
  8. package/dist/components/order-view/flags-action-modal/Actions.d.ts +6 -2
  9. package/dist/components/order-view/flags-action-modal/Dropdowns.d.ts +1 -0
  10. package/dist/components/order-view/flags-action-modal/Header.d.ts +1 -1
  11. package/dist/components/order-view/notification/FlagTemplate.d.ts +1 -1
  12. package/dist/components/order-view/notification/OrderTemplate.d.ts +1 -1
  13. package/dist/components/order-view/notification/Tabs.d.ts +1 -1
  14. package/dist/components/order-view/order-actions/actions/cancel-order/CancelOrderTable.d.ts +5 -0
  15. package/dist/components/order-view/order-actions/actions/cancel-order/index.d.ts +7 -1
  16. package/dist/components/order-view/order-actions/actions/change-customer-account/ChangeCustomerAccModal.d.ts +4 -1
  17. package/dist/components/order-view/order-actions/actions/charge-log/index.d.ts +11 -0
  18. package/dist/components/order-view/order-actions/actions/create-task-reminder/CreateReminderModal.d.ts +1 -13
  19. package/dist/components/order-view/order-actions/actions/create-task-reminder/TaskModal.d.ts +5 -1
  20. package/dist/components/order-view/order-actions/actions/create-task-reminder/index.d.ts +6 -2
  21. package/dist/components/order-view/order-actions/actions/hold-order/HoldOrderModal.d.ts +6 -1
  22. package/dist/components/order-view/order-actions/actions/log-service-refusal/DeliveryPoint.d.ts +5 -1
  23. package/dist/components/order-view/order-actions/actions/log-service-refusal/Notes.d.ts +5 -3
  24. package/dist/components/order-view/order-actions/actions/log-service-refusal/OrderServices.d.ts +5 -1
  25. package/dist/components/order-view/order-actions/actions/log-service-refusal/index.d.ts +1 -1
  26. package/dist/components/order-view/order-actions/actions/uncancel-order/UncancelOrder.d.ts +7 -1
  27. package/dist/components/order-view/order-actions/actions/uncancel-order/UncancelOrderTable.d.ts +5 -0
  28. package/dist/components/order-view/order-actions/actions/unhold-order/UnholdOrder.d.ts +6 -1
  29. package/dist/components/order-view/order-actions/store.d.ts +10 -8
  30. package/dist/components/order-view/order-actions/types.d.ts +38 -60
  31. package/dist/components/order-view/order-actions/utils.d.ts +2 -1
  32. package/dist/components/order-view/store.d.ts +48 -3
  33. package/dist/components/order-view/types.d.ts +11 -0
  34. package/dist/components/order-view/utils.d.ts +1 -0
  35. package/dist/components/order-view/view-reminder/ViewReminder.d.ts +5 -1
  36. package/dist/components/order-view/view-reminder/reminder-styles.d.ts +3 -1
  37. package/dist/components/store.d.ts +2 -1
  38. package/dist/dms-client-return.cjs.development.js +4812 -3095
  39. package/dist/dms-client-return.cjs.development.js.map +1 -1
  40. package/dist/dms-client-return.cjs.production.min.js +1 -1
  41. package/dist/dms-client-return.cjs.production.min.js.map +1 -1
  42. package/dist/dms-client-return.esm.js +4815 -3098
  43. package/dist/dms-client-return.esm.js.map +1 -1
  44. package/package.json +2 -2
  45. package/src/assets/icons/ArrowDownIcon.tsx +28 -0
  46. package/src/assets/icons/DeliverProductIcon.tsx +42 -0
  47. package/src/assets/icons/ReturnProductIcon.tsx +23 -0
  48. package/src/common/checkbox/index.tsx +60 -17
  49. package/src/common/modals/order-action-modal/OrderActionModal.tsx +13 -7
  50. package/src/common/radio-group/RadioButtonGroup.tsx +3 -4
  51. package/src/components/order-daily-overview/header-filters/SelectionFilter.tsx +29 -26
  52. package/src/components/order-daily-overview/header-filters/filterStore.ts +6 -8
  53. package/src/components/order-daily-overview/index.tsx +20 -7
  54. package/src/components/order-daily-overview/return-after-table/ReturnAfterTable.tsx +2 -2
  55. package/src/components/order-daily-overview/return-after-table/table/OrderTable.tsx +19 -19
  56. package/src/components/order-daily-overview/return-after-table/table-filters/ReturnFilterStore.ts +11 -9
  57. package/src/components/order-daily-overview/return-after-table/table-filters/ReturnOrderFilter.tsx +19 -4
  58. package/src/components/order-daily-overview/return-order-table/return-orders-filters/ReturnOrderTable.tsx +41 -59
  59. package/src/components/order-daily-overview/table/ReturnTable.tsx +1 -30
  60. package/src/components/order-view/details-filters/left-side-filters/dropdowns/DropDowns.tsx +52 -2
  61. package/src/components/order-view/details-filters/left-side-filters/dropdowns/MenuDropDown.tsx +37 -43
  62. package/src/components/order-view/details-filters/left-side-filters/dropdowns/OptionsDropDown.tsx +75 -44
  63. package/src/components/order-view/fakedata.ts +7 -6
  64. package/src/components/order-view/flags-action-modal/Actions.tsx +51 -25
  65. package/src/components/order-view/flags-action-modal/DetailSection.tsx +5 -5
  66. package/src/components/order-view/flags-action-modal/Dropdowns.tsx +75 -89
  67. package/src/components/order-view/flags-action-modal/Header.tsx +32 -23
  68. package/src/components/order-view/flags-action-modal/TextSection.tsx +9 -6
  69. package/src/components/order-view/flags-action-modal/index.tsx +54 -67
  70. package/src/components/order-view/general-information/dropdowns/Print.tsx +136 -70
  71. package/src/components/order-view/generic-table/AuditLogs.tsx +5 -4
  72. package/src/components/order-view/index.tsx +9 -42
  73. package/src/components/order-view/modalsPopup/CreateReturnModal.tsx +20 -18
  74. package/src/components/order-view/modalsPopup/ModalManager.tsx +4 -10
  75. package/src/components/order-view/notes/logs/index.tsx +1 -1
  76. package/src/components/order-view/notes/order-dropdown/NewReturnDropdown.tsx +5 -7
  77. package/src/components/order-view/notification/FlagTemplate.tsx +8 -8
  78. package/src/components/order-view/notification/OrderTemplate.tsx +169 -175
  79. package/src/components/order-view/notification/ReminderTemplate.tsx +23 -14
  80. package/src/components/order-view/notification/Tabs.tsx +15 -14
  81. package/src/components/order-view/notification/index.tsx +164 -92
  82. package/src/components/order-view/order-actions/actions/add-resources/index.tsx +19 -29
  83. package/src/components/order-view/order-actions/actions/cancel-order/CancelOrderTable.tsx +345 -0
  84. package/src/components/order-view/order-actions/actions/cancel-order/index.tsx +146 -71
  85. package/src/components/order-view/order-actions/actions/change-customer-account/ChangeCustomerAccModal.tsx +95 -32
  86. package/src/components/order-view/order-actions/actions/charge-log/index.tsx +395 -0
  87. package/src/components/order-view/order-actions/actions/clear-booking-status/ClearBookingStatus.tsx +1 -1
  88. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/ActionDropdown.tsx +34 -17
  89. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/ContactMobile.tsx +2 -3
  90. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/ContactPhone.tsx +2 -3
  91. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/ContactWork.tsx +2 -3
  92. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/DeliveryDate.tsx +39 -25
  93. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/EmailAddress.tsx +1 -1
  94. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/TimedServiceDropdown.tsx +4 -2
  95. package/src/components/order-view/order-actions/actions/confirm-order/customer-info/index.tsx +1 -1
  96. package/src/components/order-view/order-actions/actions/confirm-order/index.tsx +254 -66
  97. package/src/components/order-view/order-actions/actions/confirm-order/slot-and-instructions/index.tsx +1 -1
  98. package/src/components/order-view/order-actions/actions/confirm-order/tables/NotesTable.tsx +13 -9
  99. package/src/components/order-view/order-actions/actions/confirm-order/tables/ProductTable.tsx +1 -1
  100. package/src/components/order-view/order-actions/actions/create-task-reminder/CreateReminderModal.tsx +213 -117
  101. package/src/components/order-view/order-actions/actions/create-task-reminder/CreateTaskModal.tsx +97 -152
  102. package/src/components/order-view/order-actions/actions/create-task-reminder/TaskModal.tsx +30 -87
  103. package/src/components/order-view/order-actions/actions/create-task-reminder/index.tsx +77 -83
  104. package/src/components/order-view/order-actions/actions/hold-order/HoldOrderModal.tsx +57 -65
  105. package/src/components/order-view/order-actions/actions/log-service-refusal/DeliveryPoint.tsx +10 -16
  106. package/src/components/order-view/order-actions/actions/log-service-refusal/Notes.tsx +21 -4
  107. package/src/components/order-view/order-actions/actions/log-service-refusal/OrderServices.tsx +39 -11
  108. package/src/components/order-view/order-actions/actions/log-service-refusal/index.tsx +79 -8
  109. package/src/components/order-view/order-actions/actions/send-email/SendEmailModal.tsx +114 -17
  110. package/src/components/order-view/order-actions/actions/send-sms/SendSmsModal.tsx +115 -7
  111. package/src/components/order-view/order-actions/actions/split-order/index.tsx +14 -4
  112. package/src/components/order-view/order-actions/actions/uncancel-order/UncancelOrder.tsx +176 -87
  113. package/src/components/order-view/order-actions/actions/uncancel-order/UncancelOrderTable.tsx +352 -0
  114. package/src/components/order-view/order-actions/actions/unhold-order/UnholdOrder.tsx +35 -59
  115. package/src/components/order-view/order-actions/index.tsx +237 -22
  116. package/src/components/order-view/order-actions/store.ts +50 -48
  117. package/src/components/order-view/order-actions/types.ts +40 -65
  118. package/src/components/order-view/order-actions/utils.ts +15 -8
  119. package/src/components/order-view/order-details/expanded-content/customer-section/contact-info/ContactEmail.tsx +2 -1
  120. package/src/components/order-view/order-details/expanded-content/footer/index.tsx +80 -39
  121. package/src/components/order-view/order-details/expanded-content/orders-section/Carrier.tsx +10 -14
  122. package/src/components/order-view/order-details/expanded-content/orders-section/DeliveryDate.tsx +10 -1
  123. package/src/components/order-view/order-details/expanded-content/orders-section/ScheduleAfter.tsx +2 -1
  124. package/src/components/order-view/products-info/expanded-content/index.tsx +3 -2
  125. package/src/components/order-view/products-info/index.tsx +14 -11
  126. package/src/components/order-view/return-client-products/product-table/ReturnProductTable.tsx +26 -24
  127. package/src/components/order-view/store.ts +59 -2
  128. package/src/components/order-view/system-event-logs/columns/Date.tsx +4 -2
  129. package/src/components/order-view/system-event-logs/columns/Event.tsx +9 -9
  130. package/src/components/order-view/system-event-logs/columns/Note.tsx +1 -1
  131. package/src/components/order-view/system-event-logs/expanded-content/index.tsx +25 -25
  132. package/src/components/order-view/types.ts +13 -0
  133. package/src/components/order-view/utils.ts +4 -0
  134. package/src/components/order-view/view-reminder/AssigneeDropdown.tsx +183 -12
  135. package/src/components/order-view/view-reminder/ViewReminder.tsx +234 -143
  136. package/src/components/order-view/view-reminder/reminder-styles.tsx +14 -8
  137. package/src/components/store.ts +6 -0
  138. package/src/index.tsx +28 -18
@@ -1,40 +1,137 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import OrderActionModal from '../../../../../common/modals/order-action-modal/OrderActionModal';
3
- import { useCurrentAction } from '../../../store';
4
- import { ContentContainer, Label, StyledInput, StyledTextArea } from '../modalstyle';
3
+ import { useCurrentAction, useOrderDetails, useOrderId } from '../../../store';
4
+ import { ContentContainer, StyledInput, StyledTextArea } from '../modalstyle';
5
+ import { Label, useAxios } from '@bjsdistribution/dms-component-library';
6
+ import { ApiResponse } from '../../../types';
7
+ import { notification } from 'antd';
5
8
 
6
9
  function SendEmailModal() {
7
10
  const [, setCurrentAction] = useCurrentAction();
11
+ const [orderDetails] = useOrderDetails();
12
+ const [orderId] = useOrderId();
8
13
 
9
- const closeModal = () => {
10
- setCurrentAction(undefined);
14
+ const initialTo = orderDetails?.order_recipient?.contact_email || '';
15
+ const initialSubject = `${orderDetails?.trading_name ||
16
+ ''} Order Update - ${orderDetails?.consignment || ''}`;
17
+
18
+ const [formData, setFormData] = useState({
19
+ to: initialTo,
20
+ subject: initialSubject,
21
+ body: '',
22
+ });
23
+
24
+ const [emailError, setEmailError] = useState('');
25
+ const [loading, setLoading] = useState(false);
26
+
27
+ const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
28
+
29
+ const validateEmail = (email: string) => {
30
+ setEmailError(emailRegex.test(email) ? '' : 'Invalid email format');
11
31
  };
32
+
33
+ const closeModal = () => setCurrentAction(undefined);
34
+
35
+ const { fetchData: callSendEmail } = useAxios<{ data: ApiResponse[] }>({
36
+ endpoint: `orders/${orderId}/trigger-email/`,
37
+ method: 'POST',
38
+ });
39
+
40
+ const handleChange = (
41
+ e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
42
+ ) => {
43
+ const { name, value } = e.target;
44
+ setFormData(prev => ({ ...prev, [name]: value }));
45
+
46
+ if (name === 'to') validateEmail(value);
47
+ };
48
+
49
+ const handleSubmit = async () => {
50
+ const { to, subject, body } = formData;
51
+
52
+ if (!to.trim() || !subject.trim() || !body.trim()) {
53
+ alert('All fields are required!');
54
+ return;
55
+ }
56
+ if (emailError) {
57
+ alert('Please enter a valid email address.');
58
+ return;
59
+ }
60
+
61
+ const payload = [
62
+ {
63
+ order_id: Number(orderId),
64
+ email: to,
65
+ subject,
66
+ message: body,
67
+ },
68
+ ];
69
+
70
+ setLoading(true);
71
+
72
+ try {
73
+ const response = await callSendEmail({ payload });
74
+ console.log(response, 'responseresponse');
75
+ if (response) {
76
+ notification.success({
77
+ message: 'Success',
78
+ description: 'Email sent successfully!',
79
+ });
80
+ closeModal(); // Close modal on success
81
+ } else {
82
+ notification.error({
83
+ message: 'Error',
84
+ description: 'Failed to send email. Please try again.',
85
+ });
86
+ }
87
+ } catch (error) {
88
+ alert('An error occurred while sending the email.');
89
+ } finally {
90
+ setLoading(false);
91
+ }
92
+ };
93
+
94
+ const isDisabled =
95
+ Object.values(formData).some(val => !val.trim()) || !!emailError || loading;
96
+
12
97
  return (
13
98
  <OrderActionModal
14
99
  headerTitle="Send Email"
15
100
  onCloseHeader={closeModal}
16
- onSubmit={() => {}}
17
- submitBtnTitle="Send Email"
101
+ onSubmit={handleSubmit}
102
+ submitBtnTitle={loading ? 'Sending...' : 'Send Email'}
103
+ isSubmitDisabled={isDisabled}
18
104
  >
19
105
  <ContentContainer>
20
- <Label>To</Label>
106
+ <Label label="To" required />
21
107
  <StyledInput
22
108
  type="text"
23
- name=""
109
+ name="to"
24
110
  required
25
- placeholder="andy@aspire-technologies.com"
26
- defaultValue={'andy@aspire-technologies.com'}
111
+ placeholder="Enter email"
112
+ value={formData.to}
113
+ onChange={handleChange}
114
+ onBlur={() => validateEmail(formData.to)}
27
115
  />
28
- <Label>Subject</Label>
116
+ {emailError && <span style={{ color: 'red' }}>{emailError}</span>}
117
+
118
+ <Label label="Subject" required />
29
119
  <StyledInput
30
120
  type="text"
31
- name=""
121
+ name="subject"
122
+ required
123
+ value={formData.subject}
124
+ onChange={handleChange}
125
+ />
126
+
127
+ <Label label="Body" required />
128
+ <StyledTextArea
129
+ name="body"
130
+ placeholder="Write here..."
32
131
  required
33
- placeholder=""
34
- defaultValue={'RICHER SOUNDS Order Update - B7049658-4064'}
132
+ value={formData.body}
133
+ onChange={handleChange}
35
134
  />
36
- <Label>Body</Label>
37
- <StyledTextArea name="note" placeholder="Write here..." />
38
135
  </ContentContainer>
39
136
  </OrderActionModal>
40
137
  );
@@ -1,28 +1,136 @@
1
- import React from 'react';
2
- import { useCurrentAction } from '../../../store';
1
+ import React, { useState } from 'react';
2
+ import { useCurrentAction, useOrderDetails, useOrderId } from '../../../store';
3
3
  import OrderActionModal from '../../../../../common/modals/order-action-modal/OrderActionModal';
4
4
  import { ContentContainer, Label, StyledInput } from '../modalstyle';
5
+ import { TextArea, useAxios } from '@bjsdistribution/dms-component-library';
6
+ import { ApiResponse } from '../../../types';
7
+ import styled from 'styled-components';
8
+
9
+ const CustomTextArea = styled(TextArea)`
10
+ width: 700px;
11
+ height: 140px;
12
+ resize: none;
13
+ `;
14
+
15
+ const ErrorText = styled.div`
16
+ color: red;
17
+ font-size: 12px;
18
+ margin-top: 4px;
19
+ `;
5
20
 
6
21
  function SendSmsModal() {
7
22
  const [, setCurrentAction] = useCurrentAction();
23
+ const [orderDetails] = useOrderDetails();
24
+ const [orderId] = useOrderId();
25
+ const initialTo = orderDetails?.order_recipient?.contact_home || '';
26
+ const [toError, setToError] = useState('');
27
+ const [formData, setFormData] = useState({
28
+ to: initialTo,
29
+ body: '',
30
+ });
31
+
32
+ const { fetchData: callSendSms, loading } = useAxios<{ data: ApiResponse[] }>(
33
+ {
34
+ endpoint: `/v1/orders/send-sms/`,
35
+ method: 'POST',
36
+ }
37
+ );
38
+
39
+ const handleInputChange = (
40
+ e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
41
+ ) => {
42
+ const { name, value } = e.target;
43
+
44
+ if (name === 'to') {
45
+ const digitsOnly = value.replace(/\D/g, '');
46
+ let error = '';
47
+
48
+ if (digitsOnly.length < 10) {
49
+ error = 'Phone number must be exactly 10 digits';
50
+ } else if (digitsOnly.length > 10) {
51
+ error = 'Phone number cannot exceed 10 digits';
52
+ }
53
+
54
+ setToError(error);
55
+
56
+ setFormData(prev => ({
57
+ ...prev,
58
+ to: digitsOnly.slice(0, 10),
59
+ }));
60
+ } else {
61
+ setFormData(prev => ({
62
+ ...prev,
63
+ [name]: value,
64
+ }));
65
+ }
66
+ };
67
+
68
+ const handleSubmit = async () => {
69
+ const trimmedTo = formData?.to?.trim();
70
+ const trimmedBody = formData?.body?.trim();
71
+
72
+ if (trimmedTo.length !== 10) {
73
+ setToError('Phone number must be exactly 10 digits');
74
+ return;
75
+ }
76
+
77
+ const payload = {
78
+ order_id: +orderId,
79
+ receiver: trimmedTo,
80
+ message: trimmedBody,
81
+ notification_type: 'Send SMS',
82
+ };
83
+
84
+ if (!trimmedTo || !trimmedBody) {
85
+ return;
86
+ }
87
+
88
+ try {
89
+ await callSendSms({ payload: payload });
90
+ closeModal();
91
+ } catch (error) {
92
+ console.error('Error sending SMS:', error);
93
+ }
94
+ };
8
95
 
9
96
  const closeModal = () => {
10
97
  setCurrentAction(undefined);
11
98
  };
12
99
 
100
+ const isFormValid =
101
+ formData?.to.trim()?.length === 10 &&
102
+ !toError &&
103
+ formData?.body.trim().length > 0;
104
+
13
105
  return (
14
106
  <OrderActionModal
15
- headerTitle="Send Sms"
107
+ headerTitle="Send SMS"
16
108
  onCloseHeader={closeModal}
17
- onSubmit={() => {}}
18
- submitBtnTitle="Send SMS"
109
+ onSubmit={handleSubmit}
110
+ submitBtnTitle={loading ? 'Sending...' : 'Send SMS'}
111
+ isSubmitDisabled={!isFormValid || loading}
19
112
  >
20
113
  <ContentContainer>
21
114
  <Label>To</Label>
22
- <StyledInput type="text" name="" required placeholder="Enter the number" />
115
+ <StyledInput
116
+ type="text"
117
+ name="to"
118
+ value={formData.to}
119
+ onChange={handleInputChange}
120
+ required
121
+ placeholder="Enter the number"
122
+ maxLength={10}
123
+ />
124
+ {toError && <ErrorText>{toError}</ErrorText>}
23
125
 
24
126
  <Label>Body</Label>
25
- <StyledInput type="text" name="" required placeholder="Write here..." />
127
+ <CustomTextArea
128
+ name="body"
129
+ value={formData.body}
130
+ onChange={handleInputChange}
131
+ required
132
+ placeholder="Write here..."
133
+ />
26
134
  </ContentContainer>
27
135
  </OrderActionModal>
28
136
  );
@@ -8,27 +8,28 @@ import { ApiResponse } from '../../../types';
8
8
 
9
9
  import { useSelectedSplit, useSplitOrderPayload } from '../../store';
10
10
  import { notification } from 'antd';
11
+ import { useNavigate } from 'react-router-dom';
11
12
 
12
13
  function SplitOrder() {
13
14
  const [, setCurrentAction] = useCurrentAction();
14
15
  const [orderDetails] = useOrderDetails();
15
16
  const orderRecipient = orderDetails?.order_recipient;
16
17
  const infoText = `${orderRecipient?.recipient_name}, ${orderRecipient?.postcode}`;
17
- const [orderId] = useOrderId();
18
+ const [orderId, setOrderID] = useOrderId();
18
19
  const [payload] = useSplitOrderPayload();
19
20
  const [seledtedSplitOrder, setSelectedSplit] = useSelectedSplit();
20
21
 
21
22
  const onClose = () => {
22
23
  setCurrentAction(undefined);
23
24
  };
24
-
25
+ const navigate = useNavigate();
25
26
  const {
26
27
  data: response,
27
28
  setShouldPerformAction: setPerformAction,
28
29
  } = useApiHook<{
29
30
  data: ApiResponse[];
30
31
  }>({
31
- endpoint: `orders/split_order/${orderId}`,
32
+ endpoint: `/v1/return/split/${orderId}`,
32
33
  method: 'POST',
33
34
  body: payload,
34
35
  performAction: false,
@@ -39,10 +40,19 @@ function SplitOrder() {
39
40
  setPerformAction(true);
40
41
  }
41
42
  };
42
-
43
+ //@ts-ignore
44
+ const newId = response?.data?.new_order;
43
45
  useEffect(() => {
44
46
  //@ts-ignore
45
47
  if (response?.code === 200) {
48
+ const currentPath = location.pathname
49
+ .split('/')
50
+ .slice(0, -1)
51
+ .join('/');
52
+ console.log(currentPath, 'currentPath');
53
+ navigate(`${currentPath}/${newId}`);
54
+ setOrderID(newId);
55
+ setSelectedSplit([]);
46
56
  notification.success({
47
57
  message: 'Success',
48
58
  description:
@@ -1,26 +1,29 @@
1
1
  import React, { useEffect, useState } from 'react';
2
+ import { TextArea, useAxios } from '@bjsdistribution/dms-component-library';
2
3
  import {
3
- AntSelect,
4
- Label,
5
- TextArea,
6
- useApiHook,
7
- } from '@bjsdistribution/dms-component-library';
8
- import {
4
+ useCancelOrderProducts,
9
5
  useCurrentAction,
10
6
  useCustomerInfo,
11
- useOrderDetails,
12
7
  useOrderId,
13
8
  useOrderStaticData,
14
- usePrevOrderDetails,
9
+ useProductDetails,
15
10
  } from '../../../store';
16
11
  import OrderActionModal from '../../../../../common/modals/order-action-modal/OrderActionModal';
17
- import { HoldContentContainer, HoldRow, SplitText } from '../modalstyle';
18
- import { ApiResponse, OrdersType } from '../../../types';
12
+ import { HoldRow, Label } from '../modalstyle';
13
+ import { ApiResponse, CancelOrderProductsType } from '../../../types';
19
14
  import styled from 'styled-components';
20
- import { useLoading } from '../../../../order-daily-overview/store/store';
21
15
  import { notification } from 'antd';
16
+ import OrderActionsDropdown from '../../Dropdown';
17
+ import UnCancelOrderTable from './UncancelOrderTable';
18
+
19
+ interface IProps {
20
+ callOrdersApi: any;
21
+ callOrderStatusApi: any;
22
+ callOrderAlertsApi: any;
23
+ callOrderProductsApi: any;
24
+ }
22
25
 
23
- function UncancelOrder() {
26
+ function UncancelOrder(props: IProps) {
24
27
  const [orderId] = useOrderId();
25
28
  const [, setCurrentAction] = useCurrentAction();
26
29
 
@@ -33,10 +36,12 @@ function UncancelOrder() {
33
36
  undefined
34
37
  );
35
38
  const [unCancelNotes, setUncancelNotes] = useState<string>('');
36
- const [, setOrderDetails] = useOrderDetails();
37
- const [, setPrevOrderDetails] = usePrevOrderDetails();
38
- const [, setLoading] = useLoading();
39
39
  const [customerInfo] = useCustomerInfo();
40
+ const [
41
+ cancelOrderProducts,
42
+ setCancelOrderProducts,
43
+ ] = useCancelOrderProducts();
44
+ const [orderProductDetails] = useProductDetails();
40
45
  const infoText = `${customerInfo?.recipient_name}, ${customerInfo?.postcode}`;
41
46
 
42
47
  const unCancelReasonOptions = orderStaticData?.uncancel_reasons?.map(
@@ -48,77 +53,135 @@ function UncancelOrder() {
48
53
  }
49
54
  );
50
55
 
51
- const {
52
- data: response,
53
- setShouldPerformAction: setPerformAction,
54
- } = useApiHook<{
56
+ const { fetchData: performUnCancelAction } = useAxios<{
55
57
  data: ApiResponse[];
56
58
  }>({
57
- endpoint: `orders/${orderId}/uncancel/?uncancelled_reason=${unCancelReason}&uncancelled_notes=${unCancelNotes}`,
59
+ endpoint: `v1/orders/uncancel/?order_id=${orderId}`,
58
60
  method: 'POST',
59
- performAction: false,
60
- });
61
-
62
- const { data: fetchedData, loading, setShouldPerformAction } = useApiHook<{
63
- data: OrdersType[];
64
- }>({
65
- endpoint: `orders/${orderId}`,
66
- method: 'GET',
67
- performAction: false,
68
61
  });
69
62
 
70
63
  useEffect(() => {
71
- setLoading(loading);
72
- if (fetchedData && fetchedData.data) {
73
- const requiredData = fetchedData?.data;
74
- setOrderDetails(requiredData[0]);
75
- setPrevOrderDetails(requiredData[0]);
76
- setCurrentAction(undefined);
64
+ const receivedProducts = orderProductDetails?.filter(
65
+ (product: any) =>
66
+ product?.status_value === 'received' &&
67
+ product?.order_product_type?.type !== 'return'
68
+ );
69
+ const modifiedReceivedProducts =
70
+ receivedProducts?.length > 0
71
+ ? receivedProducts?.map((product: any) => {
72
+ return {
73
+ order_product_id: product?.id,
74
+ action: '',
75
+ return_action: '',
76
+ return_reason: '',
77
+ code: product?.code,
78
+ description: product?.description,
79
+ sku: product?.sku,
80
+ product_type: product?.order_product_type?.type,
81
+ previous_product_type: product?.previous_order_product_type,
82
+ };
83
+ })
84
+ : [];
85
+ setCancelOrderProducts(modifiedReceivedProducts);
86
+ }, [orderProductDetails]);
87
+
88
+ const onChange = (event: any) => {
89
+ setUncancelNotes(event.target.value);
90
+ };
91
+
92
+ const onChangeUnCancelReason = (value: string) => {
93
+ setUncancelReason(value);
94
+ };
95
+
96
+ const onSubmit = async () => {
97
+ const productsPayload = cancelOrderProducts?.map(
98
+ (product: CancelOrderProductsType) => {
99
+ if (product?.action === 'deliver') {
100
+ return {
101
+ order_product_id: product?.order_product_id,
102
+ action: product?.action,
103
+ };
104
+ }
105
+ return {
106
+ order_product_id: product?.order_product_id,
107
+ action: product?.action,
108
+ return_action: product?.return_action,
109
+ return_reason: product?.return_reason,
110
+ };
111
+ }
112
+ );
113
+
114
+ // VALIDATIONS START
115
+
116
+ const productsPayloadActions = productsPayload?.map(
117
+ (product: CancelOrderProductsType) => {
118
+ if (product?.action !== '') {
119
+ return true;
120
+ }
121
+ return false;
122
+ }
123
+ );
124
+
125
+ if (productsPayloadActions?.includes(false)) {
126
+ notification.error({
127
+ message: 'Error',
128
+ description: `please fill product status field`,
129
+ });
130
+ return;
77
131
  }
78
- if (
79
- (fetchedData && fetchedData?.data === null) ||
80
- fetchedData?.data?.length === 0
81
- ) {
82
- setCurrentAction(undefined);
132
+
133
+ const productsPayloadValidate = productsPayload?.map(
134
+ (product: CancelOrderProductsType) => {
135
+ if (product?.action === 'return') {
136
+ return product?.return_action !== '' && product?.return_reason !== '';
137
+ }
138
+ return true;
139
+ }
140
+ );
141
+
142
+ if (productsPayloadValidate?.includes(false)) {
143
+ notification.error({
144
+ message: 'Error',
145
+ description: `please fill all the mandatory fields`,
146
+ });
147
+ return;
83
148
  }
84
- }, [loading]);
85
149
 
86
- useEffect(() => {
87
- if (response) {
88
- //@ts-ignore
89
- if (response?.data && response?.code === 200) {
90
- setShouldPerformAction(true);
150
+ // VALIDATIONS END
151
+
152
+ const apiPayload = {
153
+ uncancelled_reason: unCancelReason,
154
+ uncancelled_notes: unCancelNotes,
155
+ products: productsPayload,
156
+ };
157
+
158
+ if (orderId) {
159
+ const response = (await performUnCancelAction({
160
+ payload: apiPayload,
161
+ })) as {
162
+ code: number | null;
163
+ error?: string | null | undefined;
164
+ [key: string]: any;
165
+ };
166
+ if (response?.code === 200) {
91
167
  notification.success({
92
168
  message: 'Success',
93
- description:
94
- //@ts-ignore
95
- response?.message || 'Sucess',
169
+ description: `${response.message}`,
96
170
  });
97
- } else {
171
+ // call orders api to update status
172
+ await props?.callOrderProductsApi();
173
+ await props?.callOrderAlertsApi();
174
+ await props?.callOrderStatusApi();
175
+ await props?.callOrdersApi();
176
+ }
177
+ if (response?.code !== 200) {
98
178
  notification.error({
99
179
  message: 'Error',
100
- description:
101
- //@ts-ignore
102
- response?.error_traceback ||
103
- 'An error has occurred. Please try again later.',
180
+ description: `${response.error}`,
104
181
  });
105
182
  setCurrentAction(undefined);
106
183
  }
107
184
  }
108
- }, [response]);
109
-
110
- const onChange = (event: any) => {
111
- setUncancelNotes(event.target.value);
112
- };
113
-
114
- const onChangeUnCancelReason = (value: string) => {
115
- setUncancelReason(value);
116
- };
117
-
118
- const onSubmit = () => {
119
- if (orderId) {
120
- setPerformAction(true);
121
- }
122
185
  };
123
186
 
124
187
  const showSubmitBtn =
@@ -134,32 +197,58 @@ function UncancelOrder() {
134
197
  submitBtnTitle="Save Details"
135
198
  isSubmitDisabled={!showSubmitBtn}
136
199
  >
137
- <HoldContentContainer>
138
- <SplitText>
200
+ <MainContainer>
201
+ <Container>
202
+ <OrderActionsDropdown
203
+ required
204
+ label="Un-cancel Reason"
205
+ placeholder="Select un-cancel Reason"
206
+ options={unCancelReasonOptions || []}
207
+ onSelect={onChangeUnCancelReason}
208
+ value={unCancelReason}
209
+ className="uncancelReasonDropdown"
210
+ />
139
211
  <HoldRow>
140
- <Label label="Un-cancel Reason" required></Label>
141
- <AntSelect
142
- options={unCancelReasonOptions || []}
143
- placeholder="Select un-cancel Reason"
144
- onChange={onChangeUnCancelReason}
145
- disabled={false}
146
- style={{ width: '346px', height: 40 }}
147
- showSearch={true}
148
- popupClassName={'dropDownStyle'}
149
- selectWrapperClass={'rounded'}
150
- defaultValue={unCancelReason}
151
- />
152
- </HoldRow>
153
- <HoldRow>
154
- <Label label="Un-cancel Note"></Label>
212
+ <div style={{ display: 'flex', flexDirection: 'row' }}>
213
+ <Label>Un-cancel Note</Label>{' '}
214
+ <RequiredAsterisk>*</RequiredAsterisk>
215
+ </div>
155
216
  <CustomTextArea rows={5} onChange={onChange} />
156
217
  </HoldRow>
157
- </SplitText>
158
- </HoldContentContainer>
218
+ </Container>
219
+ <UnCancelOrderTable />
220
+ </MainContainer>
159
221
  </OrderActionModal>
160
222
  );
161
223
  }
162
224
 
225
+ const RequiredAsterisk = styled.span`
226
+ color: red;
227
+ margin-left: 2px;
228
+ font-size: x-small;
229
+ `;
230
+
231
+ const Container = styled.div`
232
+ display: flex;
233
+ justify-content: space-between;
234
+ padding: 15px;
235
+ gap: 30px;
236
+ border-radius: 16px;
237
+ border: 1px solid#edebe8;
238
+ background: #f8fafc;
239
+
240
+ .uncancelReasonDropdown {
241
+ flex: 1;
242
+ }
243
+ `;
244
+
245
+ const MainContainer = styled.div`
246
+ display: flex;
247
+ flex-direction: column;
248
+ padding: 20px;
249
+ gap: 10px;
250
+ `;
251
+
163
252
  const CustomTextArea = styled(TextArea)`
164
253
  width: 346px;
165
254
  `;