From bab85178798090553d524ec16d06ed0a3e02e2ac Mon Sep 17 00:00:00 2001 From: Julien Nahum Date: Wed, 20 Dec 2023 18:38:43 +0100 Subject: [PATCH] Fixed most of the form/show pages --- client/components/global/Navbar.vue | 2 +- .../components/global/WorkspaceDropdown.vue | 4 +- .../components/AdvancedFormUrlSettings.vue | 10 +- .../open/forms/components/FormEditor.vue | 4 +- .../open/forms/components/FormStats.vue | 3 +- .../open/forms/components/FormSubmissions.vue | 5 +- .../templates/FormTemplateModal.vue | 2 +- .../components/pages/forms/show/ExtraMenu.vue | 10 +- .../pages/forms/show/RegenerateFormLink.vue | 2 +- client/composables/stores/useContentStore.js | 2 +- client/pages/forms/[slug]/edit.vue | 34 +-- client/pages/forms/[slug]/show.vue | 254 ++++++++++++++++ client/pages/forms/[slug]/show/index.vue | 275 +----------------- client/pages/forms/[slug]/show/share.vue | 10 +- client/pages/forms/[slug]/show/stats.vue | 5 +- client/pages/forms/show-public.vue | 2 +- client/pages/home.vue | 9 +- client/stores/forms.js | 13 +- .../open/forms/components/FormSubmissions.vue | 6 +- 19 files changed, 317 insertions(+), 335 deletions(-) create mode 100644 client/pages/forms/[slug]/show.vue diff --git a/client/components/global/Navbar.vue b/client/components/global/Navbar.vue index 6f62237..6853527 100644 --- a/client/components/global/Navbar.vue +++ b/client/components/global/Navbar.vue @@ -162,7 +162,7 @@ export default { helpUrl: () => this.config.links.help_url, form () { if (this.$route.name && this.$route.name.startsWith('forms.show_public')) { - return this.formsStore.getBySlug(this.$route.params.slug) + return this.formsStore.getByKey(this.$route.params.slug) } return null }, diff --git a/client/components/global/WorkspaceDropdown.vue b/client/components/global/WorkspaceDropdown.vue index e01f0ed..2cad14c 100644 --- a/client/components/global/WorkspaceDropdown.vue +++ b/client/components/global/WorkspaceDropdown.vue @@ -80,13 +80,13 @@ export default { switchWorkspace (workspace) { this.workspacesStore.setCurrentId(workspace.id) this.formsStore.resetState() - this.formsStore.load(workspace.id) + this.formsStore.loadAll(workspace.id) const router = useRouter() const route = useRoute() if (route.name !== 'home') { router.push({ name: 'home' }) } - this.formsStore.load(workspace.id) + this.formsStore.loadAll(workspace.id) }, isUrl (str) { try { diff --git a/client/components/open/forms/components/AdvancedFormUrlSettings.vue b/client/components/open/forms/components/AdvancedFormUrlSettings.vue index 16f0ed2..d7a73ec 100644 --- a/client/components/open/forms/components/AdvancedFormUrlSettings.vue +++ b/client/components/open/forms/components/AdvancedFormUrlSettings.vue @@ -9,13 +9,13 @@ - - { this.formsStore.addOrUpdate(data.form) this.$emit('on-save') - this.$router.push({ name: 'forms.show', params: { slug: this.form.slug } }) + this.$router.push({ name: 'forms-slug-show', params: { slug: this.form.slug } }) this.amplitude.logEvent('form_saved', { form_id: this.form.id, form_slug: this.form.slug }) this.displayFormModificationAlert(data) }).catch((error) => { diff --git a/client/components/open/forms/components/FormStats.vue b/client/components/open/forms/components/FormStats.vue index 7c5032d..1c70a54 100644 --- a/client/components/open/forms/components/FormStats.vue +++ b/client/components/open/forms/components/FormStats.vue @@ -105,8 +105,7 @@ export default { getChartData () { if (!this.form) { return null } this.isLoading = true - axios.get('/api/open/workspaces/' + this.form.workspace_id + '/form-stats/' + this.form.id).then((response) => { - const statsData = response.data + opnFetch('/open/workspaces/' + this.form.workspace_id + '/form-stats/' + this.form.id).then((statsData) => { if (statsData && statsData.views !== undefined) { this.chartData.labels = Object.keys(statsData.views) this.chartData.datasets[0].data = statsData.views diff --git a/client/components/open/forms/components/FormSubmissions.vue b/client/components/open/forms/components/FormSubmissions.vue index c67c43a..eabdad8 100644 --- a/client/components/open/forms/components/FormSubmissions.vue +++ b/client/components/open/forms/components/FormSubmissions.vue @@ -210,9 +210,7 @@ export default { return } this.isLoading = true - axios.get('/api/open/forms/' + this.form.id + '/submissions?page=' + this.currentPage).then((response) => { - const resData = response.data - + opnFetch('/open/forms/' + this.form.id + '/submissions?page=' + this.currentPage).then((resData) => { this.tableData = this.tableData.concat(resData.data.map((record) => record.data)) this.dataChanged() @@ -235,6 +233,7 @@ export default { } }, onChangeDisplayColumns () { + if (process.client) window.localStorage.setItem('display-columns-formid-' + this.form.id, JSON.stringify(this.displayColumns)) this.form.properties = this.properties.concat(this.removed_properties).filter((field) => { return this.displayColumns[field.id] === true diff --git a/client/components/open/forms/components/templates/FormTemplateModal.vue b/client/components/open/forms/components/templates/FormTemplateModal.vue index cb723c7..c0f21a0 100644 --- a/client/components/open/forms/components/templates/FormTemplateModal.vue +++ b/client/components/open/forms/components/templates/FormTemplateModal.vue @@ -117,7 +117,7 @@ export default { related_templates: null, questions: [] }) - this.templatesStore.loadIfEmpty() + loadAllTemplates(this.templatesStore) }, computed: { diff --git a/client/components/pages/forms/show/ExtraMenu.vue b/client/components/pages/forms/show/ExtraMenu.vue index 4200001..1fcb65c 100644 --- a/client/components/pages/forms/show/ExtraMenu.vue +++ b/client/components/pages/forms/show/ExtraMenu.vue @@ -169,7 +169,7 @@ export default { }), computed: { - formEndpoint: () => '/api/open/forms/{id}' + formEndpoint: () => '/open/forms/{id}' }, methods: { @@ -185,9 +185,9 @@ export default { duplicateForm () { if (this.loadingDuplicate) return this.loadingDuplicate = true - axios.post(this.formEndpoint.replace('{id}', this.form.id) + '/duplicate').then((response) => { - this.formsStore.addOrUpdate(response.data.new_form) - this.$router.push({ name: 'forms.show', params: { slug: response.data.new_form.slug } }) + opnFetch(this.formEndpoint.replace('{id}', this.form.id) + '/duplicate',{method: 'POST'}).then((data) => { + this.formsStore.save(data.new_form) + this.$router.push({ name: 'forms-show', params: { slug: data.new_form.slug } }) this.alertSuccess('Form was successfully duplicated.') this.loadingDuplicate = false }) @@ -195,7 +195,7 @@ export default { deleteForm () { if (this.loadingDelete) return this.loadingDelete = true - axios.delete(this.formEndpoint.replace('{id}', this.form.id)).then(() => { + opnFetch(this.formEndpoint.replace('{id}', this.form.id),{method:'DELETE'}).then(() => { this.formsStore.remove(this.form) this.$router.push({ name: 'home' }) this.alertSuccess('Form was deleted.') diff --git a/client/components/pages/forms/show/RegenerateFormLink.vue b/client/components/pages/forms/show/RegenerateFormLink.vue index 3d35ef1..27e6a59 100644 --- a/client/components/pages/forms/show/RegenerateFormLink.vue +++ b/client/components/pages/forms/show/RegenerateFormLink.vue @@ -105,7 +105,7 @@ export default { this.loadingNewLink = true axios.put(this.formEndpoint.replace('{id}', this.form.id) + '/regenerate-link/' + option).then((response) => { this.formsStore.addOrUpdate(response.data.form) - this.$router.push({name: 'forms.show', params: {slug: response.data.form.slug}}) + this.$router.push({name: 'forms-slug-show', params: {slug: response.data.form.slug}}) this.alertSuccess(response.data.message) this.loadingNewLink = false }).finally(() => { diff --git a/client/composables/stores/useContentStore.js b/client/composables/stores/useContentStore.js index 8a3caa8..59603a6 100644 --- a/client/composables/stores/useContentStore.js +++ b/client/composables/stores/useContentStore.js @@ -32,7 +32,7 @@ export const useContentStore = (mapKey = 'id') => { }) } function remove(item) { - content.value.remove(item[mapKey]) + content.value.delete( typeof item === 'object' ? item[mapKey] : item) } function startLoading() { diff --git a/client/pages/forms/[slug]/edit.vue b/client/pages/forms/[slug]/edit.vue index 71dc4a2..5e07894 100644 --- a/client/pages/forms/[slug]/edit.vue +++ b/client/pages/forms/[slug]/edit.vue @@ -16,37 +16,15 @@ diff --git a/client/pages/forms/[slug]/show/index.vue b/client/pages/forms/[slug]/show/index.vue index 6bb3134..0092cc3 100644 --- a/client/pages/forms/[slug]/show/index.vue +++ b/client/pages/forms/[slug]/show/index.vue @@ -1,270 +1,9 @@ - - - diff --git a/client/pages/forms/[slug]/show/share.vue b/client/pages/forms/[slug]/show/share.vue index a570ef0..a1563da 100644 --- a/client/pages/forms/[slug]/show/share.vue +++ b/client/pages/forms/[slug]/show/share.vue @@ -38,10 +38,14 @@ export default { AdvancedFormUrlSettings, EmbedFormAsPopupModal }, + props: { - form: { type: Object, required: true } + form: {type: Object, required: true}, + }, + + mounted() { + console.log('form',this.form) }, - mixins: [SeoMeta], data: () => ({ shareFormConfig: { @@ -50,8 +54,6 @@ export default { } }), - mounted() {}, - computed: { metaTitle() { return (this.form) ? 'Form Share - '+this.form.title : 'Form Share' diff --git a/client/pages/forms/[slug]/show/stats.vue b/client/pages/forms/[slug]/show/stats.vue index d111300..414641b 100644 --- a/client/pages/forms/[slug]/show/stats.vue +++ b/client/pages/forms/[slug]/show/stats.vue @@ -12,14 +12,11 @@ import FormStats from '../../../../components/open/forms/components/FormStats.vu import SeoMeta from '../../../../mixins/seo-meta.js' export default { - name: 'Stats', components: {FormStats}, + props: { form: {type: Object, required: true}, }, - mixins: [SeoMeta], - - data: () => ({}), computed: { metaTitle() { diff --git a/client/pages/forms/show-public.vue b/client/pages/forms/show-public.vue index 3c5271a..330e636 100644 --- a/client/pages/forms/show-public.vue +++ b/client/pages/forms/show-public.vue @@ -184,7 +184,7 @@ export default { return this.$route.params.slug }, form () { - return this.formsStore.getBySlug(this.formSlug) + return this.formsStore.getByKey(this.formSlug) }, isIframe () { return window.location !== window.parent.location || window.frameElement diff --git a/client/pages/home.vue b/client/pages/home.vue index d3bbbbb..c9378f7 100644 --- a/client/pages/home.vue +++ b/client/pages/home.vue @@ -133,13 +133,14 @@ definePageMeta({ const authStore = useAuthStore() const formsStore = useFormsStore() -formsStore.startLoading() const workspacesStore = useWorkspacesStore() +formsStore.startLoading() onMounted(() => { if (!formsStore.allLoaded) { - console.log('starting to load') - formsStore.load(workspacesStore.currentId) + formsStore.loadAll(workspacesStore.currentId) + } else { + formsStore.stopLoading() } }) @@ -164,7 +165,7 @@ const onTagClick = (tag) => { } } const viewForm = (form) => { - useRouter.push({name: 'forms.show', params: {slug: form.slug}}) + useRouter().push({name: 'forms-slug-show', params: {slug: form.slug}}) } // Computed diff --git a/client/stores/forms.js b/client/stores/forms.js index 1191afb..4d4f1be 100644 --- a/client/stores/forms.js +++ b/client/stores/forms.js @@ -9,7 +9,7 @@ export const useFormsStore = defineStore('forms', () => { const allLoaded = ref(false) const currentPage = ref(1) - const load = (workspaceId) => { + const loadAll = (workspaceId) => { contentStore.startLoading() return opnFetch(formsEndpoint.replace('{workspaceId}', workspaceId),{query: {page: currentPage.value}}) .then((response) => { @@ -21,7 +21,7 @@ export const useFormsStore = defineStore('forms', () => { } if (currentPage.value < response.meta.last_page) { currentPage.value++ - load(workspaceId) + loadAll(workspaceId) } else { allLoaded.value = true contentStore.stopLoading() @@ -30,6 +30,14 @@ export const useFormsStore = defineStore('forms', () => { }) } + const load = (workspaceId, slug) => { + contentStore.startLoading() + return opnFetch(formsEndpoint.replace('{workspaceId}', workspaceId) + '/' + slug) + .then((response) => { + console.log(response.data.value) + }) + } + const allTags = computed(() => { let tags = [] contentStore.getAll.value.forEach((form) => { @@ -44,6 +52,7 @@ export const useFormsStore = defineStore('forms', () => { ...contentStore, allLoaded, allTags, + loadAll, load } }) diff --git a/resources/js/components/open/forms/components/FormSubmissions.vue b/resources/js/components/open/forms/components/FormSubmissions.vue index d2d7a4e..c2de8a2 100644 --- a/resources/js/components/open/forms/components/FormSubmissions.vue +++ b/resources/js/components/open/forms/components/FormSubmissions.vue @@ -80,7 +80,6 @@