🚸 (editor) Avoid highlighting variables in text bubble if not created
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import { useTypebot } from '@/features/editor/providers/TypebotProvider'
|
||||||
|
|
||||||
export const PlateText = ({
|
export const PlateText = ({
|
||||||
text,
|
text,
|
||||||
bold,
|
bold,
|
||||||
@@ -22,17 +24,25 @@ export const PlateText = ({
|
|||||||
return <PlateTextContent text={text} />
|
return <PlateTextContent text={text} />
|
||||||
}
|
}
|
||||||
|
|
||||||
const PlateTextContent = ({ text }: { text: string }) => (
|
const PlateTextContent = ({ text }: { text: string }) => {
|
||||||
<>
|
const { typebot } = useTypebot()
|
||||||
{text.split(/\{\{(.*?\}\})/g).map((str, idx) => {
|
return (
|
||||||
if (str.endsWith('}}')) {
|
<>
|
||||||
return (
|
{text.split(/\{\{(.*?\}\})/g).map((str, idx) => {
|
||||||
<span className="slate-variable" key={idx}>
|
if (str.endsWith('}}')) {
|
||||||
{str.trim().slice(0, -2)}
|
const variableName = str.trim().slice(0, -2)
|
||||||
</span>
|
const matchingVariable = typebot?.variables.find(
|
||||||
)
|
(variable) => variable.name === variableName
|
||||||
}
|
)
|
||||||
return str
|
if (!matchingVariable) return '{{' + str
|
||||||
})}
|
return (
|
||||||
</>
|
<span className="slate-variable" key={idx}>
|
||||||
)
|
{str.trim().slice(0, -2)}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user