diff --git a/web/src/store/modules/athletes.ts b/web/src/store/modules/athletes.ts index 5fb5aa3..a65e47b 100644 --- a/web/src/store/modules/athletes.ts +++ b/web/src/store/modules/athletes.ts @@ -16,6 +16,7 @@ export default class Athletes extends VuexModule { private athlete = {}; private trainer = {}; private athletes = [{}]; + private err = {} get currentAthlete() { return this.athlete; @@ -29,6 +30,10 @@ export default class Athletes extends VuexModule { return this.athletes; } + get getErrAthlete() { + return this.err + } + @Mutation private save_athlete(athlete: AthleteInterface) { this.athlete = athlete; @@ -50,6 +55,11 @@ export default class Athletes extends VuexModule { this.athletes = [{}]; } + @Mutation + private update_error(err: Error) { + this.err = err + } + @Action private getAthletes() { return new Promise((resolve, reject) => { @@ -77,6 +87,7 @@ export default class Athletes extends VuexModule { }) .then((resp: AxiosResponse) => { this.context.commit('save_athlete', resp.data) + resolve(resp) }) .catch((err: Error) => { reject(err) diff --git a/web/src/store/modules/user.ts b/web/src/store/modules/user.ts index 1de72e1..5ae8bab 100644 --- a/web/src/store/modules/user.ts +++ b/web/src/store/modules/user.ts @@ -15,6 +15,7 @@ export interface UserInterface { export default class User extends VuexModule { private user = {}; private userStatus = false; + private err = {}; get currentUser() { return this.user; @@ -24,6 +25,10 @@ export default class User extends VuexModule { return this.userStatus; } + get getErrUser() { + return this.err + } + @Mutation private auth_success(user: UserInterface) { this.user = user; @@ -31,8 +36,9 @@ export default class User extends VuexModule { } @Mutation - private auth_error() { + private auth_error(err: Error) { this.userStatus = false; + this.err = err } @Mutation @@ -41,6 +47,11 @@ export default class User extends VuexModule { this.userStatus = false; } + @Mutation + private update_error(err: Error) { + this.err = err + } + @Action private login(user: UserInterface) { return new Promise((resolve, reject) => { @@ -54,7 +65,7 @@ export default class User extends VuexModule { resolve(resp) }) .catch((err: Error) => { - this.context.commit('auth_error') + this.context.commit('auth_error', err) reject(err) }) }) @@ -95,7 +106,7 @@ export default class User extends VuexModule { }) }) } - + @Action private specificUser(id: string) { return new Promise((resolve, reject) => { @@ -125,6 +136,7 @@ export default class User extends VuexModule { resolve(resp) }) .catch((err: Error) => { + this.context.commit('update_error', err) reject(err) }) }) diff --git a/web/src/views/Athlete.vue b/web/src/views/Athlete.vue index e4de06a..5398c2e 100644 --- a/web/src/views/Athlete.vue +++ b/web/src/views/Athlete.vue @@ -8,7 +8,7 @@
- +
@@ -20,13 +20,13 @@

Online

Offline

-
+
{{ msgError }}
-
+
{{ msgSuccess }}
-
+
  • Client name is randomly generated on device connection. Change to athlete's name, so to be easily identified. @@ -50,7 +50,7 @@

    Trainer Status

    -
    +

      It seems that this athlete has no trainer attached to him!

      By adopting an athlete you can edit his personal details and view his performance stats.

      @@ -111,11 +111,11 @@ export default class Athlete extends Vue { Object.assign(this.athlete, user) this.$store.dispatch('updateAthlete', this.athlete) .then((res: any) => { - console.log('updated') this.msgSuccess = 'Athlete updated' this.athlete = res.data; }) - .catch((err: any) => this.msgError = err.response.data.errors.message || err.message || 'Something went wrong!') + .catch(() => this.msgError = this.$store.getters.getErrAthlete.response.data.errors.message || + 'Something went wrong!') } } diff --git a/web/src/views/Login.vue b/web/src/views/Login.vue index 89eca60..bfe8ba0 100644 --- a/web/src/views/Login.vue +++ b/web/src/views/Login.vue @@ -62,7 +62,7 @@ export default class Login extends Vue { private getCurrentUser() { this.$store.dispatch('getCurrentUser') .then((res: any) => this.$router.push({name: 'Dashboard', params: {username: res.data.username}})) - .catch((err: any) => { + .catch(() => { this.$router.push('/login') }) } @@ -72,9 +72,8 @@ export default class Login extends Vue { this.$store.dispatch('login', user) .then(() => this.$router.push({name: 'Dashboard', params: {username: this.username}})) - .catch((err: any) => { - this.msg = err.response.data.errors.message || err.message || 'Something went wrong!' - this.$router.push('/login') + .catch(() => { + this.msg = this.$store.getters.getErr.response.data.errors.message || 'Something went wrong!' }) } } diff --git a/web/src/views/Profile.vue b/web/src/views/Profile.vue index 0025eab..e4a05ed 100644 --- a/web/src/views/Profile.vue +++ b/web/src/views/Profile.vue @@ -8,7 +8,7 @@
      - +
      @@ -21,7 +21,7 @@
      - +
      @@ -31,26 +31,20 @@

      Change Password

      - - - - + +

      - - - - + +

      - - - - + +

      @@ -60,13 +54,13 @@

      -
      +
      {{ msgError }}
      -
      +
      {{ msgSuccess }}
      -
      +

      According to the traditional advice—which is still good—a strong password:

      • Has 12 Characters, Minimum
      • @@ -92,7 +86,7 @@ interface UpdatedUser extends UserInterface { export default class Profile extends Vue { private user = {}; - private date: string = ''; + private date = ''; private msgSuccess = ''; private msgError = ''; @@ -117,21 +111,9 @@ export default class Profile extends Vue { } this.$store.dispatch('updateUser', user) - .then(() => { - this.msgSuccess = 'User updated!'; - this.$router.push({ - name: 'Profile', - params: {username: this.user.username} - }) - }) - .catch((err: any) => { - this.msgError = err.data.errors.message || err.message || 'Something went wrong!'; - this.$router.push({ - name: 'Profile', - params: {username: this.user.username} - }) - } - ) + .then(() => this.msgSuccess = 'User updated!') + .catch(() => this.msgError = this.$store.getters.getErrUser.response.data.errors.message || + 'Something went wrong!') } }