Skip to content

Commit 91efaf4

Browse files
author
molker
committed
PR Comments
1 parent f1d1c1c commit 91efaf4

4 files changed

Lines changed: 39 additions & 44 deletions

File tree

packages/contact-center/cc-components/src/components/task/OutdialCall/outdial-call.style.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
row-gap: 1rem;
3030
column-gap: 1.5rem;
3131
padding: 1.5rem 0;
32+
list-style-type: none;
33+
margin: 0;
3234
}
3335

3436
.key {

packages/contact-center/cc-components/src/components/task/OutdialCall/outdial-call.tsx

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useState} from 'react';
1+
import React, {useMemo, useState} from 'react';
22
import {OutdialCallComponentProps} from '../task.types';
33
import './outdial-call.style.scss';
44
import {withMetrics} from '@webex/cc-ui-logging';
@@ -15,8 +15,8 @@ import {OutdialStrings, KEY_LIST} from './constants';
1515
* @property {number} version - The version number of the ANI entry.
1616
* @property {string} name - The name assigned to the ANI entry.
1717
* @property {string} number - The phone number associated with the ANI entry.
18-
* @property {number} createdTime - The timestamp(in epoch millis) when the ANI entry was created.
19-
* @property {number} lastUpdatedTime - The timestamp(in epoch millis) when the ANI entry was last updated.
18+
* @property {number} createdTime - The timestamp(in epoch milliseconds) when the ANI entry was created.
19+
* @property {number} lastUpdatedTime - The timestamp(in epoch milliseconds) when the ANI entry was last updated.
2020
*/
2121
interface OutdialANIEntry {
2222
organizationId?: string;
@@ -38,16 +38,21 @@ interface OutdialANIEntry {
3838
*
3939
* @param props - Properties for the OutdialCallComponent.
4040
* @property startOutdial - Function to initiate the outdial call with the entered destination number.
41-
* @property dialNumberRegex - Optional regular expression provided by the CC Store for validating destination number format.
4241
*/
4342
const OutdialCallComponent: React.FunctionComponent<OutdialCallComponentProps> = (props) => {
44-
const {startOutdial, dialNumberRegex} = props;
43+
const {startOutdial} = props;
4544

4645
// State Hooks
4746
const [destination, setDestination] = useState('');
48-
const [error, setError] = useState('');
47+
const [isValidNumber, setIsValidNumber] = useState('');
4948
const [selectedANI, setSelectedANI] = useState('');
5049

50+
// Validate the input format using regex from agent desktop
51+
const regExForDnSpecialChars = useMemo(
52+
() => new RegExp('^[+1][0-9]{3,18}$|^[*#][+1][0-9*#:]{3,18}$|^[0-9*#]{3,18}$'),
53+
[]
54+
);
55+
5156
const outdialANIEntries: OutdialANIEntry[] = [
5257
{number: '+1(234)567-8910', name: 'name 1'},
5358
{number: '+1(019)876-5432', name: 'name 2'},
@@ -65,25 +70,15 @@ const OutdialCallComponent: React.FunctionComponent<OutdialCallComponentProps> =
6570
];
6671

6772
/**
68-
* updateOutboundNumber
73+
* validateOutboundNumber
6974
* @param e The input change event
70-
* Updates the destination state with validated input
71-
* If the input is invalid, sets an error message
75+
* If the input is invalid, sets an error message on dialnumber input
7276
*/
73-
const updateOutboundNumber = (e: React.ChangeEvent<HTMLInputElement>) => {
74-
// Allow only valid input that is digits, #, *, and +
75-
const VALID_KEYPAD_CHARS = /[\d#*+]/g;
76-
const inputValue = e.target.value;
77-
const filteredValue = inputValue.match(VALID_KEYPAD_CHARS)?.join('') || '';
78-
setDestination(inputValue);
79-
80-
// Validate the input format
81-
const regexForDn = new RegExp(dialNumberRegex ?? '1[0-9]{3}[2-9][0-9]{6}([,]{1,10}[0-9]+){0,1}');
82-
83-
if (inputValue !== filteredValue || (inputValue && !regexForDn.test(inputValue))) {
84-
setError(OutdialStrings.INCORRECT_DN_FORMAT);
77+
const validateOutboundNumber = (value: string) => {
78+
if (value && !regExForDnSpecialChars.test(value)) {
79+
setIsValidNumber(OutdialStrings.INCORRECT_DN_FORMAT);
8580
} else {
86-
setError('');
81+
setIsValidNumber('');
8782
}
8883
};
8984

@@ -93,12 +88,13 @@ const OutdialCallComponent: React.FunctionComponent<OutdialCallComponentProps> =
9388
* Appends the pressed key to the destination input field
9489
*/
9590
const handleKeyPress = (value: string) => {
96-
updateOutboundNumber({target: {value: destination + value}} as React.ChangeEvent<HTMLInputElement>);
91+
setDestination(destination + value);
92+
validateOutboundNumber(destination + value);
9793
};
9894

9995
return (
100-
<div className="keypad">
101-
<div role="tablist" id="outdial-tablist">
96+
<article className="keypad">
97+
<header role="tablist" id="outdial-tablist">
10298
<Tab
10399
active={true}
104100
text={OutdialStrings.DIALPAD_LABEL}
@@ -107,25 +103,29 @@ const OutdialCallComponent: React.FunctionComponent<OutdialCallComponentProps> =
107103
variant="pill"
108104
aria-controls="dialpad-panel"
109105
></Tab>
110-
</div>
106+
</header>
111107
<Input
112108
className="input"
113109
id="outdial-number-input"
114-
helpText={error}
115-
helpTextType={error ? 'error' : 'default'}
110+
helpText={isValidNumber}
111+
helpTextType={isValidNumber ? 'error' : 'default'}
116112
placeholder={OutdialStrings.DN_PLACEHOLDER}
117113
value={destination}
118114
onChange={(e: unknown) => {
119-
updateOutboundNumber(e as React.ChangeEvent<HTMLInputElement>);
115+
const inputValue = (e as React.ChangeEvent<HTMLInputElement>).target.value;
116+
setDestination(inputValue);
117+
validateOutboundNumber(inputValue);
120118
}}
121119
/>
122-
<div className="keys">
120+
<ul className="keys">
123121
{KEY_LIST.map((key) => (
124-
<Button key={key} className="key button" onClick={() => handleKeyPress(key)}>
125-
{key}
126-
</Button>
122+
<li key={key}>
123+
<Button className="key button" onClick={() => handleKeyPress(key)}>
124+
{key}
125+
</Button>
126+
</li>
127127
))}
128-
</div>
128+
</ul>
129129
<Select
130130
className="input"
131131
label={OutdialStrings.ANI_SELECT_LABEL}
@@ -154,9 +154,9 @@ const OutdialCallComponent: React.FunctionComponent<OutdialCallComponentProps> =
154154
className="button"
155155
prefixIcon={'handset-regular'}
156156
onClick={() => startOutdial(destination)}
157-
disabled={!!error || !destination}
157+
disabled={!!isValidNumber || !destination}
158158
/>
159-
</div>
159+
</article>
160160
);
161161
};
162162

packages/contact-center/cc-components/src/components/task/task.types.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,14 +474,9 @@ export interface OutdialCallProps {
474474
* Logger instance for logging purpose.
475475
*/
476476
logger: ILogger;
477-
478-
/**
479-
* Regex pattern for validating the a phone number.
480-
*/
481-
dialNumberRegex?: string;
482477
}
483478

484-
export type OutdialCallComponentProps = Pick<OutdialCallProps, 'startOutdial' | 'dialNumberRegex'>;
479+
export type OutdialCallComponentProps = Pick<OutdialCallProps, 'startOutdial'>;
485480

486481
/**
487482
* Interface representing the properties for CallControlListItem component.

packages/contact-center/task/src/OutdialCall/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ import {useOutdialCall} from '../helper';
77

88
const OutdialCallInternal: React.FunctionComponent = observer(() => {
99
const {cc, logger} = store;
10-
const dialNumberRegex = cc?.agentConfig?.regexUS;
1110

1211
const result = useOutdialCall({cc, logger});
1312
const props = {
1413
...result,
15-
dialNumberRegex,
1614
};
1715

1816
return <OutdialCallComponent {...props} />;

0 commit comments

Comments
 (0)