diff options
author | dartcafe <github@dartcafe.de> | 2021-02-27 13:10:48 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2021-02-27 13:10:48 +0300 |
commit | 985fa6e5ebc878b00c64cd371079e45a491d2b58 (patch) | |
tree | a9a56b8afb4c56e316fddea30073f7e0ed280c7a /src/js/components/Shares | |
parent | 7a05a361da2b5e0879e9e83dcb2f6d9fa3009671 (diff) |
use async/await
Signed-off-by: dartcafe <github@dartcafe.de>
Diffstat (limited to 'src/js/components/Shares')
-rw-r--r-- | src/js/components/Shares/SharesEffective.vue | 41 | ||||
-rw-r--r-- | src/js/components/Shares/SharesPublic.vue | 30 | ||||
-rw-r--r-- | src/js/components/Shares/SharesUnsent.vue | 50 |
3 files changed, 57 insertions, 64 deletions
diff --git a/src/js/components/Shares/SharesEffective.vue b/src/js/components/Shares/SharesEffective.vue index 6828df69..75de1595 100644 --- a/src/js/components/Shares/SharesEffective.vue +++ b/src/js/components/Shares/SharesEffective.vue @@ -77,31 +77,28 @@ export default { }, methods: { - sendInvitation(share) { - this.$store.dispatch('shares/sendInvitation', { share: share }) - .then((response) => { - if ('sentResult.sentMails' in response.data) { - response.data.sentResult.sentMails.forEach((item) => { - showSuccess(t('polls', 'Invitation sent to {name}', { name: item.displayName })) - }) - } - if ('sentResult.abortedMails' in response.data) { - response.data.sentResult.abortedMails.forEach((item) => { - console.error('Mail could not be sent!', { recipient: item }) - showError(t('polls', 'Error sending invitation to {name}', { name: item.dispalyName })) - }) - } + async sendInvitation(share) { + const response = await this.$store.dispatch('shares/sendInvitation', { share: share }) + if ('sentResult.sentMails' in response.data) { + response.data.sentResult.sentMails.forEach((item) => { + showSuccess(t('polls', 'Invitation sent to {name}', { name: item.displayName })) }) + } + if ('sentResult.abortedMails' in response.data) { + response.data.sentResult.abortedMails.forEach((item) => { + console.error('Mail could not be sent!', { recipient: item }) + showError(t('polls', 'Error sending invitation to {name}', { name: item.dispalyName })) + }) + } }, - copyLink(payload) { - this.$copyText(payload.url) - .then(() => { - showSuccess(t('polls', 'Link copied to clipboard')) - }) - .catch(() => { - showError(t('polls', 'Error while copying link to clipboard')) - }) + async copyLink(payload) { + try { + await this.$copyText(payload.url) + showSuccess(t('polls', 'Link copied to clipboard')) + } catch (e) { + showError(t('polls', 'Error while copying link to clipboard')) + } }, removeShare(share) { diff --git a/src/js/components/Shares/SharesPublic.vue b/src/js/components/Shares/SharesPublic.vue index 50dccfd0..496c828d 100644 --- a/src/js/components/Shares/SharesPublic.vue +++ b/src/js/components/Shares/SharesPublic.vue @@ -69,33 +69,31 @@ export default { }, methods: { - copyLink(payload) { - this - .$copyText(payload.url) - .then(() => { - showSuccess(t('polls', 'Link copied to clipboard')) - }) - .catch(() => { - showError(t('polls', 'Error while copying link to clipboard')) - }) + async copyLink(payload) { + try { + this.$copyText(payload.url) + showSuccess(t('polls', 'Link copied to clipboard')) + } catch (e) { + showError(t('polls', 'Error while copying link to clipboard')) + } }, removeShare(share) { this.$store.dispatch('shares/delete', { share: share }) }, - addShare(payload) { - this.$store - .dispatch('shares/add', { + async addShare(payload) { + try { + await this.$store.dispatch('shares/add', { share: payload, type: payload.type, id: payload.id, emailAddress: payload.emailAddress, }) - .catch(error => { - console.error('Error while adding share - Error: ', error) - showError(t('polls', 'Error while adding share')) - }) + } catch (e) { + console.error('Error while adding share - Error: ', e) + showError(t('polls', 'Error adding share')) + } }, }, } diff --git a/src/js/components/Shares/SharesUnsent.vue b/src/js/components/Shares/SharesUnsent.vue index e0db748d..5365be3b 100644 --- a/src/js/components/Shares/SharesUnsent.vue +++ b/src/js/components/Shares/SharesUnsent.vue @@ -73,35 +73,33 @@ export default { }, methods: { - resolveGroup(share) { - this.$store.dispatch('shares/resolveGroup', { share: share }) - .catch((error) => { - if (error.response.status === 409 && error.response.data === 'Circles is not enabled for this user') { - showError(t('polls', 'Resolving of {name} is not possible. The circles app is not enabled.', { name: share.displayName })) - } else if (error.response.status === 409 && error.response.data === 'Contacts is not enabled') { - showError(t('polls', 'Resolving of {name} is not possible. The contacts app is not enabled.', { name: share.displayName })) - } else { - showError(t('polls', 'Error resolving {name}.', { name: share.displayName })) - } - - }) + async resolveGroup(share) { + try { + await this.$store.dispatch('shares/resolveGroup', { share: share }) + } catch (e) { + if (e.response.status === 409 && e.response.data === 'Circles is not enabled for this user') { + showError(t('polls', 'Resolving of {name} is not possible. The circles app is not enabled.', { name: share.displayName })) + } else if (e.response.status === 409 && e.response.data === 'Contacts is not enabled') { + showError(t('polls', 'Resolving of {name} is not possible. The contacts app is not enabled.', { name: share.displayName })) + } else { + showError(t('polls', 'Error resolving {name}.', { name: share.displayName })) + } + } }, - sendInvitation(share) { - this.$store.dispatch('shares/sendInvitation', { share: share }) - .then((response) => { - if ('sentResult.sentMails' in response.data) { - response.data.sentResult.sentMails.forEach((item) => { - showSuccess(t('polls', 'Invitation sent to {name}', { name: item.displayName })) - }) - } - if ('sentResult.abortedMails' in response.data) { - response.data.sentResult.abortedMails.forEach((item) => { - console.error('Mail could not be sent!', { recipient: item }) - showError(t('polls', 'Error sending invitation to {name}', { name: item.dispalyName })) - }) - } + async sendInvitation(share) { + const response = await this.$store.dispatch('shares/sendInvitation', { share: share }) + if ('sentResult.sentMails' in response.data) { + response.data.sentResult.sentMails.forEach((item) => { + showSuccess(t('polls', 'Invitation sent to {name}', { name: item.displayName })) + }) + } + if ('sentResult.abortedMails' in response.data) { + response.data.sentResult.abortedMails.forEach((item) => { + console.error('Mail could not be sent!', { recipient: item }) + showError(t('polls', 'Error sending invitation to {name}', { name: item.dispalyName })) }) + } }, removeShare(share) { |