All files / app/assets/javascripts/issuable/components issuable_by_email.vue

81.81% Statements 9/11
0% Branches 0/2
75% Functions 3/4
90% Lines 9/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190                            6x                                                                                                                   18x             11x     11x     11x         3x     3x 1x   2x                                                                                                                                                                                          
<script>
import {
  GlButton,
  GlModal,
  GlModalDirective,
  GlTooltipDirective,
  GlSprintf,
  GlLink,
  GlFormInputGroup,
  GlIcon,
} from '@gitlab/ui';
import { TYPE_ISSUE } from '~/issues/constants';
import axios from '~/lib/utils/axios_utils';
import { sprintf, __ } from '~/locale';
import ModalCopyButton from '~/vue_shared/components/modal_copy_button.vue';
 
export default {
  i18n: {
    sendEmail: __('Send email'),
  },
  name: 'IssuableByEmail',
  components: {
    GlButton,
    GlModal,
    GlSprintf,
    GlLink,
    GlFormInputGroup,
    GlIcon,
    ModalCopyButton,
  },
  directives: {
    GlModal: GlModalDirective,
    GlTooltip: GlTooltipDirective,
  },
  inject: {
    initialEmail: {
      default: null,
    },
    issuableType: {
      default: TYPE_ISSUE,
    },
    emailsHelpPagePath: {
      default: '',
    },
    quickActionsHelpPath: {
      default: '',
    },
    markdownHelpPath: {
      default: '',
    },
    resetPath: {
      default: '',
    },
  },
  props: {
    buttonClass: {
      type: String,
      required: false,
      default: null,
    },
    variant: {
      type: String,
      required: false,
      default: 'link',
    },
    text: {
      type: String,
      required: false,
      default: __('Email a new %{name} to this project'),
    },
  },
  data() {
    return {
      email: this.initialEmail,
      issuableName: this.issuableType === TYPE_ISSUE ? __('issue') : __('merge request'),
    };
  },
  computed: {
    mailToLink() {
      const subject = sprintf(__('Enter the %{name} title'), {
        name: this.issuableName,
      });
      const body = sprintf(__('Enter the %{name} description'), {
        name: this.issuableName,
      });
      return `mailto:${this.email}?subject=${subject}&body=${body}`;
    },
  },
  methods: {
    async resetIncomingEmailToken() {
      try {
        const {
          data: { new_address: newAddress },
        } = await axios.put(this.resetPath);
        this.email = newAddress;
      } catch {
        this.$toast.show(__('There was an error when reseting email token.'));
      }
    },
    cancelHandler() {
      this.$refs.modal.hide();
    },
  },
  modalId: 'issuable-email-modal',
};
</script>
 
<template>
  <div>
    <gl-button v-gl-modal="$options.modalId" :class="buttonClass" :variant="variant"
      ><gl-sprintf :message="text"
        ><template #name>{{ issuableName }}</template></gl-sprintf
      ></gl-button
    >
    <gl-modal ref="modal" :modal-id="$options.modalId">
      <template #modal-title>
        <gl-sprintf :message="__('Create new %{name} by email')">
          <template #name>{{ issuableName }}</template>
        </gl-sprintf>
      </template>
      <p>
        <gl-sprintf
          :message="
            __(
              'You can create a new %{name} inside this project by sending an email to the following email address:',
            )
          "
        >
          <template #name>{{ issuableName }}</template>
        </gl-sprintf>
      </p>
      <gl-form-input-group :value="email" readonly select-on-click class="gl-mb-4">
        <template #append>
          <modal-copy-button :text="email" :title="__('Copy')" :modal-id="$options.modalId" />
          <gl-button
            v-gl-tooltip.hover
            :href="mailToLink"
            :title="$options.i18n.sendEmail"
            :aria-label="$options.i18n.sendEmail"
            icon="mail"
          />
        </template>
      </gl-form-input-group>
      <p>
        <gl-sprintf
          :message="
            __(
              'The subject will be used as the title of the new issue, and the message will be the description. %{quickActionsLinkStart}Quick actions%{quickActionsLinkEnd} and styling with %{markdownLinkStart}Markdown%{markdownLinkEnd} are supported.',
            )
          "
        >
          <template #quickActionsLink="{ content }">
            <gl-link :href="quickActionsHelpPath" target="_blank">{{ content }}</gl-link>
          </template>
          <template #markdownLink="{ content }">
            <gl-link :href="markdownHelpPath" target="_blank">{{ content }}</gl-link>
          </template>
        </gl-sprintf>
      </p>
      <p>
        <gl-sprintf
          :message="
            __(
              'This is a private email address %{helpIcon} generated just for you. Anyone who has it can create issues or merge requests as if they were you. If that happens, %{resetLinkStart}reset this token%{resetLinkEnd}.',
            )
          "
        >
          <template #helpIcon>
            <gl-link :href="emailsHelpPagePath" target="_blank">
              <gl-icon class="gl-text-blue-600" name="question-o" />
            </gl-link>
          </template>
          <template #resetLink="{ content }">
            <gl-button
              variant="link"
              data-testid="reset_email_token_link"
              @click="resetIncomingEmailToken"
            >
              {{ content }}
            </gl-button>
          </template>
        </gl-sprintf>
      </p>
      <template #modal-footer>
        <gl-button category="secondary" @click="cancelHandler">{{ __('Cancel') }}</gl-button>
      </template>
    </gl-modal>
  </div>
</template>