Skip to content

Commit

Permalink
sync departArrive in calltaker as well
Browse files Browse the repository at this point in the history
  • Loading branch information
miles-grant-ibigroup committed Oct 22, 2024
1 parent 98467b5 commit 3112eae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
35 changes: 32 additions & 3 deletions lib/components/form/call-taker/date-time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { OverlayTrigger, Tooltip } from 'react-bootstrap'
import coreUtils from '@opentripplanner/core-utils'
import React, { useEffect, useRef, useState } from 'react'

import * as narriativeActions from '../../../actions/narrative'
import { DepartArriveTypeMap, DepartArriveValue } from '../date-time-modal'
import { FilterType, SortType } from '../../../util/state-types'

const { getCurrentDate, OTP_API_DATE_FORMAT, OTP_API_TIME_FORMAT } =
coreUtils.time

Expand Down Expand Up @@ -80,8 +84,11 @@ type Props = {
departArrive: string
time: string
}) => void
sort: SortType
syncSortWithDepartArrive?: boolean
time?: string
timeFormat: string
updateItineraryFilter: (payload: FilterType) => void
}
/**
* Contains depart/arrive selector and time/date inputs for the admin-oriented
Expand All @@ -103,8 +110,11 @@ const DateTimeOptions = ({
homeTimezone,
onKeyDown,
setQueryParam,
sort,
syncSortWithDepartArrive,
time: initialTime,
timeFormat
timeFormat,
updateItineraryFilter
}: Props) => {
const [departArrive, setDepartArrive] = useState(
initialDate || initialTime ? 'DEPART' : 'NOW'
Expand Down Expand Up @@ -187,6 +197,18 @@ const DateTimeOptions = ({
})
})
}

if (
syncSortWithDepartArrive &&
DepartArriveTypeMap[departArrive as DepartArriveValue] !== sort.type
) {
updateItineraryFilter({
sort: {
...sort,
type: DepartArriveTypeMap[departArrive as DepartArriveValue]
}
})
}
}, [dateTime, departArrive, homeTimezone, setQueryParam])

// Handler for updating the time and date fields when NOW is selected
Expand Down Expand Up @@ -283,11 +305,18 @@ const DateTimeOptions = ({

// connect to the redux store
const mapStateToProps = (state: any) => {
const { dateTime, homeTimezone } = state.otp.config
const { dateTime, homeTimezone, itinerary } = state.otp.config
const { syncSortWithDepartArrive } = itinerary
const { sort } = state.otp.filter
return {
homeTimezone,
sort,
syncSortWithDepartArrive,
timeFormat: dateTime?.timeFormat || 'h:mm a'
}
}
const mapDispatchToProps = {
updateItineraryFilter: narriativeActions.updateItineraryFilter
}

export default connect(mapStateToProps)(DateTimeOptions)
export default connect(mapStateToProps, mapDispatchToProps)(DateTimeOptions)
4 changes: 2 additions & 2 deletions lib/components/form/date-time-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ type Props = {
updateItineraryFilter: (payload: FilterType) => void
}

type DepartArriveValue = 'NOW' | 'DEPART' | 'ARRIVE'
export type DepartArriveValue = 'NOW' | 'DEPART' | 'ARRIVE'

const DepartArriveTypeMap: Record<
export const DepartArriveTypeMap: Record<
DepartArriveValue,
FilterType['sort']['type']
> = {
Expand Down

0 comments on commit 3112eae

Please sign in to comment.