@@ -23,6 +23,8 @@ export const handleAuthorize = async (
2323 setError ( { } )
2424 setIsLoading ( true )
2525
26+ setIsLoading ( true )
27+
2628 try {
2729 const result = await bitsFetch ( { accessToken : confTmp . accessToken } , 'line_authorization' )
2830
@@ -31,21 +33,31 @@ export const handleAuthorize = async (
3133 setisAuthorized ( true )
3234 setSnackbar ( { show : true , msg : __ ( 'Authorized Successfully' , 'bit-integrations' ) } )
3335 } else {
34- const msg =
35- result ?. data ?. data || ( ! result . success && typeof result . data === 'string' )
36- ? `${ __ ( 'Authorization failed Cause:' , 'bit-integrations' ) } ${ result . data ?. data || result . data } . ${ __ ( 'please try again' , 'bit-integrations' ) } `
37- : __ ( 'Authorization failed. please try again' , 'bit-integrations' )
36+ const msg = result ?. data ?. data
37+ ? `${ __ ( 'Authorization failed Cause:' , 'bit-integrations' ) } ${ result . data . data } . ${ __ ( 'Please try again' , 'bit-integrations' ) } `
38+ : typeof result ?. data === 'string'
39+ ? `${ __ ( 'Authorization failed Cause:' , 'bit-integrations' ) } ${ result . data } . ${ __ ( 'Please try again' , 'bit-integrations' ) } `
40+ : __ ( 'Authorization failed. Please try again' , 'bit-integrations' )
3841
3942 setSnackbar ( { show : true , msg } )
4043 }
41- } finally {
44+
45+ setIsLoading ( false )
46+ } catch ( error ) {
47+ setSnackbar ( {
48+ show : true ,
49+ msg : `${ __ ( 'An error occurred during authorization:' , 'bit-integrations' ) } ${ error ?. message || error } `
50+ } )
51+
4252 setIsLoading ( false )
4353 }
4454}
4555
4656const updateFieldMap = ( prevConf , type , index , updater ) => {
4757 const newConf = { ...prevConf }
58+
4859 if ( ! Array . isArray ( newConf [ type ] ) ) newConf [ type ] = [ ]
60+
4961 if ( ! newConf [ type ] [ index ] ) newConf [ type ] [ index ] = { }
5062 newConf [ type ] [ index ] = { ...newConf [ type ] [ index ] , ...updater ( newConf [ type ] [ index ] ) }
5163 return newConf
@@ -68,6 +80,7 @@ export const handleCustomValue = (event, index, _, setConf, type) => {
6880export const delFieldMap = ( index , _ , setConf , type ) => {
6981 setConf ( prev => {
7082 const fieldMap = prev [ type ] || [ ]
83+
7184 if ( fieldMap . length <= 1 ) return prev
7285
7386 const updatedFieldMap = fieldMap [ index ] ?. groupId
@@ -88,6 +101,7 @@ export const addFieldMap = (i, confTmp, setConf, FieldMappings, mapKey) => {
88101
89102 setConf ( prev => {
90103 const newConf = { ...prev }
104+
91105 if ( ! Array . isArray ( newConf [ mapKey ] ) ) newConf [ mapKey ] = [ ]
92106 newConf [ mapKey ] . splice ( i , 0 , ...newFieldMap )
93107 return newConf
@@ -148,11 +162,13 @@ export const getLineValidationMessages = lineConf => {
148162 case 'sendPushMessage' :
149163 if ( ! lineConf . recipientId ?. trim ( ) )
150164 messages . push ( __ ( 'Recipient ID is required' , 'bit-integrations' ) )
165+
151166 if ( ! isMessageFieldConfigured ( lineConf ) )
152167 messages . push ( __ ( 'Message field mapping is required' , 'bit-integrations' ) )
153168 break
154169 case 'sendReplyMessage' :
155170 if ( ! lineConf . replyToken ?. trim ( ) ) messages . push ( __ ( 'Reply Token is required' , 'bit-integrations' ) )
171+
156172 if ( ! isMessageFieldConfigured ( lineConf ) )
157173 messages . push ( __ ( 'Message field mapping is required' , 'bit-integrations' ) )
158174 break
0 commit comments