2
0

feat(dashboard): Add lead generation template

While creating the template I also made sure to fix and improve everything I stumble upon
This commit is contained in:
Baptiste Arnaud
2022-02-07 07:13:16 +01:00
parent 524ef0812c
commit 1f320c5d99
20 changed files with 397 additions and 46 deletions

View File

@ -16,22 +16,28 @@ import {
StepType,
StepWithOptionsType,
PublicStep,
ImageBubbleStep,
VideoBubbleStep,
} from 'models'
export const sendRequest = async <ResponseData>({
url,
method,
body,
}: {
url: string
method: string
body?: Record<string, unknown>
}): Promise<{ data?: ResponseData; error?: Error }> => {
export const sendRequest = async <ResponseData>(
params:
| {
url: string
method: string
body?: Record<string, unknown>
}
| string
): Promise<{ data?: ResponseData; error?: Error }> => {
try {
const url = typeof params === 'string' ? params : params.url
const response = await fetch(url, {
method,
method: typeof params === 'string' ? 'GET' : params.method,
mode: 'cors',
body: body ? JSON.stringify(body) : undefined,
body:
typeof params !== 'string' && isDefined(params.body)
? JSON.stringify(params.body)
: undefined,
})
if (!response.ok) throw new Error(response.statusText)
const data = await response.json()
@ -63,6 +69,11 @@ export const isTextBubbleStep = (
step: Step | PublicStep
): step is TextBubbleStep => step.type === BubbleStepType.TEXT
export const isMediaBubbleStep = (
step: Step
): step is ImageBubbleStep | VideoBubbleStep =>
step.type === BubbleStepType.IMAGE || step.type === BubbleStepType.VIDEO
export const isTextInputStep = (
step: Step | PublicStep
): step is TextInputStep => step.type === InputStepType.TEXT