import Vue from 'vue'; import { isObject } from 'lodash'; import {AxiosError} from "axios"; export default Vue.component('change-password', { data: function () { return { current: '', newPassword: '', confirmNew: '', }; }, methods: { submitForm: function () { this.$flash.clear(); this.$validator.pause(); window.axios.put(this.route('api.client.account.update-password'), { current_password: this.current, password: this.newPassword, password_confirmation: this.confirmNew, }) .then(() => this.current = '') .then(() => { this.newPassword = ''; this.confirmNew = ''; this.$flash.success(this.$t('dashboard.account.password.updated')); }) .catch((err: AxiosError) => { if (!err.response) { this.$flash.error('There was an error with the network request. Please try again.'); console.error(err); return; } const response = err.response; if (response.data && isObject(response.data.errors)) { response.data.errors.forEach((error: any) => { this.$flash.error(error.detail); }); } }) .then(() => { this.$validator.resume(); (this.$refs.current as HTMLElement).focus(); }) } }, template: `

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

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

{{ $t('dashboard.account.password.requirements') }}

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

`, });