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:
Chirag Chhatrala
2024-10-22 14:04:29 +05:30
committed by GitHub
parent 2fdf2a439b
commit dad5c825b1
50 changed files with 1903 additions and 874 deletions

View File

@@ -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
View 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
}