99 stringifyWithPreservingUndefinedAsNull ,
1010} from './utils' ;
1111
12- import NiceModal from '@ebay/nice-modal-react' ;
1312import { Store } from 'react-notifications-component' ;
1413import keyBy from 'lodash/keyBy' ;
1514
@@ -114,27 +113,21 @@ class Api {
114113 }
115114 }
116115
117- urlProvider = async ( ) : Promise < string > => {
118- const promise = new Promise < string > ( ( resolve ) => {
119- const url = new URL ( this . url )
120- let token = new URLSearchParams ( window . location . search ) . get ( "token" )
121- ?? local . get < string > ( TOKEN_LOCAL_STORAGE_ITEM_NAME ) ;
122- const authRequired = ! ! local . get ( AUTH_FLAG_LOCAL_STORAGE_ITEM_NAME ) ;
123- if ( authRequired ) {
124- if ( ! token ) {
125- NiceModal . show ( 'auth-form' , { onAuth : ( token : string ) => {
126- local . set ( TOKEN_LOCAL_STORAGE_ITEM_NAME , token ) ;
127- url . searchParams . append ( "token" , token ) ;
128- resolve ( url . toString ( ) ) ;
129- } } ) ;
130- return ;
116+ urlProvider = async ( ) => {
117+ const url = new URL ( this . url )
118+ let token = new URLSearchParams ( window . location . search ) . get ( "token" )
119+ ?? local . get < string > ( TOKEN_LOCAL_STORAGE_ITEM_NAME ) ;
120+ const authRequired = ! ! local . get ( AUTH_FLAG_LOCAL_STORAGE_ITEM_NAME ) ;
121+ if ( authRequired ) {
122+ if ( ! token ) {
123+ token = prompt ( "Enter your z2m admin token" ) as string ;
124+ if ( token ) {
125+ local . set ( TOKEN_LOCAL_STORAGE_ITEM_NAME , token ) ;
131126 }
132- url . searchParams . append ( "token" , token ) ;
133127 }
134- resolve ( url . toString ( ) ) ;
135- } ) ;
136-
137- return promise ;
128+ url . searchParams . append ( "token" , token ) ;
129+ }
130+ return url . toString ( ) ;
138131 }
139132
140133 connect ( ) : void {
@@ -284,7 +277,7 @@ class Api {
284277 if ( e . code === UNAUTHORIZED_ERROR_CODE ) {
285278 local . set ( AUTH_FLAG_LOCAL_STORAGE_ITEM_NAME , true ) ;
286279 local . remove ( TOKEN_LOCAL_STORAGE_ITEM_NAME ) ;
287- showNotify ( ' error' , "Unauthorized" , false ) ;
280+ NotificationManager . error ( "Unauthorized" ) ;
288281 setTimeout ( ( ) => {
289282 window . location . reload ( ) ;
290283 } , 1000 ) ;
@@ -303,7 +296,7 @@ class Api {
303296 this . processDeviceStateMessage ( data ) ;
304297 }
305298 } catch ( e ) {
306- showNotify ( ' error' , e . message , false ) ;
299+ NotificationManager . error ( e . message ) ;
307300 console . error ( event . data ) ;
308301 }
309302
0 commit comments