useEmail.js
2.24 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
export const useEmail = () => {
const route = useRoute('apps-email-filter')
const updateEmails = async (ids, data) => {
await $api('apps/email', {
method: 'POST',
body: JSON.stringify({ ids, data }),
})
}
const updateEmailLabels = async (ids, label) => {
await $api('/apps/email', {
method: 'POST',
body: { ids, label },
})
}
const emailMoveToFolderActions = [
{ action: 'inbox', icon: 'ri-mail-line' },
{ action: 'spam', icon: 'ri-spam-2-line' },
{ action: 'trash', icon: 'ri-delete-bin-line' },
]
const labels = [
{
title: 'personal',
color: 'success',
},
{
title: 'company',
color: 'primary',
},
{
title: 'important',
color: 'warning',
},
{
title: 'private',
color: 'error',
},
]
const resolveLabelColor = label => {
if (label === 'personal')
return 'success'
if (label === 'company')
return 'primary'
if (label === 'important')
return 'warning'
if (label === 'private')
return 'error'
return 'secondary'
}
const shallShowMoveToActionFor = action => {
if (action === 'trash')
return route.params.filter !== 'trashed'
else if (action === 'inbox')
return !(route.params.filter === undefined || route.params.filter === 'sent' || route.params.filter === 'draft')
else if (action === 'spam')
return !(route.params.filter === 'spam' || route.params.filter === 'sent' || route.params.filter === 'draft')
return false
}
const moveSelectedEmailTo = async (action, selectedEmails) => {
const dataToUpdate = {}
if (action === 'inbox') {
if (route.params.filter === 'trashed')
dataToUpdate.isDeleted = false
dataToUpdate.folder = 'inbox'
}
else if (action === 'spam') {
if (route.params.filter === 'trashed')
dataToUpdate.isDeleted = false
dataToUpdate.folder = 'spam'
}
else if (action === 'trash') {
dataToUpdate.isDeleted = true
}
await updateEmails(selectedEmails, dataToUpdate)
}
return {
labels,
resolveLabelColor,
shallShowMoveToActionFor,
emailMoveToFolderActions,
moveSelectedEmailTo,
updateEmails,
updateEmailLabels,
}
}