Skip to content

Commit

Permalink
feat(bot): 💄 Responsive rating input
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jun 20, 2022
1 parent 6938533 commit 49bf178
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Props = {

export const RatingInputContent = ({ block }: Props) => (
<Text noOfLines={1} pr="6">
Rate from 1 to {block.options.length}
Rate from {block.options.buttonType === 'Icons' ? 1 : 0} to{' '}
{block.options.length}
</Text>
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ export const RatingInputSettings = ({
const handleLeftLabelChange = (left: string) =>
onOptionsChange({ ...options, labels: { ...options.labels, left } })

const handleMiddleLabelChange = (middle: string) =>
onOptionsChange({ ...options, labels: { ...options.labels, middle } })

const handleRightLabelChange = (right: string) =>
onOptionsChange({ ...options, labels: { ...options.labels, right } })

Expand Down Expand Up @@ -92,7 +89,7 @@ export const RatingInputSettings = ({
)}
<Stack>
<FormLabel mb="0" htmlFor="button">
1 label:
{options.buttonType === 'Icons' ? '1' : '0'} label:
</FormLabel>
<Input
id="button"
Expand All @@ -101,19 +98,6 @@ export const RatingInputSettings = ({
placeholder="Not likely at all"
/>
</Stack>
{options.length >= 4 && (
<Stack>
<FormLabel mb="0" htmlFor="button">
{Math.floor(options.length / 2)} label:
</FormLabel>
<Input
id="button"
defaultValue={options.labels.middle}
onChange={handleMiddleLabelChange}
placeholder="Neutral"
/>
</Stack>
)}
<Stack>
<FormLabel mb="0" htmlFor="button">
{options.length} label:
Expand Down
8 changes: 3 additions & 5 deletions apps/builder/playwright/tests/inputs/rating.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,21 @@ test('options should work', async ({ page }) => {
await typebotViewer(page).locator(`text=8`).click()
await typebotViewer(page).locator(`text=Send`).click()
await expect(typebotViewer(page).locator(`text=8`)).toBeVisible()
await page.click('text=Rate from 1 to 10')
await page.click('text=10')
await page.click('text=5')
await page.click('text=Rate from 0 to 10')
await page.click('text="10"')
await page.click('text="5"')
await page.click('text=Numbers')
await page.click('text=Icons')
await page.click('text="Custom icon?"')
await page.fill('[placeholder="<svg>...</svg>"]', boxSvg)
await page.fill('[placeholder="Not likely at all"]', 'Not likely at all')
await page.fill('[placeholder="Neutral"]', 'Neutral')
await page.fill('[placeholder="Extremely likely"]', 'Extremely likely')
await page.click('text="Restart"')
await expect(typebotViewer(page).locator(`text=8`)).toBeHidden()
await expect(typebotViewer(page).locator(`text=4`)).toBeHidden()
await expect(
typebotViewer(page).locator(`text=Not likely at all`)
).toBeVisible()
await expect(typebotViewer(page).locator(`text=Neutral`)).toBeVisible()
await expect(
typebotViewer(page).locator(`text=Extremely likely`)
).toBeVisible()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RatingInputOptions, RatingInputBlock } from 'models'
import React, { FormEvent, useRef, useState } from 'react'
import React, { FormEvent, useState } from 'react'
import { isDefined, isEmpty, isNotDefined } from 'utils'
import { InputSubmitContent } from '../InputChatBlock'
import { SendButton } from './SendButton'
Expand All @@ -11,7 +11,6 @@ type Props = {

export const RatingForm = ({ block, onSubmit }: Props) => {
const [rating, setRating] = useState<number>()
const scaleElement = useRef<HTMLDivElement | null>(null)

const handleSubmit = (e: FormEvent) => {
e.preventDefault()
Expand All @@ -23,33 +22,32 @@ export const RatingForm = ({ block, onSubmit }: Props) => {

return (
<form className="flex flex-col" onSubmit={handleSubmit}>
<div className="flex flex-col" ref={scaleElement}>
<div className="flex">
{Array.from(Array(block.options.length)).map((_, idx) => (
<RatingButton
{...block.options}
key={idx}
rating={rating}
idx={idx + 1}
onClick={handleClick}
/>
))}
</div>

<div className="flex justify-between mr-2 mb-2">
{<span className="text-sm w-full ">{block.options.labels.left}</span>}
{!isEmpty(block.options.labels.middle) && (
<span className="text-sm w-full text-center">
{block.options.labels.middle}
</span>
)}
{
<span className="text-sm w-full text-right">
{block.options.labels.right}
</span>
}
</div>
{block.options.labels.left && (
<span className="text-sm w-full mb-2 rating-label">
{block.options.labels.left}
</span>
)}
<div className="flex flex-wrap justify-center">
{Array.from(
Array(
block.options.length +
(block.options.buttonType === 'Numbers' ? 1 : 0)
)
).map((_, idx) => (
<RatingButton
{...block.options}
key={idx}
rating={rating}
idx={idx + (block.options.buttonType === 'Numbers' ? 0 : 1)}
onClick={handleClick}
/>
))}
</div>
{block.options.labels.right && (
<span className="text-sm w-full text-right mb-2 pr-2 rating-label">
{block.options.labels.right}
</span>
)}

<div className="flex justify-end mr-2">
{isDefined(rating) && (
Expand Down
1 change: 0 additions & 1 deletion packages/models/src/typebot/blocks/input/rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const ratingInputOptionsSchema = optionBaseSchema.and(
labels: z.object({
left: z.string().optional(),
right: z.string().optional(),
middle: z.string().optional(),
button: z.string(),
}),
customIcon: z.object({
Expand Down

5 comments on commit 49bf178

@vercel
Copy link

@vercel vercel bot commented on 49bf178 Jun 20, 2022

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 49bf178 Jun 20, 2022

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-alpha – ./apps/viewer

bt.id8rs.com
bot.aws.bj
ar.nigerias.io
apo.nigerias.io
vhpage.cr8.ai
apr.nigerias.io
am.nigerias.io
sat.cr8.ai
aso.nigerias.io
an.nigerias.io
eventhub.com.au
games.klujo.com
chat.sureb4.com
sakuranembro.it
bot.piccinato.co
bot.upfunnel.art
clo.closeer.work
stan.vselise.com
feedback.ofx.one
faqs.nigerias.io
voicehelp.cr8.ai
goalsettingbot.com
app.chatforms.net
this-is-a-test.com
bot.eventhub.com.au
zap.techadviser.in
typebot.stillio.com
forms.webisharp.com
bot.ansuraniphone.my
bot.cotemeuplano.com
chat.hayurihijab.com
get.freebotoffer.xyz
bot.incusservices.com
bot.meuesocial.com.br
chat.missarkansas.org
cdd.searchcube.com.sg
form.searchcube.com.sg
apply.ansuraniphone.my
c23111azqw.nigerias.io
gcase.barrettamario.it
info.clickasuransi.com
kodawariab736.skeep.it
view.onlinebotdemo.xyz
83242573.actualizar.xyz
mainmenu.diddancing.com
hunterbot.saleshunter.ai
type.opaulovieira.com.br
serviziaziendali.online
form.sergiolimajr.com.br
boyfriend-breakup.riku.ai
type.dericsoncalari.com.br
aibot.angrybranding.co.uk
onboarding.libertydreamcare.ie
piazzatorre.barrettamario.it
type.talitasouzamarques.com.br
designguide.techyscouts.com
agendamento.sergiolimajr.com.br
bot.comercializadoraomicron.com
bookings.littlepartymonkeys.com
preagendamento.sergiolimajr.com.br
studiotecnicoimmobiliaremerelli.it
personal-trainer.barrettamario.it
viewer-v2-alpha-typebot-io.vercel.app
viewer-v2-alpha-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 49bf178 Jun 20, 2022

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-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 49bf178 Jun 20, 2022

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.vercel.app
docs.typebot.io
docs-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 49bf178 Jun 20, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.