2
0

feat(viewer): Custom head code

This commit is contained in:
Baptiste Arnaud
2022-04-21 10:33:16 -07:00
parent 12f43cdb88
commit 2dc0e45a65
6 changed files with 82 additions and 9 deletions

View File

@ -3,9 +3,11 @@ import { Answer, PublicTypebot, VariableWithValue } from 'models'
import { useRouter } from 'next/router'
import React, { useEffect, useState } from 'react'
import { upsertAnswer } from 'services/answer'
import { isDefined } from 'utils'
import { SEO } from '../components/Seo'
import { createResult, updateResult } from '../services/result'
import { ErrorPage } from './ErrorPage'
import sanitizeHtml from 'sanitize-html'
export type TypebotPageProps = {
typebot?: PublicTypebot
@ -39,6 +41,13 @@ export const TypebotPage = ({
})
setPredefinedVariables(predefinedVariables)
initializeResult().then()
const { customHeadCode } = typebot.settings.metadata
if (isDefined(customHeadCode) && customHeadCode !== '')
document.head.innerHTML =
document.head.innerHTML +
sanitizeHtml(customHeadCode ?? '', {
allowedTags: ['script', 'meta'],
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])