opnform/client/pages/forms/create/guest.vue

106 lines
3.0 KiB
Vue
Raw Permalink Normal View History

2023-12-09 14:47:03 +00:00
<template>
<div class="flex flex-wrap flex-col">
<transition v-if="stateReady" name="fade" mode="out-in">
<div key="2">
<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"
@openRegister="registerModal=true"
2023-12-09 14:47:03 +00:00
/>
<div v-else class="text-center mt-4 py-6">
<Loader class="h-6 w-6 text-nt-blue mx-auto"/>
2023-12-09 14:47:03 +00:00
</div>
</div>
</transition>
<quick-register :show-register-modal="registerModal" @close="registerModal=false" @reopen="registerModal=true"
@afterLogin="afterLogin"
/>
</div>
</template>
<script setup>
import FormEditor from "~/components/open/forms/components/FormEditor.vue"
2023-12-09 14:47:03 +00:00
import QuickRegister from '~/components/pages/auth/components/QuickRegister.vue'
2023-12-09 16:02:23 +00:00
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 14:47:03 +00:00
const templatesStore = useTemplatesStore()
const workingFormStore = useWorkingFormStore()
const workspacesStore = useWorkspacesStore()
const route = useRoute()
// Fetch the template
if (route.query.template !== undefined && route.query.template) {
const {data} = await fetchTemplate(route.query.template)
templatesStore.save(data.value)
}
2023-12-09 14:47:03 +00:00
// Store values
const workspace = computed(() => workspacesStore.getCurrent)
const workspacesLoading = computed(() => workspacesStore.loading)
const form = storeToRefs(workingFormStore).content
2023-12-09 14:47:03 +00:00
useOpnSeoMeta({
title: 'Create a new Form for free',
})
definePageMeta({
middleware: "guest"
})
// Data
const stateReady = ref(false)
const loading = ref(false)
const error = ref('')
const registerModal = ref(false)
const isGuest = ref(true)
const showInitialFormModal = ref(false)
2023-12-09 14:47:03 +00:00
// Component ref
const editor = ref(null)
2023-12-09 14:47:03 +00:00
onMounted(() => {
// Set as guest user
workspacesStore.set([{
id: null,
name: 'Guest Workspace',
is_enterprise: false,
is_pro: false
}])
2023-12-09 14:47:03 +00:00
form.value = initForm({}, true)
if (route.query.template !== undefined && route.query.template) {
const template = templatesStore.getByKey(route.query.template)
if (template && template.structure) {
form.value = useForm({...form.value.data(), ...template.structure})
2023-12-09 14:47:03 +00:00
}
} else {
// No template loaded, ask how to start
showInitialFormModal.value = true
}
stateReady.value = true
})
2023-12-09 14:47:03 +00:00
const afterLogin = () => {
registerModal.value = false
isGuest.value = false
fetchAllWorkspaces()
setTimeout(() => {
if (editor) {
editor.value.saveFormCreate()
2023-12-09 14:47:03 +00:00
}
}, 500)
}
2023-12-09 14:47:03 +00:00
const formGenerated = (newForm) => {
form.value = useForm({...form.value.data(), ...newForm})
2023-12-09 14:47:03 +00:00
}
</script>