2
0

Remember result in either local or session storage (#514)

Closes #513
This commit is contained in:
Baptiste Arnaud
2023-05-16 14:58:56 +02:00
committed by GitHub
parent 0ae2a4ba8b
commit 27b009dd76
11 changed files with 129 additions and 50 deletions

View File

@@ -124,8 +124,11 @@ const startSession = async (startParams?: StartParams, userId?: string) => {
isPreview: startParams.isPreview || typeof startParams.typebot !== 'string',
typebotId: typebot.id,
prefilledVariables,
isNewResultOnRefreshEnabled:
typebot.settings.general.isNewResultOnRefreshEnabled ?? false,
isRememberUserEnabled:
typebot.settings.general.rememberUser?.isEnabled ??
(isDefined(typebot.settings.general.isNewResultOnRefreshEnabled)
? !typebot.settings.general.isNewResultOnRefreshEnabled
: false),
})
const startVariables =
@@ -291,11 +294,11 @@ const getResult = async ({
isPreview,
resultId,
prefilledVariables,
isNewResultOnRefreshEnabled,
isRememberUserEnabled,
}: Pick<StartParams, 'isPreview' | 'resultId'> & {
typebotId: string
prefilledVariables: Variable[]
isNewResultOnRefreshEnabled: boolean
isRememberUserEnabled: boolean
}) => {
if (isPreview) return
const select = {
@@ -305,7 +308,7 @@ const getResult = async ({
} satisfies Prisma.ResultSelect
const existingResult =
resultId && !isNewResultOnRefreshEnabled
resultId && isRememberUserEnabled
? ((await prisma.result.findFirst({
where: { id: resultId },
select,

View File

@@ -21,7 +21,10 @@ test('Result should be overwritten on page refresh', async ({ page }) => {
...defaultSettings,
general: {
...defaultSettings.general,
isNewResultOnRefreshEnabled: false,
rememberUser: {
isEnabled: true,
storage: 'session',
},
},
},
...parseDefaultGroupWithBlock({