-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
ET-103: task validation modal
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1031,3 +1031,31 @@ def post(self, request, *args, **kwargs): | |
|
||
response.status_code = 303 | ||
return response | ||
|
||
|
||
class TaskValidationView(GenericAPIView): | ||
def post(self, request, *args, **kwargs): | ||
data = self.request.data.copy() | ||
data['userid'] = request.user.hashed_uuid if request.user.is_authenticated else None | ||
|
||
email_address = request.user.email if request.user.is_authenticated else '[email protected]' | ||
|
||
sender = Sender( | ||
email_address=email_address, | ||
country_code=None, | ||
) | ||
|
||
action = actions.SaveOnlyInDatabaseAction( | ||
full_name='NA', | ||
email_address=email_address, | ||
subject='NA', | ||
sender=sender, | ||
form_url=self.request.get_full_path(), | ||
) | ||
|
||
save_result = action.save(data) | ||
|
||
response = HttpResponse() | ||
response.status_code = save_result.status_code | ||
|
||
return response |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
GreatFrontend = window.GreatFrontend || {} | ||
|
||
GreatFrontend.TaskValidation = { | ||
init: () => { | ||
const cards = document.querySelectorAll('[data-task-validation]') | ||
const form = document.getElementById('task-validation-form') | ||
|
||
const ga = (category, title, location) => { | ||
window.dataLayer.push({ | ||
event: 'DEPCardClick', | ||
category: category, | ||
title: title, | ||
location: location, | ||
}) | ||
} | ||
|
||
const redirectUserToCardHref = (href) => { | ||
window.location = href | ||
} | ||
|
||
if (form) { | ||
GreatFrontend.utils.hideElement(form) | ||
} | ||
|
||
if (cards.length >= 1) { | ||
cards.forEach((card) => { | ||
card.addEventListener('click', async (e) => { | ||
e.preventDefault() | ||
|
||
const href = card.href | ||
|
||
const title = card.querySelector('[data-title]').dataset.title | ||
const question = document.getElementById('task-validation-question') | ||
|
||
if (title === 'Calculate how much duty you need to pay') { | ||
question.innerHTML = | ||
'We think you’re looking for the amount of duty you need to pay on your goods. Is this correct?' | ||
} | ||
|
||
if (title === 'Find the right commodity code') { | ||
question.innerHTML = | ||
'We think you’re looking for the correct commodity (HS) code for your product. Is this correct?' | ||
} | ||
|
||
if (sessionStorage.getItem('task_validation')) { | ||
ga('service', title, 'main-area') | ||
redirectUserToCardHref(href) | ||
} else { | ||
sessionStorage.setItem('task_validation', 'true') | ||
|
||
if (form) { | ||
GreatFrontend.utils.showElement(form) | ||
|
||
form.querySelectorAll('button').forEach((button) => { | ||
button.addEventListener('click', async (e) => { | ||
e.preventDefault() | ||
|
||
try { | ||
await fetch('/contact/task-validation', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
question: question, | ||
answer: button.innerText, | ||
}), | ||
}) | ||
ga('service', title, 'main-area') | ||
redirectUserToCardHref(href) | ||
} catch (e) { | ||
console.log(e) | ||
} | ||
}) | ||
}) | ||
} | ||
} | ||
}) | ||
}) | ||
} | ||
}, | ||
} |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.