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 ) {
0 commit comments