Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions web/components/tables/TaskList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,8 @@ export const TaskList = forwardRef<TaskListRef, TaskListProps>(({ tasks: initial
<TaskRowRefreshingGate taskId={row.original.id}>
<InTableDateTimeEditPopUp
value={row.original.dueDate}
flexible
mode={DueDateUtils.isDateOnly(row.original.dueDate) ? 'date' : 'dateTime'}
onUpdate={next => {
if (next === row.original.dueDate) {
return
Expand All @@ -685,6 +687,7 @@ export const TaskList = forwardRef<TaskListRef, TaskListProps>(({ tasks: initial
<DateDisplay
date={row.original.dueDate}
mode="absolute"
showTime={!DueDateUtils.isDateOnly(row.original.dueDate)}
className={clsx(colorClass, 'truncate')}
/>
<Edit2 className="size-4 min-w-4 group-hover:block hidden"/>
Expand Down
45 changes: 33 additions & 12 deletions web/components/tables/in-table-edit/InTableDateTimeEditPopUp.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ReactNode } from 'react'
import { useState, type ComponentProps } from 'react'
import type { ButtonProps } from '@helpwave/hightide'
import { Button, DateTimeInput, PopUp, PopUpContext, PopUpOpener, PopUpRoot } from '@helpwave/hightide'
import { Button, DateTimeInput, FlexibleDateTimeInput, PopUp, PopUpContext, PopUpOpener, PopUpRoot } from '@helpwave/hightide'
import { useTasksTranslation } from '@/i18n/useTasksTranslation'
import clsx from 'clsx'

Expand All @@ -21,6 +21,12 @@ type InTableDateTimeEditPopUpProps = {
buttonProps?: ButtonProps,
children: ReactNode,
mode?: 'date' | 'dateTime',
/**
* When true, lets the user choose between a date-only and a date+time value via the
* input's built in toggle. A date-only selection is stored at the end of the day so it
* carries no meaningful time. `mode` is used as the initial mode.
*/
flexible?: boolean,
dateTimeInputProps?: Omit<
ComponentProps<typeof DateTimeInput>,
'value' | 'onValueChange' | 'onEditComplete' | 'mode'
Expand All @@ -33,6 +39,7 @@ export function InTableDateTimeEditPopUp({
buttonProps,
children,
mode = 'dateTime',
flexible = false,
dateTimeInputProps,
options = { horizontalAlignment: 'afterStart', verticalAlignment: 'afterEnd' },
className = 'p-2',
Expand Down Expand Up @@ -68,17 +75,31 @@ export function InTableDateTimeEditPopUp({
}}
</PopUpOpener>
<PopUp options={options} className={clsx(className, 'flex-col-2 items-end')} onClick={e => e.stopPropagation()}>
<DateTimeInput
mode={mode}
{...dateTimeInputProps}
value={draft}
onValueChange={next => {
setDraft(next)
}}
onEditComplete={v => {
setDraft(v)
}}
/>
{flexible ? (
<FlexibleDateTimeInput
defaultMode={mode === 'dateTime' ? 'dateTime' : 'date'}
{...dateTimeInputProps}
value={draft}
onValueChange={next => {
setDraft(next)
}}
onEditComplete={v => {
setDraft(v)
}}
/>
) : (
<DateTimeInput
mode={mode}
{...dateTimeInputProps}
value={draft}
onValueChange={next => {
setDraft(next)
}}
onEditComplete={v => {
setDraft(v)
}}
/>
)}
<PopUpContext.Consumer>
{({ setIsOpen }) => (
<div className="flex-row-2 justify-end items-center gap-x-2">
Expand Down
3 changes: 2 additions & 1 deletion web/components/tasks/TaskCardView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AvatarStatusComponent } from '@/components/AvatarStatusComponent'
import { Clock, Combine, User, Users, Flag } from 'lucide-react'
import clsx from 'clsx'
import { DateDisplay } from '@/components/Date/DateDisplay'
import { DueDateUtils } from '@/utils/dueDate'
import { LocationChipsBySetting } from '@/components/patients/LocationChipsBySetting'
import type { TaskViewModel } from '@/components/tables/TaskList'
import { useRouter } from 'next/router'
Expand Down Expand Up @@ -285,7 +286,7 @@ export const TaskCardView = ({ task, onToggleDone: _onToggleDone, onClick, showA
{dueDate && (
<div className={clsx('flex items-center gap-2 min-w-0', dueDateColorClass)}>
<Clock className="size-4 shrink-0" />
<DateDisplay date={dueDate} mode="absolute" showTime={true} />
<DateDisplay date={dueDate} mode="absolute" showTime={!DueDateUtils.isDateOnly(dueDate)} />
</div>
)}
</div>
Expand Down
25 changes: 25 additions & 0 deletions web/utils/dueDate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { describe, expect, it } from 'vitest'
import { DueDateUtils } from '@/utils/dueDate'

describe('DueDateUtils.isDateOnly', () => {
it('returns true for a date-only due date (end of day sentinel)', () => {
const date = new Date(2026, 5, 10, 23, 59, 59, 999)
expect(DueDateUtils.isDateOnly(date)).toBe(true)
})

it('returns false for a due date with a real time of day', () => {
const date = new Date(2026, 5, 10, 9, 30, 0, 0)
expect(DueDateUtils.isDateOnly(date)).toBe(false)
})

it('returns false when the time is only partially matching the sentinel', () => {
const date = new Date(2026, 5, 10, 23, 59, 59, 0)
expect(DueDateUtils.isDateOnly(date)).toBe(false)
})

it('returns false for null, undefined and invalid input', () => {
expect(DueDateUtils.isDateOnly(null)).toBe(false)
expect(DueDateUtils.isDateOnly(undefined)).toBe(false)
expect(DueDateUtils.isDateOnly('not-a-date')).toBe(false)
})
})
20 changes: 19 additions & 1 deletion web/utils/dueDate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
// A "date only" due date (no time-of-day selected) is represented by fixing the time
// component to the end of the day (23:59:59.999). This matches the sentinel used by
// hightide's FlexibleDateTimeInput and lets us render such due dates without a
// meaningless time component.
const DATE_ONLY_HOURS = 23
const DATE_ONLY_MINUTES = 59
const DATE_ONLY_SECONDS = 59
const DATE_ONLY_MILLISECONDS = 999

export const DueDateUtils = {
isDateOnly: (dueDate: Date | string | undefined | null): boolean => {
if (!dueDate) return false
const date = new Date(dueDate)
if (Number.isNaN(date.getTime())) return false
return date.getHours() === DATE_ONLY_HOURS
&& date.getMinutes() === DATE_ONLY_MINUTES
&& date.getSeconds() === DATE_ONLY_SECONDS
&& date.getMilliseconds() === DATE_ONLY_MILLISECONDS
},
isOverdue: (dueDate: Date | undefined | null, done: boolean): boolean => {
if (!dueDate || done) return false
return new Date(dueDate).getTime() < Date.now()
Expand All @@ -10,4 +28,4 @@ export const DueDateUtils = {
const oneHour = 60 * 60 * 1000
return dueTime > now && dueTime - now <= oneHour
}
}
}
Loading