Templates pages migration (#275)

This commit is contained in:
formsdev 2024-01-05 15:30:34 +05:30 committed by GitHub
parent 04170ca9fb
commit 9c7d46b53b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 121 additions and 139 deletions

View File

@ -203,7 +203,7 @@ export default {
return !this.appStore.navbarHidden return !this.appStore.navbarHidden
}, },
userOnboarded() { userOnboarded() {
return this.user && this.user.workspaces_count > 0 return this.user && this.user.has_forms === true
}, },
hasCrisp() { hasCrisp() {
return this.config.crispWebsiteId return this.config.crispWebsiteId

View File

@ -1,5 +1,5 @@
<template> <template>
<modal :show="show" @close="$emit('close')"> <modal :show="show" @close="emit('close')">
<template #icon> <template #icon>
<svg class="w-10 h-10 text-blue" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg class="w-10 h-10 text-blue" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
<path <path
@ -57,11 +57,11 @@
</template> </template>
</v-button> </v-button>
<v-button v-if="template" color="red" class="mr-2" <v-button v-if="template" color="red" class="mr-2"
@click.prevent="alertConfirm('Do you really want to delete this template?', deleteFormTemplate)" @click.prevent="useAlert().confirm('Do you really want to delete this template?', deleteFormTemplate)"
> >
Delete Delete
</v-button> </v-button>
<v-button color="white" @click.prevent="$emit('close')"> <v-button color="white" @click.prevent="emit('close')">
Close Close
</v-button> </v-button>
</div> </div>
@ -71,38 +71,29 @@
</modal> </modal>
</template> </template>
<script> <script setup>
import { computed } from 'vue' import { ref, defineProps, defineEmits, computed } from 'vue'
import QuestionsEditor from './QuestionsEditor.vue' import QuestionsEditor from './QuestionsEditor.vue'
export default { const props = defineProps({
name: 'FormTemplateModal',
components: { QuestionsEditor },
props: {
show: { type: Boolean, required: true }, show: { type: Boolean, required: true },
form: { type: Object, required: true }, form: { type: Object, required: true },
template: { type: Object, required: false, default: () => {} } template: { type: Object, required: false, default: () => {} }
}, })
setup () {
const authStore = useAuthStore() const authStore = useAuthStore()
const templatesStore = useTemplatesStore() const templatesStore = useTemplatesStore()
return { const router = useRouter()
templatesStore, let user = computed(() => authStore.user)
user : computed(() => authStore.user), let templates = computed(() => [...templatesStore.content.values()])
templates : computed(() => templatesStore.content), let industries = computed(() => [...templatesStore.industries.values()])
industries : computed(() => templatesStore.industries), let types = computed(() => [...templatesStore.types.values()])
types : computed(() => templatesStore.types),
useAlert: useAlert()
}
},
data: () => ({ let templateForm = ref(null)
templateForm: null const emit = defineEmits(['close'])
}),
mounted () { onMounted(() => {
this.templateForm = useForm(this.template ?? { templateForm.value = useForm(props.template ?? {
publicly_listed: false, publicly_listed: false,
name: '', name: '',
slug: '', slug: '',
@ -114,75 +105,70 @@ export default {
related_templates: null, related_templates: null,
questions: [] questions: []
}) })
loadAllTemplates(this.templatesStore) loadAllTemplates(templatesStore)
}, })
computed: { let typesOptions = computed(() => {
typesOptions () { return Object.values(types.value).map((type) => {
return Object.values(this.types).map((type) => {
return { return {
name: type.name, name: type.name,
value: type.slug value: type.slug
} }
}) })
}, })
industriesOptions () { let industriesOptions = computed(() => {
return Object.values(this.industries).map((industry) => { return Object.values(industries.value).map((industry) => {
return { return {
name: industry.name, name: industry.name,
value: industry.slug value: industry.slug
} }
}) })
}, })
templatesOptions () { let templatesOptions = computed(() => {
return this.templates.map((template) => { return Object.values(templates.value).map((template) => {
return { return {
name: template.name, name: template.name,
value: template.slug value: template.slug
} }
}) })
} })
},
methods: { const onSubmit = () => {
onSubmit () { if (props.template) {
if (this.template) { updateFormTemplate()
this.updateFormTemplate()
} else { } else {
this.createFormTemplate() createFormTemplate()
} }
},
async createFormTemplate () {
this.templateForm.form = this.form
await this.templateForm.post('/api/templates').then((response) => {
if (response.data.message) {
this.useAlert.success(response.data.message)
} }
this.templatesStore.save(response.data.data) const createFormTemplate = async () => {
this.$emit('close') templateForm.value.form = props.form
}) await templateForm.value.post('/templates').then((data) => {
},
async updateFormTemplate () {
this.templateForm.form = this.form
await this.templateForm.put('/api/templates/' + this.template.id).then((response) => {
if (response.data.message) {
this.useAlert.success(response.data.message)
}
this.templatesStore.save(response.data.data)
this.$emit('close')
})
},
async deleteFormTemplate () {
if (!this.template) return
opnFetch('/templates/' + this.template.id, {method:'DELETE'}).then((data) => {
if (data.message) { if (data.message) {
this.useAlert.success(data.message) useAlert().success(data.message)
} }
this.$router.push({ name: 'templates' }) templatesStore.save(data.data)
this.templatesStore.remove(this.template) emit('close')
this.$emit('close')
}) })
} }
const updateFormTemplate = async () => {
templateForm.value.form = props.form
await templateForm.value.put('/templates/' + props.template.id).then((data) => {
if (data.message) {
useAlert().success(data.message)
} }
templatesStore.save(data.data)
emit('close')
})
}
const deleteFormTemplate = async () => {
if (!props.template) return
opnFetch('/templates/' + props.template.id, {method:'DELETE'}).then((data) => {
if (data.message) {
useAlert().success(data.message)
}
router.push({ name: 'templates' })
templatesStore.remove(props.template)
emit('close')
})
} }
</script> </script>

View File

@ -6,9 +6,9 @@
<v-button color="gray" size="small" @click.prevent="showFormTemplateModal=true"> <v-button color="gray" size="small" @click.prevent="showFormTemplateModal=true">
Edit Template Edit Template
</v-button> </v-button>
<!-- <form-template-modal v-if="form" :form="form" :template="template" :show="showFormTemplateModal"--> <form-template-modal v-if="form" :form="form" :template="template" :show="showFormTemplateModal"
<!-- @close="showFormTemplateModal=false"--> @close="showFormTemplateModal=false"
<!-- />--> />
</div> </div>
</template> </template>
<template #right> <template #right>
@ -199,7 +199,8 @@ import {computed} from 'vue'
import OpenCompleteForm from '../../components/open/forms/OpenCompleteForm.vue' import OpenCompleteForm from '../../components/open/forms/OpenCompleteForm.vue'
import Breadcrumb from '~/components/global/Breadcrumb.vue' import Breadcrumb from '~/components/global/Breadcrumb.vue'
import SingleTemplate from '../../components/pages/templates/SingleTemplate.vue' import SingleTemplate from '../../components/pages/templates/SingleTemplate.vue'
import {fetchTemplate} from "~/stores/templates.js"; import {fetchTemplate} from "~/stores/templates.js"
import FormTemplateModal from '~/components/open/forms/components/templates/FormTemplateModal.vue'
defineRouteRules({ defineRouteRules({
prerender: true prerender: true
@ -262,7 +263,8 @@ const copyTemplateUrl = () => {
useOpnSeoMeta({ useOpnSeoMeta({
title: () => { title: () => {
return template ? template.value.name : 'Form Template' if (!template || !template.value) return 'Form Template'
return template.value.name
}, },
description () { description () {
if (!template || !template.value) return null if (!template || !template.value) return null

View File

@ -23,7 +23,7 @@
</section> </section>
<templates-list :templates="templates" :filter-industries="false" :show-industrys="false"> <templates-list :templates="templates" :filter-industries="false" :show-industries="false">
<template #before-lists> <template #before-lists>
<section class="py-12 bg-white border-t border-gray-200 sm:py-16"> <section class="py-12 bg-white border-t border-gray-200 sm:py-16">
<div class="px-4 mx-auto sm:px-6 lg:px-8 max-w-7xl"> <div class="px-4 mx-auto sm:px-6 lg:px-8 max-w-7xl">

View File

@ -13,34 +13,28 @@
</div> </div>
</section> </section>
<!-- <templates-list :only-my="true" />--> <templates-list :templates="templates" :loading="loading" :show-types="false" :show-industries="false"/>
</div> </div>
</template> </template>
<script> <script setup>
import TemplatesList from '../../components/pages/templates/TemplatesList.vue'
export default {
components: { TemplatesList },
setup () {
definePageMeta({ definePageMeta({
middleware: "auth" middleware: "auth"
}) })
useOpnSeoMeta({ useOpnSeoMeta({
title: 'My Templates', title: 'My Templates',
description: 'Our collection of beautiful templates to create your own forms!' description: 'Our collection of beautiful templates to create your own forms!'
}) })
},
data () { let loading = ref(false)
return {} let templates = ref([])
},
mounted () {}, onMounted(() => {
loading.value = true
computed: {}, opnFetch('templates',{query: {onlymy: true}}).then((data) => {
loading.value = false
methods: {} templates.value = data
} })
})
</script> </script>