From 95df3522a15631abc51a4295cae0ea401a8d4e1e Mon Sep 17 00:00:00 2001 From: Markus Hatvan Date: Tue, 14 Sep 2021 19:58:52 +0200 Subject: feat: add eslint-plugin-unicorn (#1936) --- src/stores/UserStore.js | 78 +++++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 29 deletions(-) (limited to 'src/stores/UserStore.js') diff --git a/src/stores/UserStore.js b/src/stores/UserStore.js index 2e009893a..e3d57c662 100644 --- a/src/stores/UserStore.js +++ b/src/stores/UserStore.js @@ -46,7 +46,10 @@ export default class UserStore extends Store { @observable updateUserInfoRequest = new Request(this.api.user, 'updateInfo'); - @observable getLegacyServicesRequest = new CachedRequest(this.api.user, 'getLegacyServices'); + @observable getLegacyServicesRequest = new CachedRequest( + this.api.user, + 'getLegacyServices', + ); @observable deleteAccountRequest = new CachedRequest(this.api.user, 'delete'); @@ -81,13 +84,17 @@ export default class UserStore extends Store { // Register action handlers this.actions.user.login.listen(this._login.bind(this)); - this.actions.user.retrievePassword.listen(this._retrievePassword.bind(this)); + this.actions.user.retrievePassword.listen( + this._retrievePassword.bind(this), + ); this.actions.user.logout.listen(this._logout.bind(this)); this.actions.user.signup.listen(this._signup.bind(this)); this.actions.user.invite.listen(this._invite.bind(this)); this.actions.user.update.listen(this._update.bind(this)); this.actions.user.resetStatus.listen(this._resetStatus.bind(this)); - this.actions.user.importLegacyServices.listen(this._importLegacyServices.bind(this)); + this.actions.user.importLegacyServices.listen( + this._importLegacyServices.bind(this), + ); this.actions.user.delete.listen(this._delete.bind(this)); // Reactions @@ -176,7 +183,14 @@ export default class UserStore extends Store { } @action async _signup({ - firstname, lastname, email, password, accountType, company, plan, currency, + firstname, + lastname, + email, + password, + accountType, + company, + plan, + currency, }) { const authToken = await this.signupRequest.execute({ firstname, @@ -205,7 +219,7 @@ export default class UserStore extends Store { } @action async _invite({ invites }) { - const data = invites.filter((invite) => invite.email !== ''); + const data = invites.filter(invite => invite.email !== ''); const response = await this.inviteRequest.execute(data)._promise; @@ -220,7 +234,8 @@ export default class UserStore extends Store { @action async _update({ userData }) { if (!this.isLoggedIn) return; - const response = await this.updateUserInfoRequest.execute(userData)._promise; + const response = await this.updateUserInfoRequest.execute(userData) + ._promise; this.getUserInfoRequest.patch(() => response.data); this.actionStatus = response.status || []; @@ -250,19 +265,27 @@ export default class UserStore extends Store { this.isImportLegacyServicesExecuting = true; // Reduces recipe duplicates - const recipes = services.filter((obj, pos, arr) => arr.map((mapObj) => mapObj.recipe.id).indexOf(obj.recipe.id) === pos).map((s) => s.recipe.id); + const recipes = services + .filter( + (obj, pos, arr) => + arr.map(mapObj => mapObj.recipe.id).indexOf(obj.recipe.id) === pos, + ) + .map(s => s.recipe.id); // Install recipes - for (const recipe of recipes) { // eslint-disable-line no-unused-vars - // eslint-disable-next-line + for (const recipe of recipes) { + // eslint-disable-line no-unused-vars + // eslint-disable-next-line no-await-in-loop await this.stores.recipes._install({ recipeId: recipe }); } - for (const service of services) { // eslint-disable-line no-unused-vars + for (const service of services) { + // eslint-disable-line no-unused-vars this.actions.service.createFromLegacyService({ data: service, }); - await this.stores.services.createServiceRequest._promise; // eslint-disable-line + // eslint-disable-next-line no-await-in-loop + await this.stores.services.createServiceRequest._promise; } this.isImportLegacyServicesExecuting = false; @@ -281,8 +304,7 @@ export default class UserStore extends Store { const { router } = this.stores; const currentRoute = window.location.hash; - if (!this.isLoggedIn - && currentRoute.includes('token=')) { + if (!this.isLoggedIn && currentRoute.includes('token=')) { router.push(this.WELCOME_ROUTE); const token = currentRoute.split('=')[1]; @@ -293,20 +315,18 @@ export default class UserStore extends Store { this._tokenLogin(token); }, 1000); } - } else if (!this.isLoggedIn - && !currentRoute.includes(this.BASE_ROUTE)) { + } else if (!this.isLoggedIn && !currentRoute.includes(this.BASE_ROUTE)) { router.push(this.WELCOME_ROUTE); - } else if (this.isLoggedIn - && currentRoute === this.LOGOUT_ROUTE) { + } else if (this.isLoggedIn && currentRoute === this.LOGOUT_ROUTE) { this.actions.user.logout(); router.push(this.LOGIN_ROUTE); - } else if (this.isLoggedIn - && currentRoute.includes(this.BASE_ROUTE) - && (this.hasCompletedSignup - || this.hasCompletedSignup === null)) { - if (!isDevMode) { - this.stores.router.push('/'); - } + } else if ( + this.isLoggedIn && + currentRoute.includes(this.BASE_ROUTE) && + (this.hasCompletedSignup || this.hasCompletedSignup === null) && + !isDevMode + ) { + this.stores.router.push('/'); } }; @@ -316,7 +336,7 @@ export default class UserStore extends Store { let data; try { data = await this.getUserInfoRequest.execute()._promise; - } catch (e) { + } catch { return false; } @@ -336,12 +356,12 @@ export default class UserStore extends Store { try { const decoded = jwt.decode(authToken); - return ({ + return { id: decoded.userId, tokenExpiry: moment.unix(decoded.exp).toISOString(), authToken, - }); - } catch (err) { + }; + } catch { this._logout(); return false; } @@ -372,7 +392,7 @@ export default class UserStore extends Store { async _migrateUserLocale() { try { await this.getUserInfoRequest._promise; - } catch (e) { + } catch { return false; } -- cgit v1.2.3-54-g00ecf