Fix composable issue

This commit is contained in:
Julien Nahum 2024-01-11 17:16:50 +01:00
parent 5a3978874a
commit aa0b9ae02c
6 changed files with 117 additions and 196 deletions

View File

@ -20,7 +20,7 @@
{{ form.title }} {{ form.title }}
</h2> </h2>
<div class="flex"> <div class="flex">
<extra-menu :form="form" /> <extra-menu :form="form"/>
<v-button v-track.view_form_click="{form_id:form.id, form_slug:form.slug}" target="_blank" <v-button v-track.view_form_click="{form_id:form.id, form_slug:form.slug}" target="_blank"
:href="form.share_url" color="white" :href="form.share_url" color="white"
@ -38,7 +38,7 @@
/> />
</svg> </svg>
</v-button> </v-button>
<v-button class="text-white" @click="openEdit"> <v-button class="text-white" :to="{name: 'forms-slug-edit', params: {slug: slug}}">
<svg class="inline mr-1 -mt-1" width="18" height="17" viewBox="0 0 18 17" fill="none" <svg class="inline mr-1 -mt-1" width="18" height="17" viewBox="0 0 18 17" fill="none"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
> >
@ -81,25 +81,25 @@
<p v-if="form.closes_at" class="text-yellow-500"> <p v-if="form.closes_at" class="text-yellow-500">
<span v-if="form.is_closed"> This form stopped accepting submissions on the {{ <span v-if="form.is_closed"> This form stopped accepting submissions on the {{
displayClosesDate displayClosesDate
}} </span> }} </span>
<span v-else> This form will stop accepting submissions on the {{ displayClosesDate }} </span> <span v-else> This form will stop accepting submissions on the {{ displayClosesDate }} </span>
</p> </p>
<p v-if="form.max_submissions_count > 0" class="text-yellow-500"> <p v-if="form.max_submissions_count > 0" class="text-yellow-500">
<span v-if="form.max_number_of_submissions_reached"> The form is now closed because it reached its limit of {{ <span v-if="form.max_number_of_submissions_reached"> The form is now closed because it reached its limit of {{
form.max_submissions_count form.max_submissions_count
}} submissions. </span> }} submissions. </span>
<span v-else> This form will stop accepting submissions after {{ form.max_submissions_count }} submissions. </span> <span v-else> This form will stop accepting submissions after {{ form.max_submissions_count }} submissions. </span>
</p> </p>
<form-cleanings class="mt-4" :form="form" /> <form-cleanings class="mt-4" :form="form"/>
<div class="border-b border-gray-200 dark:border-gray-700"> <div class="border-b border-gray-200 dark:border-gray-700">
<ul class="flex flex-wrap -mb-px text-sm font-medium text-center"> <ul class="flex flex-wrap -mb-px text-sm font-medium text-center">
<li v-for="(tab, i) in tabsList" :key="i+1" class="mr-6"> <li v-for="(tab, i) in tabsList" :key="i+1" class="mr-6">
<nuxt-link :to="{ name: tab.route }" <nuxt-link :to="{ name: tab.route }"
class="hover:no-underline inline-block py-4 rounded-t-lg border-b-2 text-gray-500 hover:text-gray-600" class="hover:no-underline inline-block py-4 rounded-t-lg border-b-2 text-gray-500 hover:text-gray-600"
active-class="text-blue-600 hover:text-blue-900 dark:text-blue-500 dark:hover:text-blue-500 border-blue-600 dark:border-blue-500" active-class="text-blue-600 hover:text-blue-900 dark:text-blue-500 dark:hover:text-blue-500 border-blue-600 dark:border-blue-500"
> >
{{ tab.name }} {{ tab.name }}
</nuxt-link> </nuxt-link>
@ -118,7 +118,7 @@
</div> </div>
</template> </template>
<div v-else-if="loading" class="text-center w-full p-5"> <div v-else-if="loading" class="text-center w-full p-5">
<Loader class="h-6 w-6 mx-auto" /> <Loader class="h-6 w-6 mx-auto"/>
</div> </div>
<div v-else class="text-center w-full p-5"> <div v-else class="text-center w-full p-5">
Form not found. Form not found.
@ -126,126 +126,74 @@
</div> </div>
</template> </template>
<script> <script setup>
import { computed } from 'vue' import {computed} from 'vue'
import ProTag from '~/components/global/ProTag.vue' import ProTag from '~/components/global/ProTag.vue'
import VButton from '~/components/global/VButton.vue' import VButton from '~/components/global/VButton.vue'
import ExtraMenu from '../../../components/pages/forms/show/ExtraMenu.vue' import ExtraMenu from '../../../components/pages/forms/show/ExtraMenu.vue'
import FormCleanings from '../../../components/pages/forms/show/FormCleanings.vue' import FormCleanings from '../../../components/pages/forms/show/FormCleanings.vue'
export default {
name: 'ShowForm',
components: {
VButton,
ProTag,
ExtraMenu,
FormCleanings
},
setup () { definePageMeta({
definePageMeta({ middleware: "auth"
middleware: "auth" })
}) useOpnSeoMeta({
useOpnSeoMeta({ title: 'Home'
title: 'Home' })
})
const authStore = useAuthStore() const authStore = useAuthStore()
const formsStore = useFormsStore() const formsStore = useFormsStore()
const workingFormStore = useWorkingFormStore() const workingFormStore = useWorkingFormStore()
const workspacesStore = useWorkspacesStore() const workspacesStore = useWorkspacesStore()
const route = useRoute()
if (!formsStore.getByKey(route.params.slug)) { const slug = useRoute().params.slug
formsStore.loadAll(useWorkspacesStore().currentId)
}
workingFormStore.set(null) // Reset old working form
return { const user = computed(() => authStore.user)
formsStore, const form = computed(() => formsStore.getByKey(slug))
workingFormStore, const workspace = computed(() => workspacesStore.getByKey(form?.value?.workspace_id))
workspacesStore, const loading = computed(() => formsStore.loading || workspacesStore.loading)
user: computed(() => authStore.user), const displayClosesDate = computed(() => {
formsLoading: computed(() => formsStore.loading), if (form.value && form.value.closes_at) {
workspacesLoading: computed(() => workspacesStore.loading) const dateObj = new Date(form.value.closes_at)
} return dateObj.getFullYear() + '-' +
}, String(dateObj.getMonth() + 1).padStart(2, '0') + '-' +
String(dateObj.getDate()).padStart(2, '0') + ' ' +
data () { String(dateObj.getHours()).padStart(2, '0') + ':' +
return { String(dateObj.getMinutes()).padStart(2, '0')
tabsList: [
{
name: 'Submissions',
route: 'forms-slug-show-submissions'
},
{
name: 'Analytics',
route: 'forms-slug-show-stats'
},
{
name: 'Share',
route: 'forms-slug-show-share'
}
]
}
},
computed: {
workingForm: {
get () {
return this.workingFormStore.content
},
/* We add a setter */
set (value) {
this.workingFormStore.set(value)
}
},
workspace () {
if (!this.form) return null
return this.workspacesStore.getByKey(this.form.workspace_id)
},
form () {
return this.formsStore.getByKey(this.$route.params.slug)
},
formEndpoint: () => '/api/open/forms/{id}',
loading () {
return this.formsLoading || this.workspacesLoading
},
displayClosesDate () {
if (this.form.closes_at) {
const dateObj = new Date(this.form.closes_at)
return dateObj.getFullYear() + '-' +
String(dateObj.getMonth() + 1).padStart(2, '0') + '-' +
String(dateObj.getDate()).padStart(2, '0') + ' ' +
String(dateObj.getHours()).padStart(2, '0') + ':' +
String(dateObj.getMinutes()).padStart(2, '0')
}
return ''
}
},
watch: {
form () {
this.workingForm = useForm(this.form)
}
},
mounted () {
if (this.form) {
this.workingForm = useForm(this.form)
}
},
methods: {
openCrisp () {
window.$crisp.push(['do', 'chat:show'])
window.$crisp.push(['do', 'chat:open'])
},
goBack () {
this.$router.push({ name: 'home' })
},
openEdit () {
this.$router.push({ name: 'forms-slug-edit', params: { slug: this.form.slug } })
}
} }
return ''
})
const tabsList = [
{
name: 'Submissions',
route: 'forms-slug-show-submissions'
},
{
name: 'Analytics',
route: 'forms-slug-show-stats'
},
{
name: 'Share',
route: 'forms-slug-show-share'
}
]
onMounted(() => {
workingFormStore.set(null) // Reset old working form
if (form.value) {
workingFormStore.set(form.value)
} else {
formsStore.loadAll(useWorkspacesStore().currentId)
}
})
watch(() => form?.value?.id, (id) => {
if (id) {
workingFormStore.set(form)
}
})
const goBack = () => {
useRouter().push({name: 'home'})
} }
</script> </script>

