2022-11-16 10:56:49 +00:00
|
|
|
<template>
|
|
|
|
<div class="flex flex-wrap flex-col">
|
|
|
|
<transition v-if="stateReady" name="fade" mode="out-in">
|
|
|
|
<div key="2">
|
2023-03-27 13:38:45 +00:00
|
|
|
<create-form-base-modal @form-generated="formGenerated" :show="showInitialFormModal"
|
|
|
|
@close="showInitialFormModal=false"/>
|
2022-11-16 10:56:49 +00:00
|
|
|
<form-editor v-if="!workspacesLoading" ref="editor"
|
|
|
|
class="w-full flex flex-grow"
|
2023-09-05 14:25:33 +00:00
|
|
|
:error="error"
|
2022-11-16 10:56:49 +00:00
|
|
|
:isGuest="isGuest"
|
|
|
|
@openRegister="openRegister"
|
|
|
|
/>
|
|
|
|
<div v-else class="text-center mt-4 py-6">
|
|
|
|
<loader class="h-6 w-6 text-nt-blue mx-auto"/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
|
|
|
|
<quick-register :showRegisterModal="registerModal" @close="registerModal=false" @reopen="registerModal=true"
|
|
|
|
@afterLogin="afterLogin"/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import store from '~/store'
|
|
|
|
import Form from 'vform'
|
|
|
|
import {mapState, mapActions} from 'vuex'
|
2023-01-21 11:57:37 +00:00
|
|
|
import QuickRegister from '../auth/components/QuickRegister.vue'
|
|
|
|
import initForm from "../../mixins/form_editor/initForm.js"
|
|
|
|
import SeoMeta from '../../mixins/seo-meta.js'
|
2023-03-27 13:38:45 +00:00
|
|
|
import CreateFormBaseModal from "../../components/pages/forms/create/CreateFormBaseModal.vue"
|
2022-11-16 10:56:49 +00:00
|
|
|
|
|
|
|
const loadTemplates = function () {
|
|
|
|
store.commit('open/templates/startLoading')
|
|
|
|
store.dispatch('open/templates/loadIfEmpty').then(() => {
|
|
|
|
store.commit('open/templates/stopLoading')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'CreateFormGuest',
|
2022-12-22 10:55:17 +00:00
|
|
|
mixins: [initForm, SeoMeta],
|
2022-11-16 10:56:49 +00:00
|
|
|
components: {
|
2023-03-27 13:38:45 +00:00
|
|
|
QuickRegister, CreateFormBaseModal
|
2022-11-16 10:56:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
middleware: 'guest',
|
|
|
|
|
|
|
|
beforeRouteEnter(to, from, next) {
|
|
|
|
loadTemplates()
|
|
|
|
next()
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2022-12-22 10:55:17 +00:00
|
|
|
metaTitle: 'Create a new Form as Guest',
|
2022-11-16 10:56:49 +00:00
|
|
|
stateReady: false,
|
|
|
|
loading: false,
|
|
|
|
error: '',
|
|
|
|
registerModal: false,
|
2023-03-27 13:38:45 +00:00
|
|
|
isGuest: true,
|
|
|
|
showInitialFormModal: false
|
2022-11-16 10:56:49 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
|
|
|
workspaces: state => state['open/workspaces'].content,
|
|
|
|
workspacesLoading: state => state['open/workspaces'].loading,
|
|
|
|
}),
|
|
|
|
form: {
|
|
|
|
get() {
|
|
|
|
return this.$store.state['open/working_form'].content
|
|
|
|
},
|
|
|
|
/* We add a setter */
|
|
|
|
set(value) {
|
|
|
|
this.$store.commit('open/working_form/set', value)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
workspace() {
|
|
|
|
return this.$store.getters['open/workspaces/getCurrent']()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
workspace() {
|
|
|
|
if (this.workspace) {
|
|
|
|
this.form.workspace_id = this.workspace.id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
// Set as guest user
|
|
|
|
const guestWorkspace = {
|
|
|
|
id: null,
|
|
|
|
name: "Guest Workspace",
|
|
|
|
is_enterprise: false,
|
|
|
|
is_pro: false
|
|
|
|
}
|
|
|
|
this.$store.commit('open/workspaces/set', [guestWorkspace])
|
|
|
|
this.$store.commit('open/workspaces/setCurrentId', guestWorkspace.id)
|
|
|
|
|
|
|
|
this.initForm()
|
|
|
|
if (this.$route.query.template !== undefined && this.$route.query.template) {
|
|
|
|
const template = this.$store.getters['open/templates/getBySlug'](this.$route.query.template)
|
|
|
|
if (template && template.structure) {
|
|
|
|
this.form = new Form({...this.form.data(), ...template.structure})
|
|
|
|
}
|
2023-03-27 13:38:45 +00:00
|
|
|
} else {
|
|
|
|
// No template loaded, ask how to start
|
|
|
|
this.showInitialFormModal = true
|
2022-11-16 10:56:49 +00:00
|
|
|
}
|
|
|
|
this.closeAlert()
|
|
|
|
this.stateReady = true
|
|
|
|
},
|
|
|
|
|
2023-09-05 14:25:33 +00:00
|
|
|
created() {},
|
|
|
|
destroyed() {},
|
2022-11-16 10:56:49 +00:00
|
|
|
|
|
|
|
methods: {
|
|
|
|
...mapActions({
|
|
|
|
loadWorkspaces: 'open/workspaces/load'
|
|
|
|
}),
|
|
|
|
openRegister() {
|
|
|
|
this.registerModal = true
|
|
|
|
},
|
|
|
|
afterLogin() {
|
|
|
|
this.registerModal = false
|
|
|
|
this.isGuest = false
|
|
|
|
this.loadWorkspaces()
|
|
|
|
setTimeout(() => {
|
2023-10-08 16:49:33 +00:00
|
|
|
if (this.$refs.editor) {
|
|
|
|
this.$refs.editor.saveFormCreate()
|
|
|
|
}
|
2022-11-16 10:56:49 +00:00
|
|
|
}, 500)
|
2023-03-27 13:38:45 +00:00
|
|
|
},
|
|
|
|
formGenerated(form) {
|
|
|
|
this.form = new Form({...this.form.data(), ...form})
|
2022-11-16 10:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|