Skip to content

Commit 38decac

Browse files
committed
Add setting to manage notifiications
1 parent 1bd5353 commit 38decac

2 files changed

Lines changed: 113 additions & 6 deletions

File tree

web/pages/settings/index.vue

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,44 @@
301301
</tbody>
302302
</template>
303303
</v-simple-table>
304+
<h5 id="email-notifications" class="text-h4 mb-3 mt-12">
305+
Email Notifications
306+
</h5>
307+
<p class="text--secondary">
308+
Manage the email notifications which you receive from httpSMS.
309+
Feel free to turn on/off individual notifications anytime so you
310+
don't get overloaded with emails
311+
</p>
312+
<v-switch
313+
v-model="notificationSettings.heartbeat_enabled"
314+
label="Heartbeat emails"
315+
:disabled="updatingEmailNotifications"
316+
hint="This switch controls email notifications we send when we don't receive a heartbeat from your phone for 1 hour."
317+
persistent-hint
318+
></v-switch>
319+
<v-switch
320+
v-model="notificationSettings.webhook_enabled"
321+
label="Webhook and discord emails"
322+
:disabled="updatingEmailNotifications"
323+
hint="This switch controls email notifications we send when we can't forward events to your discord server or to your webhook."
324+
persistent-hint
325+
></v-switch>
326+
<v-switch
327+
v-model="notificationSettings.message_status_enabled"
328+
label="Message status emails"
329+
:disabled="updatingEmailNotifications"
330+
hint="This switch controls email notifications we send when we your message is failed or expired."
331+
persistent-hint
332+
></v-switch>
333+
<v-btn
334+
color="primary"
335+
:loading="updatingEmailNotifications"
336+
class="mt-4"
337+
@click="saveEmailNotifications"
338+
>
339+
<v-icon></v-icon>
340+
Save Notification Settings
341+
</v-btn>
304342
</v-col>
305343
</v-row>
306344
</v-container>
@@ -671,6 +709,12 @@ export default Vue.extend({
671709
server_id: '',
672710
incoming_channel_id: '',
673711
},
712+
updatingEmailNotifications: false,
713+
notificationSettings: {
714+
webhook_enabled: true,
715+
message_status_enabled: true,
716+
heartbeat_enabled: true,
717+
},
674718
updatingWebhook: false,
675719
loadingWebhooks: false,
676720
discords: [],
@@ -691,7 +735,7 @@ export default Vue.extend({
691735
},
692736
head() {
693737
return {
694-
title: 'Settings - Http SMS',
738+
title: 'Settings - httpSMS',
695739
}
696740
},
697741
computed: {
@@ -710,15 +754,31 @@ export default Vue.extend({
710754
})
711755
},
712756
},
713-
mounted() {
714-
this.$store.dispatch('clearAxiosError')
715-
this.$store.dispatch('loadUser')
716-
this.$store.dispatch('loadPhones')
757+
async mounted() {
758+
await Promise.all([
759+
this.$store.dispatch('clearAxiosError'),
760+
this.$store.dispatch('loadUser'),
761+
this.$store.dispatch('loadPhones'),
762+
])
717763
this.loadWebhooks()
718764
this.loadDiscordIntegrations()
765+
this.updateEmailNotifications()
766+
if (this.$route.hash) {
767+
await this.$vuetify.goTo(this.$route.hash)
768+
}
719769
},
720770
721771
methods: {
772+
updateEmailNotifications() {
773+
this.notificationSettings = {
774+
webhook_enabled:
775+
this.$store.getters.getUser.notification_webhook_enabled,
776+
message_status_enabled:
777+
this.$store.getters.getUser.notification_message_status_enabled,
778+
heartbeat_enabled:
779+
this.$store.getters.getUser.notification_heartbeat_enabled,
780+
}
781+
},
722782
showEditPhone(phoneId) {
723783
const phone = this.$store.getters.getPhones.find((x) => x.id === phoneId)
724784
if (!phone) {
@@ -794,7 +854,7 @@ export default Vue.extend({
794854
},
795855
796856
async updatePhone() {
797-
this.updatingPhone = true
857+
thisPhone = true
798858
await this.$store.dispatch('clearAxiosError')
799859
this.$store.dispatch('updatePhone', this.activePhone).finally(() => {
800860
if (!this.$store.getters.getAxiosError) {
@@ -830,6 +890,22 @@ export default Vue.extend({
830890
})
831891
},
832892
893+
saveEmailNotifications() {
894+
this.updatingEmailNotifications = true
895+
this.$store
896+
.dispatch('saveEmailNotifications', this.notificationSettings)
897+
.then(() => {
898+
this.$store.dispatch('addNotification', {
899+
message: 'Email notifications saved successfully',
900+
type: 'success',
901+
})
902+
this.updateEmailNotifications()
903+
})
904+
.finally(() => {
905+
this.updatingEmailNotifications = false
906+
})
907+
},
908+
833909
updateDiscord() {
834910
this.resetErrors()
835911
this.updatingDiscord = true

web/store/index.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ import { BillingUsage } from '~/models/billing'
99
import {
1010
EntitiesDiscord,
1111
EntitiesPhone,
12+
EntitiesUser,
1213
EntitiesWebhook,
1314
RequestsDiscordStore,
1415
RequestsDiscordUpdate,
16+
RequestsUserNotificationUpdate,
1517
RequestsWebhookStore,
1618
RequestsWebhookUpdate,
1719
ResponsesDiscordResponse,
1820
ResponsesDiscordsResponse,
1921
ResponsesNoContent,
2022
ResponsesOkString,
23+
ResponsesUserResponse,
2124
ResponsesWebhookResponse,
2225
ResponsesWebhooksResponse,
2326
} from '~/models/api'
@@ -856,4 +859,32 @@ export const actions = {
856859
})
857860
})
858861
},
862+
863+
saveEmailNotifications(
864+
context: ActionContext<State, State>,
865+
payload: RequestsUserNotificationUpdate,
866+
): Promise<EntitiesUser> {
867+
return new Promise<EntitiesUser>((resolve, reject) => {
868+
axios
869+
.put<ResponsesUserResponse>(
870+
`/v1/users/${context.state.user?.id}/notifications`,
871+
payload,
872+
)
873+
.then((response: AxiosResponse<ResponsesUserResponse>) => {
874+
context.commit('setUser', response.data.data)
875+
resolve(response.data.data)
876+
})
877+
.catch(async (error: AxiosError) => {
878+
await Promise.all([
879+
context.dispatch('addNotification', {
880+
message:
881+
(error.response?.data as any)?.message ??
882+
'Error while updating email notification settings',
883+
type: 'error',
884+
}),
885+
])
886+
reject(getErrorMessages(error))
887+
})
888+
})
889+
},
859890
}

0 commit comments

Comments
 (0)