View File

@ -2,25 +2,25 @@
<div class="mb-20"> <div class="mb-20">
<div class="mb-6 pb-6 border-b w-full flex flex-col sm:flex-row gap-2"> <div class="mb-6 pb-6 border-b w-full flex flex-col sm:flex-row gap-2">
<regenerate-form-link class="sm:w-1/2 flex" :form="form" /> <regenerate-form-link class="sm:w-1/2 flex" :form="form"/>
<url-form-prefill class="sm:w-1/2" :form="form" :extra-query-param="shareUrlForQueryParams" /> <url-form-prefill class="sm:w-1/2" :form="form" :extra-query-param="shareUrlForQueryParams"/>
<embed-form-as-popup-modal class="sm:w-1/2 flex" :form="form" /> <embed-form-as-popup-modal class="sm:w-1/2 flex" :form="form"/>
</div> </div>
<share-link class="mt-4" :form="form" :extra-query-param="shareUrlForQueryParams" /> <share-link class="mt-4" :form="form" :extra-query-param="shareUrlForQueryParams"/>
<embed-code class="mt-6" :form="form" :extra-query-param="shareUrlForQueryParams" /> <embed-code class="mt-6" :form="form" :extra-query-param="shareUrlForQueryParams"/>
<form-qr-code class="mt-6" :form="form" :extra-query-param="shareUrlForQueryParams" /> <form-qr-code class="mt-6" :form="form" :extra-query-param="shareUrlForQueryParams"/>
<advanced-form-url-settings :form="form" v-model="shareFormConfig" /> <advanced-form-url-settings :form="form" v-model="shareFormConfig"/>
</div> </div>
</template> </template>
<script> <script setup>
import ShareLink from '../../../../components/pages/forms/show/ShareLink.vue' import ShareLink from '../../../../components/pages/forms/show/ShareLink.vue'
import EmbedCode from '../../../../components/pages/forms/show/EmbedCode.vue' import EmbedCode from '../../../../components/pages/forms/show/EmbedCode.vue'
import FormQrCode from '../../../../components/pages/forms/show/FormQrCode.vue' import FormQrCode from '../../../../components/pages/forms/show/FormQrCode.vue'
@ -29,47 +29,28 @@ import RegenerateFormLink from '../../../../components/pages/forms/show/Regenera
import AdvancedFormUrlSettings from '../../../../components/open/forms/components/AdvancedFormUrlSettings.vue' import AdvancedFormUrlSettings from '../../../../components/open/forms/components/AdvancedFormUrlSettings.vue'
import EmbedFormAsPopupModal from '../../../../components/pages/forms/show/EmbedFormAsPopupModal.vue' import EmbedFormAsPopupModal from '../../../../components/pages/forms/show/EmbedFormAsPopupModal.vue'
export default { const props = {form: {type: Object, required: true}}
components: {
ShareLink,
EmbedCode,
FormQrCode,
UrlFormPrefill,
RegenerateFormLink,
AdvancedFormUrlSettings,
EmbedFormAsPopupModal
},
props: { definePageMeta({
form: {type: Object, required: true}, middleware: "auth"
}, })
useOpnSeoMeta({
title: (props.form) ? 'Share Form - ' + props.form.title : 'Share Form'
})
setup (props) {
definePageMeta({
middleware: "auth"
})
useOpnSeoMeta({
title: (props.form) ? 'Share Form - '+props.form.title : 'Share Form'
})
},
data: () => ({ const shareFormConfig = ref({
shareFormConfig: { hide_title: false,
hide_title: false, auto_submit: false
auto_submit: false })
const shareUrlForQueryParams = computed(() => {
let queryStr = ''
for (const [key, value] of Object.entries(shareFormConfig.value)) {
if (value && value !== 'false' && value !== false) {
queryStr += '&' + encodeURIComponent(key) + "=" + encodeURIComponent(value)
} }
}), }
return queryStr.slice(1)
computed: { })
shareUrlForQueryParams () {
let queryStr = ''
for (const [key, value] of Object.entries(this.shareFormConfig)) {
if(value && value !== 'false' && value !== false){
queryStr += '&' + encodeURIComponent(key) + "=" + encodeURIComponent(value)
}
}
return queryStr.slice(1)
}
},
}
</script> </script>

