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
95
96
97
|
import api from '@/store/api';
import i18n from '@/i18n';
const SmtpStore = {
namespaced: true,
state: {
settings: {},
subscribers: [],
},
getters: {
settings: (state) => state.settings,
subscribers: (state) => state.subscribers,
},
mutations: {
saveSettings: (state, data) => (state.settings = data),
setSubscribers: (state, data) => (state.subscribers = data),
},
actions: {
async deleteSubscriber({ dispatch }, email) {
return await api
.get(`/redfish/v1/Smtp/DeleteMails&${email}`)
.then(async () => {
await dispatch('getSubscribers');
return i18n.t('pageTransfer.smtp.deleteSubscriberSuсcess');
})
.catch((error) => {
console.log(error);
throw new Error(i18n.t('pageTransfer.smtp.deleteSubscriberError'));
});
},
async addSubscriber({ dispatch }, payload) {
return await api
.get(`/redfish/v1/Smtp/AddMails&${payload.email}`)
.then(async () => {
await dispatch('getSubscribers');
return i18n.t('pageTransfer.smtp.saveSubscriberSuсcess');
})
.catch((error) => {
console.log(error);
throw new Error(i18n.t('pageTransfer.smtp.saveSubscriberError'));
});
},
async getSubscribers({ commit }) {
return await api
.get('/redfish/v1/Smtp/GetMails')
.then(({ data: { mails = [] } = {} }) =>
mails.map((host) => {
return {
host,
};
})
)
.then((subscribers) => commit('setSubscribers', subscribers))
.catch((error) => {
console.log(error);
throw new Error(i18n.t('pageUserManagement.toast.errorLoadUsers'));
});
},
async setSettings({ dispatch }, payload) {
let url = `/redfish/v1/Smtp/SetSettings`;
for (let key in payload) {
url += `&${key}=${payload[key]}`;
}
return await api
.get(url)
.then(async () => {
await dispatch('getSettings');
return i18n.t('pageTransfer.saveSmtpSuсcess');
})
.catch((error) => {
console.log(error);
throw new Error(i18n.t('pageTransfer.saveSmtpError'));
});
},
async getSettings({ commit }) {
return await api
.get('/redfish/v1/Smtp/GetSettings')
.then(({ data = {} }) => {
commit('saveSettings', data);
})
.catch((error) => console.log(error));
},
async sendTestMessage(_, payload) {
return await api
.post('/redfish/v1/Smtp/SendMail', payload)
.catch((error) => console.log(error));
},
},
};
export default SmtpStore;
|