-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
76 lines (63 loc) · 1.99 KB
/
Copy pathapp.js
File metadata and controls
76 lines (63 loc) · 1.99 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
// Toast function
function toast({
title = '',
message = '',
type = 'info',
duration = 3000
}) {
const main = document.getElementById('toast')
if (main) {
const toast = document.createElement('div')
const autoRemoveId = setTimeout(function() {
main.removeChild(toast)
}, duration + 1000)
toast.onclick = function(e) {
if (e.target.closest('.toast__close')) {
main.removeChild(toast)
clearTimeout(autoRemoveId)
}
}
const icons = {
success: 'fas fa-check-circle',
info: 'fas fa-info-circle',
warning: 'fas fa-exclamation-circle',
error: 'fas fa-exclamation-circle',
}
const icon = icons[type]
const delay = (duration / 1000).toFixed(2)
toast.classList.add('toast', `toast--${type}`)
toast.style.animation = `slideInLeft ease 0.3s, fadeOut linear 1s ${delay}s forwards`
toast.innerHTML = `
<div class="toast__icon">
<i class="${icon}"></i>
</div>
<div class="toast__body">
<h3 class="toast__title">${title}</h3>
<p class="toast__msg">${message}</p>
</div>
<div class="toast__close">
<i class="fas fa-times"></i>
</div>
`
main.appendChild(toast)
// document.querySelector('.toast__close').onclick = function() {
// main.removeChild(toast)
// }
}
}
function showSuccessToast() {
toast({
title: "Thành công",
message: "Bạn đã đăng kí thành công tài khoản tại PHONG",
type: "success",
duration: 5000
})
}
function showErrorToast() {
toast({
title: "Thất bại",
message: "Có lỗi xảy ra vui lòng lên hệ quản trị viên",
type: "error",
duration: 5000
})
}