2
0

🚸 (editor) Avoid highlighting variables in text bubble if not created

This commit is contained in:
Baptiste Arnaud
2023-08-29 18:15:18 +02:00
parent da272f2f9c
commit a0a719626c

View File

@@ -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
})}
</>
)
}