From e2818fbf21ee3bd55b8e97901725d3a599ae52fa Mon Sep 17 00:00:00 2001 From: ogerly Date: Fri, 18 Oct 2019 12:27:52 +0200 Subject: [PATCH 1/3] step back --- backend/src/schema/resolvers/registration.spec.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/schema/resolvers/registration.spec.js b/backend/src/schema/resolvers/registration.spec.js index 29116ef70..180950f94 100644 --- a/backend/src/schema/resolvers/registration.spec.js +++ b/backend/src/schema/resolvers/registration.spec.js @@ -290,8 +290,7 @@ describe('Signup', () => { it('throws AuthorizationError', async () => { await expect(mutate({ mutation, variables })).resolves.toMatchObject({ - // errors: [{ message: 'Not Authorised!' }], - errors: undefined, + errors: [{ message: 'Not Authorised!' }], }) }) From 9dccb5fc0a1d6de331091a3eb91f48a3f2288349 Mon Sep 17 00:00:00 2001 From: ogerly Date: Tue, 22 Oct 2019 11:34:04 +0200 Subject: [PATCH 2/3] Save language for the user permanently when changing the language --- .../src/schema/resolvers/registration.spec.js | 2 +- .../components/LocaleSwitch/LocaleSwitch.vue | 31 +++++++++++++++++++ webapp/graphql/User.js | 11 +++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/backend/src/schema/resolvers/registration.spec.js b/backend/src/schema/resolvers/registration.spec.js index e79a107e8..c2b83324d 100644 --- a/backend/src/schema/resolvers/registration.spec.js +++ b/backend/src/schema/resolvers/registration.spec.js @@ -390,7 +390,7 @@ describe('SignupVerification', () => { nonce: $nonce about: $about termsAndConditionsAgreedVersion: $termsAndConditionsAgreedVersion - locale: $language + locale: $locale ) { id termsAndConditionsAgreedVersion diff --git a/webapp/components/LocaleSwitch/LocaleSwitch.vue b/webapp/components/LocaleSwitch/LocaleSwitch.vue index 88959e27b..2251dc7ff 100644 --- a/webapp/components/LocaleSwitch/LocaleSwitch.vue +++ b/webapp/components/LocaleSwitch/LocaleSwitch.vue @@ -37,6 +37,8 @@ import Dropdown from '~/components/Dropdown' import find from 'lodash/find' import orderBy from 'lodash/orderBy' import locales from '~/locales' +import { mapGetters, mapMutations } from 'vuex' +import { localeMutation } from '~/graphql/User.js' export default { components: { @@ -64,15 +66,44 @@ export default { }) return routes }, + ...mapGetters({ + currentUser: 'auth/user', + }), }, methods: { changeLanguage(locale, toggleMenu) { this.$i18n.set(locale) + this.change() toggleMenu() }, matcher(locale) { return locale === this.$i18n.locale() }, + + ...mapMutations({ + setCurrentUser: 'auth/SET_USER', + }), + async change() { + try { + await this.$apollo.mutate({ + mutation: localeMutation(), + variables: { + id: this.currentUser.id, + locale: this.$i18n.locale(), + }, + update: (store, { data: { UpdateUser } }) => { + const { locale } = UpdateUser + this.setCurrentUser({ + ...this.currentUser, + locale, + }) + }, + }) + this.$toast.success(this.$t('contribution.success')) + } catch (err) { + this.$toast.error(err.message) + } + }, }, } diff --git a/webapp/graphql/User.js b/webapp/graphql/User.js index 8e3ff06af..e82280689 100644 --- a/webapp/graphql/User.js +++ b/webapp/graphql/User.js @@ -153,3 +153,14 @@ export const checkSlugAvailableQuery = gql` } } ` + +export const localeMutation = () => { + return gql` + mutation($id: ID!, $locale: String) { + UpdateUser(id: $id, locale: $locale) { + id + locale + } + } + ` +} From b584f12bb16c04e228ddc472298067861d8511ba Mon Sep 17 00:00:00 2001 From: Alexander Friedland Date: Thu, 24 Oct 2019 08:52:24 +0200 Subject: [PATCH 3/3] change change() change to updateUserLocale() --- webapp/components/LocaleSwitch/LocaleSwitch.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/components/LocaleSwitch/LocaleSwitch.vue b/webapp/components/LocaleSwitch/LocaleSwitch.vue index 2251dc7ff..307425aca 100644 --- a/webapp/components/LocaleSwitch/LocaleSwitch.vue +++ b/webapp/components/LocaleSwitch/LocaleSwitch.vue @@ -73,7 +73,7 @@ export default { methods: { changeLanguage(locale, toggleMenu) { this.$i18n.set(locale) - this.change() + this.updateUserLocale() toggleMenu() }, matcher(locale) { @@ -83,7 +83,7 @@ export default { ...mapMutations({ setCurrentUser: 'auth/SET_USER', }), - async change() { + async updateUserLocale() { try { await this.$apollo.mutate({ mutation: localeMutation(),