Skip to content

Commit

Permalink
🐛 (typebotLink) Make sure to update all linked bot variable values
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Dec 12, 2022
1 parent 578e41c commit 656d1e3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
7 changes: 5 additions & 2 deletions apps/builder/src/features/dashboard/dashboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ test('folders navigation should work', async ({ page }) => {
await createFolderButton.click()
await page.click('text="New folder"')
await page.fill('input[value="New folder"]', 'My folder #1')
await page.press('input[value="My folder #1"]', 'Enter'),
await page.click('li:has-text("My folder #1")')
await Promise.all([
page.waitForResponse((resp) => resp.request().method() === 'PATCH'),
page.press('input[value="My folder #1"]', 'Enter'),
])
await page.click('li:has-text("My folder #1")')
await expect(page.locator('h1:has-text("My folder #1")')).toBeVisible()
await createFolderButton.click()
await page.click('text="New folder"')
Expand Down
4 changes: 3 additions & 1 deletion packages/bot-engine/src/providers/AnswersProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export const AnswersProvider = ({
setResultValues((resultValues) => {
const updatedVariables = [
...resultValues.variables.filter((v) =>
serializedNewVariables.every((variable) => variable.id !== v.id)
serializedNewVariables.every(
(variable) => variable.id !== v.id || variable.name !== v.name
)
),
...serializedNewVariables,
].filter((variable) => isDefined(variable.value)) as VariableWithValue[]
Expand Down
21 changes: 17 additions & 4 deletions packages/bot-engine/src/providers/TypebotProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { safeStringify } from '@/features/variables'
import { sendEventToParent } from '@/utils/chat'
import { Log } from 'db'
import { Edge, PublicTypebot, Typebot } from 'models'
import React, {
import {
createContext,
ReactNode,
useContext,
useEffect,
useState,
} from 'react'
import { isDefined } from 'utils'

export type LinkedTypebot = Pick<
PublicTypebot | Typebot,
Expand Down Expand Up @@ -78,16 +79,28 @@ export const TypebotProvider = ({
sendEventToParent({
newVariableValue: {
name:
typebot.variables.find((variable) => variable.id === variableId)
localTypebot.variables.find((variable) => variable.id === variableId)
?.name ?? '',
value: formattedValue ?? '',
},
})

const variable = localTypebot.variables.find((v) => v.id === variableId)
const otherVariablesWithSameName = localTypebot.variables.filter(
(v) => v.name === variable?.name && v.id !== variableId
)
const variablesToUpdate = [variable, ...otherVariablesWithSameName].filter(
isDefined
)

setLocalTypebot((typebot) => ({
...typebot,
variables: typebot.variables.map((v) =>
v.id === variableId ? { ...v, value: formattedValue } : v
variables: typebot.variables.map((variable) =>
variablesToUpdate.some(
(variableToUpdate) => variableToUpdate.id === variable.id
)
? { ...variable, value: formattedValue }
: variable
),
}))
}
Expand Down

5 comments on commit 656d1e3

@vercel
Copy link

@vercel vercel bot commented on 656d1e3 Dec 12, 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:

docs – ./apps/docs

docs-typebot-io.vercel.app
docs-git-main-typebot-io.vercel.app
docs.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 656d1e3 Dec 12, 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 656d1e3 Dec 12, 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:

viewer-v2-alpha – ./apps/viewer

bot.maitempah.com
bot.phuonghub.com
bot.reviewzer.com
cares.urlabout.me
fmm.wpwakanda.com
gentleman-shop.fr
k1.kandabrand.com
lb.ticketfute.com
ov1.wpwakanda.com
ov2.wpwakanda.com
ov3.wpwakanda.com
1988.bouclidom.com
andreimayer.com.br
bot.megafox.com.br
bot.neferlopez.com
bots.robomotion.io
cadu.uninta.edu.br
dicanatural.online
goalsettingbot.com
positivobra.com.br
survey.digienge.io
this-is-a-test.com
zap.techadviser.in
bot.digitalbled.com
bot.eventhub.com.au
bot.jepierre.com.br
bot.winglabs.com.br
carsalesenquiry.com
demo.botscientis.us
forms.webisharp.com
kbsub.wpwakanda.com
live.botscientis.us
mentoria.omelhor.vc
nutrisamirbayde.com
order.maitempah.com
quest.wpwakanda.com
survey1.digienge.io
test.botscientis.us
typebot.stillio.com
wordsandimagery.com
bium.gratirabbit.com
bot.ansuraniphone.my
bot.cotemeuplano.com
chat.hayurihijab.com
chatbee.agfunnel.com
click.sevenoways.com
connect.growthguy.in
kuiz.sistemniaga.com
offer.botscientis.us
sellmycarglasgow.com
talkbot.agfunnel.com
tenorioadvogados.com
uppity.wpwakanda.com
abutton.wpwakanda.com
reward.onlinebotdemo.xyz
type.opaulovieira.com.br
aibot.angrybranding.co.uk
bot.aidigitalmarketing.kr
bot.arraesecenteno.com.br
bot.blackboxsports.com.br
bot.cabinrentalagency.com
bot.fusionstarreviews.com
boyfriend-breakup.riku.ai
brigadeirosemdrama.com.br
chat.ertcrebateportal.com
chat.thisiscrushhouse.com
sellmyharleylouisiana.com
verfica.botmachine.com.br
configurator.bouclidom.com
help.atlasoutfittersk9.com
ted.meujalecobrasil.com.br
type.dericsoncalari.com.br
chatbot.berbelanjabiz.trade
designguide.techyscouts.com
presente.empresarias.com.mx
sell.sellthemotorhome.co.uk
anamnese.odontopavani.com.br
austin.channelautomation.com
bot.marketingplusmindset.com
piazzatorre.barrettamario.it
requests.swamprecordsgnv.com
type.cookieacademyonline.com
bot.brigadeirosemdrama.com.br
onboarding.libertydreamcare.ie
type.talitasouzamarques.com.br
agendamento.sergiolimajr.com.br
anamnese.clinicamegasjdr.com.br
bookings.littlepartymonkeys.com
bot.comercializadoraomicron.com
elevateyourmind.groovepages.com
yourfeedback.comebackreward.com
personal-trainer.barrettamario.it
preagendamento.sergiolimajr.com.br
studiotecnicoimmobiliaremerelli.it
download.thailandmicespecialist.com
register.thailandmicespecialist.com
viewer-v2-alpha-typebot-io.vercel.app
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
viewer-v2-alpha-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 656d1e3 Dec 12, 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
builder-v2-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 656d1e3 Dec 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.