Get rid of mutation_types file, use inline approach. Minor fixes

This commit is contained in:
raeno 2018-12-05 23:07:58 +04:00
parent 636be3b681
commit a3e19cbafa
3 changed files with 17 additions and 28 deletions

View file

@ -1,7 +1,6 @@
import { validationMixin } from 'vuelidate' import { validationMixin } from 'vuelidate'
import { required, sameAs } from 'vuelidate/lib/validators' import { required, sameAs } from 'vuelidate/lib/validators'
import { mapActions, mapState } from 'vuex' import { mapActions, mapState } from 'vuex'
import { SIGN_UP } from '../../mutation_types'
const registration = { const registration = {
mixins: [validationMixin], mixins: [validationMixin],
@ -12,8 +11,7 @@ const registration = {
username: '', username: '',
password: '', password: '',
confirm: '' confirm: ''
}, }
clientValidationFailed: false
}), }),
validations: { validations: {
user: { user: {
@ -37,8 +35,8 @@ const registration = {
...mapState({ ...mapState({
registrationOpen: (state) => state.instance.registrationOpen, registrationOpen: (state) => state.instance.registrationOpen,
signedIn: (state) => !!state.users.currentUser, signedIn: (state) => !!state.users.currentUser,
isPending: (state) => state.users[SIGN_UP.isPending], isPending: (state) => state.users.signUpPending,
serverValidationErrors: (state) => state.users[SIGN_UP.errors], serverValidationErrors: (state) => state.users.signUpErrors,
termsOfService: (state) => state.instance.tos termsOfService: (state) => state.instance.tos
}) })
}, },

View file

@ -1,7 +1,6 @@
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js' import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
import { compact, map, each, merge } from 'lodash' import { compact, map, each, merge } from 'lodash'
import { set } from 'vue' import { set } from 'vue'
import { SIGN_UP } from '../mutation_types'
import oauthApi from '../services/new_api/oauth' import oauthApi from '../services/new_api/oauth'
import {humanizeErrors} from './errors' import {humanizeErrors} from './errors'
@ -50,26 +49,27 @@ export const mutations = {
const user = state.usersObject[id] const user = state.usersObject[id]
set(user, 'highlight', highlighted) set(user, 'highlight', highlighted)
}, },
[SIGN_UP.PENDING] (state) { signUpPending (state) {
state[SIGN_UP.isPending] = true state.signUpPending = true
state[SIGN_UP.errors] = [] state.signUpErrors = []
}, },
[SIGN_UP.SUCCESS] (state) { signUpSuccess (state) {
state[SIGN_UP.isPending] = false state.signUpPending = false
}, },
[SIGN_UP.FAILURE] (state, errors) { signUpFailure (state, errors) {
state[SIGN_UP.isPending] = false state.signUpPending = false
state[SIGN_UP.errors] = errors state.signUpErrors = errors
} }
} }
export const defaultState = { export const defaultState = {
loggingIn: false,
lastLoginName: false, lastLoginName: false,
currentUser: false, currentUser: false,
users: [], users: [],
usersObject: {}, usersObject: {},
sign_up_pending: false, signUpPending: false,
sign_up_errors: [] signUpErrors: []
} }
const users = { const users = {
@ -96,7 +96,7 @@ const users = {
}) })
}, },
async signUp (store, userInfo) { async signUp (store, userInfo) {
store.commit(SIGN_UP.PENDING) store.commit('signUpPending')
let rootState = store.rootState let rootState = store.rootState
@ -113,13 +113,13 @@ const users = {
username: userInfo.username, username: userInfo.username,
password: userInfo.password password: userInfo.password
}) })
store.commit(SIGN_UP.SUCCESS) store.commit('signUpSuccess')
store.commit('setToken', result.access_token) store.commit('setToken', result.access_token)
store.dispatch('loginUser', result.access_token) store.dispatch('loginUser', result.access_token)
} else { } else {
let data = await response.json() let data = await response.json()
let errors = humanizeErrors(JSON.parse(data.error)) let errors = humanizeErrors(JSON.parse(data.error))
store.commit(SIGN_UP.FAILURE, errors) store.commit('signUpFailure', errors)
throw Error(errors) throw Error(errors)
} }
}, },

View file

@ -1,9 +0,0 @@
export const SIGN_UP = {
// mutations
SUCCESS: 'SIGN_UP_SUCCESS',
FAILURE: 'SIGN_UP_FAILURE',
PENDING: 'SIGN_UP_PENDING',
// state
isPending: 'sign_up_pending',
errors: 'sign_up_errors'
}