3636 </p >
3737 <TextInput
3838 input-type =" textarea"
39- v-model =" form.text "
39+ v-model =" form.content "
4040 class =" text-input"
4141 data-test =" ask-mentorship-text"
4242 :placeholder =" $t('profile.edit.skills.mentorship.contact.fields.text.placeholder')"
43- @blur =" v$.form.text .$validate"
43+ @blur =" v$.form.content .$validate"
4444 />
45- <FieldErrors :errors =" v$.form.text .$errors" />
45+ <FieldErrors :errors =" v$.form.content .$errors" />
4646 </div >
4747
4848 <div class =" form-input" >
5353 {{ $t('profile.edit.skills.mentorship.contact.fields.email.notice') }}
5454 </p >
5555 <TextInput
56- v-model =" form.email "
56+ v-model =" form.reply_to "
5757 class =" text-input"
5858 data-test =" ask-mentorship-email"
5959 :placeholder =" $t('profile.edit.skills.mentorship.contact.fields.email.placeholder')"
60- @blur =" v$.form.email .$validate"
60+ @blur =" v$.form.reply_to .$validate"
6161 />
62- <FieldErrors :errors =" v$.form.email .$errors" />
62+ <FieldErrors :errors =" v$.form.reply_to .$errors" />
6363 </div >
6464 </BaseDrawer >
6565</template >
6666<script >
67+ import useToasterStore from ' @/stores/useToaster.ts'
6768import BaseDrawer from ' @/components/base/BaseDrawer.vue'
6869import TextInput from ' @/components/base/form/TextInput.vue'
6970import useValidate from ' @vuelidate/core'
7071import { email , helpers , required } from ' @vuelidate/validators'
7172import FieldErrors from ' @/components/base/form/FieldErrors.vue'
73+ import { askMentorship , offerMentorship } from ' @/api/skill.service.ts'
74+ import useOrganizationsStore from ' @/stores/useOrganizations.ts'
7275export function defaultForm () {
7376 return {
7477 title: ' ' ,
75- text : ' ' ,
76- email : ' ' ,
78+ content : ' ' ,
79+ reply_to : ' ' ,
7780 }
7881}
7982
@@ -85,6 +88,10 @@ export default {
8588 components: { BaseDrawer, TextInput, FieldErrors },
8689
8790 props: {
91+ skill: {
92+ type: Object ,
93+ required: true ,
94+ },
8895 isOpen: {
8996 type: Boolean ,
9097 default: false ,
@@ -99,7 +106,15 @@ export default {
99106 default: false ,
100107 },
101108 },
109+ setup () {
110+ const toaster = useToasterStore ()
111+ const organizationsStore = useOrganizationsStore ()
102112
113+ return {
114+ toaster,
115+ organizationsStore,
116+ }
117+ },
103118 data () {
104119 return {
105120 v$: useValidate (),
@@ -116,13 +131,13 @@ export default {
116131 required
117132 ),
118133 },
119- text : {
134+ content : {
120135 required: helpers .withMessage (
121136 this .$t (' profile.edit.skills.mentorship.contact.fields.title.required' ),
122137 required
123138 ),
124139 },
125- email : {
140+ reply_to : {
126141 required: helpers .withMessage (
127142 this .$t (' profile.edit.skills.mentorship.contact.fields.title.required' ),
128143 required
@@ -156,16 +171,19 @@ export default {
156171 if (isValid) {
157172 this .isLoading = true
158173 try {
159- await new Promise ((resolve ) => setTimeout (resolve, 1000 ))
160- this .$store .dispatch (' notifications/pushToast' , {
161- message: this .$t (' profile.edit.skills.mentorship.contact.success' ),
162- type: ' success' ,
163- })
174+ const orgCode = this .organizationsStore .current ? .code
175+ if (this .isOffer ) {
176+ await offerMentorship (orgCode, this .skill , this .form )
177+ } else {
178+ await askMentorship (orgCode, this .skill , this .form )
179+ }
180+ this .toaster .pushSuccess (
181+ this .$t (' profile.edit.skills.mentorship.contact.success' )
182+ )
164183 } catch (error) {
165- this .$store .dispatch (' notifications/pushToast' , {
166- message: ` ${ this .$t (' profile.edit.skills.mentorship.contact.error' )} (${ error} )` ,
167- type: ' error' ,
168- })
184+ this .toaster .pushError (
185+ ` ${ this .$t (' profile.edit.skills.mentorship.contact.error' )} (${ error} )`
186+ )
169187 console .error (error)
170188 } finally {
171189 this .isLoading = false
0 commit comments