• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / blurts-server / 21e1ed73-620e-461c-8b35-b9b55116427a

pending completion
21e1ed73-620e-461c-8b35-b9b55116427a

push

circleci

GitHub
Merge pull request #2950 from mozilla/rename-ga4-events-taxonomy

282 of 1601 branches covered (17.61%)

Branch coverage included in aggregate %.

12 of 12 new or added lines in 7 files covered. (100.0%)

959 of 4322 relevant lines covered (22.19%)

3.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/client/js/partials/add-email.js
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4

5
let dialogEl, form
6

7
function init () {
8
  dialogEl = document.querySelector('dialog[data-partial="add-email"]')
×
9
  if (!dialogEl) return
×
10

11
  form = dialogEl.querySelector('form')
×
12
  form.addEventListener('submit', handleSubmit)
×
13
  dialogEl.addEventListener('close', kill)
×
14
}
15

16
async function handleSubmit (e) {
17
  e.preventDefault()
×
18

19
  try {
×
20
    form.elements['email-submit'].toggleAttribute('disabled', true)
×
21
    const res = await fetch('/api/v1/user/email', {
×
22
      headers: {
23
        'Content-Type': 'application/json',
24
        'x-csrf-token': form.elements['csrf-token'].value,
25
        Accept: 'text/html' // set to request localized response
26
      },
27
      mode: 'same-origin',
28
      method: 'POST',
29
      body: JSON.stringify({
30
        email: form.elements['email-address'].value
31
      })
32
    })
33

34
    if (!res.ok) throw new Error()
×
35

36
    window.gtag('event', 'added_email', { result: 'success' })
×
37

38
    const { newEmailCount } = await res.json()
×
39

40
    renderSuccess({
×
41
      email: form.elements['email-address'].value,
42
      newEmailCount
43
    })
44
  } catch (e) {
45
    // TODO: localize error messages
46
    const toast = document.createElement('toast-alert')
×
47
    toast.textContent = `Could not add email. ${e.message}`
×
48
    dialogEl.append(toast)
×
49
    console.error('Could not add email.', e)
×
50
    window.gtag('event', 'added_email', { result: 'fail' })
×
51
  } finally {
52
    form.elements['email-submit'].toggleAttribute('disabled', false)
×
53
  }
54
}
55

56
function renderSuccess (data) {
57
  const content = dialogEl.querySelector('template[data-success]').content.cloneNode(true)
×
58
  const messageEl = content.querySelector('p.add-email-success')
×
59

60
  messageEl.style.setProperty('--form-height', `${form.clientHeight}px`)
×
61
  messageEl.querySelector('.current-email').textContent = data.email
×
62
  form.replaceWith(content)
×
63
  dialogEl.dispatchEvent(new CustomEvent('email-added', {
×
64
    bubbles: true,
65
    detail: data
66
  }))
67
}
68

69
function kill () {
70
  form.removeEventListener('submit', handleSubmit)
×
71
  dialogEl.removeEventListener('close', kill)
×
72
}
73

74
export default init
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc