2023-12-09 15:47:03 +01:00
|
|
|
<template>
|
2024-09-23 20:02:38 +02:00
|
|
|
<div class="flex flex-wrap flex-col flex-grow">
|
|
|
|
|
<create-form-base-modal
|
|
|
|
|
:show="showInitialFormModal"
|
|
|
|
|
@form-generated="formGenerated"
|
|
|
|
|
@close="showInitialFormModal = false"
|
|
|
|
|
/>
|
|
|
|
|
<form-editor
|
|
|
|
|
v-if="!workspacesLoading"
|
|
|
|
|
ref="editor"
|
|
|
|
|
class="w-full flex flex-grow"
|
|
|
|
|
:error="error"
|
|
|
|
|
:is-guest="isGuest"
|
|
|
|
|
@open-register="registerModal = true"
|
|
|
|
|
/>
|
|
|
|
|
<div
|
|
|
|
|
v-else
|
|
|
|
|
class="text-center mt-4 py-6"
|
|
|
|
|
>
|
|
|
|
|
<Loader class="h-6 w-6 text-nt-blue mx-auto" />
|
2024-04-15 19:39:03 +02:00
|
|
|
</div>
|
2024-09-23 20:02:38 +02:00
|
|
|
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2024-04-15 19:39:03 +02:00
|
|
|
<quick-register
|
|
|
|
|
:show-register-modal="registerModal"
|
|
|
|
|
@close="registerModal = false"
|
|
|
|
|
@reopen="registerModal = true"
|
|
|
|
|
@after-login="afterLogin"
|
2023-12-09 15:47:03 +01:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2023-12-25 19:57:00 +01:00
|
|
|
<script setup>
|
|
|
|
|
import FormEditor from "~/components/open/forms/components/FormEditor.vue"
|
2024-04-15 19:39:03 +02:00
|
|
|
import QuickRegister from "~/components/pages/auth/components/QuickRegister.vue"
|
|
|
|
|
import CreateFormBaseModal from "../../../components/pages/forms/create/CreateFormBaseModal.vue"
|
|
|
|
|
import { initForm } from "~/composables/forms/initForm.js"
|
|
|
|
|
import { fetchTemplate } from "~/stores/templates.js"
|
|
|
|
|
import { fetchAllWorkspaces } from "~/stores/workspaces.js"
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2023-12-25 19:57:00 +01:00
|
|
|
const templatesStore = useTemplatesStore()
|
|
|
|
|
const workingFormStore = useWorkingFormStore()
|
|
|
|
|
const workspacesStore = useWorkspacesStore()
|
|
|
|
|
const route = useRoute()
|
2024-01-03 11:30:48 +01:00
|
|
|
|
|
|
|
|
// Fetch the template
|
|
|
|
|
if (route.query.template !== undefined && route.query.template) {
|
2024-04-15 19:39:03 +02:00
|
|
|
const { data } = await fetchTemplate(route.query.template)
|
2024-01-03 11:30:48 +01:00
|
|
|
templatesStore.save(data.value)
|
|
|
|
|
}
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2023-12-25 19:57:00 +01:00
|
|
|
// Store values
|
|
|
|
|
const workspacesLoading = computed(() => workspacesStore.loading)
|
|
|
|
|
const form = storeToRefs(workingFormStore).content
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2024-01-04 18:38:50 +01:00
|
|
|
useOpnSeoMeta({
|
2024-04-15 19:39:03 +02:00
|
|
|
title: "Create a new Form for free",
|
2024-01-04 18:38:50 +01:00
|
|
|
})
|
2024-01-05 10:47:36 +01:00
|
|
|
definePageMeta({
|
2024-08-05 12:06:20 +02:00
|
|
|
middleware: ["guest", "self-hosted"],
|
2024-01-05 10:47:36 +01:00
|
|
|
})
|
2024-01-04 18:38:50 +01:00
|
|
|
|
2023-12-25 19:57:00 +01:00
|
|
|
// Data
|
|
|
|
|
const stateReady = ref(false)
|
2024-04-15 19:39:03 +02:00
|
|
|
const error = ref("")
|
2023-12-25 19:57:00 +01:00
|
|
|
const registerModal = ref(false)
|
|
|
|
|
const isGuest = ref(true)
|
|
|
|
|
const showInitialFormModal = ref(false)
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2023-12-25 19:57:00 +01:00
|
|
|
// Component ref
|
|
|
|
|
const editor = ref(null)
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2023-12-25 19:57:00 +01:00
|
|
|
onMounted(() => {
|
|
|
|
|
// Set as guest user
|
2024-04-15 19:39:03 +02:00
|
|
|
workspacesStore.set([
|
|
|
|
|
{
|
|
|
|
|
id: null,
|
|
|
|
|
name: "Guest Workspace",
|
|
|
|
|
is_enterprise: false,
|
|
|
|
|
is_pro: false,
|
|
|
|
|
},
|
|
|
|
|
])
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2024-02-01 18:21:30 +01:00
|
|
|
form.value = initForm({}, true)
|
2023-12-25 19:57:00 +01:00
|
|
|
if (route.query.template !== undefined && route.query.template) {
|
2024-01-03 11:30:48 +01:00
|
|
|
const template = templatesStore.getByKey(route.query.template)
|
2023-12-25 19:57:00 +01:00
|
|
|
if (template && template.structure) {
|
2024-04-15 19:39:03 +02:00
|
|
|
form.value = useForm({ ...form.value.data(), ...template.structure })
|
2023-12-09 15:47:03 +01:00
|
|
|
}
|
2023-12-25 19:57:00 +01:00
|
|
|
} else {
|
|
|
|
|
// No template loaded, ask how to start
|
|
|
|
|
showInitialFormModal.value = true
|
|
|
|
|
}
|
|
|
|
|
stateReady.value = true
|
|
|
|
|
})
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2023-12-25 19:57:00 +01:00
|
|
|
const afterLogin = () => {
|
|
|
|
|
registerModal.value = false
|
|
|
|
|
isGuest.value = false
|
|
|
|
|
fetchAllWorkspaces()
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if (editor) {
|
2024-01-03 11:30:48 +01:00
|
|
|
editor.value.saveFormCreate()
|
2023-12-09 15:47:03 +01:00
|
|
|
}
|
2023-12-25 19:57:00 +01:00
|
|
|
}, 500)
|
|
|
|
|
}
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2023-12-25 19:57:00 +01:00
|
|
|
const formGenerated = (newForm) => {
|
2024-04-15 19:39:03 +02:00
|
|
|
form.value = useForm({ ...form.value.data(), ...newForm })
|
2023-12-09 15:47:03 +01:00
|
|
|
}
|
|
|
|
|
</script>
|