@@ -42,7 +42,7 @@ class GoogleContacts extends Component {
4242 }
4343
4444 handleImportContacts ( res , pageToken = null ) {
45- const { onFailure } = this . props
45+ const { onFailure, maxResults } = this . props
4646
4747 if ( res ) {
4848 const authResponse = res . getAuthResponse ( )
@@ -52,7 +52,7 @@ class GoogleContacts extends Component {
5252 path : 'https://people.googleapis.com/v1/otherContacts' ,
5353 params : {
5454 readMask : 'names,emailAddresses' ,
55- pageSize : this . props . maxResults > 1000 ? 1000 : this . props . maxResults ,
55+ pageSize : maxResults > 1000 ? 1000 : maxResults ,
5656 ...( pageToken && { pageToken } )
5757 } ,
5858 headers : {
@@ -69,14 +69,15 @@ class GoogleContacts extends Component {
6969 }
7070
7171 handleNextDataFetch ( response , authResponse ) {
72+ const { maxResults } = this . props
7273 // Parse the response body
7374 const parsedData = JSON . parse ( response . body )
7475
7576 // Store the fetched data so that we can use it later
7677 this . allData = [ ...this . allData , ...parsedData . otherContacts ]
7778
7879 // If we have more data and the number of data we fethced is less than maxResults then fetch again using the nextPageToken
79- if ( 'nextPageToken' in parsedData && this . props . maxResults < this . allData . length ) {
80+ if ( 'nextPageToken' in parsedData && maxResults < this . allData . length ) {
8081 this . handleImportContacts ( authResponse , parsedData . nextPageToken )
8182 } else {
8283 this . handleParseContacts ( )
@@ -118,6 +119,8 @@ class GoogleContacts extends Component {
118119 onSuccess
119120 } = this . props
120121
122+ const { disable } = this . state
123+
121124 const params = {
122125 client_id : clientId ,
123126 cookie_policy : cookiePolicy ,
@@ -137,7 +140,7 @@ class GoogleContacts extends Component {
137140 if ( e ) {
138141 e . preventDefault ( ) // to prevent submit if used within form
139142 }
140- if ( ! this . state . disabled ) {
143+ if ( ! disable ) {
141144 const _signIn = ( ) => {
142145 const auth2 = window . gapi . auth2 . getAuthInstance ( )
143146 const options = { prompt }
@@ -166,8 +169,9 @@ class GoogleContacts extends Component {
166169 }
167170
168171 render ( ) {
169- const { tag, type, className, disabledStyle, buttonText, children, render, theme, icon } = this . props
170- const disabled = this . state . disabled || this . props . disabled
172+ const { tag, type, className, disabledStyle, buttonText, children, render, theme, icon, disabled : disabledProps } = this . props
173+ const { active, hovered, disabled : disabledState } = this . state
174+ const disabled = disabledState || disabledProps
171175
172176 if ( render ) {
173177 return render ( { onClick : this . signIn } )
@@ -204,15 +208,15 @@ class GoogleContacts extends Component {
204208 return Object . assign ( { } , initialStyle , disabledStyle )
205209 }
206210
207- if ( this . state . active ) {
211+ if ( active ) {
208212 if ( theme === 'dark' ) {
209213 return Object . assign ( { } , initialStyle , activeStyle )
210214 }
211215
212216 return Object . assign ( { } , initialStyle , activeStyle )
213217 }
214218
215- if ( this . state . hovered ) {
219+ if ( hovered ) {
216220 return Object . assign ( { } , initialStyle , hoveredStyle )
217221 }
218222
@@ -232,7 +236,7 @@ class GoogleContacts extends Component {
232236 className
233237 } ,
234238 [
235- icon && < Icon key = { 1 } active = { this . state . active } /> ,
239+ icon && < Icon key = { 1 } active = { active } /> ,
236240 < ButtonContent key = { 2 } icon = { icon } >
237241 { children || buttonText }
238242 </ ButtonContent >
@@ -244,50 +248,50 @@ class GoogleContacts extends Component {
244248}
245249
246250GoogleContacts . propTypes = {
247- onSuccess : PropTypes . func . isRequired ,
248- onFailure : PropTypes . func . isRequired ,
249- clientId : PropTypes . string . isRequired ,
250- jsSrc : PropTypes . string ,
251- onRequest : PropTypes . func ,
251+ accessType : PropTypes . string ,
252252 buttonText : PropTypes . node ,
253+ children : PropTypes . node ,
253254 className : PropTypes . string ,
254- redirectUri : PropTypes . string ,
255+ clientId : PropTypes . string . isRequired ,
255256 cookiePolicy : PropTypes . string ,
256- loginHint : PropTypes . string ,
257- hostedDomain : PropTypes . string ,
258- children : PropTypes . node ,
259- disabledStyle : PropTypes . object ,
260- prompt : PropTypes . string ,
261- tag : PropTypes . string ,
262257 disabled : PropTypes . bool ,
258+ disabledStyle : PropTypes . object ,
263259 discoveryDocs : PropTypes . array ,
264- uxMode : PropTypes . string ,
265- responseType : PropTypes . string ,
266- type : PropTypes . string ,
267- accessType : PropTypes . string ,
260+ hostedDomain : PropTypes . string ,
261+ icon : PropTypes . bool ,
262+ jsSrc : PropTypes . string ,
263+ loginHint : PropTypes . string ,
264+ maxResults : PropTypes . number ,
265+ onFailure : PropTypes . func . isRequired ,
266+ onRequest : PropTypes . func ,
267+ onSuccess : PropTypes . func . isRequired ,
268+ prompt : PropTypes . string ,
269+ redirectUri : PropTypes . string ,
268270 render : PropTypes . func ,
271+ responseType : PropTypes . string ,
272+ tag : PropTypes . string ,
269273 theme : PropTypes . string ,
270- icon : PropTypes . bool ,
271- maxResults : PropTypes . number
274+ type : PropTypes . string ,
275+ uxMode : PropTypes . string
272276}
273277
274278GoogleContacts . defaultProps = {
275- type : 'button' ,
276- tag : 'button' ,
277- buttonText : 'Import from Gmail' ,
278279 accessType : 'online' ,
279- prompt : 'consent ' ,
280+ buttonText : 'Import from Gmail ' ,
280281 cookiePolicy : 'single_host_origin' ,
281- uxMode : 'popup' ,
282282 disabled : false ,
283- maxResults : 999 ,
284283 disabledStyle : {
285284 opacity : 0.6
286285 } ,
287286 icon : true ,
288- theme : 'light' ,
287+ jsSrc : 'https://apis.google.com/js/api.js' ,
288+ maxResults : 999 ,
289289 onRequest : ( ) => { } ,
290- jsSrc : 'https://apis.google.com/js/api.js'
290+ prompt : 'consent' ,
291+ tag : 'button' ,
292+ theme : 'light' ,
293+ type : 'button' ,
294+ uxMode : 'popup'
291295}
292296
293297export default GoogleContacts
0 commit comments