Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
96 lines
4.0 KiB
TypeScript
96 lines
4.0 KiB
TypeScript
"use client"
|
||
|
||
import * as React from "react"
|
||
import { CalendarIcon } from "lucide-react"
|
||
|
||
import { Button } from "@/app/components/ui/button"
|
||
import { Calendar } from "@/app/components/ui/calendar"
|
||
import { DmyInput, calendarBounds } from "@/app/components/ui/date-picker"
|
||
import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "@/app/components/ui/popover"
|
||
import { dateToIso, isoToDate } from "@/app/lib/date-input"
|
||
import { cn } from "@/app/lib/utils"
|
||
import { useT } from "@/app/lib/i18n/MessagesProvider"
|
||
|
||
type DateRangeValue = { from: string; to: string }
|
||
|
||
interface DateRangePickerProps {
|
||
value: DateRangeValue
|
||
onChange: (range: DateRangeValue) => void
|
||
/** aria-labels of the two boxes — keep the labels the native inputs had. */
|
||
fromLabel: string
|
||
toLabel: string
|
||
disabled?: boolean
|
||
/** Earliest / latest pickable day ("yyyy-MM-dd"); days outside are disabled and the months bounded. */
|
||
min?: string
|
||
max?: string
|
||
/**
|
||
* The shown range is a default, not a choice: the next calendar click starts a one-day range on the clicked day
|
||
* instead of extending it (Event Summary shows the server's default day).
|
||
*/
|
||
freshStart?: boolean
|
||
className?: string
|
||
}
|
||
|
||
/** From/To filter: two read-only boxes showing DD/MM/YYYY, one two-month range calendar. Never emits to < from. */
|
||
function DateRangePicker({ value, onChange, fromLabel, toLabel, disabled, min, max, freshStart, className }: DateRangePickerProps) {
|
||
const t = useT()
|
||
const [open, setOpen] = React.useState(false)
|
||
const anchorRef = React.useRef<HTMLDivElement>(null)
|
||
const bounds = calendarBounds(min, max)
|
||
|
||
return (
|
||
<Popover open={open} onOpenChange={setOpen}>
|
||
<PopoverAnchor asChild>
|
||
<div ref={anchorRef} data-slot="date-range-picker" className={cn("flex items-center gap-1", className)}>
|
||
<DmyInput aria-label={fromLabel} value={value.from} onOpen={() => setOpen(true)} disabled={disabled} className="h-9 w-[120px] shrink-0" />
|
||
<span aria-hidden="true" className="text-muted-foreground">–</span>
|
||
<DmyInput aria-label={toLabel} value={value.to} onOpen={() => setOpen(true)} disabled={disabled} className="h-9 w-[120px] shrink-0" />
|
||
<PopoverTrigger asChild>
|
||
<Button
|
||
type="button"
|
||
variant="outline"
|
||
size="icon"
|
||
disabled={disabled}
|
||
aria-label={t("UiOpenCalendarRange", { from: fromLabel, to: toLabel })}
|
||
>
|
||
<CalendarIcon />
|
||
</Button>
|
||
</PopoverTrigger>
|
||
</div>
|
||
</PopoverAnchor>
|
||
<PopoverContent className="w-auto p-3" align="start" onInteractOutside={(e) => {
|
||
// The From/To boxes sit in PopoverAnchor, outside the content, so radix treats a click on them
|
||
// as outside and closes; keep it open (the box re-opens, the icon still toggles).
|
||
if (anchorRef.current?.contains(e.target as Node)) e.preventDefault()
|
||
}}>
|
||
<Calendar
|
||
mode="range"
|
||
numberOfMonths={2}
|
||
selected={{ from: isoToDate(value.from), to: isoToDate(value.to) }}
|
||
defaultMonth={isoToDate(value.from) ?? (min ? isoToDate(min) : undefined)}
|
||
startMonth={bounds.startMonth}
|
||
endMonth={bounds.endMonth}
|
||
disabled={bounds.disabled}
|
||
onSelect={(r, clicked) => {
|
||
if (freshStart) {
|
||
const day = dateToIso(clicked)
|
||
onChange({ from: day, to: day })
|
||
return
|
||
}
|
||
if (!r) return // clicking a one-day range's day again deselects; keep the range
|
||
onChange({ from: r.from ? dateToIso(r.from) : "", to: r.to ? dateToIso(r.to) : "" })
|
||
}}
|
||
/>
|
||
<div className="flex justify-end border-t pt-2">
|
||
<Button type="button" variant="ghost" size="sm" onClick={() => { onChange({ from: "", to: "" }); setOpen(false) }}>
|
||
{t("UiClear")}
|
||
</Button>
|
||
</div>
|
||
</PopoverContent>
|
||
</Popover>
|
||
)
|
||
}
|
||
|
||
export { DateRangePicker }
|
||
export type { DateRangePickerProps, DateRangeValue }
|