Files
docuseal/app/javascript/submission_form/completed.vue
T

120 lines
2.8 KiB
Vue
Raw Normal View History

2023-05-25 22:47:52 +03:00
<template>
2023-06-16 23:39:55 +03:00
<div class="mx-auto max-w-md flex flex-col">
<p class="font-medium text-2xl flex items-center space-x-1.5 mx-auto">
<IconCircleCheck
class="inline text-green-600"
:width="30"
:height="30"
/>
2023-05-25 22:47:52 +03:00
<span>
2023-06-16 23:39:55 +03:00
Form has been completed!
2023-05-25 22:47:52 +03:00
</span>
2023-06-16 23:39:55 +03:00
</p>
<div class="space-y-3 mt-5">
<button
class="white-button flex items-center space-x-1 w-full"
:disabled="isSendingCopy"
@click.prevent="sendCopyToEmail"
>
<IconInnerShadowTop
v-if="isSendingCopy"
class="animate-spin"
/>
<IconMail v-else />
<span>
Send copy via email
</span>
</button>
<button
class="base-button flex items-center space-x-1 w-full"
:disabled="isDownloading"
@click.prevent="download"
>
<IconInnerShadowTop
v-if="isDownloading"
class="animate-spin"
/>
<IconDownload v-else />
<span>
Download
</span>
</button>
</div>
2023-05-25 22:47:52 +03:00
</div>
</template>
<script>
2023-06-16 23:39:55 +03:00
import { IconCircleCheck, IconMail, IconDownload, IconInnerShadowTop } from '@tabler/icons-vue'
import confetti from 'canvas-confetti'
2023-05-25 22:47:52 +03:00
export default {
name: 'FormCompleted',
2023-06-16 23:39:55 +03:00
components: {
IconCircleCheck,
IconInnerShadowTop,
IconMail,
IconDownload
},
2023-05-25 22:47:52 +03:00
props: {
2023-06-13 00:29:07 +03:00
submitterSlug: {
2023-05-25 22:47:52 +03:00
type: String,
required: true
}
},
data () {
return {
isSendingCopy: false,
isDownloading: false
}
},
2023-06-16 23:39:55 +03:00
mounted () {
confetti({
particleCount: 50,
startVelocity: 30,
spread: 140
})
},
2023-05-25 22:47:52 +03:00
methods: {
sendCopyToEmail () {
this.isSendingCopy = true
2023-06-13 00:29:07 +03:00
fetch(`/send_submission_email.json?submitter_slug=${this.submitterSlug}`, {
2023-05-25 22:47:52 +03:00
method: 'POST'
2023-06-16 23:39:55 +03:00
}).then(() => {
alert('Email has been sent')
2023-05-25 22:47:52 +03:00
}).finally(() => {
this.isSendingCopy = false
})
},
download () {
this.isDownloading = true
2023-06-16 23:39:55 +03:00
fetch(`/submitters/${this.submitterSlug}/download`).then((response) => response.json()).then((urls) => {
2023-06-22 01:31:39 +03:00
const fileRequests = urls.map((url) => {
return () => {
return fetch(url).then(async (resp) => {
const blobUrl = URL.createObjectURL(await resp.blob())
const link = document.createElement('a')
2023-05-25 22:47:52 +03:00
2023-06-22 01:31:39 +03:00
link.href = blobUrl
link.setAttribute('download', decodeURI(resp.headers.get('content-disposition').split('"')[1]))
2023-05-25 22:47:52 +03:00
2023-06-22 01:31:39 +03:00
link.click()
2023-05-25 22:47:52 +03:00
2023-06-22 01:31:39 +03:00
URL.revokeObjectURL(url)
})
}
2023-06-16 23:39:55 +03:00
})
2023-06-22 01:31:39 +03:00
fileRequests.reduce(
(prevPromise, request) => prevPromise.then(() => request()),
Promise.resolve()
)
2023-05-25 22:47:52 +03:00
this.isDownloading = false
})
}
}
}
</script>