summaryrefslogtreecommitdiff
path: root/src/store/modules/Settings/SmtpStore.js
diff options
context:
space:
mode:
authorVitalii Lysak <v.lysak@dunice.net>2022-09-20 13:35:38 +0300
committerVitalii Lysak <v.lysak@dunice.net>2022-09-20 13:35:38 +0300
commit4d04ae12f310f1bccf1270f1d3a4090b888ecf6e (patch)
tree793e75c70b133a1ddf2dbfe56134ef869ca7fc62 /src/store/modules/Settings/SmtpStore.js
parentab93e8470ddb49f4a522446dfb9c7882ff37daaf (diff)
parent37f6f72ff1ed6d4795c3f67ca2ba92367582e562 (diff)
downloadwebui-vue-4d04ae12f310f1bccf1270f1d3a4090b888ecf6e.tar.xz
merge smtp, snmp, syslog
Diffstat (limited to 'src/store/modules/Settings/SmtpStore.js')
-rw-r--r--src/store/modules/Settings/SmtpStore.js100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/store/modules/Settings/SmtpStore.js b/src/store/modules/Settings/SmtpStore.js
new file mode 100644
index 00000000..195f245a
--- /dev/null
+++ b/src/store/modules/Settings/SmtpStore.js
@@ -0,0 +1,100 @@
+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) {
+ let url = `/redfish/v1/Smtp/SendMail`;
+ for (let key in payload) {
+ url += `&${key}=${payload[key]}`;
+ }
+
+ return await api.get(url);
+ },
+ },
+};
+
+export default SmtpStore;