Skip to content

Commit

Permalink
feat(settings): ⚡️ Can disable query params auto hide
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed May 14, 2022
1 parent 731e646 commit 4272186
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
13 changes: 13 additions & 0 deletions apps/builder/components/settings/GeneralSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export const GeneralSettingsForm = ({
isInputPrefillEnabled,
})

const handleHideQueryParamsChange = (isHideQueryParamsEnabled: boolean) =>
onGeneralSettingsChange({
...generalSettings,
isHideQueryParamsEnabled,
})

return (
<Stack spacing={6}>
<UpgradeModal isOpen={isOpen} onClose={onClose} />
Expand Down Expand Up @@ -78,6 +84,13 @@ export const GeneralSettingsForm = ({
initialValue={generalSettings.isNewResultOnRefreshEnabled ?? false}
onCheckChange={handleNewResultOnRefreshChange}
/>
<SwitchWithLabel
id="query-params"
label="Hide query params on bot start"
initialValue={generalSettings.isHideQueryParamsEnabled ?? true}
onCheckChange={handleHideQueryParamsChange}
moreInfoContent="If your URL contains query params, they will be automatically hidden when the bot starts."
/>
</Stack>
)
}
6 changes: 5 additions & 1 deletion apps/viewer/layouts/TypebotPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export const TypebotPage = ({

const clearQueryParams = () => {
const hasQueryParams = asPath.includes('?')
if (hasQueryParams) push(asPath.split('?')[0], undefined, { shallow: true })
if (
hasQueryParams &&
typebot.settings.general.isHideQueryParamsEnabled !== false
)
push(asPath.split('?')[0], undefined, { shallow: true })
}

const initializeResult = async () => {
Expand Down
13 changes: 13 additions & 0 deletions apps/viewer/playwright/services/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ export const createTypebots = async (partialTypebots: Partial<Typebot>[]) => {
})
}

export const updateTypebot = async (
partialTypebot: Partial<Typebot> & { id: string }
) => {
await prisma.typebot.updateMany({
where: { id: partialTypebot.id },
data: partialTypebot,
})
return prisma.publicTypebot.updateMany({
where: { typebotId: partialTypebot.id },
data: partialTypebot,
})
}

const parseTypebotToPublicTypebot = (
id: string,
typebot: Typebot
Expand Down
34 changes: 33 additions & 1 deletion apps/viewer/playwright/tests/settings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import test, { expect } from '@playwright/test'
import { createTypebots, parseDefaultBlockWithStep } from '../services/database'
import {
createTypebots,
parseDefaultBlockWithStep,
updateTypebot,
} from '../services/database'
import cuid from 'cuid'
import { defaultSettings, defaultTextInputOptions, InputStepType } from 'models'

Expand Down Expand Up @@ -71,3 +75,31 @@ test.describe('Create result on page refresh enabled', () => {
expect(resultId).toBe(null)
})
})

test('Hide query params', async ({ page }) => {
const typebotId = cuid()
await createTypebots([
{
id: typebotId,
...parseDefaultBlockWithStep({
type: InputStepType.TEXT,
options: defaultTextInputOptions,
}),
},
])
await page.goto(`/${typebotId}-public?Name=John`)
await page.waitForTimeout(1000)
expect(page.url()).toEqual(`http://localhost:3001/${typebotId}-public`)
await updateTypebot({
id: typebotId,
settings: {
...defaultSettings,
general: { ...defaultSettings.general, isHideQueryParamsEnabled: false },
},
})
await page.goto(`/${typebotId}-public?Name=John`)
await page.waitForTimeout(1000)
expect(page.url()).toEqual(
`http://localhost:3001/${typebotId}-public?Name=John`
)
})
2 changes: 2 additions & 0 deletions packages/models/src/typebot/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type GeneralSettings = {
isBrandingEnabled: boolean
isNewResultOnRefreshEnabled?: boolean
isInputPrefillEnabled?: boolean
isHideQueryParamsEnabled?: boolean
}

export type TypingEmulation = {
Expand All @@ -29,6 +30,7 @@ export const defaultSettings: Settings = {
isBrandingEnabled: true,
isNewResultOnRefreshEnabled: false,
isInputPrefillEnabled: true,
isHideQueryParamsEnabled: true,
},
typingEmulation: { enabled: true, speed: 300, maxDelay: 1.5 },
metadata: {
Expand Down

4 comments on commit 4272186

@vercel
Copy link

@vercel vercel bot commented on 4272186 May 14, 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 4272186 May 14, 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 4272186 May 14, 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-git-main-typebot-io.vercel.app
app.typebot.io
builder-v2-typebot-io.vercel.app

Please sign in to comment.