Work in progress for form create guess user

This commit is contained in:
Julien Nahum 2023-12-25 19:57:00 +01:00
parent 5df3245543
commit b4365b5e30
4 changed files with 78 additions and 121 deletions

View File

@ -90,6 +90,7 @@ const closeOnEscape = (e) => {
onMounted(() => { onMounted(() => {
if (process.server) return if (process.server) return
document.addEventListener('keydown', closeOnEscape) document.addEventListener('keydown', closeOnEscape)
initMotions()
}) })
onBeforeUnmount(() => { onBeforeUnmount(() => {
@ -160,13 +161,15 @@ const content = ref(null)
const backdropMotion = ref(null) const backdropMotion = ref(null)
const contentMotion = ref(null) const contentMotion = ref(null)
watch(() => props.show, (newVal, oldVal) => { const initMotions = () => {
if (newVal) { if (props.show) {
nextTick(() => { nextTick(() => {
backdropMotion.value = useMotion(backdrop.value, motionFadeIn) backdropMotion.value = useMotion(backdrop.value, motionFadeIn)
contentMotion.value = useMotion(content.value, motionSlideBottom) contentMotion.value = useMotion(content.value, motionSlideBottom)
}) })
} }
}) }
watch(() => props.show, initMotions)
</script> </script>

View File

@ -61,6 +61,7 @@ export default {
setup () { setup () {
return { return {
authStore: useAuthStore(), authStore: useAuthStore(),
formsStore: useFormsStore(),
workspaceStore: useWorkspacesStore() workspaceStore: useWorkspacesStore()
} }
}, },
@ -88,6 +89,9 @@ export default {
const workspaces = await fetchAllWorkspaces() const workspaces = await fetchAllWorkspaces()
this.workspaceStore.set(workspaces.data.value) this.workspaceStore.set(workspaces.data.value)
// Load forms
this.formsStore.loadAll(this.workspaceStore.currentId)
// Redirect home. // Redirect home.
this.redirect() this.redirect()
}, },

View File

@ -1,5 +1,5 @@
<template> <template>
<modal :show="show" :closeable="!aiForm.busy" @close="$emit('close')"> <Modal :show="show" :closeable="!aiForm.busy" @close="$emit('close')">
<template #icon> <template #icon>
<template v-if="state=='default'"> <template v-if="state=='default'">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-10 h-10 text-blue"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-10 h-10 text-blue">
@ -87,7 +87,7 @@
~60 sec ~60 sec
</p> </p>
</div> </div>
</modal> </Modal>
</template> </template>
<script> <script>

View File

@ -9,7 +9,7 @@
class="w-full flex flex-grow" class="w-full flex flex-grow"
:error="error" :error="error"
:is-guest="isGuest" :is-guest="isGuest"
@openRegister="openRegister" @openRegister="registerModal=true"
/> />
<div v-else class="text-center mt-4 py-6"> <div v-else class="text-center mt-4 py-6">
<Loader class="h-6 w-6 text-nt-blue mx-auto"/> <Loader class="h-6 w-6 text-nt-blue mx-auto"/>
@ -23,124 +23,74 @@
</div> </div>
</template> </template>
<script> <script setup>
import {initForm} from "~/composables/forms/initForm.js" import FormEditor from "~/components/open/forms/components/FormEditor.vue"
import QuickRegister from '~/components/pages/auth/components/QuickRegister.vue' import QuickRegister from '~/components/pages/auth/components/QuickRegister.vue'
import CreateFormBaseModal from '../../../components/pages/forms/create/CreateFormBaseModal.vue' 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";
const loadTemplates = function () { // middleware: 'guest',
const templatesStore = useTemplatesStore()
templatesStore.startLoading()
templatesStore.loadIfEmpty().then(() => {
templatesStore.stopLoading()
})
}
export default {
name: 'CreateFormGuest',
components: {
QuickRegister, CreateFormBaseModal
},
middleware: 'guest',
beforeRouteEnter (to, from, next) {
loadTemplates()
next()
},
setup () {
const templatesStore = useTemplatesStore() const templatesStore = useTemplatesStore()
const workingFormStore = useWorkingFormStore() const workingFormStore = useWorkingFormStore()
const workspacesStore = useWorkspacesStore() const workspacesStore = useWorkspacesStore()
return { const route = useRoute()
templatesStore, loadAllTemplates(templatesStore)
workingFormStore,
workspacesStore,
workspaces : computed(() => workspacesStore.content),
workspacesLoading : computed(() => workspacesStore.loading)
}
},
data () { // Store values
return { const workspace = computed(() => workspacesStore.getCurrent)
metaTitle: 'Create a new Form as Guest', const workspacesLoading = computed(() => workspacesStore.loading)
stateReady: false, const form = storeToRefs(workingFormStore).content
loading: false,
error: '',
registerModal: false,
isGuest: true,
showInitialFormModal: false
}
},
computed: { // metaTitle: 'Create a new Form as Guest',
form: { // Data
get () { const stateReady = ref(false)
return this.workingFormStore.content const loading = ref(false)
}, const error = ref('')
/* We add a setter */ const registerModal = ref(false)
set (value) { const isGuest = ref(true)
this.workingFormStore.set(value) const showInitialFormModal = ref(false)
}
},
workspace () {
return this.workspacesStore.getCurrent()
}
},
watch: { // Component ref
workspace () { const editor = ref(null)
if (this.workspace) {
this.form.workspace_id = this.workspace.id
}
}
},
mounted () { onMounted(() => {
// Set as guest user // Set as guest user
const guestWorkspace = { workspacesStore.set([{
id: null, id: null,
name: 'Guest Workspace', name: 'Guest Workspace',
is_enterprise: false, is_enterprise: false,
is_pro: false is_pro: false
} }])
this.workspacesStore.set([guestWorkspace])
this.workspacesStore.setCurrentId(guestWorkspace.id)
this.form = initForm() form.value = initForm()
if (this.$route.query.template !== undefined && this.$route.query.template) { if (route.query.template !== undefined && route.query.template) {
const template = this.templatesStore.getByKey(this.$route.query.template) const template = this.templatesStore.getByKey(route.query.template)
if (template && template.structure) { if (template && template.structure) {
this.form = useForm({ ...this.form.data(), ...template.structure }) form.value = useForm({...this.form.data(), ...template.structure})
} }
} else { } else {
// No template loaded, ask how to start // No template loaded, ask how to start
this.showInitialFormModal = true showInitialFormModal.value = true
} }
this.closeAlert() // this.closeAlert()
this.stateReady = true stateReady.value = true
}, })
created () {}, const afterLogin = () => {
unmounted () {}, registerModal.value = false
isGuest.value = false
methods: { fetchAllWorkspaces()
openRegister () {
this.registerModal = true
},
afterLogin () {
this.registerModal = false
this.isGuest = false
this.workspacesStore.load()
setTimeout(() => { setTimeout(() => {
if (this.$refs.editor) { if (editor) {
this.$refs.editor.saveFormCreate() editor.saveFormCreate()
} }
}, 500) }, 500)
},
formGenerated (form) {
this.form = useForm({ ...this.form.data(), ...form })
}
} }
const formGenerated = (newForm) => {
form.value = useForm({...form.value.data(), ...newForm})
} }
</script> </script>