-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from indec-it/feat/dateValidations
feat: add date without range validations
- Loading branch information
Showing
15 changed files
with
183 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
src/components/DatePicker/DateTimePickerSelector/DatePickerSelector.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import PropTypes from 'prop-types'; | ||
import {DatePicker as MuiDatePicker} from '@mui/x-date-pickers/DatePicker'; | ||
import {DateTimePicker as MuiDateTimePicker} from '@mui/x-date-pickers/DateTimePicker'; | ||
|
||
import dateTypes from '@/constants/dateTypes'; | ||
|
||
function DateTimePickerSelector({type, onChange, value, ...props}) { | ||
const handleChange = date => { | ||
onChange(date ? date.toISOString() : date); | ||
}; | ||
if ([dateTypes.DATE_WITH_HOUR, dateTypes.RANGE_WITH_HOUR].includes(type)) { | ||
return ( | ||
<MuiDateTimePicker | ||
{...props} | ||
ampm={false} | ||
inputFormat="dd/MM/yyyy HH:mm" | ||
onChange={handleChange} | ||
value={value ? new Date(value) : value} | ||
/> | ||
); | ||
} | ||
return ( | ||
<MuiDatePicker | ||
{...props} | ||
inputFormat="dd/MM/yyyy" | ||
onChange={handleChange} | ||
value={value ? new Date(value) : value} | ||
/> | ||
); | ||
} | ||
|
||
DateTimePickerSelector.propTypes = { | ||
onChange: PropTypes.func.isRequired, | ||
type: PropTypes.oneOf(Object.values(dateTypes)).isRequired, | ||
value: PropTypes.string | ||
}; | ||
|
||
DateTimePickerSelector.defaultProps = { | ||
value: undefined | ||
}; | ||
|
||
export default DateTimePickerSelector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import DateTimePickerSelector from './DatePickerSelector'; | ||
|
||
export default DateTimePickerSelector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.