-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05-feedback-dialog.js
More file actions
97 lines (85 loc) · 2.6 KB
/
05-feedback-dialog.js
File metadata and controls
97 lines (85 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
;(function () {
'use strict'
const dialog = document.getElementById('feedback_dialog')
const form = document.getElementById('feedback_form')
if (!dialog) return
const hide = (element) => {
element.classList.remove('opacity-100')
element.classList.add('opacity-0')
setTimeout(() => {
element.classList.add('hidden')
}, 150)
}
const show = (element) => {
element.classList.remove('opacity-0')
element.classList.add('opacity-100')
setTimeout(() => {
element.classList.remove('hidden')
}, 150)
}
const showThankYou = () => {
const buttons = document.getElementById('feedback_buttons')
const thankYou = document.getElementById('feedback_thank_you')
hide(buttons)
setTimeout(() => {
show(thankYou)
}, 150)
setTimeout(() => {
hide(thankYou)
setTimeout(() => {
show(buttons)
}, 150)
}, 5 * 1000)
}
form.onsubmit = (e) => {
e.preventDefault()
const message = form.elements.message.value
if (message && window.analytics && window.getSegmentCommonProperties) {
const commonProps = window.getSegmentCommonProperties('User Form')
// Map to IBM User Form schema
window.analytics.track('User Form', {
...commonProps,
action: 'submitted',
formId: 'feedback_form',
formType: 'feedback',
field: 'feedback_message',
fieldType: 'text_field',
title: 'Give Feedback',
data: message,
})
}
form.elements.message.value = ''
dialog.close()
showThankYou()
}
const feedbackButtonYes = document.getElementById('feedback_button_yes')
feedbackButtonYes.addEventListener('click', (e) => {
if (window.analytics && window.getSegmentCommonProperties) {
const commonProps = window.getSegmentCommonProperties('User Form')
// Track positive feedback button click
window.analytics.track('User Form', {
...commonProps,
action: 'clicked',
formId: 'feedback_buttons',
formType: 'feedback',
field: 'helpful_yes',
fieldType: 'button',
title: 'Was This Helpful?',
})
}
showThankYou()
})
const cancelButton = document.getElementById('feedback_form_cancel_button')
cancelButton.addEventListener('click', (e) => {
form.elements.message.value = ''
})
const escButton = document.getElementById('feedback_form_esc_button')
escButton.addEventListener('click', (e) => {
form.elements.message.value = ''
})
// if ESC pressed
dialog.addEventListener('cancel', (e) => {
form.elements.message.value = ''
showThankYou()
})
})()