mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-26 13:48:33 +02:00
refactor: fix crash on empty target date (#798)
* refactor: fix crash on empty target date * refactor: remove date input clear button
This commit is contained in:
parent
960460e61c
commit
3850cb42bd
@ -1,5 +1,5 @@
|
||||
import { ConstraintFormHeader } from '../ConstraintFormHeader/ConstraintFormHeader';
|
||||
import { format } from 'date-fns';
|
||||
import { format, isValid } from 'date-fns';
|
||||
import Input from 'component/common/Input/Input';
|
||||
interface IDateSingleValueProps {
|
||||
setValue: (value: string) => void;
|
||||
@ -31,14 +31,25 @@ export const DateSingleValue = ({
|
||||
value={parseDateValue(value)}
|
||||
onChange={e => {
|
||||
setError('');
|
||||
setValue(new Date(e.target.value).toISOString());
|
||||
const parsedDate = parseValidDate(e.target.value);
|
||||
const dateString = parsedDate?.toISOString();
|
||||
dateString && setValue(dateString);
|
||||
}}
|
||||
InputLabelProps={{
|
||||
shrink: true,
|
||||
}}
|
||||
error={Boolean(error)}
|
||||
errorText={error}
|
||||
required
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const parseValidDate = (value: string): Date | undefined => {
|
||||
const parsed = new Date(value);
|
||||
|
||||
if (isValid(parsed)) {
|
||||
return parsed;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user