2
0

feat(editor): Restore published version button

Had to migrate webhooks into a standalone table
This commit is contained in:
Baptiste Arnaud
2022-03-01 07:13:09 +01:00
parent 0df719d531
commit e17a1a0869
46 changed files with 578 additions and 348 deletions

View File

@ -7,7 +7,7 @@ import {
Block,
} from 'models'
import { NextApiRequest, NextApiResponse } from 'next'
import { byId, isDefined } from '.'
import { byId, isDefined } from './utils'
export const methodNotAllowed = (res: NextApiResponse) =>
res.status(405).json({ message: 'Method Not Allowed' })

View File

@ -15,7 +15,6 @@ import {
WebhookStep,
StepType,
StepWithOptionsType,
PublicStep,
ImageBubbleStep,
VideoBubbleStep,
} from 'models'
@ -62,50 +61,42 @@ export const isNotDefined = <T>(
value: T | undefined | null
): value is undefined | null => value === undefined || value === null
export const isInputStep = (step: Step | PublicStep): step is InputStep =>
export const isInputStep = (step: Step): step is InputStep =>
(Object.values(InputStepType) as string[]).includes(step.type)
export const isBubbleStep = (step: Step | PublicStep): step is BubbleStep =>
export const isBubbleStep = (step: Step): step is BubbleStep =>
(Object.values(BubbleStepType) as string[]).includes(step.type)
export const isLogicStep = (step: Step | PublicStep): step is LogicStep =>
export const isLogicStep = (step: Step): step is LogicStep =>
(Object.values(LogicStepType) as string[]).includes(step.type)
export const isTextBubbleStep = (
step: Step | PublicStep
): step is TextBubbleStep => step.type === BubbleStepType.TEXT
export const isTextBubbleStep = (step: Step): step is TextBubbleStep =>
step.type === BubbleStepType.TEXT
export const isMediaBubbleStep = (
step: Step | PublicStep
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
export const isTextInputStep = (step: Step): step is TextInputStep =>
step.type === InputStepType.TEXT
export const isChoiceInput = (
step: Step | PublicStep
): step is ChoiceInputStep => step.type === InputStepType.CHOICE
export const isChoiceInput = (step: Step): step is ChoiceInputStep =>
step.type === InputStepType.CHOICE
export const isSingleChoiceInput = (
step: Step | PublicStep
): step is ChoiceInputStep =>
export const isSingleChoiceInput = (step: Step): step is ChoiceInputStep =>
step.type === InputStepType.CHOICE &&
'options' in step &&
!step.options.isMultipleChoice
export const isConditionStep = (
step: Step | PublicStep
): step is ConditionStep => step.type === LogicStepType.CONDITION
export const isConditionStep = (step: Step): step is ConditionStep =>
step.type === LogicStepType.CONDITION
export const isIntegrationStep = (
step: Step | PublicStep
): step is IntegrationStep =>
export const isIntegrationStep = (step: Step): step is IntegrationStep =>
(Object.values(IntegrationStepType) as string[]).includes(step.type)
export const isWebhookStep = (step: Step | PublicStep): step is WebhookStep =>
'webhook' in step
export const isWebhookStep = (step: Step): step is WebhookStep =>
'webhookId' in step
export const isBubbleStepType = (type: StepType): type is BubbleStepType =>
(Object.values(BubbleStepType) as string[]).includes(type)
@ -132,9 +123,29 @@ export const stepTypeHasItems = (
type === LogicStepType.CONDITION || type === InputStepType.CHOICE
export const stepHasItems = (
step: Step | PublicStep
step: Step
): step is ConditionStep | ChoiceInputStep => 'items' in step
export const byId = (id?: string) => (obj: { id: string }) => obj.id === id
export const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1)
interface Omit {
// eslint-disable-next-line @typescript-eslint/ban-types
<T extends object, K extends [...(keyof T)[]]>(obj: T, ...keys: K): {
[K2 in Exclude<keyof T, K[number]>]: T[K2]
}
}
export const omit: Omit = (obj, ...keys) => {
const ret = {} as {
[K in keyof typeof obj]: typeof obj[K]
}
let key: keyof typeof obj
for (key in obj) {
if (!keys.includes(key)) {
ret[key] = obj[key]
}
}
return ret
}