debian-mirror-gitlab/app/assets/javascripts/boards/components/sidebar/board_sidebar_subscription.vue

76 lines
2.1 KiB
Vue
Raw Normal View History

2021-01-29 00:20:46 +05:30
<script>
import { GlToggle } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { mapGetters, mapActions } from 'vuex';
2021-01-29 00:20:46 +05:30
import { __, s__ } from '~/locale';
export default {
i18n: {
header: {
title: __('Notifications'),
/* Any change to subscribeDisabledDescription
must be reflected in app/helpers/notifications_helper.rb */
subscribeDisabledDescription: __(
'Notifications have been disabled by the project or group owner',
),
},
updateSubscribedErrorMessage: s__(
2021-03-08 18:12:59 +05:30
'IssueBoards|An error occurred while setting notifications status. Please try again.',
2021-01-29 00:20:46 +05:30
),
},
components: {
GlToggle,
},
2021-04-29 21:17:54 +05:30
inject: ['emailsDisabled'],
2021-01-29 00:20:46 +05:30
data() {
return {
loading: false,
};
},
computed: {
2021-04-29 21:17:54 +05:30
...mapGetters(['activeBoardItem', 'projectPathForActiveIssue', 'isEpicBoard']),
isEmailsDisabled() {
return this.isEpicBoard ? this.emailsDisabled : this.activeBoardItem.emailsDisabled;
},
2021-01-29 00:20:46 +05:30
notificationText() {
2021-04-29 21:17:54 +05:30
return this.isEmailsDisabled
2021-01-29 00:20:46 +05:30
? this.$options.i18n.header.subscribeDisabledDescription
: this.$options.i18n.header.title;
},
},
methods: {
2021-09-04 01:27:46 +05:30
...mapActions(['setActiveItemSubscribed', 'setError']),
2021-01-29 00:20:46 +05:30
async handleToggleSubscription() {
this.loading = true;
try {
2021-04-29 21:17:54 +05:30
await this.setActiveItemSubscribed({
subscribed: !this.activeBoardItem.subscribed,
2021-01-29 00:20:46 +05:30
projectPath: this.projectPathForActiveIssue,
});
} catch (error) {
2021-09-04 01:27:46 +05:30
this.setError({ error, message: this.$options.i18n.updateSubscribedErrorMessage });
2021-01-29 00:20:46 +05:30
} finally {
this.loading = false;
}
},
},
};
</script>
<template>
<div
class="gl-display-flex gl-align-items-center gl-justify-content-space-between"
data-testid="sidebar-notifications"
>
<span data-testid="notification-header-text"> {{ notificationText }} </span>
<gl-toggle
2021-04-29 21:17:54 +05:30
v-if="!isEmailsDisabled"
:value="activeBoardItem.subscribed"
2021-01-29 00:20:46 +05:30
:is-loading="loading"
2021-04-17 20:07:23 +05:30
:label="$options.i18n.header.title"
label-position="hidden"
2021-01-29 00:20:46 +05:30
data-testid="notification-subscribe-toggle"
@change="handleToggleSubscription"
/>
</div>
</template>