From 40d224e8c0132e0da7ccb5493a62feeb292fad21 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 8 Jun 2019 00:07:30 -0400 Subject: [PATCH] feat: admin mail - send test email --- client/components/admin/admin-mail.vue | 33 +- client/components/admin/admin-pages.vue | 2 +- .../components/admin/admin-users-create.vue | 6 +- .../admin/mail/mail-mutation-sendtest.gql | 12 + server/core/mail.js | 2 +- server/graph/resolvers/mail.js | 27 +- server/graph/schemas/mail.graphql | 4 + server/helpers/error.js | 60 ++-- server/templates/test.html | 291 ++++++++++++++++++ 9 files changed, 405 insertions(+), 32 deletions(-) create mode 100644 client/graph/admin/mail/mail-mutation-sendtest.gql create mode 100644 server/templates/test.html diff --git a/client/components/admin/admin-mail.vue b/client/components/admin/admin-mail.vue index 91ac6e83..6fda10c1 100644 --- a/client/components/admin/admin-mail.vue +++ b/client/components/admin/admin-mail.vue @@ -136,11 +136,11 @@ :label='$t(`admin:mail.testRecipient`)' :counter='255' prepend-icon='mail' - disabled + :disabled='testLoading' ) v-card-chin v-spacer - v-btn(color='teal', :dark='false', disabled) {{ $t('admin:mail.testSend') }} + v-btn(color='teal', dark, @click='sendTest', :loading='testLoading') {{ $t('admin:mail.testSend') }} @@ -149,6 +149,7 @@ import _ from 'lodash' import { get } from 'vuex-pathify' import mailConfigQuery from 'gql/admin/mail/mail-query-config.gql' import mailUpdateConfigMutation from 'gql/admin/mail/mail-mutation-save-config.gql' +import mailTestMutation from 'gql/admin/mail/mail-mutation-sendtest.gql' export default { data() { @@ -166,7 +167,8 @@ export default { dkimKeySelector: '', dkimPrivateKey: '' }, - testEmail: '' + testEmail: '', + testLoading: false } }, computed: { @@ -202,6 +204,31 @@ export default { } catch (err) { this.$store.commit('pushGraphError', err) } + }, + async sendTest () { + try { + const resp = await this.$apollo.mutate({ + mutation: mailTestMutation, + variables: { + recipientEmail: this.testEmail + }, + watchLoading (isLoading) { + this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-mail-test') + } + }) + if (!_.get(resp, 'data.mail.sendTest.responseResult.succeeded', false)) { + throw new Error(_.get(resp, 'data.mail.sendTest.responseResult.message', 'An unexpected error occured.')) + } + + this.testEmail = '' + this.$store.commit('showNotification', { + style: 'success', + message: this.$t('admin:mail.sendTestSuccess'), + icon: 'check' + }) + } catch (err) { + this.$store.commit('pushGraphError', err) + } } }, apollo: { diff --git a/client/components/admin/admin-pages.vue b/client/components/admin/admin-pages.vue index 159dce4c..0da626a6 100644 --- a/client/components/admin/admin-pages.vue +++ b/client/components/admin/admin-pages.vue @@ -14,7 +14,7 @@ v-icon(left) add span New Page v-card.wiki-form.mt-3 - v-toolbar(flat, :color='$vuetify.dark ? `grey darken-3-d5` : `white`', height='80') + v-toolbar(flat, :color='$vuetify.dark ? `grey darken-3-d5` : `grey lighten-5`', height='80') v-spacer v-text-field( outline diff --git a/client/components/admin/admin-users-create.vue b/client/components/admin/admin-users-create.vue index 63e335fc..1deeacee 100644 --- a/client/components/admin/admin-users-create.vue +++ b/client/components/admin/admin-users-create.vue @@ -64,8 +64,8 @@ v-card-chin v-spacer v-btn(flat, @click='isShown = false') Cancel - v-btn(color='primary', @click='newUser') Create - v-btn(color='primary', @click='newUser') Create and Close + v-btn(color='primary', @click='newUser(true)') Create + v-btn(color='primary', @click='newUser(false)') Create and Close