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 (
{ if (inputValues.from === '' && inputValues.to === '') return e.preventDefault() onSubmit( `${inputValues.from}${isRange ? ` to ${inputValues.to}` : ''}` ) }} >
{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" />
)}
) }