Skip to content

Commit

Permalink
🐛 (typebotLink) Fix typebotIds infinite query param
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Feb 15, 2023
1 parent 44d7740 commit 2f7e71f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,18 @@ export const TypebotProvider = ({
},
] = useUndo<Typebot | undefined>(undefined)

const linkedTypebotIds = localTypebot?.groups
.flatMap((b) => b.blocks)
.reduce<string[]>(
(typebotIds, block) =>
block.type === LogicBlockType.TYPEBOT_LINK &&
isDefined(block.options.typebotId)
? [...typebotIds, block.options.typebotId]
: typebotIds,
[]
)
const linkedTypebotIds =
localTypebot?.groups
.flatMap((b) => b.blocks)
.reduce<string[]>(
(typebotIds, block) =>
block.type === LogicBlockType.TYPEBOT_LINK &&
isDefined(block.options.typebotId) &&
!typebotIds.includes(block.options.typebotId)
? [...typebotIds, block.options.typebotId]
: typebotIds,
[]
) ?? []

const { typebots: linkedTypebots } = useLinkedTypebots({
workspaceId: localTypebot?.workspaceId ?? undefined,
Expand Down
6 changes: 3 additions & 3 deletions apps/builder/src/hooks/useLinkedTypebots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const useLinkedTypebots = ({
}: {
workspaceId?: string
typebotId?: string
typebotIds?: string[]
typebotIds: string[]
onError: (error: Error) => void
}) => {
const params = stringify({ typebotIds, workspaceId }, { indices: false })
Expand All @@ -21,8 +21,8 @@ export const useLinkedTypebots = ({
},
Error
>(
workspaceId
? typebotIds?.every((id) => typebotId === id)
workspaceId && typebotIds.length > 0
? typebotIds.every((id) => typebotId === id)
? undefined
: `/api/typebots?${params}`
: null,
Expand Down
58 changes: 10 additions & 48 deletions apps/builder/src/pages/api/typebots.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plan, WorkspaceRole } from 'db'
import { Plan } from 'db'
import prisma from '@/lib/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import {
Expand All @@ -18,67 +18,29 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
try {
if (req.method === 'GET') {
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)
const typebotIds = req.query.typebotIds as string[] | undefined
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 typebotIds = req.query.typebotIds as string[]
const typebots = await prisma.typebot.findMany({
where: {
OR: [
{
workspace: { members: { some: { userId: user.id } } },
id: { in: typebotIds },
isArchived: { not: true },
folderId,
workspace: {
id: workspaceId,
members: {
some: {
userId: user.id,
role: { not: WorkspaceRole.GUEST },
},
},
},
},
{
isArchived: { not: true },
workspace: {
id: workspaceId,
members: {
some: { userId: user.id, role: WorkspaceRole.GUEST },
id: { in: typebotIds },
collaborators: {
some: {
userId: user.id,
},
},
isArchived: { not: true },
},
],
},
orderBy: { createdAt: 'desc' },
select: { name: true, id: true, icon: true },
select: { name: true, id: true, groups: true, variables: true },
})
return res.send({ typebots })
}
Expand Down

4 comments on commit 2f7e71f

@vercel
Copy link

@vercel vercel bot commented on 2f7e71f Feb 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 2f7e71f Feb 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2 – ./apps/viewer

stan.vselise.com
start.taxtree.io
typebot.aloe.bot
voicehelp.cr8.ai
zap.fundviser.in
app.chatforms.net
bot.hostnation.de
bot.maitempah.com
bot.phuonghub.com
bot.reviewzer.com
bot.rihabilita.it
cares.urlabout.me
chat.gaswadern.de
fmm.wpwakanda.com
gentleman-shop.fr
k1.kandabrand.com
lb.ticketfute.com
ov1.wpwakanda.com
ov2.wpwakanda.com
ov3.wpwakanda.com
support.triplo.ai
viewer.typebot.io
1988.bouclidom.com
andreimayer.com.br
bot.danyservice.it
bot.iconicbrows.it
bot.megafox.com.br
bot.neferlopez.com
bots.robomotion.io
cadu.uninta.edu.br
dicanatural.online
digitalhelp.com.au
goalsettingbot.com
pant.maxbot.com.br
positivobra.com.br
survey.digienge.io
this-is-a-test.com
zap.techadviser.in
bot.boston-voip.com
bot.cabinpromos.com
bot.digitalbled.com
bot.dsignagency.com
bot.eventhub.com.au
bot.jepierre.com.br
bot.ltmidias.com.br
bot.viralsangat.com
bots.baptiste-arnaud.fr
help.comebackreward.com
link.venturasuceder.com
mainmenu.diddancing.com
manualhandlingcourse.ie
register.kandabrand.com
signup.hypemarketing.in
subfooter.wpwakanda.com
survey.hypemarketing.in
testbot.afterorigin.com
typebot.influencer.love
form.sergiolimajr.com.br
liveconvert.kandalearn.com
mainmenu1one.wpwakanda.com
tarian.theiofoundation.org
ted.meujalecobrasil.com.br
type.dericsoncalari.com.br
bot.pinpointinteractive.com
bot.polychromes-project.com
bot.seidinembroseanchetu.it
chatbot.berbelanjabiz.trade
designguide.techyscouts.com
liveconvert2.kandalearn.com
presente.empresarias.com.mx
sell.sellthemotorhome.co.uk
anamnese.odontopavani.com.br
austin.channelautomation.com
bot.marketingplusmindset.com
bot.seidibergamoseanchetu.it
desabafe.sergiolimajr.com.br
download.venturemarketing.in
piazzatorre.barrettamario.it
type.cookieacademyonline.com
bot.brigadeirosemdrama.com.br
forms.escoladeautomacao.com.br
onboarding.libertydreamcare.ie
type.talitasouzamarques.com.br
agendamento.sergiolimajr.com.br
anamnese.clinicamegasjdr.com.br
bookings.littlepartymonkeys.com
bot.comercializadoraomicron.com
elevateyourmind.groovepages.com
viewer-v2-typebot-io.vercel.app
yourfeedback.comebackreward.com
gerador.verificadordehospedes.com
personal-trainer.barrettamario.it
preagendamento.sergiolimajr.com.br
studiotecnicoimmobiliaremerelli.it
download.thailandmicespecialist.com
register.thailandmicespecialist.com
bot.studiotecnicoimmobiliaremerelli.it
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
viewer-v2-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 2f7e71f Feb 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./apps/docs

docs.typebot.io
docs-typebot-io.vercel.app
docs-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 2f7e71f Feb 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-typebot-io.vercel.app
app.typebot.io
builder-v2-git-main-typebot-io.vercel.app

Please sign in to comment.