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 <julien@nahum.net>
This commit is contained in:
Favour Olayinka 2024-03-12 12:48:51 +01:00 committed by GitHub
parent 18afd44664
commit 478b68074d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 43 additions and 25 deletions

View File

@ -175,7 +175,7 @@ export default {
} }
}, },
openFileUpload () { openFileUpload () {
if (this.disabled) return if (this.disabled || !this.$refs['actual-input']) return
this.$refs['actual-input'].click() this.$refs['actual-input'].click()
}, },
manualFileUpload (e) { manualFileUpload (e) {

View File

@ -13,10 +13,10 @@ const props = defineProps({
modelValue: { type: Boolean, default: false }, modelValue: { type: Boolean, default: false },
disabled: { type: Boolean, default: false } disabled: { type: Boolean, default: false }
}) })
const emits = defineEmits(['update:modelValue']) const emit = defineEmits(['update:modelValue'])
const onClick = () => { const onClick = () => {
if (props.disabled) return if (props.disabled) return
emits('update:modelValue', !props.modelValue) emit('update:modelValue', !props.modelValue)
} }
</script> </script>

View File

@ -71,7 +71,7 @@ const props = defineProps({
} }
}) })
const emits = defineEmits(['close']) const emit = defineEmits(['close'])
useHead({ useHead({
bodyAttrs: { bodyAttrs: {
@ -152,7 +152,7 @@ const onLeave = (el, done) => {
const close = () => { const close = () => {
if (props.closeable) { if (props.closeable) {
emits('close') emit('close')
} }
} }

View File

@ -17,7 +17,7 @@ const props = defineProps({
modelValue: {type: Boolean}, modelValue: {type: Boolean},
maxHeight: {type: Number, default: 200}, maxHeight: {type: Number, default: 200},
}) })
const emits = defineEmits(['click-away']) const emit = defineEmits(['click-away'])
const motion = ref(null) const motion = ref(null)
const collapsible = ref(null) const collapsible = ref(null)
@ -47,6 +47,6 @@ const onLeave = (el, done) => {
} }
const onClickAway = (event) => { const onClickAway = (event) => {
emits('click-away', event) emit('click-away', event)
} }
</script> </script>

View File

@ -33,9 +33,11 @@ const error = ref(null)
const formInitialHash = ref(null) const formInitialHash = ref(null)
function isDirty() { function isDirty() {
return formInitialHash.value && try {
updatedForm.value && return formInitialHash.value && updatedForm.value && formInitialHash.value !== hash(JSON.stringify(updatedForm?.value?.data() ?? null))
formInitialHash.value !== hash(JSON.stringify(updatedForm?.value?.data() ?? null)) } catch (e) {
return false
}
} }
function initUpdatedForm() { function initUpdatedForm() {

View File

@ -123,7 +123,11 @@ onMounted(() => {
if (process.client) { if (process.client) {
if (form.value.custom_code) { if (form.value.custom_code) {
const scriptEl = document.createRange().createContextualFragment(form.value.custom_code) const scriptEl = document.createRange().createContextualFragment(form.value.custom_code)
try {
document.head.append(scriptEl) document.head.append(scriptEl)
} catch (e) {
console.error('Error appending custom code', e)
}
} }
if (!isIframe) focusOnFirstFormElement() if (!isIframe) focusOnFirstFormElement()
} }
@ -135,22 +139,28 @@ onBeforeRouteLeave((to, from) => {
disableDarkMode() disableDarkMode()
}) })
const pageMeta = computed(() => {
if (form.value && form.value.is_pro && form.value.seo_meta) {
return form.value.seo_meta
}
return {}
})
useOpnSeoMeta({ useOpnSeoMeta({
title: () => { title: () => {
if (form && form.value?.is_pro && form.value.seo_meta.page_title) { if (pageMeta.value.page_title) {
return form.value.seo_meta.page_title return pageMeta.value.page_title
} }
return form.value ? form.value.title : 'Create beautiful forms' return form.value ? form.value.title : 'Create beautiful forms'
}, },
description: () => { description: () => {
if (form && form.value?.is_pro && form.value.seo_meta.page_description) { if (pageMeta.value.description) {
return form.value.seo_meta.page_description return pageMeta.value.description
} }
return (form && form.value?.description) ? form.value?.description.substring(0, 160) : null return (form && form.value?.description) ? form.value?.description.substring(0, 160) : null
}, },
ogImage: () => { ogImage: () => {
if (form && form.value?.is_pro && form.value.seo_meta.page_thumbnail) { if (pageMeta.value.page_thumbnail) {
return form.value.seo_meta.page_thumbnail return pageMeta.value.page_thumbnail
} }
return (form && form.value?.cover_picture) ? form.value?.cover_picture : null return (form && form.value?.cover_picture) ? form.value?.cover_picture : null
}, },
@ -160,7 +170,7 @@ useOpnSeoMeta({
}) })
useHead({ useHead({
titleTemplate: (titleChunk) => { 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 // Disable template if custom SEO title
return titleChunk return titleChunk
} }

View File

@ -69,17 +69,21 @@
<NuxtLink :to="{name:'forms-slug-show-submissions', params: {slug:form.slug}}" <NuxtLink :to="{name:'forms-slug-show-submissions', params: {slug:form.slug}}"
class="absolute inset-0"/> class="absolute inset-0"/>
<span class="font-semibold text-gray-900 dark:text-white">{{ form.title }}</span> <span class="font-semibold text-gray-900 dark:text-white">{{ form.title }}</span>
<ul class="flex text-gray-500"> <ul class="flex text-gray-500 text-sm gap-4">
<li class="pr-1"> <li class="pr-1 mr-3">
{{ form.views_count }} view{{ form.views_count > 0 ? 's' : '' }} {{ form.views_count }} view{{ form.views_count > 0 ? 's' : '' }}
</li> </li>
<li class="list-disc ml-6 pr-1"> <li class="list-disc mr-3">
{{ form.submissions_count }} {{ form.submissions_count }}
submission{{ form.submissions_count > 0 ? 's' : '' }} submission{{ form.submissions_count > 0 ? 's' : '' }}
</li> </li>
<li class="list-disc ml-6"> <li class="list-disc mr-3">
Edited {{ form.last_edited_human }} Edited {{ form.last_edited_human }}
</li> </li>
<li class='list-disc hidden lg:list-item'>
By
{{ form.creator.name }}
</li>
</ul> </ul>
<div v-if="['draft','closed'].includes(form.visibility) || (form.tags && form.tags.length > 0)" <div v-if="['draft','closed'].includes(form.visibility) || (form.tags && form.tags.length > 0)"
class="mt-1 flex items-center flex-wrap gap-3"> class="mt-1 flex items-center flex-wrap gap-3">

View File

@ -41,6 +41,8 @@ const update = () => {
form.patch('/settings/password').then((response) => { form.patch('/settings/password').then((response) => {
form.reset() form.reset()
useAlert().success('Password updated.') useAlert().success('Password updated.')
}).catch((error) => {
console.error(error)
}) })
} }
</script> </script>

View File

@ -46,7 +46,7 @@ export default defineNuxtPlugin({
if (event.exception.values.length) { if (event.exception.values.length) {
// Don't send validation exceptions to Sentry // Don't send validation exceptions to Sentry
if (event.exception.values[0].type === 'FetchError' && 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 return null
} }

View File

@ -14,7 +14,7 @@ export const useWorkingFormStore = defineStore('working_form', {
this.content = form this.content = form
}, },
setProperties (properties) { setProperties (properties) {
this.content.properties = properties this.content.properties = [...properties]
}, },
openSettingsForField (index) { openSettingsForField (index) {
// If field is passed, compute index // If field is passed, compute index