From cb91b0514ad1f23b12ee764a1839becbc7084962 Mon Sep 17 00:00:00 2001 From: mahula Date: Thu, 28 Jul 2022 15:07:41 +0200 Subject: [PATCH] add mixins --- frontend/src/mixins/copyLinks.js | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 frontend/src/mixins/copyLinks.js diff --git a/frontend/src/mixins/copyLinks.js b/frontend/src/mixins/copyLinks.js new file mode 100644 index 000000000..415358c9b --- /dev/null +++ b/frontend/src/mixins/copyLinks.js @@ -0,0 +1,44 @@ +export const copyLinks = { + props: { + link: { type: String, required: true }, + amount: { type: String, required: true }, + memo: { type: String, required: true }, + validUntil: { type: String, required: true }, + }, + data() { + return { + canCopyLink: true, + } + }, + methods: { + copyLink() { + navigator.clipboard + .writeText(this.link) + .then(() => { + this.toastSuccess(this.$t('gdd_per_link.link-copied')) + }) + .catch(() => { + this.canCopyLink = false + this.toastError(this.$t('gdd_per_link.not-copied')) + }) + }, + copyLinkWithText() { + navigator.clipboard + .writeText( + `${this.link} +${this.$store.state.firstName} ${this.$t('transaction-link.send_you')} ${this.amount} Gradido. +"${this.memo}" +${this.$t('gdd_per_link.credit-your-gradido')} ${this.$t('gdd_per_link.validUntilDate', { + date: this.$d(new Date(this.validUntil), 'short'), + })}`, + ) + .then(() => { + this.toastSuccess(this.$t('gdd_per_link.link-and-text-copied')) + }) + .catch(() => { + this.canCopyLink = false + this.toastError(this.$t('gdd_per_link.not-copied')) + }) + }, + }, +}