gradido/frontend/src/composables/useCopyLinks.js
MateuszMichalowski 76e5994441
fix(frontend): migration remaining fixes (#3356)
* fix(frontend): fix password update validation, cleanup code, fix pipe operator in i18n issue, fixes to redeem via code.

* fix(frontend): fix transaction links

* fix(frontend): revert changes in admin components file

* fix(frontend): linters fixes
2024-08-19 10:11:17 +02:00

54 lines
1.3 KiB
JavaScript

import { ref, computed } from 'vue'
import { useStore } from 'vuex'
import { useI18n } from 'vue-i18n'
import { useAppToast } from '@/composables/useToast'
export const useCopyLinks = ({ link, amount, memo, validUntil }) => {
const canCopyLink = ref(true)
const store = useStore()
const { toastSuccess, toastError } = useAppToast()
const { t, d } = useI18n()
const copyLink = () => {
navigator.clipboard
.writeText(link)
.then(() => {
toastSuccess(t('gdd_per_link.link-copied'))
})
.catch(() => {
canCopyLink.value = false
toastError(t('gdd_per_link.not-copied'))
})
}
const copyLinkWithText = () => {
navigator.clipboard
.writeText(linkText.value)
.then(() => {
toastSuccess(t('gdd_per_link.link-and-text-copied'))
})
.catch(() => {
canCopyLink.value = false
toastError(t('gdd_per_link.not-copied'))
})
}
const linkText = computed(() => {
return `${link}
${store.state.firstName} ${t('transaction-link.send_you')} ${amount} Gradido.
"${memo}"
${t('gdd_per_link.credit-your-gradido')} ${t('gdd_per_link.validUntilDate', {
date: d(new Date(validUntil), 'short'),
})}
${t('gdd_per_link.link-hint')}`
})
return {
canCopyLink,
copyLink,
copyLinkWithText,
linkText,
}
}