diff --git a/webapp/views/App/views/Home/SurveyInfo/CyclesEditor/CycleEditor/DateContainer/DateContainer.js b/webapp/views/App/views/Home/SurveyInfo/CyclesEditor/CycleEditor/DateContainer/DateContainer.js index 48d91a7ef2..a3bd8e497b 100644 --- a/webapp/views/App/views/Home/SurveyInfo/CyclesEditor/CycleEditor/DateContainer/DateContainer.js +++ b/webapp/views/App/views/Home/SurveyInfo/CyclesEditor/CycleEditor/DateContainer/DateContainer.js @@ -1,45 +1,32 @@ -import React, { useRef } from 'react' +import React, { useCallback } from 'react' import PropTypes from 'prop-types' -import * as R from 'ramda' import { useI18n } from '@webapp/store/system' +import { DateInput } from '@webapp/components/form/DateTimeInput' +import { DateFormats, Dates } from '@openforis/arena-core' -const DateEditor = ({ date, onChange }) => { - const [year, month, day] = R.pipe(R.defaultTo('--'), R.split('-'))(date) - - const yearRef = useRef(null) - const monthRef = useRef(null) - const dayRef = useRef(null) - - const onChangeDate = () => onChange(`${yearRef.current.value}-${monthRef.current.value}-${dayRef.current.value}`) - - return ( - - - - - - - - - - ) -} - -DateEditor.propTypes = { - date: PropTypes.string, - onChange: PropTypes.func.isRequired, -} - -DateEditor.defaultProps = { - date: null, -} - -const DateContainer = ({ date, keyLabel, readOnly, onChange }) => { +const DateContainer = ({ date, keyLabel, readOnly, onChange: onChangeProp }) => { const i18n = useI18n() + const dateFormatted = Dates.convertDate({ dateStr: date, formatTo: DateFormats.dateDisplay }) + + const onChange = useCallback( + (newDate) => { + const newDateFormatted = newDate + ? Dates.convertDate({ + dateStr: newDate, + formatFrom: DateFormats.dateDisplay, + formatTo: DateFormats.dateStorage, + }) + : null + onChangeProp(newDateFormatted) + }, + [onChangeProp] + ) return (