Skip to content

Commit

Permalink
🧑‍💻 Improve apiOrigin detection
Browse files Browse the repository at this point in the history
Closes #1696
  • Loading branch information
baptisteArno committed Aug 14, 2024
1 parent e649e49 commit 86263f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions apps/docs/editor/variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ They can be initialized in the URL as [URL parameters](https://www.semrush.com/b

Then the variables will be prefilled as following:

- Email => <test@test.com>
- First name => John
- Email => `test@test.com`
- First name => `John`

Prefilling variables using the embed library is even easier. You need to add an object named `prefilledVariables` that contains a dictionary of your values. For example:

Expand Down
7 changes: 6 additions & 1 deletion apps/viewer/src/components/TypebotPageV3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useMemo } from 'react'

export type TypebotV3PageProps = {
url: string
isMatchingViewerUrl?: boolean
name: string
publicId: string | null
font: Font | null
Expand All @@ -19,6 +20,7 @@ export type TypebotV3PageProps = {

export const TypebotPageV3 = ({
font,
isMatchingViewerUrl,
publicId,
name,
url,
Expand All @@ -41,7 +43,10 @@ export const TypebotPageV3 = ({
push(asPath.split('?')[0], undefined, { shallow: true })
}

const apiOrigin = useMemo(() => new URL(url).origin, [url])
const apiOrigin = useMemo(() => {
if (isMatchingViewerUrl) return
return new URL(url).origin
}, [isMatchingViewerUrl, url])

return (
<div
Expand Down
3 changes: 3 additions & 0 deletions apps/viewer/src/pages/[[...publicId]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const getServerSideProps: GetServerSideProps = async (
props: {
publishedTypebot,
incompatibleBrowser,
isMatchingViewerUrl,
url: `${protocol}://${forwardedHost ?? host}${pathname}`,
},
}
Expand Down Expand Up @@ -203,6 +204,7 @@ const App = ({
isIE: boolean
customHeadCode: string | null
url: string
isMatchingViewerUrl?: boolean
publishedTypebot:
| TypebotPageProps['publishedTypebot']
| Pick<
Expand Down Expand Up @@ -238,6 +240,7 @@ const App = ({
) : (
<TypebotPageV3
url={props.url}
isMatchingViewerUrl={props.isMatchingViewerUrl}
name={publishedTypebot.name}
publicId={publishedTypebot.publicId}
isHideQueryParamsEnabled={
Expand Down

0 comments on commit 86263f0

Please sign in to comment.