🚸 (account) Improve account form and fix cyclic dependencies
This commit is contained in:
@ -17,11 +17,11 @@ import {
|
||||
useState,
|
||||
} from 'react'
|
||||
import { isDefined, isNotDefined, omit } from 'utils'
|
||||
import { edgesAction, EdgesActions } from './actions/edges'
|
||||
import { itemsAction, ItemsActions } from './actions/items'
|
||||
import { GroupsActions, groupsActions } from './actions/groups'
|
||||
import { blocksAction, BlocksActions } from './actions/blocks'
|
||||
import { variablesAction, VariablesActions } from './actions/variables'
|
||||
import { edgesAction, EdgesActions } from './actions/edges'
|
||||
import { itemsAction, ItemsActions } from './actions/items'
|
||||
import { dequal } from 'dequal'
|
||||
import cuid from 'cuid'
|
||||
import { useToast } from '@/hooks/useToast'
|
||||
@ -30,17 +30,19 @@ import useUndo from '../../hooks/useUndo'
|
||||
import { useLinkedTypebots } from '@/hooks/useLinkedTypebots'
|
||||
import { updateTypebotQuery } from '../../queries/updateTypebotQuery'
|
||||
import { preventUserFromRefreshing } from '@/utils/helpers'
|
||||
import { updatePublishedTypebotQuery } from '@/features/publish'
|
||||
import { saveWebhookQuery } from '@/features/blocks/integrations/webhook/queries/saveWebhookQuery'
|
||||
import {
|
||||
createPublishedTypebotQuery,
|
||||
updatePublishedTypebotQuery,
|
||||
deletePublishedTypebotQuery,
|
||||
} from '@/features/publish/queries'
|
||||
import { saveWebhookQuery } from '@/features/blocks/integrations/webhook/queries/saveWebhookQuery'
|
||||
import {
|
||||
checkIfTypebotsAreEqual,
|
||||
checkIfPublished,
|
||||
parseTypebotToPublicTypebot,
|
||||
parseDefaultPublicId,
|
||||
parsePublicTypebotToTypebot,
|
||||
} from '@/features/publish'
|
||||
} from '@/features/publish/utils'
|
||||
import { useAutoSave } from '@/hooks/useAutoSave'
|
||||
|
||||
const autoSaveTimeout = 10000
|
||||
@ -60,6 +62,7 @@ type UpdateTypebotPayload = Partial<{
|
||||
export type SetTypebot = (
|
||||
newPresent: Typebot | ((current: Typebot) => Typebot)
|
||||
) => void
|
||||
|
||||
const typebotContext = createContext<
|
||||
{
|
||||
typebot?: Typebot
|
||||
|
@ -5,7 +5,6 @@ import {
|
||||
DraggableBlockType,
|
||||
BlockIndices,
|
||||
} from 'models'
|
||||
import { removeEmptyGroups } from './groups'
|
||||
import { WritableDraft } from 'immer/dist/types/types-external'
|
||||
import { SetTypebot } from '../TypebotProvider'
|
||||
import produce from 'immer'
|
||||
@ -13,7 +12,7 @@ import { cleanUpEdgeDraft, deleteEdgeDraft } from './edges'
|
||||
import cuid from 'cuid'
|
||||
import { byId, isWebhookBlock, blockHasItems } from 'utils'
|
||||
import { duplicateItemDraft } from './items'
|
||||
import { parseNewBlock } from '@/features/graph'
|
||||
import { parseNewBlock } from '@/features/graph/utils'
|
||||
|
||||
export type BlocksActions = {
|
||||
createBlock: (
|
||||
@ -30,7 +29,7 @@ export type BlocksActions = {
|
||||
deleteBlock: (indices: BlockIndices) => void
|
||||
}
|
||||
|
||||
const blocksAction = (setTypebot: SetTypebot): BlocksActions => ({
|
||||
export const blocksAction = (setTypebot: SetTypebot): BlocksActions => ({
|
||||
createBlock: (
|
||||
groupId: string,
|
||||
block: DraggableBlock | DraggableBlockType,
|
||||
@ -78,7 +77,7 @@ const removeBlockFromGroup =
|
||||
typebot.groups[groupIndex].blocks.splice(blockIndex, 1)
|
||||
}
|
||||
|
||||
const createBlockDraft = (
|
||||
export const createBlockDraft = (
|
||||
typebot: WritableDraft<Typebot>,
|
||||
block: DraggableBlock | DraggableBlockType,
|
||||
groupId: string,
|
||||
@ -134,7 +133,7 @@ const moveBlockToGroup = (
|
||||
typebot.groups[groupIndex].blocks.splice(blockIndex ?? 0, 0, newBlock)
|
||||
}
|
||||
|
||||
const duplicateBlockDraft =
|
||||
export const duplicateBlockDraft =
|
||||
(groupId: string) =>
|
||||
(block: Block): Block => {
|
||||
const blockId = cuid()
|
||||
@ -162,4 +161,19 @@ const duplicateBlockDraft =
|
||||
}
|
||||
}
|
||||
|
||||
export { blocksAction, createBlockDraft, duplicateBlockDraft }
|
||||
export const deleteGroupDraft =
|
||||
(typebot: WritableDraft<Typebot>) => (groupIndex: number) => {
|
||||
cleanUpEdgeDraft(typebot, typebot.groups[groupIndex].id)
|
||||
typebot.groups.splice(groupIndex, 1)
|
||||
}
|
||||
|
||||
export const removeEmptyGroups = (typebot: WritableDraft<Typebot>) => {
|
||||
const emptyGroupsIndices = typebot.groups.reduce<number[]>(
|
||||
(arr, group, idx) => {
|
||||
group.blocks.length === 0 && arr.push(idx)
|
||||
return arr
|
||||
},
|
||||
[]
|
||||
)
|
||||
emptyGroupsIndices.forEach(deleteGroupDraft(typebot))
|
||||
}
|
||||
|
@ -1,16 +1,12 @@
|
||||
import cuid from 'cuid'
|
||||
import { produce } from 'immer'
|
||||
import { WritableDraft } from 'immer/dist/internal'
|
||||
import {
|
||||
Group,
|
||||
DraggableBlock,
|
||||
DraggableBlockType,
|
||||
BlockIndices,
|
||||
Typebot,
|
||||
} from 'models'
|
||||
import { Group, DraggableBlock, DraggableBlockType, BlockIndices } from 'models'
|
||||
import { SetTypebot } from '../TypebotProvider'
|
||||
import { cleanUpEdgeDraft } from './edges'
|
||||
import { createBlockDraft, duplicateBlockDraft } from './blocks'
|
||||
import {
|
||||
deleteGroupDraft,
|
||||
createBlockDraft,
|
||||
duplicateBlockDraft,
|
||||
} from './blocks'
|
||||
import { Coordinates } from '@/features/graph'
|
||||
|
||||
export type GroupsActions = {
|
||||
@ -82,21 +78,4 @@ const groupsActions = (setTypebot: SetTypebot): GroupsActions => ({
|
||||
),
|
||||
})
|
||||
|
||||
const deleteGroupDraft =
|
||||
(typebot: WritableDraft<Typebot>) => (groupIndex: number) => {
|
||||
cleanUpEdgeDraft(typebot, typebot.groups[groupIndex].id)
|
||||
typebot.groups.splice(groupIndex, 1)
|
||||
}
|
||||
|
||||
const removeEmptyGroups = (typebot: WritableDraft<Typebot>) => {
|
||||
const emptyGroupsIndices = typebot.groups.reduce<number[]>(
|
||||
(arr, group, idx) => {
|
||||
group.blocks.length === 0 && arr.push(idx)
|
||||
return arr
|
||||
},
|
||||
[]
|
||||
)
|
||||
emptyGroupsIndices.forEach(deleteGroupDraft(typebot))
|
||||
}
|
||||
|
||||
export { groupsActions, removeEmptyGroups }
|
||||
export { groupsActions }
|
||||
|
Reference in New Issue
Block a user