Skip to content

Commit e0bf0e8

Browse files
committed
Solved comments
1 parent e6ccdf6 commit e0bf0e8

4 files changed

Lines changed: 18 additions & 27 deletions

File tree

src/pages/Login/Login.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ it('should dispatch authFacebook action when the user tries to log in with Faceb
5757
}
5858
});
5959

60-
component.find('#facebook').simulate('click');
60+
component.find('.is-facebook').simulate('click');
6161

6262
expect(authActions.authFacebook).toHaveBeenCalled();
6363
});
@@ -69,7 +69,7 @@ it('should dispatch authGoogle action when the user tries to log in with Google'
6969
}
7070
});
7171

72-
component.find('#google').simulate('click');
72+
component.find('.is-google').simulate('click');
7373

7474
expect(authActions.authGoogle).toHaveBeenCalled();
7575
});
@@ -81,7 +81,7 @@ it('should dispatch authMicrosoft action when the user tries to log in with Micr
8181
}
8282
});
8383

84-
component.find('#microsoft').simulate('click');
84+
component.find('.is-microsoft').simulate('click');
8585

8686
expect(authActions.authMicrosoft).toHaveBeenCalled();
8787
});

src/pages/Login/__snapshots__/Login.test.js.snap

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ exports[`<Login /> rendering should render without crashing 1`] = `
269269
>
270270
<a
271271
className="is-facebook socialButton"
272-
id="facebook"
273272
onClick={[Function]}
274273
>
275274
<span
@@ -285,7 +284,6 @@ exports[`<Login /> rendering should render without crashing 1`] = `
285284
</a>
286285
<a
287286
className="is-google socialButton"
288-
id="google"
289287
onClick={[Function]}
290288
>
291289
<span
@@ -301,7 +299,6 @@ exports[`<Login /> rendering should render without crashing 1`] = `
301299
</a>
302300
<a
303301
className="is-microsoft socialButton"
304-
id="microsoft"
305302
onClick={[Function]}
306303
>
307304
<span

src/pages/Login/index.jsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/* eslint-disable no-undef */
2-
/* eslint-disable no-alert */
3-
import React, { useEffect, useState } from 'react';
1+
import React, { useEffect, useState, useCallback } from 'react';
42
import { useDispatch, useSelector, shallowEqual } from 'react-redux';
53
import { Redirect, Link } from 'react-router-dom';
64
import classNames from 'classnames';
@@ -72,17 +70,17 @@ const Login = () => {
7270

7371
const iconsClassName = classNames('icon', classes.icon);
7472

75-
const onFacebookHandler = () => {
73+
const onFacebookHandler = useCallback(() => {
7674
dispatch(authFacebook());
77-
};
75+
}, [dispatch, authFacebook]);
7876

79-
const onGoogleHandler = () => {
77+
const onGoogleHandler = useCallback(() => {
8078
dispatch(authGoogle());
81-
};
79+
}, [dispatch, authGoogle]);
8280

83-
const onMicrosoftHandler = () => {
81+
const onMicrosoftHandler = useCallback(() => {
8482
dispatch(authMicrosoft());
85-
};
83+
}, [dispatch, authMicrosoft]);
8684

8785
const inputs = isEmailLink
8886
? inputValidations(authData.email, authData.password, locale)
@@ -224,7 +222,6 @@ const Login = () => {
224222
'is-facebook',
225223
classes.socialButton
226224
)}
227-
id="facebook"
228225
onClick={onFacebookHandler}
229226
>
230227
<span className={iconsClassName}>
@@ -234,7 +231,6 @@ const Login = () => {
234231
</a>
235232
<a
236233
className={classNames('is-google', classes.socialButton)}
237-
id="google"
238234
onClick={onGoogleHandler}
239235
>
240236
<span className={iconsClassName}>
@@ -247,7 +243,6 @@ const Login = () => {
247243
'is-microsoft',
248244
classes.socialButton
249245
)}
250-
id="microsoft"
251246
onClick={onMicrosoftHandler}
252247
>
253248
<span className={iconsClassName}>

src/state/actions/auth.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,15 @@ const authWithProvider = provider => {
245245
return async (dispatch, getState) => {
246246
dispatch(AUTH_PROVIDER_INIT());
247247
const { locale } = getState().preferences;
248-
let result;
248+
let logInData;
249249

250250
try {
251-
result = await firebase.auth().signInWithPopup(provider);
251+
logInData = await firebase.auth().signInWithPopup(provider);
252252
} catch (error) {
253253
const errorMessage = firebaseError(error.code, locale);
254254
return dispatch(AUTH_PROVIDER_FAIL({ error: errorMessage }));
255255
}
256-
const { user, additionalUserInfo } = result;
256+
const { user, additionalUserInfo } = logInData;
257257

258258
const { uid } = firebase.auth().currentUser;
259259

@@ -267,12 +267,12 @@ const authWithProvider = provider => {
267267
name: user.displayName,
268268
createdAt,
269269
logoUrl: user.photoURL,
270-
location: location ? location.name : null
270+
location: location?.name || null
271271
};
272272

273-
let userValue;
273+
let userFromDb;
274274
try {
275-
userValue = (
275+
userFromDb = (
276276
await firebase
277277
.database()
278278
.ref(`users/${uid}`)
@@ -283,7 +283,7 @@ const authWithProvider = provider => {
283283
return dispatch(AUTH_PROVIDER_FAIL({ error: errorMessage }));
284284
}
285285

286-
if (!userValue) {
286+
if (!userFromDb) {
287287
try {
288288
await firebase
289289
.database()
@@ -296,15 +296,14 @@ const authWithProvider = provider => {
296296
}
297297

298298
return dispatch(
299-
AUTH_PROVIDER_SUCCESS({ id: uid, ...userData, ...userValue })
299+
AUTH_PROVIDER_SUCCESS({ id: uid, ...userData, ...userFromDb })
300300
);
301301
};
302302
};
303303

304304
export const authFacebook = () => {
305305
const provider = new firebase.auth.FacebookAuthProvider();
306306
provider.addScope('email');
307-
provider.addScope('user_location');
308307
return authWithProvider(provider);
309308
};
310309

0 commit comments

Comments
 (0)