From 478b68074d196bf662a2bb5aa0b9f4624a470ab1 Mon Sep 17 00:00:00 2001 From: Favour Olayinka Date: Tue, 12 Mar 2024 12:48:51 +0100 Subject: [PATCH] Apply bug fixes from Noteforms (#341) * rename const emits to emit * auth bug fixes * refactor page meta * fix file input empty ref * setProperties working_form store * add form creator to form list --------- Co-authored-by: Julien Nahum --- client/components/forms/FileInput.vue | 2 +- .../components/forms/components/VSwitch.vue | 4 +-- client/components/global/Modal.vue | 4 +-- .../global/transitions/Collapsible.vue | 4 +-- client/pages/forms/[slug]/edit.vue | 8 +++--- client/pages/forms/[slug]/index.vue | 26 +++++++++++++------ client/pages/home.vue | 12 ++++++--- client/pages/settings/password.vue | 2 ++ client/plugins/sentry.js | 2 +- client/stores/working_form.js | 4 +-- 10 files changed, 43 insertions(+), 25 deletions(-) diff --git a/client/components/forms/FileInput.vue b/client/components/forms/FileInput.vue index 4d904dc7..83936896 100644 --- a/client/components/forms/FileInput.vue +++ b/client/components/forms/FileInput.vue @@ -175,7 +175,7 @@ export default { } }, openFileUpload () { - if (this.disabled) return + if (this.disabled || !this.$refs['actual-input']) return this.$refs['actual-input'].click() }, manualFileUpload (e) { diff --git a/client/components/forms/components/VSwitch.vue b/client/components/forms/components/VSwitch.vue index 28d29451..7b9c225b 100644 --- a/client/components/forms/components/VSwitch.vue +++ b/client/components/forms/components/VSwitch.vue @@ -13,10 +13,10 @@ const props = defineProps({ modelValue: { type: Boolean, default: false }, disabled: { type: Boolean, default: false } }) -const emits = defineEmits(['update:modelValue']) +const emit = defineEmits(['update:modelValue']) const onClick = () => { if (props.disabled) return - emits('update:modelValue', !props.modelValue) + emit('update:modelValue', !props.modelValue) } diff --git a/client/components/global/Modal.vue b/client/components/global/Modal.vue index 971ef87b..39351a97 100644 --- a/client/components/global/Modal.vue +++ b/client/components/global/Modal.vue @@ -71,7 +71,7 @@ const props = defineProps({ } }) -const emits = defineEmits(['close']) +const emit = defineEmits(['close']) useHead({ bodyAttrs: { @@ -152,7 +152,7 @@ const onLeave = (el, done) => { const close = () => { if (props.closeable) { - emits('close') + emit('close') } } diff --git a/client/components/global/transitions/Collapsible.vue b/client/components/global/transitions/Collapsible.vue index 52d27f1f..ec3512ff 100644 --- a/client/components/global/transitions/Collapsible.vue +++ b/client/components/global/transitions/Collapsible.vue @@ -17,7 +17,7 @@ const props = defineProps({ modelValue: {type: Boolean}, maxHeight: {type: Number, default: 200}, }) -const emits = defineEmits(['click-away']) +const emit = defineEmits(['click-away']) const motion = ref(null) const collapsible = ref(null) @@ -47,6 +47,6 @@ const onLeave = (el, done) => { } const onClickAway = (event) => { - emits('click-away', event) + emit('click-away', event) } diff --git a/client/pages/forms/[slug]/edit.vue b/client/pages/forms/[slug]/edit.vue index 7b2f6a35..c4eb950e 100644 --- a/client/pages/forms/[slug]/edit.vue +++ b/client/pages/forms/[slug]/edit.vue @@ -33,9 +33,11 @@ const error = ref(null) const formInitialHash = ref(null) function isDirty() { - return formInitialHash.value && - updatedForm.value && - formInitialHash.value !== hash(JSON.stringify(updatedForm?.value?.data() ?? null)) + try { + return formInitialHash.value && updatedForm.value && formInitialHash.value !== hash(JSON.stringify(updatedForm?.value?.data() ?? null)) + } catch (e) { + return false + } } function initUpdatedForm() { diff --git a/client/pages/forms/[slug]/index.vue b/client/pages/forms/[slug]/index.vue index 0637b428..ad8cd48d 100644 --- a/client/pages/forms/[slug]/index.vue +++ b/client/pages/forms/[slug]/index.vue @@ -123,7 +123,11 @@ onMounted(() => { if (process.client) { if (form.value.custom_code) { const scriptEl = document.createRange().createContextualFragment(form.value.custom_code) - document.head.append(scriptEl) + try { + document.head.append(scriptEl) + } catch (e) { + console.error('Error appending custom code', e) + } } if (!isIframe) focusOnFirstFormElement() } @@ -135,22 +139,28 @@ onBeforeRouteLeave((to, from) => { disableDarkMode() }) +const pageMeta = computed(() => { + if (form.value && form.value.is_pro && form.value.seo_meta) { + return form.value.seo_meta + } + return {} +}) useOpnSeoMeta({ title: () => { - if (form && form.value?.is_pro && form.value.seo_meta.page_title) { - return form.value.seo_meta.page_title + if (pageMeta.value.page_title) { + return pageMeta.value.page_title } return form.value ? form.value.title : 'Create beautiful forms' }, description: () => { - if (form && form.value?.is_pro && form.value.seo_meta.page_description) { - return form.value.seo_meta.page_description + if (pageMeta.value.description) { + return pageMeta.value.description } return (form && form.value?.description) ? form.value?.description.substring(0, 160) : null }, ogImage: () => { - if (form && form.value?.is_pro && form.value.seo_meta.page_thumbnail) { - return form.value.seo_meta.page_thumbnail + if (pageMeta.value.page_thumbnail) { + return pageMeta.value.page_thumbnail } return (form && form.value?.cover_picture) ? form.value?.cover_picture : null }, @@ -160,7 +170,7 @@ useOpnSeoMeta({ }) useHead({ titleTemplate: (titleChunk) => { - if (form && form.value?.is_pro && form.value?.seo_meta.page_title) { + if (pageMeta.value.page_title) { // Disable template if custom SEO title return titleChunk } diff --git a/client/pages/home.vue b/client/pages/home.vue index db793054..5d3c76a0 100644 --- a/client/pages/home.vue +++ b/client/pages/home.vue @@ -69,17 +69,21 @@ {{ form.title }} -
    -
  • +
      +
    • {{ form.views_count }} view{{ form.views_count > 0 ? 's' : '' }}
    • -
    • +
    • {{ form.submissions_count }} submission{{ form.submissions_count > 0 ? 's' : '' }}
    • -
    • +
    • Edited {{ form.last_edited_human }}
    • +
    diff --git a/client/pages/settings/password.vue b/client/pages/settings/password.vue index 80a234a1..5d836b5f 100644 --- a/client/pages/settings/password.vue +++ b/client/pages/settings/password.vue @@ -41,6 +41,8 @@ const update = () => { form.patch('/settings/password').then((response) => { form.reset() useAlert().success('Password updated.') + }).catch((error) => { + console.error(error) }) } diff --git a/client/plugins/sentry.js b/client/plugins/sentry.js index 25ae3acc..2b806c25 100644 --- a/client/plugins/sentry.js +++ b/client/plugins/sentry.js @@ -46,7 +46,7 @@ export default defineNuxtPlugin({ if (event.exception.values.length) { // Don't send validation exceptions to Sentry if (event.exception.values[0].type === 'FetchError' && - event.exception.values[0].value.includes('422') + (event.exception.values[0].value.includes('422') || event.exception.values[0].value.includes('401')) ) { return null } diff --git a/client/stores/working_form.js b/client/stores/working_form.js index 94aab8fb..307443a9 100644 --- a/client/stores/working_form.js +++ b/client/stores/working_form.js @@ -14,7 +14,7 @@ export const useWorkingFormStore = defineStore('working_form', { this.content = form }, setProperties (properties) { - this.content.properties = properties + this.content.properties = [...properties] }, openSettingsForField (index) { // If field is passed, compute index @@ -44,7 +44,7 @@ export const useWorkingFormStore = defineStore('working_form', { this.showAddFieldSidebar = false this.showEditFieldSidebar = false }, - reset() { + reset () { this.content = null this.selectedFieldIndex = null this.showEditFieldSidebar = null