Skip to content

Commit

Permalink
🚸 (fileUpload) Add clear and skip button labels customization
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jan 20, 2023
1 parent aa32fe7 commit f697a5e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,28 @@ type Props = {
export const FileInputSettings = ({ options, onOptionsChange }: Props) => {
const handleButtonLabelChange = (button: string) =>
onOptionsChange({ ...options, labels: { ...options.labels, button } })

const handlePlaceholderLabelChange = (placeholder: string) =>
onOptionsChange({ ...options, labels: { ...options.labels, placeholder } })

const handleMultipleFilesChange = (isMultipleAllowed: boolean) =>
onOptionsChange({ ...options, isMultipleAllowed })

const handleVariableChange = (variable?: Variable) =>
onOptionsChange({ ...options, variableId: variable?.id })

const handleSizeLimitChange = (sizeLimit?: number) =>
onOptionsChange({ ...options, sizeLimit })

const handleRequiredChange = (isRequired: boolean) =>
onOptionsChange({ ...options, isRequired })

const updateClearButtonLabel = (clear: string) =>
onOptionsChange({ ...options, labels: { ...options.labels, clear } })

const updateSkipButtonLabel = (skip: string) =>
onOptionsChange({ ...options, labels: { ...options.labels, skip } })

return (
<Stack spacing={4}>
<SwitchWithLabel
Expand Down Expand Up @@ -56,17 +68,24 @@ export const FileInputSettings = ({ options, onOptionsChange }: Props) => {
withVariableButton={false}
/>
</Stack>
<Stack>
<FormLabel mb="0" htmlFor="button">
Button label:
</FormLabel>
<Input
id="button"
defaultValue={options.labels.button}
onChange={handleButtonLabelChange}
withVariableButton={false}
/>
</Stack>
<Input
label="Button label:"
defaultValue={options.labels.button}
onChange={handleButtonLabelChange}
withVariableButton={false}
/>
<Input
label="Clear button label:"
defaultValue={options.labels.clear}
onChange={updateClearButtonLabel}
withVariableButton={false}
/>
<Input
label="Skip button label:"
defaultValue={options.labels.skip}
onChange={updateSkipButtonLabel}
withVariableButton={false}
/>
<Stack>
<FormLabel mb="0" htmlFor="variable">
Save upload URL{options.isMultipleAllowed ? 's' : ''} in a variable:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ test('options should work', async ({ page }) => {
await page.click('text="Allow multiple files?"')
await page.fill('div[contenteditable=true]', '<strong>Upload now!!</strong>')
await page.fill('[value="Upload"]', 'Go')
await page.fill('[value="Clear"]', 'Reset')
await page.fill('[value="Skip"]', 'Pass')
await page.fill('input[value="10"]', '20')
await page.click('text="Restart"')
await expect(typebotViewer(page).locator(`text="Skip"`)).toBeVisible()
await expect(typebotViewer(page).locator(`text="Pass"`)).toBeVisible()
await expect(typebotViewer(page).locator(`text="Upload now!!"`)).toBeVisible()
await typebotViewer(page)
.locator(`input[type="file"]`)
Expand All @@ -49,7 +51,7 @@ test('options should work', async ({ page }) => {
getTestAsset('avatar.jpg'),
])
await expect(typebotViewer(page).locator(`text="3"`)).toBeVisible()
await typebotViewer(page).locator('text="Go 3 files"').click()
await typebotViewer(page).locator('text="Go"').click()
await expect(
typebotViewer(page).locator(`text="3 files uploaded"`)
).toBeVisible()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Spinner, SendButton } from '@/components/SendButton'
import { useAnswers } from '@/providers/AnswersProvider'
import { useTypebot } from '@/providers/TypebotProvider'
import { InputSubmitContent } from '@/types'
import { FileInputBlock } from 'models'
import { defaultFileInputOptions, FileInputBlock } from 'models'
import React, { ChangeEvent, FormEvent, useState, DragEvent } from 'react'
import { uploadFiles } from 'utils'

Expand Down Expand Up @@ -181,7 +181,7 @@ export const FileUploadForm = ({
}
onClick={onSkip}
>
Skip
{labels.skip ?? defaultFileInputOptions.labels.skip}
</button>
</div>
)}
Expand All @@ -195,17 +195,17 @@ export const FileUploadForm = ({
}
onClick={clearFiles}
>
Clear
{labels.clear ?? defaultFileInputOptions.labels.clear}
</button>
)}
<SendButton
type="submit"
label={
labels.button
labels.button === defaultFileInputOptions.labels.button
? `${labels.button} ${selectedFiles.length} file${
selectedFiles.length > 1 ? 's' : ''
}`
: 'Upload'
: labels.button
}
disableIcon
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SendButton, Spinner } from '@/components/SendButton'
import { BotContext, InputSubmitContent } from '@/types'
import { FileInputBlock } from 'models'
import { defaultFileInputOptions, FileInputBlock } from 'models'
import { createSignal, Match, Show, Switch } from 'solid-js'
import { uploadFiles } from 'utils'

Expand Down Expand Up @@ -179,7 +179,8 @@ export const FileUploadForm = (props: Props) => {
}
onClick={() => props.onSkip()}
>
Skip
{props.block.options.labels.skip ??
defaultFileInputOptions.labels.skip}
</button>
</div>
</Show>
Expand All @@ -199,15 +200,17 @@ export const FileUploadForm = (props: Props) => {
}
onClick={clearFiles}
>
Clear
{props.block.options.labels.clear ??
defaultFileInputOptions.labels.clear}
</button>
</Show>
<SendButton type="submit" disableIcon>
{props.block.options.labels.button
? `${props.block.options.labels.button} ${
selectedFiles().length
} file${selectedFiles().length > 1 ? 's' : ''}`
: 'Upload'}
{props.block.options.labels.button ===
defaultFileInputOptions.labels.button
? `Upload ${selectedFiles().length} file${
selectedFiles().length > 1 ? 's' : ''
}`
: props.block.options.labels.button}
</SendButton>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions packages/models/src/features/blocks/inputs/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const fileInputOptionsSchema = optionBaseSchema.and(
labels: z.object({
placeholder: z.string(),
button: z.string(),
clear: z.string().optional(),
skip: z.string().optional(),
}),
sizeLimit: z.number().optional(),
})
Expand All @@ -29,6 +31,8 @@ export const defaultFileInputOptions: FileInputOptions = {
</strong> or drag and drop<br>
(size limit: 10MB)`,
button: 'Upload',
clear: 'Clear',
skip: 'Skip',
},
}

Expand Down

4 comments on commit f697a5e

@vercel
Copy link

@vercel vercel bot commented on f697a5e Jan 20, 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.vercel.app
docs-git-main-typebot-io.vercel.app
docs.typebot.io

@vercel
Copy link

@vercel vercel bot commented on f697a5e Jan 20, 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

chat.hayuri.id
chicken.cr8.ai
gollum.riku.ai
gsbulletin.com
panther.cr7.ai
panther.cr8.ai
penguin.cr8.ai
talk.gocare.io
ticketfute.com
unicorn.cr8.ai
apo.nigerias.io
apr.nigerias.io
aso.nigerias.io
bot.ageenda.com
bot.artiweb.app
bot.devitus.com
bot.jesopizz.it
bot.reeplai.com
bot.tc-mail.com
chat.lalmon.com
chat.sureb4.com
eventhub.com.au
fitness.riku.ai
games.klujo.com
sakuranembro.it
typebot.aloe.do
bot.contakit.com
bot.piccinato.co
bot.sv-energy.it
botc.ceox.com.br
clo.closeer.work
cockroach.cr8.ai
faqs.nigerias.io
feedback.ofx.one
form.syncwin.com
kw.wpwakanda.com
myrentalhost.com
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
fmm.wpwakanda.com
bium.gratirabbit.com
bot.ansuraniphone.my
bot.barrettamario.it
bot.cotemeuplano.com
bot.leadbooster.help
bot.mycompay.reviews
chat.hayurihijab.com
chatbee.agfunnel.com
click.sevenoways.com
connect.growthguy.in
hello.advergreen.com
kuiz.sistemniaga.com
offer.botscientis.us
sellmycarglasgow.com
talkbot.agfunnel.com
tenorioadvogados.com
uppity.wpwakanda.com
abutton.wpwakanda.com
acelera.maxbot.com.br
aidigitalmarketing.kr
bbutton.wpwakanda.com
bot.coachayongzul.com
bot.digitalpointer.id
bot.eikju.photography
bot.incusservices.com
bot.meuesocial.com.br
bot.mycompany.reviews
bot.outstandbrand.com
bot.ramonmatos.com.br
bot.robertohairlab.it
bot.sharemyreview.net
bot.truongnguyen.live
cdd.searchcube.com.sg
chat.missarkansas.org
chatbot.ownacademy.co
criar.somaperuzzo.com
sbutton.wpwakanda.com
815639944.21000000.one
aplicacao.bmind.com.br
apply.ansuraniphone.my
bbutton.wpwwakanda.com
bot.ilmuseoaiborghi.it
bot.louismarcondes.com
bot.pratikmandalia.com
bot.t20worldcup.com.au
c23111azqw.nigerias.io
dieta.barrettamario.it
felipewelington.com.br
form.bridesquadapp.com
form.searchcube.com.sg

@vercel
Copy link

@vercel vercel bot commented on f697a5e Jan 20, 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 f697a5e Jan 20, 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-git-main-typebot-io.vercel.app
app.typebot.io
builder-v2-typebot-io.vercel.app

Please sign in to comment.