View File

@ -4,32 +4,18 @@
</div> </div>
</template> </template>
<script> <script setup>
import FormSubmissions from '../../../../components/open/forms/components/FormSubmissions.vue' import FormSubmissions from '../../../../components/open/forms/components/FormSubmissions.vue'
export default { const props = {
components: {FormSubmissions}, form: {type: Object, required: true}
props: {
form: {type: Object, required: true}
},
setup (props) {
definePageMeta({
middleware: "auth"
})
useOpnSeoMeta({
title: (props.form) ? 'Form Submissions - '+props.form.title : 'Form Submissions'
})
},
data: () => ({}),
mounted() {
},
computed: {
},
methods: {}
} }
definePageMeta({
middleware: "auth"
})
useOpnSeoMeta({
title: (props.form) ? 'Form Submissions - ' + props.form.title : 'Form Submissions'
})
</script> </script>

View File

@ -19,6 +19,9 @@ import {computed} from "vue";
useOpnSeoMeta({ useOpnSeoMeta({
title: 'Privacy Policy' title: 'Privacy Policy'
}) })
defineRouteRules({
swr: 3600
})
const notionPageStore = useNotionPagesStore() const notionPageStore = useNotionPagesStore()
await notionPageStore.load('9c97349ceda7455aab9b341d1ff70f79') await notionPageStore.load('9c97349ceda7455aab9b341d1ff70f79')

View File

@ -19,6 +19,9 @@ import {computed} from "vue";
useOpnSeoMeta({ useOpnSeoMeta({
title: 'Terms & Conditions' title: 'Terms & Conditions'
}) })
defineRouteRules({
swr: 3600
})
const notionPageStore = useNotionPagesStore() const notionPageStore = useNotionPagesStore()
await notionPageStore.load('246420da2834480ca04047b0c5a00929') await notionPageStore.load('246420da2834480ca04047b0c5a00929')

View File

@ -9,8 +9,8 @@ export const useNotionPagesStore = defineStore('notion_pages', () => {
contentStore.startLoading() contentStore.startLoading()
const apiUrl = opnformConfig.notion.worker const apiUrl = opnformConfig.notion.worker
return useOpnApi(`${apiUrl}/page/${pageId}`) return useFetch(`${apiUrl}/page/${pageId}`)
.then(({data})=> { .then(({data, error})=> {
const val = data.value const val = data.value
val['id'] = pageId val['id'] = pageId
contentStore.save(val) contentStore.save(val)