feat(editor): ♿️ Add 'Current' to Link typebot
This commit is contained in:
@@ -23,6 +23,7 @@ export const BlocksDropdown = ({
|
|||||||
)
|
)
|
||||||
|
|
||||||
const handleBlockSelect = (title: string) => {
|
const handleBlockSelect = (title: string) => {
|
||||||
|
console.log(title)
|
||||||
const id = blocks?.find((b) => b.title === title)?.id
|
const id = blocks?.find((b) => b.title === title)?.id
|
||||||
if (id) onBlockIdSelected(id)
|
if (id) onBlockIdSelected(id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export const TypebotLinkSettingsForm = ({
|
|||||||
}: Props) => {
|
}: Props) => {
|
||||||
const { linkedTypebots, typebot } = useTypebot()
|
const { linkedTypebots, typebot } = useTypebot()
|
||||||
|
|
||||||
const handleTypebotIdChange = (typebotId: string) =>
|
const handleTypebotIdChange = (typebotId: string | 'current') =>
|
||||||
onOptionsChange({ ...options, typebotId })
|
onOptionsChange({ ...options, typebotId })
|
||||||
const handleBlockIdChange = (blockId: string) =>
|
const handleBlockIdChange = (blockId: string) =>
|
||||||
onOptionsChange({ ...options, blockId })
|
onOptionsChange({ ...options, blockId })
|
||||||
@@ -29,7 +29,8 @@ export const TypebotLinkSettingsForm = ({
|
|||||||
/>
|
/>
|
||||||
<BlocksDropdown
|
<BlocksDropdown
|
||||||
blocks={
|
blocks={
|
||||||
typebot && options.typebotId === typebot.id
|
typebot &&
|
||||||
|
(options.typebotId === typebot.id || options.typebotId === 'current')
|
||||||
? typebot.blocks
|
? typebot.blocks
|
||||||
: linkedTypebots?.find(byId(options.typebotId))?.blocks ?? []
|
: linkedTypebots?.find(byId(options.typebotId))?.blocks ?? []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { byId } from 'utils'
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
typebotId?: string
|
typebotId?: string
|
||||||
onSelectTypebotId: (typebotId: string) => void
|
onSelectTypebotId: (typebotId: string | 'current') => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TypebotsDropdown = ({ typebotId, onSelectTypebotId }: Props) => {
|
export const TypebotsDropdown = ({ typebotId, onSelectTypebotId }: Props) => {
|
||||||
@@ -28,6 +28,7 @@ export const TypebotsDropdown = ({ typebotId, onSelectTypebotId }: Props) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const handleTypebotSelect = (name: string) => {
|
const handleTypebotSelect = (name: string) => {
|
||||||
|
if (name === 'Current typebot') return onSelectTypebotId('current')
|
||||||
const id = typebots?.find((s) => s.name === name)?.id
|
const id = typebots?.find((s) => s.name === name)?.id
|
||||||
if (id) onSelectTypebotId(id)
|
if (id) onSelectTypebotId(id)
|
||||||
}
|
}
|
||||||
@@ -39,7 +40,7 @@ export const TypebotsDropdown = ({ typebotId, onSelectTypebotId }: Props) => {
|
|||||||
<HStack>
|
<HStack>
|
||||||
<SearchableDropdown
|
<SearchableDropdown
|
||||||
selectedItem={currentTypebot?.name}
|
selectedItem={currentTypebot?.name}
|
||||||
items={(typebots ?? []).map((t) => t.name)}
|
items={['Current typebot', ...(typebots ?? []).map((t) => t.name)]}
|
||||||
onValueChange={handleTypebotSelect}
|
onValueChange={handleTypebotSelect}
|
||||||
placeholder={'Select a typebot'}
|
placeholder={'Select a typebot'}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ type Props = {
|
|||||||
|
|
||||||
export const TypebotLinkContent = ({ step }: Props) => {
|
export const TypebotLinkContent = ({ step }: Props) => {
|
||||||
const { linkedTypebots, typebot } = useTypebot()
|
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
|
const linkedTypebot = isCurrentTypebot
|
||||||
? typebot
|
? typebot
|
||||||
: linkedTypebots?.find(byId(step.options.typebotId))
|
: linkedTypebots?.find(byId(step.options.typebotId))
|
||||||
|
|||||||
@@ -43,6 +43,14 @@ export const SearchableDropdown = ({
|
|||||||
const dropdownRef = useRef(null)
|
const dropdownRef = useRef(null)
|
||||||
const inputRef = useRef(null)
|
const inputRef = useRef(null)
|
||||||
|
|
||||||
|
useEffect(
|
||||||
|
() => () => {
|
||||||
|
debounced.flush()
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (filteredItems.length > 0) return
|
if (filteredItems.length > 0) return
|
||||||
setFilteredItems([
|
setFilteredItems([
|
||||||
|
|||||||
@@ -25,12 +25,13 @@ export const SmartNumberInput = ({
|
|||||||
process.env.NEXT_PUBLIC_E2E_TEST ? 0 : debounceTimeout
|
process.env.NEXT_PUBLIC_E2E_TEST ? 0 : debounceTimeout
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(
|
||||||
return () => {
|
() => () => {
|
||||||
debounced.flush()
|
debounced.flush()
|
||||||
}
|
},
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [])
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
const handleValueChange = (value: string) => {
|
const handleValueChange = (value: string) => {
|
||||||
setCurrentValue(value)
|
setCurrentValue(value)
|
||||||
|
|||||||
@@ -139,8 +139,10 @@ const executeTypebotLink = async (
|
|||||||
}> => {
|
}> => {
|
||||||
const { typebot, linkedTypebots, onNewLog, createEdge } = context
|
const { typebot, linkedTypebots, onNewLog, createEdge } = context
|
||||||
const linkedTypebot =
|
const linkedTypebot =
|
||||||
[typebot, ...linkedTypebots].find(byId(step.options.typebotId)) ??
|
step.options.typebotId === 'current'
|
||||||
(await fetchAndInjectTypebot(step, context))
|
? typebot
|
||||||
|
: [typebot, ...linkedTypebots].find(byId(step.options.typebotId)) ??
|
||||||
|
(await fetchAndInjectTypebot(step, context))
|
||||||
if (!linkedTypebot) {
|
if (!linkedTypebot) {
|
||||||
onNewLog({
|
onNewLog({
|
||||||
status: 'error',
|
status: 'error',
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ export type CodeOptions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type TypebotLinkOptions = {
|
export type TypebotLinkOptions = {
|
||||||
typebotId?: string
|
typebotId?: string | 'current'
|
||||||
blockId?: string
|
blockId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user