-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡ Better error toast when previewing bot
Closes #475
- Loading branch information
1 parent
3c6a666
commit d448e64
Showing
7 changed files
with
235 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { Flex, HStack, IconButton, Stack, Text } from '@chakra-ui/react' | ||
import { AlertIcon, CloseIcon, InfoIcon, SmileIcon } from './icons' | ||
import { CodeEditor } from './inputs/CodeEditor' | ||
import { LanguageName } from '@uiw/codemirror-extensions-langs' | ||
|
||
export type ToastProps = { | ||
title?: string | ||
description?: string | ||
details?: { | ||
content: string | ||
lang: LanguageName | ||
} | ||
status?: 'info' | 'error' | 'success' | ||
icon?: React.ReactNode | ||
primaryButton?: React.ReactNode | ||
secondaryButton?: React.ReactNode | ||
onClose: () => void | ||
} | ||
|
||
export const Toast = ({ | ||
status = 'error', | ||
title, | ||
description, | ||
details, | ||
icon, | ||
primaryButton, | ||
secondaryButton, | ||
onClose, | ||
}: ToastProps) => { | ||
return ( | ||
<Flex | ||
p={3} | ||
rounded="md" | ||
bgColor="white" | ||
borderWidth="1px" | ||
shadow="sm" | ||
fontSize="sm" | ||
pos="relative" | ||
maxW="450px" | ||
> | ||
<HStack alignItems="flex-start" pr="7" spacing="3" w="full"> | ||
<Icon customIcon={icon} status={status} />{' '} | ||
<Stack spacing={3} flex="1"> | ||
<Stack spacing={1}> | ||
{title && <Text fontWeight="semibold">{title}</Text>} | ||
{description && <Text>{description}</Text>} | ||
</Stack> | ||
|
||
{details && ( | ||
<CodeEditor | ||
isReadOnly | ||
value={details.content} | ||
lang={details.lang} | ||
maxHeight="200px" | ||
maxWidth="calc(450px - 100px)" | ||
/> | ||
)} | ||
{(secondaryButton || primaryButton) && ( | ||
<HStack> | ||
{secondaryButton} | ||
{primaryButton} | ||
</HStack> | ||
)} | ||
</Stack> | ||
</HStack> | ||
|
||
<IconButton | ||
aria-label="Close" | ||
icon={<CloseIcon />} | ||
size="sm" | ||
onClick={onClose} | ||
variant="ghost" | ||
pos="absolute" | ||
top={1} | ||
right={1} | ||
/> | ||
</Flex> | ||
) | ||
} | ||
|
||
const Icon = ({ | ||
customIcon, | ||
status, | ||
}: { | ||
customIcon?: React.ReactNode | ||
status: ToastProps['status'] | ||
}) => { | ||
const color = parseColor(status) | ||
const icon = parseIcon(status, customIcon) | ||
return ( | ||
<Flex | ||
bgColor={`${color}.50`} | ||
boxSize="40px" | ||
justifyContent="center" | ||
alignItems="center" | ||
rounded="full" | ||
flexShrink={0} | ||
> | ||
<Flex | ||
bgColor={`${color}.100`} | ||
boxSize="30px" | ||
justifyContent="center" | ||
alignItems="center" | ||
rounded="full" | ||
fontSize="18px" | ||
color={`${color}.600`} | ||
> | ||
{icon} | ||
</Flex> | ||
</Flex> | ||
) | ||
} | ||
|
||
const parseColor = (status: ToastProps['status']) => { | ||
if (!status) return 'red' | ||
switch (status) { | ||
case 'error': | ||
return 'red' | ||
case 'success': | ||
return 'green' | ||
case 'info': | ||
return 'blue' | ||
} | ||
} | ||
|
||
const parseIcon = ( | ||
status: ToastProps['status'], | ||
customIcon?: React.ReactNode | ||
) => { | ||
if (customIcon) return customIcon | ||
switch (status) { | ||
case 'error': | ||
return <AlertIcon /> | ||
case 'success': | ||
return <SmileIcon /> | ||
case 'info': | ||
return <InfoIcon /> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Toast, ToastProps } from '@/components/Toast' | ||
import { useToast as useChakraToast } from '@chakra-ui/react' | ||
import { useCallback } from 'react' | ||
|
||
export const useToast = () => { | ||
const toast = useChakraToast() | ||
|
||
const showToast = useCallback( | ||
({ | ||
title, | ||
description, | ||
status = 'error', | ||
icon, | ||
details, | ||
primaryButton, | ||
secondaryButton, | ||
}: Omit<ToastProps, 'onClose'>) => { | ||
toast({ | ||
position: 'top-right', | ||
duration: details ? null : undefined, | ||
render: ({ onClose }) => ( | ||
<Toast | ||
title={title} | ||
description={description} | ||
status={status} | ||
icon={icon} | ||
details={details} | ||
onClose={onClose} | ||
primaryButton={primaryButton} | ||
secondaryButton={secondaryButton} | ||
/> | ||
), | ||
}) | ||
}, | ||
[toast] | ||
) | ||
|
||
return { showToast } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d448e64
There was a problem hiding this comment.
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:
landing-page-v2 – ./apps/landing-page
typebot.io
www.get-typebot.com
landing-page-v2-typebot-io.vercel.app
landing-page-v2-git-main-typebot-io.vercel.app
get-typebot.com
www.typebot.io
d448e64
There was a problem hiding this comment.
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
builder-v2-git-main-typebot-io.vercel.app
app.typebot.io
d448e64
There was a problem hiding this comment.
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
chat.tuanpakya.com
chat.webisharp.com
dicanatural.online
digitalhelp.com.au
goalsettingbot.com
pant.maxbot.com.br
pantherview.cr8.ai
positivobra.com.br
rollingball.cr8.ai
survey.digienge.io
this-is-a-test.com
zap.techadviser.in
ai.digitaldaftar.in
bot.boston-voip.com
bot.cabinpromos.com
bot.carnaval.studio
bot.digitalbled.com
bot.dsignagency.com
bot.eventhub.com.au
bot.jepierre.com.br
bot.leadgenpod.site
bot.ltmidias.com.br
bot.viralsangat.com
bot.winglabs.com.br
carsalesenquiry.com
chat.marius.digital
chat.sr7digital.com
chatbot.matthesv.de
chatbot.repplai.com
demo.botscientis.us
demo.wemakebots.xyz
hrbot.robomotion.io
inearephones.cr8.ai
kbsub.wpwakanda.com
limitenahora.com.br
live.botscientis.us
mentoria.omelhor.vc
nutrisamirbayde.com
order.maitempah.com
profileadscloud.com
quest.wpwakanda.com
support.wawplus.com
survey1.digienge.io
surveys.essiell.com
test.botscientis.us
test.getreview.help
test.reventepro.com
typebot.stillio.com
wordsandimagery.com
815639944.21000000.one
83720273.bouclidom.com
aplicacao.bmind.com.br
apply.ansuraniphone.my
bbutton.wpwwakanda.com
bolsamaisbrasil.app.br
bot.ilmuseoaiborghi.it
ted.meujalecobrasil.com.br
type.dericsoncalari.com.br
bot.pinpointinteractive.com
bot.polychromes-project.com
bot.seidinembroseanchetu.it
chat.semanalimpanome.com.br
designguide.techyscouts.com
liveconvert2.kandalearn.com
presente.empresarias.com.mx
register.algorithmpress.com
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
upload.atlasoutfittersk9.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
bot.cabin-rentals-of-georgia.net
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
chrome-os-inquiry-system.itschromeos.com
viewer-v2-git-main-typebot-io.vercel.app
main-menu-for-itschromeos.itschromeos.com
d448e64
There was a problem hiding this comment.
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-git-main-typebot-io.vercel.app
docs-typebot-io.vercel.app
docs.typebot.io