-
Notifications
You must be signed in to change notification settings - Fork 0
/
MessageModal.js
69 lines (62 loc) · 2.24 KB
/
MessageModal.js
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
export default class MessageModal {
constructor(contacts, onSubmit) {
this.el = document.createElement('div');
this.el.classList.add('modal');
this.el.classList.add('message-modal');
this.onSubmit = onSubmit;
this.contacts = contacts;
}
getContactList() {
return this.contacts.map(contact => {
return `
<div class="contact-reminder">
${contact.name} -- ${contact.screen_name}
</div>
`;
}).join('');
}
render() {
this.el.innerHTML = `
<div class="alert">
<h3 class="OnNo"><span class="oh">OH NO! </span></br>
Are you sure you want</br> to send this DM?</h3>
<p class='msgContent'><strong>Content of the message:</strong> </br>
Hey, {name}! <br />
I'm sending you this message as a trusted friend - I have reason to believe that I may very soon have an encounter with law enforcement. <br />
Please check on me soon! If I'm not answering there is a chance I just got arrested. <br />
I chose the local bail fund below in advance, please contact them on my behalf <br />
if you feel comfortable. <br />
{fund contact info} <br />
<div class="alertBtnDiv">
<button class="alertBtnClose">Cancel</button>
<button class="alertBtn">Send Alerts</button>
</div>
</div>
`
this.el.querySelector('.alertBtn').addEventListener('click', async () => {
try {
await this.onSubmit();
const errorEl = this.el.querySelector('.error-alert');
!!errorEl && errorEl.remove();
this.confirmSent();
} catch (e) {
const markup = `
<p class="error-alert" style="color: red;">It looks like something went wrong. Try re-submitting</p>
`;
this.el.querySelector('.msgContent').innerHTML = markup;
}
});
this.el.querySelector('.alertBtnClose').addEventListener('click', () => this.close());
return this.el;
}
close() {
this.el.hidden = true;
}
confirmSent() {
this.el.querySelector('.alert').innerHTML = `
<h2 class="staySafe alert">Message Sent! </br> Stay Safe!</h2>
<button class="alertBtnClose alert-two">Close</button>
`;
this.el.querySelector('.alert button').addEventListener('click', () => this.close());
}
}