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'}
/>