@bjsdistribution/dms-client-return 0.1.18-prod → 0.1.19-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.18-prod",
2
+ "version": "0.1.19-prod",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -61,7 +61,7 @@ function SelectionFilter() {
61
61
  });
62
62
 
63
63
  useEffect(() => {
64
- if (!clientPortal) {
64
+ if (!clientPortal && clientPortal !== undefined) {
65
65
  fetchData();
66
66
  }
67
67
  }, []);
@@ -57,8 +57,9 @@ function ReturnMainTable() {
57
57
  pagination: { is_pagination: false },
58
58
  showLoader: false,
59
59
  });
60
+
60
61
  useEffect(() => {
61
- if (!clientPortal) {
62
+ if (!clientPortal && clientPortal !== undefined) {
62
63
  fetchData();
63
64
  }
64
65
  }, []);
@@ -85,7 +86,7 @@ function ReturnMainTable() {
85
86
  showLoader: false,
86
87
  });
87
88
  useEffect(() => {
88
- if (!clientPortal) {
89
+ if (!clientPortal && clientPortal !== undefined) {
89
90
  fetchProductStats();
90
91
  }
91
92
  }, []);
@@ -1,25 +1,48 @@
1
1
  import { Input, Label } from '@bjsdistribution/dms-component-library';
2
2
  import React from 'react';
3
3
  import styled from 'styled-components';
4
- import { errorAtom, useAtom, useOrderDetails } from '../../../../store';
4
+ import {
5
+ errorAtom,
6
+ useAtom,
7
+ useOrderDetails,
8
+ usePrevOrderDetails,
9
+ } from '../../../../store';
5
10
  import { handleKeyDown } from '../../../../utils';
11
+ import { useClientPortal } from '../../../../../store';
6
12
 
7
- // const LANDLINE_REGEX = /^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}|\d{3}\)?[\s-]?\d{3}[\\s-]?\d{3,4}|\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{5}\)?[\s-]?\d{4,5}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$/;
13
+ //import { VALIDATE_UK_IRISH_NUMBER_REGEX } from '../../../helper';
14
+ import CallCustomer from './CallCustomer';
8
15
 
9
16
  function ContactHome() {
10
17
  const [errors, setErrors] = useAtom(errorAtom);
11
-
12
- // Show call icons only if number is valid
13
- // show copy icon if there is input value
18
+ const [isClientPortal] = useClientPortal();
14
19
  const [orderDetails, setOrderDetails] = useOrderDetails();
20
+ const [prevOrderDetails] = usePrevOrderDetails();
21
+ const apiContactHome = prevOrderDetails?.order_recipient?.contact_home;
15
22
  const orderRecipient = orderDetails?.order_recipient;
16
23
 
17
24
  const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
18
- const val = e.target.value;
25
+ let val = e.target.value.replace(/\s+/g, '');
26
+ console.log(val, 'valuee');
27
+
28
+ if (!/^\+?\d*$/.test(val)) return;
29
+
30
+ const validPrefixes = ['+44', '44', '0', '+353', '353'];
31
+
32
+ let matchedPrefix = validPrefixes.find(prefix => val.startsWith(prefix));
33
+ let prefix = matchedPrefix || '';
34
+ let numberPart = val.slice(prefix.length);
35
+
36
+ const digitLimit = prefix === '+353' || prefix === '353' ? 9 : 10;
37
+
38
+ if (numberPart.length > digitLimit) return;
39
+
40
+ const contactValue = val;
41
+
19
42
  const updatedOrderRecipient = {
20
43
  ...(orderRecipient === null
21
- ? { contact_home: val }
22
- : { ...orderRecipient, contact_home: val }),
44
+ ? { contact_home: contactValue }
45
+ : { ...orderRecipient, contact_home: contactValue }),
23
46
  };
24
47
 
25
48
  setOrderDetails(prev => ({
@@ -27,58 +50,100 @@ function ContactHome() {
27
50
  order_recipient: updatedOrderRecipient,
28
51
  }));
29
52
 
30
- if (val) {
31
- if (val.length < 10) {
32
- setErrors(prevErrors => ({
33
- ...prevErrors,
34
- homeContactError: 'Phone number must be at least 10 digits.',
35
- }));
36
- } else if (val.length > 11) {
37
- setErrors(prevErrors => ({
38
- ...prevErrors,
39
- homeContactError: 'Phone number must not exceed 11 digits.',
40
- }));
41
- } else {
42
- setErrors(prevErrors => ({
43
- ...prevErrors,
44
- homeContactError: '',
45
- }));
46
- }
47
- } else {
48
- setErrors(prevErrors => ({
49
- ...prevErrors,
50
- homeContactError: '',
53
+ if (!numberPart) {
54
+ setErrors(prev => ({ ...prev, homeContactError: '' }));
55
+ } else if (numberPart.length !== digitLimit) {
56
+ setErrors(prev => ({
57
+ ...prev,
58
+ homeContactError: `Number must have exactly ${digitLimit} digits after the prefix.`,
51
59
  }));
60
+ } else {
61
+ setErrors(prev => ({ ...prev, homeContactError: '' }));
52
62
  }
53
63
  };
54
64
 
55
65
  return (
56
- <MainContainer>
66
+ <Container>
57
67
  <Wrapper>
58
68
  <Label label="Contact Home" htmlFor="contact-home" />
59
- {/* {showCopyIcon && <CopyText text={orderRecipient?.contact_home!} />} */}
60
69
  </Wrapper>
61
70
  <InputContainer>
62
71
  <CustomInput
63
72
  name="contact-home"
73
+ // maxLength={12}
64
74
  type="text"
65
75
  placeholder="Home Number"
66
76
  onKeyDown={handleKeyDown}
67
- minLength={10}
68
- maxLength={10}
69
77
  value={orderRecipient?.contact_home || ''}
70
78
  onChange={onChange}
79
+ disabled={isClientPortal}
71
80
  />
81
+ {/*
82
+ <CallCustomer /> */}
83
+ {apiContactHome &&
84
+ (() => {
85
+ const rawNumber = apiContactHome.replace(/\s+/g, '');
86
+
87
+ let formattedNumber = rawNumber.replace(/\D/g, ''); // digits only
88
+ let prefix = '';
89
+ let numberPart = '';
90
+
91
+ if (rawNumber.startsWith('+44')) {
92
+ prefix = '+44';
93
+ numberPart = formattedNumber.slice(2);
94
+ } else if (rawNumber.startsWith('44')) {
95
+ prefix = '44';
96
+ numberPart = formattedNumber.slice(2);
97
+ } else if (rawNumber.startsWith('0')) {
98
+ prefix = '0';
99
+ numberPart = formattedNumber.slice(1);
100
+ } else if (rawNumber.startsWith('+353')) {
101
+ prefix = '+353';
102
+ numberPart = formattedNumber.slice(3);
103
+ } else if (rawNumber.startsWith('353')) {
104
+ prefix = '353';
105
+ numberPart = formattedNumber.slice(3);
106
+ } else {
107
+ numberPart = formattedNumber;
108
+ }
109
+
110
+ // Set digit limit based on prefix
111
+ const digitLimit = prefix === '+353' || prefix === '353' ? 9 : 10;
112
+
113
+ if (numberPart.length !== digitLimit) return null;
114
+
115
+ let hrefPrefix = '';
72
116
 
73
- {/* <CallCustomer /> */}
117
+ if (prefix === '0' || prefix === '44' || prefix === '+44') {
118
+ hrefPrefix = '+44';
119
+ } else if (prefix === '353' || prefix === '+353') {
120
+ hrefPrefix = '+353';
121
+ } else {
122
+ hrefPrefix = '+44';
123
+ }
124
+
125
+ const finalHref = `tel:${hrefPrefix}${numberPart}`;
126
+
127
+ return (
128
+ <a href={finalHref} style={{ cursor: 'pointer' }}>
129
+ <CallCustomer />
130
+ </a>
131
+ );
132
+ })()}
74
133
  </InputContainer>
75
134
  {errors.homeContactError && (
76
135
  <ErrorText>{errors.homeContactError}</ErrorText>
77
136
  )}
78
- </MainContainer>
137
+ </Container>
79
138
  );
80
139
  }
81
140
 
141
+ const InputContainer = styled.div`
142
+ display: flex;
143
+ gap: 7px;
144
+ align-items: center;
145
+ `;
146
+
82
147
  const Wrapper = styled.div`
83
148
  display: flex;
84
149
  align-items: center;
@@ -87,9 +152,6 @@ const Wrapper = styled.div`
87
152
 
88
153
  const CustomInput = styled(Input)`
89
154
  width: 80%;
90
- // @media (max-width: 1024px) {
91
- // width: 80%;
92
- // }
93
155
 
94
156
  &::-webkit-outer-spin-button,
95
157
  &::-webkit-inner-spin-button {
@@ -101,13 +163,7 @@ const CustomInput = styled(Input)`
101
163
  }
102
164
  `;
103
165
 
104
- const InputContainer = styled.div`
105
- display: flex;
106
- gap: 7px;
107
- align-items: center;
108
- `;
109
-
110
- const MainContainer = styled.div`
166
+ const Container = styled.div`
111
167
  display: flex;
112
168
  flex-direction: column;
113
169
  gap: 6px;
@@ -119,4 +175,5 @@ const ErrorText = styled.span`
119
175
  font-size: 0.85rem;
120
176
  margin-top: 4px;
121
177
  `;
178
+
122
179
  export default ContactHome;
@@ -3,16 +3,21 @@ import React from 'react';
3
3
  import styled from 'styled-components';
4
4
  import CopyText from '../../../../../../common/copy/CopyText';
5
5
  import CallCustomer from './CallCustomer';
6
- import { errorAtom, useAtom, useOrderDetails } from '../../../../store';
6
+ import {
7
+ errorAtom,
8
+ useAtom,
9
+ useOrderDetails,
10
+ usePrevOrderDetails,
11
+ } from '../../../../store';
7
12
  import { handleKeyDown } from '../../../../utils';
8
- // const MOBILE_REGEX = /^(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$/;
13
+ import { useClientPortal } from '../../../../../store';
9
14
 
10
15
  function ContactMobile() {
11
16
  const [errors, setErrors] = useAtom(errorAtom);
12
-
13
- // Show call icons only if number is valid
14
- // show copy icon if there is input value
17
+ const [isClientPortal] = useClientPortal();
15
18
  const [orderDetails, setOrderDetails] = useOrderDetails();
19
+ const [prevOrderDetails] = usePrevOrderDetails();
20
+ const apiContactMobile = prevOrderDetails?.order_recipient?.contact_mobile;
16
21
  const orderRecipient = orderDetails?.order_recipient;
17
22
 
18
23
  const showCopyIcon =
@@ -21,11 +26,26 @@ function ContactMobile() {
21
26
  orderRecipient?.contact_mobile?.length > 0;
22
27
 
23
28
  const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
24
- const val = e.target.value;
29
+ let val = e.target.value.replace(/\s+/g, '');
30
+
31
+ if (!/^\+?\d*$/.test(val)) return;
32
+
33
+ const validPrefixes = ['+44', '44', '0', '+353', '353'];
34
+
35
+ let matchedPrefix = validPrefixes.find(prefix => val.startsWith(prefix));
36
+ let prefix = matchedPrefix || '';
37
+ let numberPart = val.slice(prefix.length);
38
+
39
+ const digitLimit = prefix === '+353' || prefix === '353' ? 9 : 10;
40
+
41
+ if (numberPart.length > digitLimit) return;
42
+
43
+ const contactValue = val;
44
+
25
45
  const updatedOrderRecipient = {
26
46
  ...(orderRecipient === null
27
- ? { contact_mobile: val }
28
- : { ...orderRecipient, contact_mobile: val }),
47
+ ? { contact_mobile: contactValue }
48
+ : { ...orderRecipient, contact_mobile: contactValue }),
29
49
  };
30
50
 
31
51
  setOrderDetails(prev => ({
@@ -33,50 +53,89 @@ function ContactMobile() {
33
53
  order_recipient: updatedOrderRecipient,
34
54
  }));
35
55
 
36
- if (val) {
37
- if (val.length < 10) {
38
- setErrors(prevErrors => ({
39
- ...prevErrors,
40
- mobileError: 'Phone number must be at least 10 digits.',
41
- }));
42
- } else if (val.length > 11) {
43
- setErrors(prevErrors => ({
44
- ...prevErrors,
45
- mobileError: 'Phone number must not exceed 11 digits.',
46
- }));
47
- } else {
48
- setErrors(prevErrors => ({
49
- ...prevErrors,
50
- mobileError: '',
51
- }));
52
- }
53
- } else {
54
- setErrors(prevErrors => ({
55
- ...prevErrors,
56
- mobileError: '',
56
+ // Validation errors
57
+ if (!numberPart) {
58
+ setErrors(prev => ({ ...prev, mobileError: '' }));
59
+ } else if (numberPart.length !== digitLimit) {
60
+ setErrors(prev => ({
61
+ ...prev,
62
+ mobileError: `Number must have exactly ${digitLimit} digits after the prefix.`,
57
63
  }));
64
+ } else {
65
+ setErrors(prev => ({ ...prev, mobileError: '' }));
58
66
  }
59
67
  };
60
68
 
61
69
  return (
62
70
  <Container>
63
71
  <Wrapper>
64
- <Label label="Contact Mobile" htmlFor="contact-work" />
72
+ <Label label="Contact Mobile" htmlFor="contact-mobile" />
65
73
  {showCopyIcon && <CopyText text={orderRecipient?.contact_mobile!} />}
66
74
  </Wrapper>
67
75
  <InputContainer>
68
76
  <CustomInput
69
- name="contact-work"
70
- minLength={10}
71
- maxLength={10}
77
+ name="contact-mobile"
78
+ // maxLength={12}
72
79
  type="text"
73
80
  placeholder="Mobile Number"
74
81
  onKeyDown={handleKeyDown}
75
82
  value={orderRecipient?.contact_mobile || ''}
76
83
  onChange={onChange}
84
+ disabled={isClientPortal}
77
85
  />
78
- <CallCustomer />
86
+
87
+ {apiContactMobile &&
88
+ (() => {
89
+ const rawNumber = apiContactMobile.replace(/\s+/g, '');
90
+
91
+ let formattedNumber = rawNumber.replace(/\D/g, '');
92
+ let prefix = '';
93
+ let numberPart = '';
94
+
95
+ if (rawNumber.startsWith('+44')) {
96
+ prefix = '+44';
97
+ numberPart = formattedNumber.slice(2);
98
+ } else if (rawNumber.startsWith('44')) {
99
+ prefix = '44';
100
+ numberPart = formattedNumber.slice(2);
101
+ } else if (rawNumber.startsWith('0')) {
102
+ prefix = '0';
103
+ numberPart = formattedNumber.slice(1);
104
+ } else if (rawNumber.startsWith('+353')) {
105
+ prefix = '+353';
106
+ numberPart = formattedNumber.slice(3);
107
+ } else if (rawNumber.startsWith('353')) {
108
+ prefix = '353';
109
+ numberPart = formattedNumber.slice(3);
110
+ } else {
111
+ numberPart = formattedNumber;
112
+ }
113
+
114
+ // Set digit limit based on prefix
115
+ const digitLimit = prefix === '+353' || prefix === '353' ? 9 : 10;
116
+
117
+ if (numberPart.length !== digitLimit) return null;
118
+
119
+ let hrefPrefix = '';
120
+
121
+ if (prefix === '0' || prefix === '44' || prefix === '+44') {
122
+ hrefPrefix = '+44';
123
+ } else if (prefix === '353' || prefix === '+353') {
124
+ hrefPrefix = '+353';
125
+ } else {
126
+ hrefPrefix = '+44';
127
+ }
128
+
129
+ const finalHref = `tel:${hrefPrefix}${numberPart}`;
130
+
131
+ return (
132
+ <a href={finalHref} style={{ cursor: 'pointer' }}>
133
+ <CallCustomer />
134
+ </a>
135
+ );
136
+ })()}
79
137
  </InputContainer>
138
+
80
139
  {errors.mobileError && <ErrorText>{errors.mobileError}</ErrorText>}
81
140
  </Container>
82
141
  );
@@ -1,52 +1,59 @@
1
1
  import { Input, Label } from '@bjsdistribution/dms-component-library';
2
2
  import React from 'react';
3
3
  import styled from 'styled-components';
4
- import { errorAtom, useAtom, useOrderDetails } from '../../../../store';
4
+ import {
5
+ errorAtom,
6
+ useAtom,
7
+ useOrderDetails,
8
+ usePrevOrderDetails,
9
+ } from '../../../../store';
5
10
  import { handleKeyDown } from '../../../../utils';
11
+ import CallCustomer from './CallCustomer';
6
12
 
7
13
  function ContactWork() {
8
14
  const [errors, setErrors] = useAtom(errorAtom);
9
15
  const [orderDetails, setOrderDetails] = useOrderDetails();
10
16
  const orderRecipient = orderDetails?.order_recipient;
11
-
17
+ const [prevOrderDetails] = usePrevOrderDetails();
18
+ const apiContactWork = prevOrderDetails?.order_recipient?.contact_work;
12
19
  const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
13
- const val = e.target.value;
20
+ let val = e.target.value.replace(/\s+/g, '');
21
+
22
+ if (!/^\+?\d*$/.test(val)) return;
23
+
24
+ const validPrefixes = ['+44', '44', '0', '+353', '353'];
25
+
26
+ let matchedPrefix = validPrefixes.find(prefix => val.startsWith(prefix));
27
+ let prefix = matchedPrefix || '';
28
+ let numberPart = val.slice(prefix.length);
29
+
30
+ const digitLimit = prefix === '+353' || prefix === '353' ? 9 : 10;
31
+
32
+ if (numberPart.length > digitLimit) return;
33
+
34
+ const contactValue = val;
35
+
14
36
  const updatedOrderRecipient = {
15
37
  ...(orderRecipient === null
16
- ? { contact_work: val }
17
- : { ...orderRecipient, contact_work: val }),
38
+ ? { contact_work: contactValue }
39
+ : { ...orderRecipient, contact_work: contactValue }),
18
40
  };
41
+
19
42
  setOrderDetails(prev => ({
20
43
  ...prev,
21
44
  order_recipient: updatedOrderRecipient,
22
45
  }));
23
-
24
- // Validate only if there is a value entered
25
- if (val) {
26
- if (val.length < 10) {
27
- setErrors(prevErrors => ({
28
- ...prevErrors,
29
- workCOntanctError: 'Phone number must be at least 10 digits.',
30
- }));
31
- } else if (val.length > 10) {
32
- setErrors(prevErrors => ({
33
- ...prevErrors,
34
- workCOntanctError: 'Phone number must not exceed 10 digits.',
35
- }));
36
- } else {
37
- setErrors(prevErrors => ({
38
- ...prevErrors,
39
- workCOntanctError: '',
40
- }));
41
- }
42
- } else {
43
- setErrors(prevErrors => ({
44
- ...prevErrors,
45
- workCOntanctError: '',
46
+ if (!numberPart) {
47
+ setErrors(prev => ({ ...prev, workCOntanctError: '' }));
48
+ } else if (numberPart.length !== digitLimit) {
49
+ setErrors(prev => ({
50
+ ...prev,
51
+ workCOntanctError: `Number must have exactly ${digitLimit} digits after the prefix.`,
46
52
  }));
53
+ } else {
54
+ setErrors(prev => ({ ...prev, workCOntanctError: '' }));
47
55
  }
48
56
  };
49
-
50
57
  return (
51
58
  <Container>
52
59
  <Wrapper>
@@ -60,9 +67,59 @@ function ContactWork() {
60
67
  onKeyDown={handleKeyDown}
61
68
  value={orderRecipient?.contact_work || ''}
62
69
  onChange={onChange}
63
- minLength={10}
64
- maxLength={10}
70
+ // minLength={10}
71
+ // maxLength={10}
65
72
  />
73
+ {apiContactWork &&
74
+ (() => {
75
+ const rawNumber = apiContactWork.replace(/\s+/g, '');
76
+
77
+ let formattedNumber = rawNumber.replace(/\D/g, '');
78
+ let prefix = '';
79
+ let numberPart = '';
80
+
81
+ if (rawNumber.startsWith('+44')) {
82
+ prefix = '+44';
83
+ numberPart = formattedNumber.slice(2);
84
+ } else if (rawNumber.startsWith('44')) {
85
+ prefix = '44';
86
+ numberPart = formattedNumber.slice(2);
87
+ } else if (rawNumber.startsWith('0')) {
88
+ prefix = '0';
89
+ numberPart = formattedNumber.slice(1);
90
+ } else if (rawNumber.startsWith('+353')) {
91
+ prefix = '+353';
92
+ numberPart = formattedNumber.slice(3);
93
+ } else if (rawNumber.startsWith('353')) {
94
+ prefix = '353';
95
+ numberPart = formattedNumber.slice(3);
96
+ } else {
97
+ numberPart = formattedNumber;
98
+ }
99
+
100
+ // Set digit limit based on prefix
101
+ const digitLimit = prefix === '+353' || prefix === '353' ? 9 : 10;
102
+
103
+ if (numberPart.length !== digitLimit) return null;
104
+
105
+ let hrefPrefix = '';
106
+
107
+ if (prefix === '0' || prefix === '44' || prefix === '+44') {
108
+ hrefPrefix = '+44';
109
+ } else if (prefix === '353' || prefix === '+353') {
110
+ hrefPrefix = '+353';
111
+ } else {
112
+ hrefPrefix = '+44';
113
+ }
114
+
115
+ const finalHref = `tel:${hrefPrefix}${numberPart}`;
116
+
117
+ return (
118
+ <a href={finalHref} style={{ cursor: 'pointer' }}>
119
+ <CallCustomer />
120
+ </a>
121
+ );
122
+ })()}
66
123
  </InputContainer>
67
124
  {errors.workCOntanctError && (
68
125
  <ErrorText>{errors.workCOntanctError}</ErrorText>
@@ -145,6 +145,18 @@ export const getCookie = (name: string): string | null => {
145
145
  };
146
146
 
147
147
  export const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
148
+ // Allow common shortcuts like Ctrl+V, Ctrl+C, Ctrl+A, etc.
149
+ if (e.ctrlKey || e.metaKey) {
150
+ if (
151
+ e.key.toLowerCase() === 'v' || // Paste
152
+ e.key.toLowerCase() === 'c' || // Copy
153
+ e.key.toLowerCase() === 'x' || // Cut
154
+ e.key.toLowerCase() === 'a' // Select All
155
+ ) {
156
+ return;
157
+ }
158
+ }
159
+
148
160
  // Allowed keys: numbers (0-9), '.', '-', '+'
149
161
  const allowedKeys = [
150
162
  '0',
@@ -30,8 +30,6 @@ import { useReminderData } from '../../store';
30
30
 
31
31
  export interface IProps {
32
32
  callReminderApi: any;
33
- callReminderForCount?: any;
34
- callReminderTableApi?: any;
35
33
  }
36
34
 
37
35
  const ViewReminderModal = (props: IProps) => {
@@ -263,7 +263,7 @@ export function useNewReturnOrderData() {
263
263
  return useAtom(newReturnOrderData);
264
264
  }
265
265
 
266
- const isClientPortalAtom = atom<boolean>(false);
266
+ const isClientPortalAtom = atom<boolean | undefined>(undefined);
267
267
  function useClientPortal() {
268
268
  return useAtom(isClientPortalAtom);
269
269
  }