Skip to content

Commit 8f590e2

Browse files
committed
fix: plug mentorship contact form to backend
1 parent 0b3774f commit 8f590e2

File tree

3 files changed

+56
-19
lines changed

3 files changed

+56
-19
lines changed

src/api/skill.service.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,21 @@ export async function searchSkill(search) {
1111
})
1212
).data
1313
}
14+
15+
export async function offerMentorship(orgCode, skill, payload) {
16+
return (
17+
await axios.post(
18+
`${import.meta.env.VITE_APP_API_DEFAULT_VERSION}/organization/${orgCode}/skill/${skill.id}/contact-mentoree/`,
19+
payload
20+
)
21+
).data
22+
}
23+
24+
export async function askMentorship(orgCode, skill, payload) {
25+
return (
26+
await axios.post(
27+
`${import.meta.env.VITE_APP_API_DEFAULT_VERSION}/organization/${orgCode}/skill/${skill.id}/contact-mentor/`,
28+
payload
29+
)
30+
).data
31+
}

src/components/people/skill/MentorshipContactDrawer.vue

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
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">
@@ -53,27 +53,30 @@
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'
6768
import BaseDrawer from '@/components/base/BaseDrawer.vue'
6869
import TextInput from '@/components/base/form/TextInput.vue'
6970
import useValidate from '@vuelidate/core'
7071
import { email, helpers, required } from '@vuelidate/validators'
7172
import FieldErrors from '@/components/base/form/FieldErrors.vue'
73+
import { askMentorship, offerMentorship } from '@/api/skill.service.ts'
74+
import useOrganizationsStore from '@/stores/useOrganizations.ts'
7275
export 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

src/components/people/skill/SkillItemFull.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
</div>
5353
</transition>
5454
<MentorshipContactDrawer
55+
:skill="skill"
5556
:is-open="mentorshipDrawerIsOpen"
5657
:is-offer="mentorshipDrawerIsOffer"
5758
@close="mentorshipDrawerIsOpen = false"

0 commit comments

Comments
 (0)