2
0
Files
bot/packages/bot-engine/src/components/ChatBlock/ChatStep/inputs/DateForm.tsx

74 lines
2.5 KiB
TypeScript
Raw Normal View History

2022-01-10 08:05:03 +01:00
import { DateInputOptions } from 'models'
import React, { useState } from 'react'
import { SendButton } from './SendButton'
type DateInputProps = {
onSubmit: (inputValue: `${string} to ${string}` | string) => void
options?: DateInputOptions
}
export const DateForm = ({
onSubmit,
options,
}: DateInputProps): JSX.Element => {
const { hasTime, isRange, labels } = options ?? {}
const [inputValues, setInputValues] = useState({ from: '', to: '' })
return (
<div className="flex flex-col w-full lg:w-4/6">
<div className="flex items-center">
<form
className={
'flex justify-between rounded-lg typebot-input pr-2 items-end'
}
onSubmit={(e) => {
if (inputValues.from === '' && inputValues.to === '') return
e.preventDefault()
onSubmit(
`${inputValues.from}${isRange ? ` to ${inputValues.to}` : ''}`
)
}}
>
<div className="flex flex-col">
<div className={'flex items-center p-4 ' + (isRange ? 'pb-0' : '')}>
{isRange && (
<p className="font-semibold mr-2">{labels?.from ?? 'From:'}</p>
)}
<input
className="focus:outline-none flex-1 w-full text-input"
style={{ minHeight: '2rem', minWidth: '100px' }}
2022-01-10 08:05:03 +01:00
type={hasTime ? 'datetime-local' : 'date'}
onChange={(e) =>
setInputValues({ ...inputValues, from: e.target.value })
}
data-testid="from-date"
/>
</div>
{isRange && (
<div className="flex items-center p-4">
{isRange && (
<p className="font-semibold">{labels?.to ?? 'To:'}</p>
)}
<input
className="focus:outline-none flex-1 w-full text-input ml-2"
style={{ minHeight: '2rem', minWidth: '100px' }}
2022-01-10 08:05:03 +01:00
type={hasTime ? 'datetime-local' : 'date'}
onChange={(e) =>
setInputValues({ ...inputValues, to: e.target.value })
}
data-testid="to-date"
/>
</div>
)}
</div>
<SendButton
label={labels?.button ?? 'Send'}
isDisabled={inputValues.to === '' && inputValues.from === ''}
2022-01-12 09:10:59 +01:00
className="my-2 ml-2"
2022-01-10 08:05:03 +01:00
/>
</form>
</div>
</div>
)
}