Skip to content

Commit 8e4f481

Browse files
committed
send new values to backend
1 parent 3aacd64 commit 8e4f481

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
</template>
5050

5151
<script>
52+
/* eslint-disable vue/custom-event-name-casing */
5253
export default {
5354
props: ['name', 'type', 'currentValuePassed'],
5455
data: () => ({
@@ -71,12 +72,13 @@ export default {
7172
this.edit = false;
7273
},
7374
onSubmit() {
75+
this.edit = false;
76+
this.currentValueBackup = this.currentValue;
77+
this.$emit('saveSingleChoice', this.type, this.currentValue);
7478
if (this.type === 'password') {
7579
this.currentValue = '';
7680
this.passwordRepeat = '';
7781
}
78-
this.edit = false;
79-
this.currentValueBackup = this.currentValue;
8082
},
8183
passwordErrorHandler(error) {
8284
if (!error || error === 'The Password field is required' || error === 'The Repeat Password field is required') {

frontend/src/views/app/Settings.vue

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,27 @@
3131
<AccountInput
3232
v-bind:name="'First Name'"
3333
v-bind:type="'firstName'"
34+
v-on:saveSingleChoice="saveSingleChoice"
3435
v-bind:currentValuePassed="this.$store.getters.getLoggedInUser.first_name"></AccountInput>
3536
<AccountInput
3637
v-bind:name="'Last Name'"
3738
v-bind:type="'lastName'"
39+
v-on:saveSingleChoice="saveSingleChoice"
3840
v-bind:currentValuePassed="this.$store.getters.getLoggedInUser.last_name"></AccountInput>
3941
<AccountInput
4042
v-bind:name="'Email'"
4143
v-bind:type="'email'"
44+
v-on:saveSingleChoice="saveSingleChoice"
4245
v-bind:currentValuePassed="this.$store.getters.getLoggedInUser.email"></AccountInput>
4346
<AccountInput
4447
v-bind:name="'Username'"
4548
v-bind:type="'username'"
49+
v-on:saveSingleChoice="saveSingleChoice"
4650
v-bind:currentValuePassed="this.$store.getters.getLoggedInUser.username"></AccountInput>
4751
<AccountInput
4852
v-bind:name="'Password'"
4953
v-bind:type="'password'"
54+
v-on:saveSingleChoice="saveSingleChoice"
5055
v-bind:currentValuePassed="''"></AccountInput>
5156
</section>
5257
<section v-if="getShow === 'profile'" class="flex flex-col items-start z-10 absolute bg-white-matcha w-full top-0 left-0 md:ml-4 md:relative md:shadow-md md:rounded-md">
@@ -68,7 +73,7 @@
6873
<DropdownDisplayChoice
6974
class="inline-block"
7075
v-on:saveSingleChoice="saveSingleChoice"
71-
v-bind:name="'gender'"
76+
v-bind:name="'sexuality'"
7277
v-bind:starting-option="this.$store.getters.getLoggedInUser.orientation"
7378
v-bind:options="['heterosexual', 'homosexual', 'bisexual', 'other']"></DropdownDisplayChoice>
7479
</div>
@@ -99,6 +104,7 @@
99104
class="mx-auto"
100105
v-bind:name="'Bio'"
101106
v-bind:type="'bio'"
107+
v-on:saveSingleChoice="saveSingleChoice"
102108
v-bind:currentValuePassed="this.$store.getters.getLoggedInUser.bio"></AccountInput>
103109
</div>
104110
<div class="text-center px-8 py-8 border-t border-gray-300 w-full">
@@ -129,6 +135,7 @@
129135

130136
<script>
131137
/* eslint-disable prefer-destructuring */
138+
/* eslint-disable prefer-const */
132139
import NavBar from '@/components/shared/NavBar.vue';
133140
import MenuButton from '@/components/app/settings/MenuButton.vue';
134141
import SectionHeader from '@/components/app/settings/SectionHeader.vue';
@@ -219,17 +226,35 @@ export default {
219226
const user = await this.$http.get(`/users/${this.$store.getters.getLoggedInUser.id}`);
220227
await this.$store.dispatch('login', user.data);
221228
},
222-
saveSingleChoice(...args) {
229+
async saveSingleChoice(...args) {
223230
const [key, value] = args;
224-
if (key === 'gender') {
225-
console.log(value);
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.patch('/profile/edit/email', { email: value });
237+
} else if (key === 'username') {
238+
await this.$http.patch('/profile/edit/username', { username: value });
239+
} else if (key === 'password') {
240+
await this.$http.patch('/profile/edit/password', { password: value });
241+
} else if (key === 'bio') {
242+
await this.$http.patch('/profile/edit/bio', { bio: value });
243+
} else if (key === 'gender') {
244+
await this.$http.patch('/profile/edit/gender', { gender: value });
245+
} else if (key === 'sexuality') {
246+
await this.$http.patch('/profile/edit/orientation', { orientation: value });
226247
}
248+
const user = await this.$http.get(`/users/${this.$store.getters.getLoggedInUser.id}`);
249+
await this.$store.dispatch('login', user.data);
227250
},
228-
saveMultipleChoice(...args) {
251+
async saveMultipleChoice(...args) {
229252
const [key, value] = args;
230253
if (key === 'interests') {
231-
console.log(value);
254+
await this.$http.patch('/profile/edit/tags', { tags: value });
232255
}
256+
const user = await this.$http.get(`/users/${this.$store.getters.getLoggedInUser.id}`);
257+
await this.$store.dispatch('login', user.data);
233258
},
234259
showSetting(setting) {
235260
this.show = setting;

0 commit comments

Comments
 (0)