import { DateInputOptions } from 'models' import React, { useState } from 'react' import { parseReadableDate } from 'services/inputs' import { InputSubmitContent } from '../InputChatBlock' import { SendButton } from './SendButton' type DateInputProps = { onSubmit: (inputValue: InputSubmitContent) => void options?: DateInputOptions } export const DateForm = ({ onSubmit, options, }: DateInputProps): JSX.Element => { const { hasTime, isRange, labels } = options ?? {} const [inputValues, setInputValues] = useState({ from: '', to: '' }) return (
{ if (inputValues.from === '' && inputValues.to === '') return e.preventDefault() onSubmit({ value: `${inputValues.from}${ isRange ? ` to ${inputValues.to}` : '' }`, label: parseReadableDate({ ...inputValues, hasTime, isRange }), }) }} >
{isRange && (

{labels?.from ?? 'From:'}

)} setInputValues({ ...inputValues, from: e.target.value }) } data-testid="from-date" />
{isRange && (
{isRange && (

{labels?.to ?? 'To:'}

)} setInputValues({ ...inputValues, to: e.target.value }) } data-testid="to-date" />
)}
) }