feat(viewer): Add variables in URL support

This commit is contained in:
Baptiste Arnaud
2022-02-17 10:46:04 +01:00
parent f7d6f0b766
commit 6e0ab67502
15 changed files with 550 additions and 58 deletions

View File

@@ -22,7 +22,7 @@ import {
} from 'services/typebots'
import { fetcher, preventUserFromRefreshing } from 'services/utils'
import useSWR from 'swr'
import { isDefined } from 'utils'
import { isDefined, isNotDefined } from 'utils'
import { BlocksActions, blocksActions } from './actions/blocks'
import { stepsAction, StepsActions } from './actions/steps'
import { variablesAction, VariablesActions } from './actions/variables'
@@ -217,6 +217,13 @@ export const TypebotContext = ({
if (!localTypebot) return
const publishedTypebotId = generate()
const newLocalTypebot = { ...localTypebot }
if (
localPublishedTypebot &&
isNotDefined(localTypebot.publishedTypebotId)
) {
updateLocalTypebot({ publishedTypebotId: localPublishedTypebot.id })
await saveTypebot()
}
if (!localPublishedTypebot) {
const newPublicId = parseDefaultPublicId(
localTypebot.name,
@@ -224,8 +231,8 @@ export const TypebotContext = ({
)
updateLocalTypebot({ publicId: newPublicId, publishedTypebotId })
newLocalTypebot.publicId = newPublicId
await saveTypebot()
}
if (hasUnsavedChanges || !localPublishedTypebot) await saveTypebot()
if (localPublishedTypebot) {
await savePublishedTypebot({
...parseTypebotToPublicTypebot(newLocalTypebot),