mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-31 13:47:02 +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 { ConstraintFormHeader } from '../ConstraintFormHeader/ConstraintFormHeader';
|
||||||
import { format } from 'date-fns';
|
import { format, isValid } from 'date-fns';
|
||||||
import Input from 'component/common/Input/Input';
|
import Input from 'component/common/Input/Input';
|
||||||
interface IDateSingleValueProps {
|
interface IDateSingleValueProps {
|
||||||
setValue: (value: string) => void;
|
setValue: (value: string) => void;
|
||||||
@ -31,14 +31,25 @@ export const DateSingleValue = ({
|
|||||||
value={parseDateValue(value)}
|
value={parseDateValue(value)}
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
setError('');
|
setError('');
|
||||||
setValue(new Date(e.target.value).toISOString());
|
const parsedDate = parseValidDate(e.target.value);
|
||||||
|
const dateString = parsedDate?.toISOString();
|
||||||
|
dateString && setValue(dateString);
|
||||||
}}
|
}}
|
||||||
InputLabelProps={{
|
InputLabelProps={{
|
||||||
shrink: true,
|
shrink: true,
|
||||||
}}
|
}}
|
||||||
error={Boolean(error)}
|
error={Boolean(error)}
|
||||||
errorText={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