|
| 1 | +<!-- |
| 2 | + - SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors |
| 3 | + - SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | +--> |
| 5 | + |
| 6 | +<template> |
| 7 | + <NcActions :inline="3" force-name variant="tertiary"> |
| 8 | + <NcActionButton |
| 9 | + v-if="!invitationUrl" |
| 10 | + @click="createInvitationLink()"> |
| 11 | + <template #icon> |
| 12 | + <LinkPlus :size="20" /> |
| 13 | + </template> |
| 14 | + {{ t('contacts', 'Create link') }} |
| 15 | + </NcActionButton> |
| 16 | + <template v-else> |
| 17 | + <NcActionLink |
| 18 | + :href="invitationUrl" |
| 19 | + :icon="copyLinkIcon" |
| 20 | + @click.stop.prevent="copyToClipboard(invitationUrl)"> |
| 21 | + {{ copyButtonText }} |
| 22 | + </NcActionLink> |
| 23 | + |
| 24 | + <NcActionButton |
| 25 | + @click="confirm( |
| 26 | + t('contacts', 'This action will make it impossible to join the team using the current link. Do we really want to change the link?'), |
| 27 | + () => createInvitationLink(), |
| 28 | + )"> |
| 29 | + <template #icon> |
| 30 | + <Autorenew :size="20" /> |
| 31 | + </template> |
| 32 | + {{ t('contacts', 'Reset link') }} |
| 33 | + </NcActionButton> |
| 34 | + |
| 35 | + <NcActionButton |
| 36 | + @click="confirm( |
| 37 | + t('contacts', 'This action will make it impossible to join the team using the current link. Do we really want to delete the link?'), |
| 38 | + () => revokeInvitationLink(), |
| 39 | + )"> |
| 40 | + <template #icon> |
| 41 | + <LinkOff :size="20" /> |
| 42 | + </template> |
| 43 | + {{ t('contacts', 'Reject link') }} |
| 44 | + </NcActionButton> |
| 45 | + </template> |
| 46 | + </NcActions> |
| 47 | +</template> |
| 48 | + |
| 49 | +<script> |
| 50 | +import { generateUrl, getBaseUrl } from '@nextcloud/router' |
| 51 | +import { NcActionButton, NcActionLink, NcActions } from '@nextcloud/vue' |
| 52 | +import Autorenew from 'vue-material-design-icons/Autorenew.vue' |
| 53 | +import LinkOff from 'vue-material-design-icons/LinkOff.vue' |
| 54 | +import LinkPlus from 'vue-material-design-icons/LinkPlus.vue' |
| 55 | +import CopyToClipboardMixin from '../../../mixins/CopyToClipboardMixin.js' |
| 56 | +import Circle from '../../../models/circle.ts' |
| 57 | +
|
| 58 | +export default { |
| 59 | + name: 'InvitationLink', |
| 60 | + components: { |
| 61 | + LinkOff, |
| 62 | + Autorenew, |
| 63 | + LinkPlus, |
| 64 | + NcActions, |
| 65 | + NcActionLink, |
| 66 | + NcActionButton, |
| 67 | + }, |
| 68 | +
|
| 69 | + mixins: [CopyToClipboardMixin], |
| 70 | + props: { |
| 71 | + circle: { |
| 72 | + type: Circle, |
| 73 | + required: true, |
| 74 | + }, |
| 75 | + }, |
| 76 | +
|
| 77 | + computed: { |
| 78 | + invitationUrl() { |
| 79 | + if (!this.circle.invitationCode) { |
| 80 | + return null |
| 81 | + } |
| 82 | +
|
| 83 | + return getBaseUrl() + generateUrl( |
| 84 | + 'apps/contacts/join/{invitationCode}', |
| 85 | + { invitationCode: this.circle.invitationCode.match(/.{1,4}/g).join('-') }, |
| 86 | + ) |
| 87 | + }, |
| 88 | +
|
| 89 | + copyButtonText() { |
| 90 | + if (this.copied) { |
| 91 | + return this.copySuccess |
| 92 | + ? t('contacts', 'Copied') |
| 93 | + : t('contacts', 'Could not copy') |
| 94 | + } |
| 95 | + return t('contacts', 'Copy link') |
| 96 | + }, |
| 97 | + }, |
| 98 | +
|
| 99 | + methods: { |
| 100 | + async createInvitationLink() { |
| 101 | + const circleId = this.circle.id |
| 102 | + await this.$store.dispatch('createInvitationLink', { circleId }) |
| 103 | +
|
| 104 | + await this.copyToClipboard(this.invitationUrl) |
| 105 | + }, |
| 106 | +
|
| 107 | + async revokeInvitationLink() { |
| 108 | + const circleId = this.circle.id |
| 109 | + await this.$store.dispatch('revokeInvitationLink', { circleId }) |
| 110 | + }, |
| 111 | +
|
| 112 | + confirm(message, action) { |
| 113 | + if (window.confirm(message)) { |
| 114 | + action() |
| 115 | + } |
| 116 | + }, |
| 117 | + }, |
| 118 | +} |
| 119 | +</script> |
0 commit comments