2022-11-29 10:02:40 +01:00
|
|
|
import { executeCondition } from '@/features/blocks/logic/condition/api'
|
|
|
|
|
import { executeRedirect } from '@/features/blocks/logic/redirect/api'
|
|
|
|
|
import { executeSetVariable } from '@/features/blocks/logic/setVariable/api'
|
|
|
|
|
import { executeTypebotLink } from '@/features/blocks/logic/typebotLink/api'
|
2023-01-26 18:23:09 +01:00
|
|
|
import { executeWait } from '@/features/blocks/logic/wait/api/utils/executeWait'
|
2022-11-29 10:02:40 +01:00
|
|
|
import { LogicBlock, LogicBlockType, SessionState } from 'models'
|
|
|
|
|
import { ExecuteLogicResponse } from '../../types'
|
2023-01-27 15:58:05 +01:00
|
|
|
import { executeScript } from '@/features/blocks/logic/script/executeScript'
|
2023-03-03 15:03:31 +01:00
|
|
|
import { executeJumpBlock } from '@/features/blocks/logic/jump/executeJumpBlock'
|
2022-11-29 10:02:40 +01:00
|
|
|
|
|
|
|
|
export const executeLogic =
|
2023-01-27 10:54:59 +01:00
|
|
|
(state: SessionState, lastBubbleBlockId?: string) =>
|
2022-11-29 10:02:40 +01:00
|
|
|
async (block: LogicBlock): Promise<ExecuteLogicResponse> => {
|
|
|
|
|
switch (block.type) {
|
|
|
|
|
case LogicBlockType.SET_VARIABLE:
|
|
|
|
|
return executeSetVariable(state, block)
|
|
|
|
|
case LogicBlockType.CONDITION:
|
|
|
|
|
return executeCondition(state, block)
|
|
|
|
|
case LogicBlockType.REDIRECT:
|
2023-01-27 10:54:59 +01:00
|
|
|
return executeRedirect(state, block, lastBubbleBlockId)
|
2023-01-27 15:58:05 +01:00
|
|
|
case LogicBlockType.SCRIPT:
|
|
|
|
|
return executeScript(state, block, lastBubbleBlockId)
|
2022-11-29 10:02:40 +01:00
|
|
|
case LogicBlockType.TYPEBOT_LINK:
|
|
|
|
|
return executeTypebotLink(state, block)
|
2023-01-26 18:23:09 +01:00
|
|
|
case LogicBlockType.WAIT:
|
2023-01-27 10:54:59 +01:00
|
|
|
return executeWait(state, block, lastBubbleBlockId)
|
2023-03-03 15:03:31 +01:00
|
|
|
case LogicBlockType.JUMP:
|
|
|
|
|
return executeJumpBlock(state, block.options)
|
2022-11-29 10:02:40 +01:00
|
|
|
}
|
|
|
|
|
}
|