Add copy button to role ID in role permissions page's sidebar detail (#12706)

* refactor to useClipboard composable

* add copy button to role permissions page
This commit is contained in:
Azri Kahar
2022-04-14 05:56:29 +08:00
committed by GitHub
parent 360d5b64f5
commit 0dfbc65bad
6 changed files with 108 additions and 66 deletions

View File

@@ -80,8 +80,8 @@ import { defineComponent, ref, computed } from 'vue';
import DrawerItem from '@/views/private/components/drawer-item';
import { getRootPath } from '@/utils/get-root-path';
import { unexpectedError } from '@/utils/unexpected-error';
import { notify } from '@/utils/notify';
import { Share } from '@directus/shared/types';
import useClipboard from '@/composables/use-clipboard';
import api from '@/api';
import ShareItem from './share-item.vue';
@@ -105,6 +105,8 @@ export default defineComponent({
setup(props) {
const { t } = useI18n();
const { copyToClipboard } = useClipboard();
const shares = ref<Share[] | null>(null);
const count = ref(0);
const error = ref(null);
@@ -168,17 +170,7 @@ export default defineComponent({
async function copy(id: string) {
const url = window.location.origin + getRootPath() + 'admin/shared/' + id;
try {
await navigator?.clipboard?.writeText(url);
notify({
title: t('share_copy_link_success'),
});
} catch (err: any) {
notify({
type: 'error',
title: t('share_copy_link_error'),
});
}
await copyToClipboard(url, { success: t('share_copy_link_success'), fail: t('share_copy_link_error') });
}
function select(id: string) {