Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add indexCustomField to obtain the utm_course from custom_fields #389

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/app/views/leads/leads-form/NewLead.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const NewLead = () => {
const createLead = (event) => {
setNewLead({ ...newLead, [event.target.name]: event.target.value });
};

const selectTypeLead = (event) => {
setNewLead({
...newLead, lead_type: event.target.value,
Expand Down Expand Up @@ -116,6 +116,7 @@ const NewLead = () => {
});
};


const languages = [
{
value: 'es',
Expand All @@ -133,20 +134,28 @@ const NewLead = () => {
if (id) {
bc.marketing().getAcademySingleLead(id)
.then(({ data }) => {
const index = availableCourses.map((c) => c.slug).indexOf(data.course);
if (!availableCourses || availableCourses.length === 0){
console.error("AvailableCourses is empty")
return
}

const course =
availableCourses.find((c) => c.slug === data.custom_fields?.utm_course || c.slug === data.course
) || { slug: "default", name: "Course by default"};

setNewLead({
...data,
user: data.user?.id || data.user,
latitude: data.latitude || 0,
longitude: data.longitude || 0,
zip_code: data.zip_code || 0,
lead_type: data.lead_type || '',
course: { ...availableCourses[index] }
course,
});
})
.catch((e) => console.log(e))
}
}, []);
}, [id, availableCourses]);

const getCourses = () => {
return new Promise((resolve, reject) => {
Expand Down