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

mozilla / blurts-server / 27dbd455-244c-48ab-8e37-1ece9db5723e

pending completion
27dbd455-244c-48ab-8e37-1ece9db5723e

push

circleci

GitHub
MNTOR-983: Settings page frontend (#2765)

282 of 1281 branches covered (22.01%)

Branch coverage included in aggregate %.

86 of 86 new or added lines in 3 files covered. (100.0%)

959 of 3457 relevant lines covered (27.74%)

4.5 hits per line

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

0.0
/src/client/js/partials/settings.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
const settingsAlertOptionsInputs = document.getElementsByClassName('js-settings-alert-options-input')
×
6

7
if (settingsAlertOptionsInputs?.length) {
×
8
  for (const inputElement of settingsAlertOptionsInputs) {
×
9
    inputElement.addEventListener('change', async event => {
×
10
      try {
×
11
        const communicationOption = event.target.getAttribute('data-alert-option')
×
12
        const csrfToken = document.querySelector('.js-settings[data-csrf-token]')
×
13

14
        const response = await fetch('/api/v1/user/update-comm-option', {
×
15
          headers: {
16
            'Content-Type': 'application/json',
17
            'x-csrf-token': csrfToken
18
          },
19
          mode: 'same-origin',
20
          method: 'POST',
21
          body: JSON.stringify({ communicationOption })
22
        })
23

24
        if (response && response.redirected === true) {
×
25
          throw response.error
×
26
        }
27
      } catch (err) {
28
        throw new Error(`Updating communication option failed: ${err}`)
×
29
      }
30
      event.preventDefault()
×
31
      return false
×
32
    })
33
  }
34
}
35

36
const settingsAddEmail = document.querySelector('.js-settings-add-email-opener')
×
37
if (settingsAddEmail) {
×
38
  settingsAddEmail.addEventListener('click', async _ => {
×
39
    try {
×
40
      const addEmailDialog = document.getElementById('js-settings-modal')
×
41
      addEmailDialog.showModal()
×
42
    } catch (err) {
43
      console.error(`Error: ${err}`)
×
44
    }
45
  })
46
}
47

48
const settingsClose = document.getElementById('js-settings-close')
×
49
if (settingsClose) {
×
50
  settingsClose.addEventListener('click', async _ => {
×
51
    try {
×
52
      const addEmailDialog = document.getElementById('js-settings-modal')
×
53
      addEmailDialog.close()
×
54
    } catch (err) {
55
      console.error(`Error: ${err}`)
×
56
    }
57
  })
58
}
59

60
const settingsAddVerification = document.getElementById('js-settings-modal-send-verification')
×
61
if (settingsAddVerification) {
×
62
  settingsAddVerification.addEventListener('click', async _ => {
×
63
    const email = document.getElementById('js-settings-email-modal-input').value
×
64
    const csrfToken = document.querySelector('.js-settings[data-csrf-token]')
×
65

66
    const response = await fetch('/api/v1/user/email', {
×
67
      headers: {
68
        'Content-Type': 'application/json',
69
        'x-csrf-token': csrfToken
70
      },
71
      mode: 'same-origin',
72
      method: 'POST',
73
      body: JSON.stringify({ email })
74
    })
75

76
    if (!response?.ok) {
×
77
      throw new Error(`Sending verification email failed: ${response?.error}`)
×
78
    }
79

80
    const addEmailDialogContent = document.getElementById('js-settings-modal-content')
×
81
    // TODO: Localize string below
82
    addEmailDialogContent.textContent = `Verify the link sent to ${email} to add it to Firefox Monitor. Manage all email addresses in Settings.`
×
83

84
    const addEmailDialogControls = document.getElementById('js-settings-modal-controls')
×
85
    addEmailDialogControls.hidden = true
×
86

87
    const addEmailDialog = document.getElementById('js-settings-modal')
×
88
    addEmailDialog.addEventListener('close', _ => {
×
89
      addEmailDialogControls.hidden = false
×
90
      return window.location.reload(true)
×
91
    }, { once: true })
92
  })
93
}
94

95
const settingsRemoveEmailButtons = document.getElementsByClassName('js-remove-email-button')
×
96
if (settingsRemoveEmailButtons?.length) {
×
97
  for (const removeEmailButton of settingsRemoveEmailButtons) {
×
98
    removeEmailButton.addEventListener('click', async event => {
×
99
      try {
×
100
        const subscriberId = event.target.getAttribute('data-subscriber-id')
×
101
        const emailId = event.target.getAttribute('data-email-id')
×
102
        const csrfToken = document.querySelector('.js-settings[data-csrf-token]')
×
103

104
        const response = await fetch('/api/v1/user/remove-email', {
×
105
          headers: {
106
            'Content-Type': 'application/json',
107
            'x-csrf-token': csrfToken
108
          },
109
          mode: 'same-origin',
110
          method: 'POST',
111
          body: JSON.stringify({ emailId, subscriberId })
112
        })
113

114
        if (response && response.redirected === true) {
×
115
          return window.location.reload(true)
×
116
        }
117
      } catch (err) {
118
        console.error(`Error: ${err}`)
×
119
      }
120
    })
121
  }
122
}
123

124
const settingsResendEmailLinks = document.getElementsByClassName('js-settings-resend-email')
×
125
if (settingsResendEmailLinks?.length) {
×
126
  for (const resendEmailLink of settingsResendEmailLinks) {
×
127
    resendEmailLink.addEventListener('click', async event => {
×
128
      try {
×
129
        const emailId = event.target.getAttribute('data-email-id')
×
130
        const csrfToken = document.querySelector('.js-settings[data-csrf-token]')
×
131

132
        const response = await fetch('/api/v1/user/resend-email', {
×
133
          headers: {
134
            'Content-Type': 'application/json',
135
            'x-csrf-token': csrfToken
136
          },
137
          mode: 'same-origin',
138
          method: 'POST',
139
          body: JSON.stringify({ emailId })
140
        })
141

142
        if (response?.redirected) {
×
143
          throw response.error
×
144
        }
145
      } catch (err) {
146
        throw new Error(`Re-sending verification email failed: ${err}`)
×
147
      }
148
      event.preventDefault()
×
149
      return false
×
150
    })
151
  }
152
}
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