Skip to content

Commit 2cf0514

Browse files
committed
add errors for inputs
1 parent 6ac0524 commit 2cf0514

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

frontend/src/components/app/settings/AccountInput.vue

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<div class="w-full my-4 max-w-sm">
44
<ValidationObserver v-slot="{ handleSubmit, invalid }" class="w-full">
55
<form @submit.prevent="handleSubmit(onSubmit)" class="w-full">
6+
<h1 v-if="error" class="focus:outline-none text-md font-bold capitalize text-red-500">{{ error }}</h1>
67
<div class="flex justify-between items-center w-full">
78
<h1 class="text-md font-bold capitalize text-gray-matcha">{{ name }}</h1>
89
<div class="flex">
@@ -62,9 +63,11 @@ export default {
6263
currentValue: '',
6364
passwordRepeat: '',
6465
passwordOld: '',
66+
error: '',
6567
}),
6668
methods: {
6769
startEditing() {
70+
this.error = '';
6871
this.currentValueBackup = this.currentValue;
6972
this.edit = true;
7073
},
@@ -77,16 +80,39 @@ export default {
7780
this.currentValue = this.currentValueBackup;
7881
this.edit = false;
7982
},
80-
onSubmit() {
83+
async onSubmit() {
84+
this.error = false;
8185
this.edit = false;
8286
this.currentValueBackup = this.currentValue;
83-
if (this.type !== 'password') {
84-
this.$emit('saveSingleChoice', this.type, this.currentValue);
85-
} else {
86-
this.$emit('saveSingleChoiceOldGiven', this.type, this.currentValue, this.passwordOld);
87-
this.currentValue = '';
88-
this.passwordRepeat = '';
89-
this.passwordOld = '';
87+
try {
88+
if (this.type === 'firstName') {
89+
await this.$http.patch('/profile/edit/first_name', { first_name: this.currentValue });
90+
} else if (this.type === 'lastName') {
91+
await this.$http.patch('/profile/edit/last_name', { last_name: this.currentValue });
92+
} else if (this.type === 'email') {
93+
await this.$http.put('/profile/edit/email', { email: this.currentValue });
94+
} else if (this.type === 'username') {
95+
await this.$http.patch('/profile/edit/username', { username: this.currentValue });
96+
} else if (this.type === 'bio') {
97+
await this.$http.patch('/profile/edit/bio', { bio: this.currentValue });
98+
} else if (this.type === 'password') {
99+
await this.$http.put('/profile/edit/password', {
100+
old_password: this.passwordOld,
101+
new_password: this.currentValue,
102+
});
103+
this.currentValue = '';
104+
this.passwordRepeat = '';
105+
this.passwordOld = '';
106+
}
107+
const user = await this.$http.get(`/users/${this.$store.getters.getLoggedInUser.id}`);
108+
await this.$store.dispatch('login', user.data);
109+
} catch (error) {
110+
this.error = error.response.data.error.message;
111+
if (this.type === 'password') {
112+
this.currentValue = '';
113+
this.passwordRepeat = '';
114+
this.passwordOld = '';
115+
}
90116
}
91117
},
92118
passwordErrorHandler(error) {

frontend/src/views/app/Settings.vue

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@
117117
<div class="auth-sub-container-error mt-8" v-if="image.error">
118118
<h1 class="auth-sub-container-error-message">{{image.error}}</h1>
119119
</div>
120-
<button v-if="this.$store.getters.getLoggedInUser.images.length < 6" class="cursor-pointer relative onboarding-sub-container-content-button-outline border w-full max-w-sm my-4">
121-
<input class="cursor-pointer opacity-0 absolute top-0 left-0 w-full h-full rounded-md" type="file" v-on:change="selectFile()" ref="file">
120+
<button v-if="this.$store.getters.getLoggedInUser.images.length < 6" class="relative onboarding-sub-container-content-button-outline border w-full max-w-sm my-4">
121+
<input class="opacity-0 absolute top-0 left-0 w-full h-full rounded-md" type="file" v-on:change="selectFile()" ref="file">
122122
<img src="../../assets/onboarding/cloudPurple.png" class="w-8 mx-auto">
123123
</button>
124124
<ProfileImage
@@ -228,33 +228,14 @@ export default {
228228
},
229229
async saveSingleChoice(...args) {
230230
const [key, value] = args;
231-
if (key === 'firstName') {
232-
await this.$http.patch('/profile/edit/first_name', { first_name: value });
233-
} else if (key === 'lastName') {
234-
await this.$http.patch('/profile/edit/last_name', { last_name: value });
235-
} else if (key === 'email') {
236-
await this.$http.put('/profile/edit/email', { email: value });
237-
} else if (key === 'username') {
238-
await this.$http.patch('/profile/edit/username', { username: value });
239-
} else if (key === 'bio') {
240-
await this.$http.patch('/profile/edit/bio', { bio: value });
241-
} else if (key === 'gender') {
231+
if (key === 'gender') {
242232
await this.$http.patch('/profile/edit/gender', { gender: value });
243233
} else if (key === 'sexuality') {
244234
await this.$http.patch('/profile/edit/orientation', { orientation: value });
245235
}
246236
const user = await this.$http.get(`/users/${this.$store.getters.getLoggedInUser.id}`);
247237
await this.$store.dispatch('login', user.data);
248238
},
249-
async saveSingleChoiceOldGiven(...args) {
250-
const [key, value, old] = args;
251-
if (key === 'password') {
252-
await this.$http.put('/profile/edit/password', {
253-
old_password: old,
254-
new_password: value,
255-
});
256-
}
257-
},
258239
async saveMultipleChoice(...args) {
259240
const [key, value] = args;
260241
if (key === 'interests') {

0 commit comments

Comments
 (0)