Skip to content

Commit

Permalink
fix: use CalendarInput in StartEndDate
Browse files Browse the repository at this point in the history
  • Loading branch information
BRaimbault committed Dec 6, 2024
1 parent 68ac83b commit a4322fb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"start-server-and-test": "^2.0.3"
},
"dependencies": {
"@dhis2/analytics": "git+https://github.com/d2-ci/analytics.git#c19fab1c5abe7f15f3d7799ef1b5be8a720fa169",
"@dhis2/analytics": "git+https://github.com/d2-ci/analytics.git#19447b89130d615dc55e92d345b53869dca548ae",
"@dhis2/app-runtime": "^3.11.2",
"@dhis2/app-runtime-adapter-d2": "^1.1.0",
"@dhis2/app-service-datastore": "^1.0.0-beta.3",
Expand Down
3 changes: 2 additions & 1 deletion src/components/edit/thematic/ThematicDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class ThematicDialog extends Component {
valueType,
thematicMapType,
systemSettings,
// periodsSettings,
periodsSettings,
} = this.props

const {
Expand Down Expand Up @@ -553,6 +553,7 @@ class ThematicDialog extends Component {
endDate={endDate}
setStartDate={setStartDate}
setEndDate={setEndDate}
periodsSettings={periodsSettings}
/>
)}
{periodError && (
Expand Down
42 changes: 26 additions & 16 deletions src/components/periods/StartEndDate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import i18n from '@dhis2/d2-i18n'
import { Field, IconArrowRight16, InputField, colors } from '@dhis2/ui'
import {
Field,
IconArrowRight16,
InputField,
CalendarInput,
colors,
} from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useEffect, useState } from 'react'
import { connect } from 'react-redux'
Expand All @@ -8,7 +14,10 @@ import { DEFAULT_START_DATE, DEFAULT_END_DATE } from '../../constants/layers.js'
import styles from './StartEndDate.module.css'

const StartEndDate = (props) => {
const { startDate, endDate, setStartDate, setEndDate } = props
const { startDate, endDate, setStartDate, setEndDate, periodsSettings } =
props

console.log('🚀 ~ StartEndDate ~ periodsSettings:', periodsSettings)

const [start, setStart] = useState(startDate)
const [end, setEnd] = useState(endDate)
Expand All @@ -17,11 +26,11 @@ const StartEndDate = (props) => {
console.log('🚀 ~ StartEndDate ~ endDate:', typeof endDate)
const hasDate = startDate !== undefined && endDate !== undefined

const onStartDateChange = ({ value }) => {
const onStartDateChange = ({ calendarDateString: value }) => {
setStart(value)
setStartDate(value)
}
const onEndDateChange = ({ value }) => {
const onEndDateChange = ({ calendarDateString: value }) => {
setEnd(value)
setEndDate(value)
}
Expand All @@ -32,25 +41,25 @@ const StartEndDate = (props) => {
)}
>
<div className={styles.row}>
<InputField
value={start.slice(0, 10)}
type="date"
onChange={onStartDateChange}
<CalendarInput
label={i18n.t('Start date')}
inputWidth="200px"
max="9999-12-31"
calendar={periodsSettings.calendar}
locale={periodsSettings.locale}
date={start.slice(0, 10)}
onDateSelect={onStartDateChange}
placeholder="YYYY-MM-DD"
dataTest="start-date-input"
/>
<div className={styles.icon}>
<IconArrowRight16 color={colors.grey500} />
</div>
<InputField
value={end.slice(0, 10)}
type="date"
onChange={onEndDateChange}
<CalendarInput
label={i18n.t('End date')}
inputWidth="200px"
max="9999-12-31"
calendar={periodsSettings.calendar}
locale={periodsSettings.locale}
date={end.slice(0, 10)}
onDateSelect={onEndDateChange}
placeholder="YYYY-MM-DD"
dataTest="end-date-input"
/>
</div>
Expand All @@ -60,6 +69,7 @@ const StartEndDate = (props) => {
StartEndDate.propTypes = {
startDate: PropTypes.string,
endDate: PropTypes.string,
periodsSettings: PropTypes.object,
}

export default connect(null, { setStartDate, setEndDate })(StartEndDate)
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2018,9 +2018,9 @@
classnames "^2.3.1"
prop-types "^15.7.2"

"@dhis2/analytics@git+https://github.com/d2-ci/analytics.git#c19fab1c5abe7f15f3d7799ef1b5be8a720fa169":
"@dhis2/analytics@git+https://github.com/d2-ci/analytics.git#19447b89130d615dc55e92d345b53869dca548ae":
version "26.9.3"
resolved "git+https://github.com/d2-ci/analytics.git#c19fab1c5abe7f15f3d7799ef1b5be8a720fa169"
resolved "git+https://github.com/d2-ci/analytics.git#19447b89130d615dc55e92d345b53869dca548ae"
dependencies:
"@dhis2/multi-calendar-dates" "^1.2.2"
"@dnd-kit/core" "^6.0.7"
Expand Down

0 comments on commit a4322fb

Please sign in to comment.