Update LocaleSwitch with guard clause

- return if there is no currentUser
- do not copy graphql directory as there is no need to send messages to
backend
This commit is contained in:
mattwr18 2019-10-24 12:45:55 +02:00
parent 9d522353cc
commit 821ea6d671
2 changed files with 10 additions and 3 deletions

View File

@ -19,7 +19,6 @@ RUN yarn install --production=false --frozen-lockfile --non-interactive
COPY assets assets
COPY components/LocaleSwitch/ components/LocaleSwitch
COPY graphql graphql
COPY components/Dropdown.vue components/Dropdown.vue
COPY layouts/blank.vue layouts/blank.vue
COPY locales locales

View File

@ -33,12 +33,12 @@
</template>
<script>
import gql from 'graphql-tag'
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: {
@ -84,9 +84,17 @@ export default {
setCurrentUser: 'auth/SET_USER',
}),
async updateUserLocale() {
if (!this.currentUser || !this.currentUser.id) return null
try {
await this.$apollo.mutate({
mutation: localeMutation(),
mutation: gql`
mutation($id: ID!, $locale: String) {
UpdateUser(id: $id, locale: $locale) {
id
locale
}
}
`,
variables: {
id: this.currentUser.id,
locale: this.$i18n.locale(),