Welcome to mirror list, hosted at ThFree Co, Russian Federation.

board_sidebar_subscription.vue « sidebar « components « boards « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 376985f7cb6c9b204833189fce89ec2a12595373 (plain)
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
<script>
import { GlToggle } from '@gitlab/ui';
import { mapGetters, mapActions } from 'vuex';
import createFlash from '~/flash';
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__(
      'IssueBoards|An error occurred while setting notifications status. Please try again.',
    ),
  },
  components: {
    GlToggle,
  },
  inject: ['emailsDisabled'],
  data() {
    return {
      loading: false,
    };
  },
  computed: {
    ...mapGetters(['activeBoardItem', 'projectPathForActiveIssue', 'isEpicBoard']),
    isEmailsDisabled() {
      return this.isEpicBoard ? this.emailsDisabled : this.activeBoardItem.emailsDisabled;
    },
    notificationText() {
      return this.isEmailsDisabled
        ? this.$options.i18n.header.subscribeDisabledDescription
        : this.$options.i18n.header.title;
    },
  },
  methods: {
    ...mapActions(['setActiveItemSubscribed']),
    async handleToggleSubscription() {
      this.loading = true;

      try {
        await this.setActiveItemSubscribed({
          subscribed: !this.activeBoardItem.subscribed,
          projectPath: this.projectPathForActiveIssue,
        });
      } catch (error) {
        createFlash({ message: this.$options.i18n.updateSubscribedErrorMessage });
      } 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
      v-if="!isEmailsDisabled"
      :value="activeBoardItem.subscribed"
      :is-loading="loading"
      :label="$options.i18n.header.title"
      label-position="hidden"
      data-testid="notification-subscribe-toggle"
      @change="handleToggleSubscription"
    />
  </div>
</template>