fix: Transmit confidant_email on edit

This commit is contained in:
aldrin 2021-05-18 11:06:02 +02:00
parent 6835240173
commit a8464d7536
7 changed files with 89 additions and 14 deletions

View file

@ -2,7 +2,7 @@ import Cookies from "js-cookie";
type HTTPMethod = "GET" | "POST" | "PUT" | "PATCH";
class APIError extends Error {
export class APIError extends Error {
constructor(message: string, public readonly errors: unknown) {
super(message);
}
@ -42,8 +42,8 @@ async function request(
export class User {
email: string | undefined;
password: string | undefined;
private username: string | null = null;
private confidantEmail: string | null = null;
username: string | null = null;
confidantEmail: string | null = null;
isAuthenticated = false;
private token = "";
@ -67,6 +67,7 @@ export class User {
200,
{
username: this.username,
confidant_email: this.confidantEmail,
},
this.token
);

View file

@ -24,11 +24,15 @@
</tr>
<tr>
<td>Benutzername</td>
<td><InlineEditor v-model="user.username" @input="user.save()" /></td>
<td>
<InlineEditor v-model="user.username" @input="user.save()" />
</td>
</tr>
<tr>
<td>Vertrauensperson</td>
<td><inline-editor v-model="user.confidant_email" /></td>
<td>
<inline-editor v-model="user.confidantEmail" @input="user.save()" />
</td>
</tr>
<tr>
<td>E-Mail-Adresse</td>

19
src/mixins.ts Normal file
View file

@ -0,0 +1,19 @@
import Component from "vue-class-component";
import Vue from "vue";
@Component
export class NotifyMixin extends Vue {
showError(): void {
this.$buefy.toast.open({
message: "Es ist leider ein Fehler aufgetreten.",
type: "is-danger",
});
}
showSuccess(message: string): void {
this.$buefy.toast.open({
message,
type: "is-success",
});
}
}

View file

@ -15,24 +15,34 @@
</template>
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { Component } from "vue-property-decorator";
import LoginForm from "@/components/LoginForm.vue";
import { mixins } from "vue-class-component";
import { User } from "@/api";
import UserTable from "@/components/UserTable.vue";
import { NotifyMixin } from "@/mixins";
@Component({ components: { UserTable, LoginForm } })
export default class Home extends Vue {
export default class Home extends mixins(NotifyMixin) {
private user = new User();
public async created(): Promise<void> {
if (this.$route.name === "confirm") {
await this.doConfirm();
} else if (!this.user.isAuthenticated) {
this.$router.push({ name: "login" });
}
}
private async doConfirm() {
try {
await User.confirm(this.$route.params.uid, this.$route.params.token);
this.$router.push({ name: "login" });
this.$buefy.toast.open({
message:
"Deine E-Mail-Adresse wurde bestätigt. Du kannst dich nun anmelden.",
type: "is-success",
});
this.showSuccess(
"Deine E-Mail-Adresse wurde bestätigt. Du kannst dich nun anmelden."
);
} catch {
this.showError();
}
}
}