1- import React , { useState } from 'react' ;
1+ import React , { useMemo , useState } from 'react' ;
22import { OutdialCallComponentProps } from '../task.types' ;
33import './outdial-call.style.scss' ;
44import { 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 */
2121interface 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 */
4342const 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
0 commit comments