Skip to content

Commit

Permalink
🚸 (inputs) Improve date input response bubble formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Oct 1, 2022
1 parent 15dbc95 commit fac70b9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
17 changes: 17 additions & 0 deletions apps/builder/playwright/tests/inputs/date.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ test.describe('Date input block', () => {
typebotViewer(page).locator('[data-testid="from-date"]')
).toHaveAttribute('type', 'date')
await expect(typebotViewer(page).locator(`button`)).toBeDisabled()
await typebotViewer(page)
.locator('[data-testid="from-date"]')
.fill('2021-01-01')
await typebotViewer(page).locator(`button`).click()
await expect(typebotViewer(page).locator('text="01/01/2021"')).toBeVisible()

await page.click(`text=Pick a date...`)
await page.click('text=Is range?')
Expand All @@ -42,5 +47,17 @@ test.describe('Date input block', () => {
await expect(
typebotViewer(page).locator(`[data-testid="to-date"]`)
).toHaveAttribute('type', 'datetime-local')
await typebotViewer(page)
.locator('[data-testid="from-date"]')
.fill('2021-01-01T11:00')
await typebotViewer(page)
.locator('[data-testid="to-date"]')
.fill('2022-01-01T09:00')
await typebotViewer(page).locator(`button`).click()
await expect(
typebotViewer(page).locator(
'text="01/01/2021, 11:00 AM to 01/01/2022, 09:00 AM"'
)
).toBeVisible()
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DateInputOptions } from 'models'
import React, { useState } from 'react'
import { parseReadableDate } from 'services/inputs'
import { InputSubmitContent } from '../InputChatBlock'
import { SendButton } from './SendButton'

Expand Down Expand Up @@ -28,6 +29,7 @@ export const DateForm = ({
value: `${inputValues.from}${
isRange ? ` to ${inputValues.to}` : ''
}`,
label: parseReadableDate({ ...inputValues, hasTime, isRange }),
})
}}
>
Expand Down
27 changes: 27 additions & 0 deletions packages/bot-engine/src/services/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,30 @@ export const parseRetryBlock = (
outgoingEdgeId: newEdge.id,
}
}

export const parseReadableDate = ({
from,
to,
hasTime,
isRange,
}: {
from: string
to: string
hasTime?: boolean
isRange?: boolean
}) => {
const currentLocale = window.navigator.language
const formatOptions: Intl.DateTimeFormatOptions = {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: hasTime ? '2-digit' : undefined,
minute: hasTime ? '2-digit' : undefined,
}
const fromReadable = new Date(from).toLocaleString(
currentLocale,
formatOptions
)
const toReadable = new Date(to).toLocaleString(currentLocale, formatOptions)
return `${fromReadable}${isRange ? ` to ${toReadable}` : ''}`
}

4 comments on commit fac70b9

@vercel
Copy link

@vercel vercel bot commented on fac70b9 Oct 1, 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 fac70b9 Oct 1, 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 fac70b9 Oct 1, 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 fac70b9 Oct 1, 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

yobot.me
ns8.vn
minipost.uk
sat.cr8.ai
bot.aws.bj
biiapp.com
8jours.top
finplex.be
bot.aipr.kr
247987.com
bot.krdfy.com
bt.id8rs.com
ticketfute.com
am.nigerias.io
bot.lalmon.com
vhpage.cr8.ai
bot.enreso.org
an.nigerias.io
apo.nigerias.io
ar.nigerias.io
aso.nigerias.io
apr.nigerias.io
bot.ageenda.com
sakuranembro.it
typebot.aloe.do
games.klujo.com
chat.sureb4.com
bot.tc-mail.com
bot.artiweb.app
eventhub.com.au
bot.upfunnel.art
botc.ceox.com.br
bot.piccinato.co
clo.closeer.work
feedback.ofx.one
stan.vselise.com
form.syncwin.com
faqs.nigerias.io
kw.wpwakanda.com
myrentalhost.com
typebot.aloe.bot
voicehelp.cr8.ai
app.chatforms.net
bot.agfunnel.tech
bot.maitempah.com
bot.hostnation.de
bot.reviewzer.com
bot.phuonghub.com
fmm.wpwakanda.com
cares.urlabout.me
lb.ticketfute.com
k1.kandabrand.com
gentleman-shop.fr
ov1.wpwakanda.com
ov2.wpwakanda.com
1988.bouclidom.com
ov3.wpwakanda.com
andreimayer.com.br
bot.neferlopez.com
bot.megafox.com.br
dicanatural.online
cadu.uninta.edu.br
bots.robomotion.io
goalsettingbot.com
positivobra.com.br
zap.techadviser.in
this-is-a-test.com
survey.digienge.io
bot.eventhub.com.au
bot.digitalbled.com
demo.botscientis.us
carsalesenquiry.com
forms.webisharp.com
kbsub.wpwakanda.com
live.botscientis.us
mentoria.omelhor.vc
nutrisamirbayde.com
order.maitempah.com
quest.wpwakanda.com
test.botscientis.us
bium.gratirabbit.com
typebot.stillio.com
bot.ansuraniphone.my
bot.cotemeuplano.com
chat.hayurihijab.com
chatbee.agfunnel.com
click.sevenoways.com
connect.growthguy.in
get.freebotoffer.xyz
kuiz.sistemniaga.com
offer.botscientis.us
tenorioadvogados.com
talkbot.agfunnel.com
uppity.wpwakanda.com
bbutton.wpwakanda.com
aidigitalmarketing.kr
abutton.wpwakanda.com
bot.incusservices.com
bot.meuesocial.com.br
bot.ramonmatos.com.br

Please sign in to comment.