Skip to content

Commit

Permalink
feat(editor): ♿️ Add 'Current' to Link typebot
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 25, 2022
1 parent d06cbea commit fb60dcf
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const BlocksDropdown = ({
)

const handleBlockSelect = (title: string) => {
console.log(title)
const id = blocks?.find((b) => b.title === title)?.id
if (id) onBlockIdSelected(id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const TypebotLinkSettingsForm = ({
}: Props) => {
const { linkedTypebots, typebot } = useTypebot()

const handleTypebotIdChange = (typebotId: string) =>
const handleTypebotIdChange = (typebotId: string | 'current') =>
onOptionsChange({ ...options, typebotId })
const handleBlockIdChange = (blockId: string) =>
onOptionsChange({ ...options, blockId })
Expand All @@ -29,7 +29,8 @@ export const TypebotLinkSettingsForm = ({
/>
<BlocksDropdown
blocks={
typebot && options.typebotId === typebot.id
typebot &&
(options.typebotId === typebot.id || options.typebotId === 'current')
? typebot.blocks
: linkedTypebots?.find(byId(options.typebotId))?.blocks ?? []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { byId } from 'utils'

type Props = {
typebotId?: string
onSelectTypebotId: (typebotId: string) => void
onSelectTypebotId: (typebotId: string | 'current') => void
}

export const TypebotsDropdown = ({ typebotId, onSelectTypebotId }: Props) => {
Expand All @@ -28,6 +28,7 @@ export const TypebotsDropdown = ({ typebotId, onSelectTypebotId }: Props) => {
)

const handleTypebotSelect = (name: string) => {
if (name === 'Current typebot') return onSelectTypebotId('current')
const id = typebots?.find((s) => s.name === name)?.id
if (id) onSelectTypebotId(id)
}
Expand All @@ -39,7 +40,7 @@ export const TypebotsDropdown = ({ typebotId, onSelectTypebotId }: Props) => {
<HStack>
<SearchableDropdown
selectedItem={currentTypebot?.name}
items={(typebots ?? []).map((t) => t.name)}
items={['Current typebot', ...(typebots ?? []).map((t) => t.name)]}
onValueChange={handleTypebotSelect}
placeholder={'Select a typebot'}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ type Props = {

export const TypebotLinkContent = ({ step }: Props) => {
const { linkedTypebots, typebot } = useTypebot()
const isCurrentTypebot = typebot && step.options.typebotId === typebot.id
const isCurrentTypebot =
typebot &&
(step.options.typebotId === typebot.id ||
step.options.typebotId === 'current')
const linkedTypebot = isCurrentTypebot
? typebot
: linkedTypebots?.find(byId(step.options.typebotId))
Expand Down
8 changes: 8 additions & 0 deletions apps/builder/components/shared/SearchableDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ export const SearchableDropdown = ({
const dropdownRef = useRef(null)
const inputRef = useRef(null)

useEffect(
() => () => {
debounced.flush()
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[]
)

useEffect(() => {
if (filteredItems.length > 0) return
setFilteredItems([
Expand Down
9 changes: 5 additions & 4 deletions apps/builder/components/shared/SmartNumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ export const SmartNumberInput = ({
process.env.NEXT_PUBLIC_E2E_TEST ? 0 : debounceTimeout
)

useEffect(() => {
return () => {
useEffect(
() => () => {
debounced.flush()
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
[]
)

const handleValueChange = (value: string) => {
setCurrentValue(value)
Expand Down
6 changes: 4 additions & 2 deletions packages/bot-engine/src/services/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ const executeTypebotLink = async (
}> => {
const { typebot, linkedTypebots, onNewLog, createEdge } = context
const linkedTypebot =
[typebot, ...linkedTypebots].find(byId(step.options.typebotId)) ??
(await fetchAndInjectTypebot(step, context))
step.options.typebotId === 'current'
? typebot
: [typebot, ...linkedTypebots].find(byId(step.options.typebotId)) ??
(await fetchAndInjectTypebot(step, context))
if (!linkedTypebot) {
onNewLog({
status: 'error',
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/typebot/steps/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export type CodeOptions = {
}

export type TypebotLinkOptions = {
typebotId?: string
typebotId?: string | 'current'
blockId?: string
}

Expand Down

3 comments on commit fb60dcf

@vercel
Copy link

@vercel vercel bot commented on fb60dcf Mar 25, 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 fb60dcf Mar 25, 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

Please sign in to comment.