feat(settings): ✨ Add create result on page refresh option
This commit is contained in:
@ -7,6 +7,7 @@ import {
|
||||
useDisclosure,
|
||||
} from '@chakra-ui/react'
|
||||
import { UpgradeModal } from 'components/shared/modals/UpgradeModal.'
|
||||
import { SwitchWithLabel } from 'components/shared/SwitchWithLabel'
|
||||
import { useUser } from 'contexts/UserContext'
|
||||
import { GeneralSettings } from 'models'
|
||||
import React from 'react'
|
||||
@ -27,10 +28,19 @@ export const GeneralSettingsForm = ({
|
||||
const handleSwitchChange = () => {
|
||||
if (generalSettings?.isBrandingEnabled && isUserFreePlan) return
|
||||
onGeneralSettingsChange({
|
||||
...generalSettings,
|
||||
isBrandingEnabled: !generalSettings?.isBrandingEnabled,
|
||||
})
|
||||
}
|
||||
|
||||
const handleNewResultOnRefreshChange = (
|
||||
isNewResultOnRefreshEnabled: boolean
|
||||
) =>
|
||||
onGeneralSettingsChange({
|
||||
...generalSettings,
|
||||
isNewResultOnRefreshEnabled,
|
||||
})
|
||||
|
||||
return (
|
||||
<Stack spacing={6}>
|
||||
<UpgradeModal isOpen={isOpen} onClose={onClose} />
|
||||
@ -49,6 +59,12 @@ export const GeneralSettingsForm = ({
|
||||
onChange={handleSwitchChange}
|
||||
/>
|
||||
</Flex>
|
||||
<SwitchWithLabel
|
||||
id="new-result"
|
||||
label="Create new session on page refresh"
|
||||
initialValue={generalSettings.isNewResultOnRefreshEnabled ?? false}
|
||||
onCheckChange={handleNewResultOnRefreshChange}
|
||||
/>
|
||||
</Stack>
|
||||
)
|
||||
}
|
||||
|
@ -23,6 +23,10 @@ test.describe.parallel('Settings page', () => {
|
||||
await expect(
|
||||
typebotViewer(page).locator('a:has-text("Made with Typebot")')
|
||||
).toBeHidden()
|
||||
await page.click('text=Create new session on page refresh')
|
||||
await expect(
|
||||
page.locator('input[type="checkbox"] >> nth=-1')
|
||||
).toHaveAttribute('checked', '')
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -44,7 +44,8 @@ export const TypebotPage = ({
|
||||
if (error) setError(error)
|
||||
if (result) {
|
||||
setResultId(result.id)
|
||||
setResultInSession(result.id)
|
||||
if (typebot.settings.general.isNewResultOnRefreshEnabled !== true)
|
||||
setResultInSession(result.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
67
apps/viewer/playwright/tests/settings.spec.ts
Normal file
67
apps/viewer/playwright/tests/settings.spec.ts
Normal file
@ -0,0 +1,67 @@
|
||||
import test, { expect } from '@playwright/test'
|
||||
import { createTypebots, parseDefaultBlockWithStep } from '../services/database'
|
||||
import { generate } from 'short-uuid'
|
||||
import { defaultSettings, defaultTextInputOptions, InputStepType } from 'models'
|
||||
|
||||
test('Result should be in storage by default', async ({ page }) => {
|
||||
const typebotId = generate()
|
||||
await createTypebots([
|
||||
{
|
||||
id: typebotId,
|
||||
...parseDefaultBlockWithStep({
|
||||
type: InputStepType.TEXT,
|
||||
options: defaultTextInputOptions,
|
||||
}),
|
||||
},
|
||||
])
|
||||
await page.goto(`/${typebotId}-public`)
|
||||
await page.waitForResponse(
|
||||
(resp) =>
|
||||
resp.request().url().includes(`/api/typebots/${typebotId}/results`) &&
|
||||
resp.status() === 200 &&
|
||||
resp.request().method() === 'POST'
|
||||
)
|
||||
await page.reload()
|
||||
const resultId = await page.evaluate(() => sessionStorage.getItem('resultId'))
|
||||
expect(resultId).toBeDefined()
|
||||
})
|
||||
|
||||
test.describe('Create result on page refresh enabled', () => {
|
||||
test('should work', async ({ page }) => {
|
||||
const typebotId = generate()
|
||||
await createTypebots([
|
||||
{
|
||||
id: typebotId,
|
||||
settings: {
|
||||
...defaultSettings,
|
||||
general: {
|
||||
...defaultSettings.general,
|
||||
isNewResultOnRefreshEnabled: true,
|
||||
},
|
||||
},
|
||||
...parseDefaultBlockWithStep({
|
||||
type: InputStepType.TEXT,
|
||||
options: defaultTextInputOptions,
|
||||
}),
|
||||
},
|
||||
])
|
||||
await page.goto(`/${typebotId}-public`)
|
||||
await page.waitForResponse(
|
||||
(resp) =>
|
||||
resp.request().url().includes(`/api/typebots/${typebotId}/results`) &&
|
||||
resp.status() === 200 &&
|
||||
resp.request().method() === 'POST'
|
||||
)
|
||||
await page.reload()
|
||||
await page.waitForResponse(
|
||||
(resp) =>
|
||||
resp.request().url().includes(`/api/typebots/${typebotId}/results`) &&
|
||||
resp.status() === 200 &&
|
||||
resp.request().method() === 'POST'
|
||||
)
|
||||
const resultId = await page.evaluate(() =>
|
||||
sessionStorage.getItem('resultId')
|
||||
)
|
||||
expect(resultId).toBe(null)
|
||||
})
|
||||
})
|
@ -6,6 +6,7 @@ export type Settings = {
|
||||
|
||||
export type GeneralSettings = {
|
||||
isBrandingEnabled: boolean
|
||||
isNewResultOnRefreshEnabled?: boolean
|
||||
}
|
||||
|
||||
export type TypingEmulation = {
|
||||
@ -22,7 +23,7 @@ export type Metadata = {
|
||||
}
|
||||
|
||||
export const defaultSettings: Settings = {
|
||||
general: { isBrandingEnabled: true },
|
||||
general: { isBrandingEnabled: true, isNewResultOnRefreshEnabled: false },
|
||||
typingEmulation: { enabled: true, speed: 300, maxDelay: 1.5 },
|
||||
metadata: {
|
||||
description:
|
||||
|
Reference in New Issue
Block a user