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
112 lines
4.2 KiB
TypeScript
112 lines
4.2 KiB
TypeScript
"use client"
|
|
|
|
import * as React from "react"
|
|
|
|
import { DatePicker } from "@/app/components/ui/date-picker"
|
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/app/components/ui/select"
|
|
import { cn } from "@/app/lib/utils"
|
|
import { useT } from "@/app/lib/i18n/MessagesProvider"
|
|
|
|
interface DateTimePickerProps {
|
|
/** "yyyy-MM-ddTHH:mm" (seconds tolerated on input), or "". */
|
|
value: string
|
|
onChange: (value: string) => void
|
|
id?: string
|
|
"aria-label"?: string
|
|
/** Passed to the date box, e.g. when a form check fails on this field. */
|
|
"aria-invalid"?: boolean
|
|
"aria-describedby"?: string
|
|
timeLabel?: string
|
|
required?: boolean
|
|
disabled?: boolean
|
|
/** "yyyy-MM-dd" date bounds. */
|
|
min?: string
|
|
max?: string
|
|
className?: string
|
|
}
|
|
|
|
// Every 15 minutes, then 23:59 so an "ends" field can cover the whole last day.
|
|
const TIME_OPTIONS = [...Array.from({ length: 96 }, (_, i) => `${String(Math.floor(i / 4)).padStart(2, "0")}:${String((i % 4) * 15).padStart(2, "0")}`), "23:59"]
|
|
/** "09:30" -> "9:30 AM". */
|
|
function formatTime(hhmm: string, t: (code: string, params?: { [key: string]: string | number }) => string) {
|
|
const [h, m] = hhmm.split(":").map(Number)
|
|
return `${h % 12 || 12}:${String(m).padStart(2, "0")} ${h < 12 ? t("UiTimeAm") : t("UiTimePm")}`
|
|
}
|
|
|
|
/**
|
|
* Date box + calendar beside a time dropdown (15-minute steps, 12-hour labels, plus 11:59 PM). Emits "" until
|
|
* both parts are filled, like datetime-local; a date without a time says "Enter a time".
|
|
* The boxes never shrink: in a narrow column (two pickers side by side in a dialog) the time box wraps
|
|
* below the date instead of clipping its AM/PM.
|
|
*/
|
|
function DateTimePicker({
|
|
value, onChange, id, "aria-label": ariaLabel, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, timeLabel, required, disabled, min, max, className,
|
|
}: DateTimePickerProps) {
|
|
const t = useT()
|
|
const [date, setDate] = React.useState(() => value.slice(0, 10))
|
|
const [time, setTime] = React.useState(() => value.slice(11, 16))
|
|
// The last value this component emitted; any other incoming value is external and resets both parts.
|
|
// Adjusted during render, not in an effect (react-hooks/set-state-in-effect).
|
|
const [emitted, setEmitted] = React.useState(value)
|
|
if (value !== emitted) {
|
|
setEmitted(value)
|
|
setDate(value.slice(0, 10))
|
|
setTime(value.slice(11, 16))
|
|
}
|
|
|
|
// An off-grid stored time (e.g. 14:37) stays selectable so editing never silently changes it.
|
|
const offGrid = time && !TIME_OPTIONS.includes(time) ? time : ""
|
|
// Radix keeps the items mounted while closed; memoised elements let React skip all 97 on unrelated re-renders.
|
|
const items = React.useMemo(
|
|
() => (offGrid ? [...TIME_OPTIONS, offGrid].sort() : TIME_OPTIONS)
|
|
.map((tTime) => <SelectItem key={tTime} value={tTime}>{formatTime(tTime, t)}</SelectItem>),
|
|
[offGrid, t],
|
|
)
|
|
|
|
const emit = (d: string, t: string) => {
|
|
const next = d && t ? `${d}T${t}` : ""
|
|
setEmitted(next)
|
|
onChange(next)
|
|
}
|
|
|
|
return (
|
|
<div data-slot="date-time-picker" className={cn("flex flex-wrap items-center gap-2", className)}>
|
|
<DatePicker
|
|
id={id}
|
|
aria-label={ariaLabel}
|
|
aria-invalid={ariaInvalid}
|
|
aria-describedby={ariaDescribedBy}
|
|
required={required}
|
|
disabled={disabled}
|
|
min={min}
|
|
max={max}
|
|
value={date}
|
|
onChange={(d) => { setDate(d); emit(d, time) }}
|
|
className="h-9 w-[160px] shrink-0"
|
|
/>
|
|
<Select
|
|
value={time}
|
|
onValueChange={(t) => { setTime(t); emit(date, t) }}
|
|
disabled={disabled}
|
|
required={required || !!date}
|
|
>
|
|
<SelectTrigger
|
|
id={id ? `${id}-time` : undefined}
|
|
aria-label={timeLabel ?? t("Time")}
|
|
aria-required={required || !!date}
|
|
className="h-9 w-[130px] shrink-0"
|
|
>
|
|
<SelectValue placeholder={t("Time")} />
|
|
</SelectTrigger>
|
|
<SelectContent className="max-h-72">
|
|
{items}
|
|
</SelectContent>
|
|
</Select>
|
|
{date && !time && <p role="alert" className="w-full text-xs text-destructive">{t("UiEnterTime")}</p>}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export { DateTimePicker }
|
|
export type { DateTimePickerProps }
|