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 (
{i18n.t(keyLabel)} - {readOnly ? {date} : } + {readOnly ? {date} : }
) } diff --git a/webapp/views/App/views/Home/SurveyInfo/CyclesEditor/CyclesEditor.scss b/webapp/views/App/views/Home/SurveyInfo/CyclesEditor/CyclesEditor.scss index 7895336459..661414149a 100644 --- a/webapp/views/App/views/Home/SurveyInfo/CyclesEditor/CyclesEditor.scss +++ b/webapp/views/App/views/Home/SurveyInfo/CyclesEditor/CyclesEditor.scss @@ -27,7 +27,10 @@ } .date-container { - margin-left: 10px; + margin-left: 1rem; + display: flex; + align-items: center; + gap: 0.5rem; } .date-label { @@ -37,14 +40,6 @@ font-weight: 600; } - .date { - margin-left: 5px; - - input { - padding: 0.25rem 0.1rem; - } - } - .btn-delete { padding: 0.1rem; }