2
0

fix(engine): ️ Enforce lite badge even when removed

This commit is contained in:
Baptiste Arnaud
2022-03-29 14:57:53 +02:00
parent d43623bf59
commit 3552279396
2 changed files with 48 additions and 11 deletions

View File

@ -0,0 +1,46 @@
import React, { useEffect, useRef } from 'react'
import { useFrame } from 'react-frame-component'
export const LiteBadge = () => {
const { document } = useFrame()
const liteBadge = useRef<HTMLAnchorElement | null>(null)
useEffect(() => {
const container = document.querySelector(
'[data-testid="container"]'
) as HTMLDivElement
const observer = new MutationObserver(function (mutations_list) {
mutations_list.forEach(function (mutation) {
mutation.removedNodes.forEach(function (removed_node) {
if ((removed_node as HTMLElement).id == 'lite-badge') {
console.log('litebadge has been removed')
container.append(liteBadge.current as Node)
}
})
})
})
observer.observe(container, {
subtree: false,
childList: true,
})
return () => {
observer.disconnect()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
return (
<a
ref={liteBadge}
href={'https://www.typebot.io/?utm_source=litebadge'}
target="_blank"
rel="noopener noreferrer"
className="fixed py-1 px-2 bg-white z-50 rounded shadow-md lite-badge"
style={{ bottom: '20px' }}
id="lite-badge"
>
Made with <span className="text-blue-500">Typebot</span>.
</a>
)
}

View File

@ -20,6 +20,7 @@ import {
VariableWithValue, VariableWithValue,
} from 'models' } from 'models'
import { Log } from 'db' import { Log } from 'db'
import { LiteBadge } from './LiteBadge'
export type TypebotViewerProps = { export type TypebotViewerProps = {
typebot: PublicTypebot typebot: PublicTypebot
@ -113,17 +114,7 @@ export const TypebotViewer = ({
predefinedVariables={predefinedVariables} predefinedVariables={predefinedVariables}
/> />
</div> </div>
{typebot.settings.general.isBrandingEnabled && ( {typebot.settings.general.isBrandingEnabled && <LiteBadge />}
<a
href={'https://www.typebot.io/?utm_source=litebadge'}
target="_blank"
rel="noopener noreferrer"
className="fixed py-1 px-2 bg-white z-50 rounded shadow-md lite-badge"
style={{ bottom: '20px' }}
>
Made with <span className="text-blue-500">Typebot</span>.
</a>
)}
</div> </div>
</AnswersContext> </AnswersContext>
</TypebotContext> </TypebotContext>