🐛 Fix focus after selecting mark in text editor
This commit is contained in:
@@ -38,6 +38,7 @@ const TextBubbleEditorContent = ({
|
||||
const varDropdownRef = useRef<HTMLDivElement | null>(null)
|
||||
const rememberedSelection = useRef<BaseSelection | null>(null)
|
||||
const [isVariableDropdownOpen, setIsVariableDropdownOpen] = useState(false)
|
||||
const [isFirstFocus, setIsFirstFocus] = useState(true)
|
||||
|
||||
const textEditorRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
@@ -139,14 +140,16 @@ const TextBubbleEditorContent = ({
|
||||
style: editorStyle(useColorModeValue('white', colors.gray[850])),
|
||||
autoFocus: true,
|
||||
onFocus: () => {
|
||||
if (!isFirstFocus) return
|
||||
if (editor.children.length === 0) return
|
||||
selectEditor(editor, {
|
||||
edge: 'end',
|
||||
})
|
||||
setIsFirstFocus(false)
|
||||
},
|
||||
'aria-label': 'Text editor',
|
||||
onBlur: () => {
|
||||
rememberedSelection.current = editor.selection
|
||||
rememberedSelection.current = editor?.selection
|
||||
},
|
||||
onKeyDown: handleKeyDown,
|
||||
onClick: () => {
|
||||
|
||||
@@ -41,7 +41,7 @@ export const ItemNodesList = ({
|
||||
const isDraggingOnCurrentBlock =
|
||||
(draggedItem && mouseOverBlock?.id === block.id) ?? false
|
||||
const showPlaceholders =
|
||||
draggedItem !== undefined && block.items[0].type === draggedItem.type
|
||||
draggedItem !== undefined && block.items.at(0)?.type === draggedItem.type
|
||||
|
||||
const isLastBlock =
|
||||
isDefined(typebot) &&
|
||||
|
||||
@@ -81,3 +81,9 @@ export const canPublishFileInput = async ({
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
export const isUniqueConstraintError = (error: unknown) =>
|
||||
typeof error === 'object' &&
|
||||
error &&
|
||||
'code' in error &&
|
||||
error.code === 'P2002'
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { CollaborationType, WorkspaceRole } from '@typebot.io/prisma'
|
||||
import prisma from '@/lib/prisma'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { canReadTypebots, canWriteTypebots } from '@/helpers/databaseRules'
|
||||
import {
|
||||
canReadTypebots,
|
||||
canWriteTypebots,
|
||||
isUniqueConstraintError,
|
||||
} from '@/helpers/databaseRules'
|
||||
import {
|
||||
badRequest,
|
||||
forbidden,
|
||||
@@ -41,13 +45,23 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
select: { id: true },
|
||||
})
|
||||
if (existingUser) {
|
||||
await prisma.collaboratorsOnTypebots.create({
|
||||
data: {
|
||||
type,
|
||||
typebotId,
|
||||
userId: existingUser.id,
|
||||
},
|
||||
})
|
||||
try {
|
||||
await prisma.collaboratorsOnTypebots.create({
|
||||
data: {
|
||||
type,
|
||||
typebotId,
|
||||
userId: existingUser.id,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
if (isUniqueConstraintError(error)) {
|
||||
return res.status(400).send({
|
||||
message: 'User already has access to this typebot.',
|
||||
})
|
||||
}
|
||||
throw error
|
||||
}
|
||||
|
||||
await prisma.memberInWorkspace.upsert({
|
||||
where: {
|
||||
userId_workspaceId: {
|
||||
|
||||
Reference in New Issue
Block a user