Skip to content

Commit

Permalink
fix(engine): ⚡️ Enforce lite badge even when removed
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 29, 2022
1 parent d43623b commit 3552279
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
46 changes: 46 additions & 0 deletions packages/bot-engine/src/components/LiteBadge.tsx
Original file line number Diff line number Diff line change
@@ -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>
)
}
13 changes: 2 additions & 11 deletions packages/bot-engine/src/components/TypebotViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
VariableWithValue,
} from 'models'
import { Log } from 'db'
import { LiteBadge } from './LiteBadge'

export type TypebotViewerProps = {
typebot: PublicTypebot
Expand Down Expand Up @@ -113,17 +114,7 @@ export const TypebotViewer = ({
predefinedVariables={predefinedVariables}
/>
</div>
{typebot.settings.general.isBrandingEnabled && (
<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>
)}
{typebot.settings.general.isBrandingEnabled && <LiteBadge />}
</div>
</AnswersContext>
</TypebotContext>
Expand Down

3 comments on commit 3552279

@vercel
Copy link

@vercel vercel bot commented on 3552279 Mar 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 3552279 Mar 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 3552279 Mar 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.