2
0

feat(editor): ️ Add 'Current' to Link typebot

This commit is contained in:
Baptiste Arnaud
2022-03-25 14:59:40 +01:00
parent d06cbeac73
commit fb60dcf5ff
8 changed files with 29 additions and 12 deletions

View File

@ -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)
}

View File

@ -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 })
@ -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 ?? []
}

View File

@ -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) => {
@ -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)
}
@ -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'}
/>

View File

@ -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))

View File

@ -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([

View File

@ -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)