Apply Mentions everywhere (#595)
* variables and mentions * fix lint * add missing changes * fix tests * update quilly, fix bugs * fix lint * apply fixes * apply fixes * Fix MentionParser * Apply Mentions everywhere * Fix MentionParserTest * Small refactoring * Fixing quill import issues * Polished email integration, added customer sender mail * Add missing changes * improve migration command --------- Co-authored-by: Frank <csskfaves@gmail.com> Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
2
client/composables/lib/vForm/Form.js
vendored
2
client/composables/lib/vForm/Form.js
vendored
@@ -89,7 +89,7 @@ class Form {
|
||||
Object.keys(this)
|
||||
.filter((key) => !Form.ignore.includes(key))
|
||||
.forEach((key) => {
|
||||
this[key] = JSON.parse(JSON.stringify(this.originalData[key]))
|
||||
this[key] = cloneDeep(this.originalData[key])
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
39
client/composables/useParseMention.js
vendored
Normal file
39
client/composables/useParseMention.js
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
import { FormSubmissionFormatter } from '~/components/forms/components/FormSubmissionFormatter'
|
||||
|
||||
export function useParseMention(content, mentionsAllowed, form, formData) {
|
||||
if (!mentionsAllowed || !form || !formData) {
|
||||
return content
|
||||
}
|
||||
|
||||
const formatter = new FormSubmissionFormatter(form, formData).setOutputStringsOnly()
|
||||
const formattedData = formatter.getFormattedData()
|
||||
|
||||
// Create a new DOMParser
|
||||
const parser = new DOMParser()
|
||||
// Parse the content as HTML
|
||||
const doc = parser.parseFromString(content, 'text/html')
|
||||
|
||||
// Find all elements with mention attribute
|
||||
const mentionElements = doc.querySelectorAll('[mention]')
|
||||
|
||||
mentionElements.forEach(element => {
|
||||
const fieldId = element.getAttribute('mention-field-id')
|
||||
const fallback = element.getAttribute('mention-fallback')
|
||||
const value = formattedData[fieldId]
|
||||
|
||||
if (value) {
|
||||
if (Array.isArray(value)) {
|
||||
element.textContent = value.join(', ')
|
||||
} else {
|
||||
element.textContent = value
|
||||
}
|
||||
} else if (fallback) {
|
||||
element.textContent = fallback
|
||||
} else {
|
||||
element.remove()
|
||||
}
|
||||
})
|
||||
|
||||
// Return the processed HTML content
|
||||
return doc.body.innerHTML
|
||||
}
|
||||
Reference in New Issue
Block a user