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

97 lines
2.9 KiB
Vue
Raw 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 {loadAllTemplates} from "~/stores/templates.js";
import {fetchAllWorkspaces} from "~/stores/workspaces.js";
2023-12-09 14:47:03 +00:00
// middleware: 'guest',
2023-12-09 14:47:03 +00:00
const templatesStore = useTemplatesStore()
const workingFormStore = useWorkingFormStore()
const workspacesStore = useWorkspacesStore()
const route = useRoute()
loadAllTemplates(templatesStore)
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
// metaTitle: 'Create a new Form as 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()
if (route.query.template !== undefined && route.query.template) {
const template = this.templatesStore.getByKey(route.query.template)
if (template && template.structure) {
form.value = useForm({...this.form.data(), ...template.structure})
2023-12-09 14:47:03 +00:00
}
} else {
// No template loaded, ask how to start
showInitialFormModal.value = true
}
// this.closeAlert()
stateReady.value = true
})
2023-12-09 14:47:03 +00:00
const afterLogin = () => {
registerModal.value = false
isGuest.value = false
fetchAllWorkspaces()
setTimeout(() => {
if (editor) {
editor.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>