import Vue from 'vue'; import { get, isObject } from 'lodash'; import { mapState } from 'vuex'; import {ApplicationState} from "../../../store/types"; import {AxiosError} from "axios"; export default Vue.component('update-email', { data: function () { return { email: get(this.$store.state, 'auth.user.email', ''), password: '', }; }, computed: { ...mapState({ user: (state: ApplicationState) => state.auth.user, }) }, methods: { /** * Update a user's email address on the Panel. */ submitForm: function () { this.$flash.clear(); this.$store.dispatch('auth/updateEmail', { email: this.email, password: this.password }) .then(() => { this.$flash.success(this.$t('dashboard.account.email.updated')); }) .catch((error: AxiosError) => { if (!error.response) { this.$flash.error(error.message); return; } const response = error.response; if (response.data && isObject(response.data.errors)) { response.data.errors.forEach((e: any) => { this.$flash.error(e.detail); }); } }) .then(() => { this.$data.password = ''; }); }, }, template: `

{{ $t('dashboard.account.email.title') }}

{{ errors.first('email') }}

`, });