🐛 (typebotLink) Fix typebotIds infinite query param
This commit is contained in:
@@ -124,16 +124,18 @@ export const TypebotProvider = ({
|
|||||||
},
|
},
|
||||||
] = useUndo<Typebot | undefined>(undefined)
|
] = useUndo<Typebot | undefined>(undefined)
|
||||||
|
|
||||||
const linkedTypebotIds = localTypebot?.groups
|
const linkedTypebotIds =
|
||||||
.flatMap((b) => b.blocks)
|
localTypebot?.groups
|
||||||
.reduce<string[]>(
|
.flatMap((b) => b.blocks)
|
||||||
(typebotIds, block) =>
|
.reduce<string[]>(
|
||||||
block.type === LogicBlockType.TYPEBOT_LINK &&
|
(typebotIds, block) =>
|
||||||
isDefined(block.options.typebotId)
|
block.type === LogicBlockType.TYPEBOT_LINK &&
|
||||||
? [...typebotIds, block.options.typebotId]
|
isDefined(block.options.typebotId) &&
|
||||||
: typebotIds,
|
!typebotIds.includes(block.options.typebotId)
|
||||||
[]
|
? [...typebotIds, block.options.typebotId]
|
||||||
)
|
: typebotIds,
|
||||||
|
[]
|
||||||
|
) ?? []
|
||||||
|
|
||||||
const { typebots: linkedTypebots } = useLinkedTypebots({
|
const { typebots: linkedTypebots } = useLinkedTypebots({
|
||||||
workspaceId: localTypebot?.workspaceId ?? undefined,
|
workspaceId: localTypebot?.workspaceId ?? undefined,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export const useLinkedTypebots = ({
|
|||||||
}: {
|
}: {
|
||||||
workspaceId?: string
|
workspaceId?: string
|
||||||
typebotId?: string
|
typebotId?: string
|
||||||
typebotIds?: string[]
|
typebotIds: string[]
|
||||||
onError: (error: Error) => void
|
onError: (error: Error) => void
|
||||||
}) => {
|
}) => {
|
||||||
const params = stringify({ typebotIds, workspaceId }, { indices: false })
|
const params = stringify({ typebotIds, workspaceId }, { indices: false })
|
||||||
@@ -21,8 +21,8 @@ export const useLinkedTypebots = ({
|
|||||||
},
|
},
|
||||||
Error
|
Error
|
||||||
>(
|
>(
|
||||||
workspaceId
|
workspaceId && typebotIds.length > 0
|
||||||
? typebotIds?.every((id) => typebotId === id)
|
? typebotIds.every((id) => typebotId === id)
|
||||||
? undefined
|
? undefined
|
||||||
: `/api/typebots?${params}`
|
: `/api/typebots?${params}`
|
||||||
: null,
|
: null,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Plan, WorkspaceRole } from 'db'
|
import { Plan } from 'db'
|
||||||
import prisma from '@/lib/prisma'
|
import prisma from '@/lib/prisma'
|
||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
import { NextApiRequest, NextApiResponse } from 'next'
|
||||||
import {
|
import {
|
||||||
@@ -18,67 +18,29 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
try {
|
try {
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
const workspaceId = req.query.workspaceId as string | undefined
|
const workspaceId = req.query.workspaceId as string | undefined
|
||||||
const folderId = req.query.allFolders
|
|
||||||
? undefined
|
|
||||||
: req.query.folderId
|
|
||||||
? req.query.folderId.toString()
|
|
||||||
: null
|
|
||||||
if (!workspaceId) return badRequest(res)
|
if (!workspaceId) return badRequest(res)
|
||||||
const typebotIds = req.query.typebotIds as string[] | undefined
|
const typebotIds = req.query.typebotIds as string[]
|
||||||
if (typebotIds) {
|
|
||||||
const typebots = await prisma.typebot.findMany({
|
|
||||||
where: {
|
|
||||||
OR: [
|
|
||||||
{
|
|
||||||
workspace: { members: { some: { userId: user.id } } },
|
|
||||||
id: { in: typebotIds },
|
|
||||||
isArchived: { not: true },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: { in: typebotIds },
|
|
||||||
collaborators: {
|
|
||||||
some: {
|
|
||||||
userId: user.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
isArchived: { not: true },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
orderBy: { createdAt: 'desc' },
|
|
||||||
select: { name: true, id: true, groups: true, variables: true },
|
|
||||||
})
|
|
||||||
return res.send({ typebots })
|
|
||||||
}
|
|
||||||
const typebots = await prisma.typebot.findMany({
|
const typebots = await prisma.typebot.findMany({
|
||||||
where: {
|
where: {
|
||||||
OR: [
|
OR: [
|
||||||
{
|
{
|
||||||
|
workspace: { members: { some: { userId: user.id } } },
|
||||||
|
id: { in: typebotIds },
|
||||||
isArchived: { not: true },
|
isArchived: { not: true },
|
||||||
folderId,
|
|
||||||
workspace: {
|
|
||||||
id: workspaceId,
|
|
||||||
members: {
|
|
||||||
some: {
|
|
||||||
userId: user.id,
|
|
||||||
role: { not: WorkspaceRole.GUEST },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
isArchived: { not: true },
|
id: { in: typebotIds },
|
||||||
workspace: {
|
collaborators: {
|
||||||
id: workspaceId,
|
some: {
|
||||||
members: {
|
userId: user.id,
|
||||||
some: { userId: user.id, role: WorkspaceRole.GUEST },
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
isArchived: { not: true },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
orderBy: { createdAt: 'desc' },
|
orderBy: { createdAt: 'desc' },
|
||||||
select: { name: true, id: true, icon: true },
|
select: { name: true, id: true, groups: true, variables: true },
|
||||||
})
|
})
|
||||||
return res.send({ typebots })
|
return res.send({ typebots })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user