2023-12-24 19:19:59 +00:00
|
|
|
<template>
|
|
|
|
<div class="flex flex-col">
|
|
|
|
<div v-if="form && !isIframe && (form.logo_picture || form.cover_picture)">
|
|
|
|
<div v-if="form.cover_picture">
|
|
|
|
<div id="cover-picture" class="max-h-56 w-full overflow-hidden flex items-center justify-center">
|
2024-01-10 15:17:47 +00:00
|
|
|
<img alt="Form Cover Picture" :src="form.cover_picture" class="w-full"/>
|
2023-12-24 19:19:59 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-if="form.logo_picture" class="w-full p-5 relative mx-auto"
|
|
|
|
:class="{'pt-20':!form.cover_picture, 'md:w-3/5 lg:w-1/2 md:max-w-2xl': form.width === 'centered', 'max-w-7xl': (form.width === 'full' && !isIframe) }"
|
|
|
|
>
|
2024-01-10 15:17:47 +00:00
|
|
|
<img alt="Logo Picture" :src="form.logo_picture"
|
2023-12-24 19:19:59 +00:00
|
|
|
:class="{'top-5':!form.cover_picture, '-top-10':form.cover_picture}"
|
|
|
|
class="w-20 h-20 object-contain absolute left-5 transition-all"
|
2024-01-05 10:41:49 +00:00
|
|
|
/>
|
2023-12-24 19:19:59 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="w-full mx-auto px-4"
|
|
|
|
:class="{'mt-6':!isIframe, 'md:w-3/5 lg:w-1/2 md:max-w-2xl': form && (form.width === 'centered'), 'max-w-7xl': (form && form.width === 'full' && !isIframe)}"
|
|
|
|
>
|
|
|
|
<div v-if="!formLoading && !form">
|
|
|
|
<h1 class="mt-6" v-text="'Whoops'"/>
|
|
|
|
<p class="mt-6">
|
2024-01-16 10:46:03 +00:00
|
|
|
Unfortunately we could not find this form. It may have been deleted.
|
2023-12-24 19:19:59 +00:00
|
|
|
</p>
|
|
|
|
<p class="mb-10 mt-4">
|
|
|
|
<router-link :to="{name:'index'}">
|
|
|
|
Create your form for free with OpnForm
|
|
|
|
</router-link>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div v-else-if="formLoading">
|
|
|
|
<p class="text-center mt-6 p-4">
|
|
|
|
<loader class="h-6 w-6 text-nt-blue mx-auto"/>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<template v-else>
|
|
|
|
<div v-if="recordLoading">
|
|
|
|
<p class="text-center mt-6 p-4">
|
|
|
|
<loader class="h-6 w-6 text-nt-blue mx-auto"/>
|
|
|
|
</p>
|
|
|
|
</div>
|
2024-01-16 12:27:54 +00:00
|
|
|
<open-complete-form v-show="!recordLoading" ref="openCompleteForm" :form="form" class="mb-10"
|
2023-12-24 19:19:59 +00:00
|
|
|
@password-entered="passwordEntered"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
import {computed} from 'vue'
|
|
|
|
import OpenCompleteForm from '../../components/open/forms/OpenCompleteForm.vue'
|
|
|
|
import sha256 from 'js-sha256'
|
|
|
|
import {onBeforeRouteLeave} from 'vue-router'
|
|
|
|
import {disableDarkMode, handleDarkMode, handleTransparentMode, focusOnFirstFormElement} from '~/lib/forms/public-page'
|
|
|
|
|
|
|
|
const crisp = useCrisp()
|
|
|
|
const formsStore = useFormsStore()
|
|
|
|
const recordsStore = useRecordsStore()
|
|
|
|
|
|
|
|
const isIframe = useIsIframe()
|
|
|
|
const formLoading = computed(() => formsStore.loading)
|
|
|
|
const recordLoading = computed(() => recordsStore.loading)
|
|
|
|
const slug = useRoute().params.slug
|
|
|
|
const form = computed(() => formsStore.getByKey(slug))
|
|
|
|
const submitted = ref(false)
|
|
|
|
|
2024-01-16 12:27:54 +00:00
|
|
|
const openCompleteForm = ref(null)
|
|
|
|
|
2023-12-24 19:19:59 +00:00
|
|
|
crisp.hideChat()
|
|
|
|
onBeforeRouteLeave((to, from) => {
|
|
|
|
crisp.showChat()
|
|
|
|
disableDarkMode()
|
|
|
|
})
|
|
|
|
|
|
|
|
const passwordEntered = function (password) {
|
|
|
|
useCookie('password-' + slug, {
|
2024-01-16 12:27:54 +00:00
|
|
|
maxAge: 60 * 60 * 7,
|
2023-12-24 19:19:59 +00:00
|
|
|
sameSite: false,
|
|
|
|
secure: true
|
|
|
|
}).value = sha256(password)
|
2024-01-16 12:27:54 +00:00
|
|
|
loadForm().then(() => {
|
2023-12-24 19:19:59 +00:00
|
|
|
if (form.value?.is_password_protected) {
|
2024-01-16 12:27:54 +00:00
|
|
|
openCompleteForm.value.addPasswordError('Invalid password.')
|
2023-12-24 19:19:59 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-01-16 12:27:54 +00:00
|
|
|
const loadForm = async (setup=false) => {
|
|
|
|
if (formsStore.loading || (form.value && !form.value.is_password_protected)) return Promise.resolve()
|
|
|
|
|
|
|
|
if (setup) {
|
|
|
|
const {data, error} = await formsStore.publicLoad(slug)
|
|
|
|
if (error.value) {
|
|
|
|
formsStore.stopLoading()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
formsStore.save(data.value)
|
|
|
|
} else {
|
|
|
|
const data = await formsStore.publicFetch(slug)
|
|
|
|
formsStore.save(data)
|
2023-12-24 19:19:59 +00:00
|
|
|
}
|
|
|
|
formsStore.stopLoading()
|
|
|
|
|
|
|
|
// Adapt page to form: colors, custom code etc
|
2024-01-16 14:00:22 +00:00
|
|
|
handleDarkMode(form.value.dark_mode)
|
|
|
|
handleTransparentMode(form.value.transparent_background)
|
2023-12-24 19:19:59 +00:00
|
|
|
|
|
|
|
if (process.server) return
|
|
|
|
if (form.value.custom_code) {
|
|
|
|
const scriptEl = document.createRange().createContextualFragment(form.value.custom_code)
|
|
|
|
document.head.append(scriptEl)
|
|
|
|
}
|
|
|
|
if (!isIframe) focusOnFirstFormElement()
|
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(() => {
|
2024-01-16 12:27:54 +00:00
|
|
|
loadForm()
|
2024-01-16 14:00:22 +00:00
|
|
|
handleDarkMode(form.value.dark_mode)
|
|
|
|
handleTransparentMode(form.value.transparent_background)
|
2023-12-24 19:19:59 +00:00
|
|
|
})
|
|
|
|
|
2024-01-16 12:27:54 +00:00
|
|
|
await loadForm(true)
|
2023-12-24 19:19:59 +00:00
|
|
|
|
2024-01-04 17:38:50 +00:00
|
|
|
useOpnSeoMeta({
|
|
|
|
title: () => {
|
2024-01-16 10:46:03 +00:00
|
|
|
if (form && form.value?.is_pro && form.value.seo_meta.page_title) {
|
2024-01-04 17:38:50 +00:00
|
|
|
return form.value.seo_meta.page_title
|
|
|
|
}
|
|
|
|
return form.value ? form.value.title : 'Create beautiful forms'
|
|
|
|
},
|
2024-01-16 10:46:03 +00:00
|
|
|
description: () => {
|
|
|
|
if (form && form.value?.is_pro && form.value.seo_meta.page_description) {
|
2024-01-04 17:38:50 +00:00
|
|
|
return form.value.seo_meta.page_description
|
|
|
|
}
|
2024-01-16 10:46:03 +00:00
|
|
|
return (form && form.value?.description) ? form.value?.description.substring(0, 160) : null
|
2024-01-04 17:38:50 +00:00
|
|
|
},
|
2024-01-16 10:46:03 +00:00
|
|
|
ogImage: () => {
|
|
|
|
if (form && form.value?.is_pro && form.value.seo_meta.page_thumbnail) {
|
2024-01-04 17:38:50 +00:00
|
|
|
return form.value.seo_meta.page_thumbnail
|
|
|
|
}
|
2024-01-16 10:46:03 +00:00
|
|
|
return (form && form.value?.cover_picture) ? form.value?.cover_picture : null
|
2024-01-04 17:38:50 +00:00
|
|
|
},
|
2024-01-12 14:59:01 +00:00
|
|
|
robots: () => {
|
2024-01-16 10:46:03 +00:00
|
|
|
return (form && form.value?.can_be_indexed) ? null : 'noindex, nofollow'
|
2024-01-04 17:38:50 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
useHead({
|
|
|
|
titleTemplate: (titleChunk) => {
|
2024-01-13 18:57:39 +00:00
|
|
|
if (form && form.value?.is_pro && form.value?.seo_meta.page_title) {
|
2024-01-04 17:38:50 +00:00
|
|
|
// Disable template if custom SEO title
|
|
|
|
return titleChunk
|
|
|
|
}
|
|
|
|
return titleChunk ? `${titleChunk} - OpnForm` : 'OpnForm';
|
|
|
|
}
|
|
|
|
})
|
2023-12-24 19:19:59 +00:00
|
|
|
</script>
|