Show warning when selected dates are in the past
This commit is contained in:
parent
909715bdf9
commit
0aaf9aa35e
|
|
@ -91,3 +91,12 @@
|
|||
color: rgba(255,255,255,.5);
|
||||
}
|
||||
}
|
||||
|
||||
.warningLabel {
|
||||
display: flex;
|
||||
padding-block: 0.9em;
|
||||
gap: 0.5em;
|
||||
align-items: center;
|
||||
opacity: .75;
|
||||
font-size: .9em;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { useCallback, useMemo, useRef, useState } from 'react'
|
||||
import { rotateArray } from '@giraugh/tools'
|
||||
import { Temporal } from '@js-temporal/polyfill'
|
||||
import { ChevronLeft, ChevronRight } from 'lucide-react'
|
||||
import { AlertTriangle, AlertTriangleIcon, ChevronLeft, ChevronRight, FileWarningIcon } from 'lucide-react'
|
||||
|
||||
import Button from '/src/components/Button/Button'
|
||||
import { useTranslation } from '/src/i18n/client'
|
||||
|
|
@ -22,7 +22,8 @@ const Month = ({ value, onChange }: MonthProps) => {
|
|||
|
||||
const weekStart = useStore(useSettingsStore, state => state.weekStart) ?? 0
|
||||
|
||||
const [page, setPage] = useState<Temporal.PlainYearMonth>(Temporal.Now.plainDateISO().toPlainYearMonth())
|
||||
const now = useMemo(() => Temporal.Now.plainDateISO(), [])
|
||||
const [page, setPage] = useState<Temporal.PlainYearMonth>(now.toPlainYearMonth())
|
||||
const dates = useMemo(() => calculateMonth(page, weekStart, i18n.language), [page, weekStart, i18n.language])
|
||||
|
||||
// Ref and state required to rerender but also access static version in callbacks
|
||||
|
|
@ -36,6 +37,12 @@ const Month = ({ value, onChange }: MonthProps) => {
|
|||
const startPos = useRef({ x: 0, y: 0 })
|
||||
const mode = useRef<'add' | 'remove'>()
|
||||
|
||||
// Is 1 or more of the selected dates in the past?
|
||||
const hasPastDates = useMemo(() => value
|
||||
.some(plainDate => Temporal.PlainDate.compare(
|
||||
now, Temporal.PlainDate.from(plainDate)
|
||||
) > 0), [value])
|
||||
|
||||
const handleFinishSelection = useCallback(() => {
|
||||
if (mode.current === 'add') {
|
||||
onChange([...value, ...selectingRef.current])
|
||||
|
|
@ -112,6 +119,11 @@ const Month = ({ value, onChange }: MonthProps) => {
|
|||
>{date.label}</button>)
|
||||
)}
|
||||
</div>
|
||||
|
||||
{hasPastDates && <div className={styles.warningLabel}>
|
||||
<AlertTriangle size='1.2em' />
|
||||
<span>{t('form.dates.warnings.date_in_past')}</span>
|
||||
</div>}
|
||||
</>
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,11 @@
|
|||
"previous": "Previous month",
|
||||
"next": "Next month",
|
||||
"today": "today"
|
||||
},
|
||||
"warnings": {
|
||||
"date_in_past": "Some of the dates you've selected are in the past"
|
||||
}
|
||||
|
||||
},
|
||||
"times": {
|
||||
"label": "What times might work?",
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@
|
|||
"previous": "Previous month",
|
||||
"next": "Next month",
|
||||
"today": "today"
|
||||
},
|
||||
"warnings": {
|
||||
"date_in_past": "Some of the dates you've selected are in the past"
|
||||
}
|
||||
},
|
||||
"times": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue